diff --git a/firmware/funk/mesh.c b/firmware/funk/mesh.c index aa56457..41eefce 100644 --- a/firmware/funk/mesh.c +++ b/firmware/funk/mesh.c @@ -39,7 +39,8 @@ void initMesh(void){ int mesh_sanity(uint8_t * pkt){ if(MO_TYPE(pkt)>0x7f || MO_TYPE(pkt)<0x20) return 1; - + if(MO_TYPE(pkt)=='T' && MO_BODY(pkt)[5]) + return 3; if(MO_TYPE(pkt)>='A' && MO_TYPE(pkt)<='Z'){ if(MO_TIME(pkt)>1325379600) return 1; @@ -88,6 +89,22 @@ MPKT * meshGetMessage(uint8_t type){ return &meshbuffer[free]; }; +void meshPanic(uint8_t * pkt){ +#if 0 + setSystemFont(); + lcdClear(); + lcdPrint("MESH-PANIC:"); + lcdNl(); + for(int i=0;i<32;i++){ + lcdPrint(IntToStrX(pkt[i],2)); + if(i%6==5) + lcdNl(); + } + lcdRefresh(); + while ((getInputRaw())==BTN_NONE); +#endif +}; + void mesh_cleanup(void){ time_t now=getSeconds(); for(int i=1;i_timet){ // Do not live in the past. - _timet = toff; - meshincctr++; - }; - if(MO_BODY(buf)[4] > meshnice) meshnice=MO_BODY(buf)[4]; - return 1; + meshgen=MO_GEN(buf); + }; }; // Discard packets with wrong generation @@ -236,6 +236,16 @@ uint8_t mesh_recvqloop_work(void){ return 0; }; + // Set new time iff newer + if(MO_TYPE(buf)=='T'){ + time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED)); + if (toff>_timet){ // Do not live in the past. + _timet = toff; + meshincctr++; + }; + return 1; + }; + // Safety: Truncate ascii packets by 0-ing the CRC buf[MESHPKTSIZE-2]=0;