Update 17 (21st Mar '08)

I've made use of the timestamp sent over from the server such that only the latest data received is used. UDP packets lost or arriving late will not be valid.
The algorithm:
data is received as [(12digits input sensors)+(timestamp e.g 22:15:40 )]
i extract the digits out from the timestamp as 221540 into a string.
time can only increase if it is not yet 12am => 22:15:40 -> 22:15:41 -> …. 22:16:00 so i realised i can easily convert it into an integer for easy comparision.
This string is then converted into a 32 bit integer value via atoi32(string).
When the program first starts the timestamp is stored in 2 separate strings.
1 string is used as the control. The 2nd string is constantly updated with the new timestamp.
If the 2nd string has a value which is of higher value e.g 22:15:41 = 221541 which is greater than 221540 previously, the 1st string is updated and the corresponding LEDs light up to represent the input sensors. If a UDP packet that arrives as 221540 , it is rejected and the LEDs do not light.
Exceptions : Since the clock resets at midnight => 00:00:00 , atoi32(string1) will give 0 which is less than 23:59:59 = 235959 which is the value of string1 and so string1 will not be updated. I simply put if(string1 == 235959){ int32 str1 = 0 } to represent 00:00:00 and so any UDP packet after 12 midnight will continue going through successfully. eg. 1 second past midnite is 00:00:01 = 1.

Here are parts of the PIC code :

if(timeflag==0){
{
time[0]=input[12];
time[1]=input[13];
time[2]=input[15];
time[3]=input[16];
time[4]=input[18];
time[5]=input[19];
time[6]='\0';
}
time1=atoi32(time);
timeflag=1;
}//end if

timecmp[0]=input[12];
timecmp[1]=input[13];
timecmp[2]=input[15];
timecmp[3]=input[16];
timecmp[4]=input[18];
timecmp[5]=input[19];
timecmp[6]='\0';
timecmp1=atoi32(timecmp);

if(timecmp1 >= time1){
ok=1;
time1=timecmp1;
if (time1 == 235959)
{time1=0;}//clock resets to 00:00:00
}

if (ok == 1) { .
.
.
.
ok=0;
}

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License