diff --git a/firmware/applications/final/mesh.c b/firmware/applications/final/mesh.c index 8fc4095..63fb4c1 100644 --- a/firmware/applications/final/mesh.c +++ b/firmware/applications/final/mesh.c @@ -104,9 +104,14 @@ char *meshmsgs(void){ hi=0xff; for(int i=0;ilo) - if(MO_TYPE(meshbuffer[i].pkt)lo) + if(MO_TYPE(meshbuffer[i].pkt)128); +}; + void initMesh(void){ for(int i=0;i0x7f || MO_TYPE(pkt)<0x20) + return 1; + if(MO_TYPE(pkt)>='A' && MO_TYPE(pkt)<='Z'){ if(MO_TIME(pkt)>1325379600) return 1; @@ -41,16 +51,15 @@ int mesh_sanity(uint8_t * pkt){ if(MO_TIME(pkt)<0) return 1; }; - if(MO_TYPE(pkt)!='E' && + if(MO_TYPE(pkt)!='A' && + MO_TYPE(pkt)!='a' && + MO_TYPE(pkt)!='E' && MO_TYPE(pkt)!='F' && MO_TYPE(pkt)!='G' && - MO_TYPE(pkt)!='T' && - 1 + MO_TYPE(pkt)!='T' ){ - return 1; + return 2; }; - if(MO_TYPE(pkt)>0x7f || MO_TYPE(pkt)<0x20) - return 1; return 0; }; @@ -95,7 +104,7 @@ void mesh_cleanup(void){ if (MO_TIME(meshbuffer[i].pkt)-now>SECS_DAY) meshbuffer[i].flags=MF_FREE; }; - if(mesh_sanity(meshbuffer[i].pkt)){ + if(mesh_sanity(meshbuffer[i].pkt)==1){ meshbuffer[i].flags=MF_FREE; #if 0 setSystemFont(); @@ -202,17 +211,15 @@ uint8_t mesh_recvqloop_work(void){ return 0; }; - if(MO_GEN(buf)>meshgen){ - if(meshgen) - meshgen++; - else - meshgen=MO_GEN(buf); - _timet=0; - meshincctr=0; - meshnice=0; - }; - + // New mesh generation? if(MO_TYPE(buf)=='T'){ + if(meshgen_gt(MO_GEN(buf))){ + meshgen=MO_GEN(buf); + _timet=0; + meshincctr=0; + meshnice=0; + }; + // Set new time iff newer time_t toff=MO_TIME(buf)-((getTimer()+(600/SYSTICKSPEED))/(1000/SYSTICKSPEED)); if (toff>_timet){ // Do not live in the past. _timet = toff; @@ -223,12 +230,18 @@ uint8_t mesh_recvqloop_work(void){ return 1; }; + // Discard packets with wrong generation + if(meshgen != MO_GEN(buf)){ + return 0; + }; + // Safety: Truncate ascii packets by 0-ing the CRC buf[MESHPKTSIZE-2]=0; // Store packet in a same/free slot MPKT* mpkt=meshGetMessage(MO_TYPE(buf)); +#if 0 // Schnitzel if(MO_TYPE(buf)=='Z'){ mpkt->flags=MF_USED|MF_LOCK; @@ -252,15 +265,18 @@ uint8_t mesh_recvqloop_work(void){ }; return 1; }; +#endif // only accept newer/better packets if(mpkt->flags==MF_USED) if(MO_TIME(buf)<=MO_TIME(mpkt->pkt)) return 2; +#if 0 if((MO_TYPE(buf)>='A' && MO_TYPE(buf)<='C') || (MO_TYPE(buf)>='a' && MO_TYPE(buf)<='c')) meshmsg=1; +#endif memcpy(mpkt->pkt,buf,MESHPKTSIZE); mpkt->flags=MF_USED;