diff --git a/rf60Xcore/src/rf60X.c b/rf60Xcore/src/rf60X.c index 6d7726ee813ddf9ddd6d9d33bb7a83178dc38c47..8b9c2d2160e9e91ea76de42ff963ec593dea311c 100644 --- a/rf60Xcore/src/rf60X.c +++ b/rf60Xcore/src/rf60X.c @@ -132,14 +132,59 @@ void rf60x_config_port_uart(rf60x_t *scanner) { scanner->uart_info); } + +int checkLowByteConsistency(const unsigned char byte,rfBool reset) { + static unsigned char lowByte = 0; + + if (lowByte==0 || reset == 0) { + // Если это первый байт, сохраняем его как младший байт для последующих сравнений + lowByte = byte & 0xF0;; + } + + if ((byte & 0xF0) != lowByte) { + lowByte = 0; // Сбрасываем младший байт при обнаружении несоответствия + return 0; + } + + return 1; +} + + + + rfUint8 *rf60x_get_measure_uart(rf60x_t *scanner, rfUint8 size) { rfInt32 RX_SIZE = size; rfUint8 *RX = (rfUint8 *)memory_platform.rf_malloc(RX_SIZE); - rfInt32 returnSize=uart_platform.uart_methods.recv_data_uart(scanner->handlePort, (void *)RX, - RX_SIZE); - if( returnSize < RX_SIZE) { + rfUint8 tempByteBuffer =0; + size_t sequenceLength=0; + for(rfUint32 i=0; ihandlePort, (void *)&tempByteBuffer, + sizeof(rfUint8)); + + if(returnSize<=0){ + break; + } + + if(checkLowByteConsistency(tempByteBuffer,1)){ + + *(RX+sequenceLength) = tempByteBuffer; + ++sequenceLength; + }else{ + memory_platform.rf_memset(RX,0,sequenceLength); + sequenceLength = 0; + if(checkLowByteConsistency(tempByteBuffer,0)){ + *(RX+sequenceLength) = tempByteBuffer; + ++sequenceLength; + } + + } + + } + + if( sequenceLength < RX_SIZE) { memory_platform.rf_free(RX); return NULL; } @@ -2513,9 +2558,42 @@ rf60x_uart_hello_t *rf60x_hello_msg_uart(rf60x_t *scanner) { rfByte RX[16]; - rfInt32 returnSize=uart_platform.uart_methods.recv_data_uart(scanner->handlePort, RX, 16); + rfByte tempByteBuffer; + size_t sequenceLength=0; + + for(rfUint32 i=0; i<16; ++i){ + + rfInt32 returnSize=uart_platform.uart_methods.recv_data_uart(scanner->handlePort, (void *)&tempByteBuffer, + sizeof(rfByte)); + + if(returnSize<=0){ + break; + } + + if(checkLowByteConsistency(tempByteBuffer,1)){ + + *(RX+sequenceLength) = tempByteBuffer; + ++sequenceLength; + }else{ + memory_platform.rf_memset(RX,0,sequenceLength); + sequenceLength = 0; + if(checkLowByteConsistency(tempByteBuffer,0)){ + *(RX+sequenceLength) = tempByteBuffer; + ++sequenceLength; + } + + } + + } + + + + + + +// rfInt32 returnSize=uart_platform.uart_methods.recv_data_uart(scanner->handlePort, RX, 16); - if( returnSize < 16) { + if( sequenceLength < 16) { memory_platform.rf_free(uart_hello); return NULL; }