Also check crc on receive now
This commit is contained in:
parent
64ee2abbd7
commit
2a62c13c7e
|
@ -111,7 +111,7 @@ int nrf_rcv_pkt_time(int maxtime, int maxsize, uint8_t * pkt){
|
||||||
int len;
|
int len;
|
||||||
uint8_t status=0;
|
uint8_t status=0;
|
||||||
uint8_t crc[2];
|
uint8_t crc[2];
|
||||||
uint16_t cmp_crc;
|
uint16_t cmpcrc;
|
||||||
|
|
||||||
nrf_write_reg(R_CONFIG,
|
nrf_write_reg(R_CONFIG,
|
||||||
R_CONFIG_PRIM_RX| // Receive mode
|
R_CONFIG_PRIM_RX| // Receive mode
|
||||||
|
@ -152,16 +152,20 @@ int nrf_rcv_pkt_time(int maxtime, int maxsize, uint8_t * pkt){
|
||||||
if(len>32 || len==0){
|
if(len>32 || len==0){
|
||||||
return -2; // no packet error
|
return -2; // no packet error
|
||||||
};
|
};
|
||||||
if(len>maxsize+2){
|
len-=2; // skip crc
|
||||||
|
if(len>maxsize){
|
||||||
return -1; // packet too large
|
return -1; // packet too large
|
||||||
};
|
};
|
||||||
|
|
||||||
nrf_read_pkt_crc(len-2,pkt,crc);
|
nrf_read_pkt_crc(len,pkt,crc);
|
||||||
|
cmpcrc=crc16(pkt,len);
|
||||||
|
|
||||||
cmpcrc=crc16(buf,14);
|
if(cmpcrc != (crc[0] <<8 | crc[1])) {
|
||||||
|
return -3; // CRC failed
|
||||||
|
};
|
||||||
|
|
||||||
CS_HIGH();
|
CS_HIGH();
|
||||||
return len-2;
|
return len;
|
||||||
};
|
};
|
||||||
|
|
||||||
char nrf_snd_pkt_crc(int size, uint8_t * pkt){
|
char nrf_snd_pkt_crc(int size, uint8_t * pkt){
|
||||||
|
|
Loading…
Reference in New Issue