Change mesh behavior: only accept time once per generation. This should fix the drifting.

This commit is contained in:
Stefan `Sec` Zehl 2012-01-26 23:37:18 +01:00
parent 8b171c946a
commit 243b9a847b
1 changed files with 19 additions and 11 deletions

View File

@ -13,6 +13,10 @@ char meshgen=0; // Generation
char meshincctr=0; char meshincctr=0;
char meshmsg=0; char meshmsg=0;
char meshnice=0; char meshnice=0;
char mesh_mode=0;
#define MM_TIME (1<<0)
#define MM_ENC (1<<1)
MPKT meshbuffer[MESHBUFSIZE]; MPKT meshbuffer[MESHBUFSIZE];
#include "SECRETS" #include "SECRETS"
@ -23,6 +27,8 @@ static int mesh_gt(char curgen, char newgen){
unsigned char dif=curgen-newgen; unsigned char dif=curgen-newgen;
if(curgen==0) if(curgen==0)
return 1; return 1;
if(newgen==0)
return 0;
return (dif>128); return (dif>128);
}; };
@ -245,6 +251,7 @@ uint8_t mesh_recvqloop_work(void){
meshincctr=0; meshincctr=0;
meshnice=MO_BODY(buf)[4]; meshnice=MO_BODY(buf)[4];
meshgen=MO_GEN(buf); meshgen=MO_GEN(buf);
mesh_mode&=~MM_TIME;
}; };
}; };
@ -253,18 +260,19 @@ uint8_t mesh_recvqloop_work(void){
return 0; return 0;
}; };
// Set new time iff newer // Set new time iff I don't have a valid one.
if((mesh_mode & MM_TIME)==0){
if(MO_TYPE(buf)=='T'){ if(MO_TYPE(buf)=='T'){
time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED)); time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED));
if (toff>_timet){ // Do not live in the past.
if( (_timet!=0) && (toff-_timet)>5){
meshPanic(buf,0x20);
};
_timet = toff; _timet = toff;
meshincctr++; if(meshgen==0 && MO_TIME(buf)<60*60*24){
; // still not valid
}else{
mesh_mode|=MM_TIME; // Got a time now.
}; };
return 1; return 1;
}; };
};
// Safety: Truncate ascii packets by 0-ing the CRC // Safety: Truncate ascii packets by 0-ing the CRC
buf[MESHPKTSIZE-2]=0; buf[MESHPKTSIZE-2]=0;