Hi Dialog,
there is a Problem with reading different lengths of UART-Messages from my sensor. The standard-length of the received UART is 4 Byte, but sometimes I will receive a 10 Byte message.
Byte 3 and 4 of the input-Array are datacounter, which only are non equal to Zero in case of a Input Array longer than 4 Byte.
So my Approach is to always read the length of 4 Byte by the command:
uart_buf[4];
uart_buf_long[6];
...
ad_uart_read(dev, uart_buf, 4, OS_EVENT_FOREVER);
Then I check the datacounter-bytes:
if(uart_buf[2] != 0 || uart_buf[3] !=0){
ad_uart_read(dev,uart_buf_long, 6, OS_EVENT_FOREVER);
}
So the first part with reading 4 Bytes is working quite well, but in case I get the 10 Byte UART-message I will get stuck in the second ad_uart_read Routine.
So can you please tell me how to manage this Problem?
Thanks

Hi dx3gerst,
I dont see anything wrong with the code that you 've pasted, the ad_uart_read() will block the task until it gets the amount of data from the UART, so as long as you send 6 bytes from the sensor then the task should unblock. If that is not working then perhaps the device has fell in sleep mode and cannot receive any data from the UART ? Have you tried to test your code without using any sleep mode ? Are you sure that the sensor sends that extra 6 bytes of data that you expect ?
Thanks MT_dialog
Hi Dialog,
thank you for your answer. My code is based on the ble_multi_link demo. I don't think there is any sleep-mode implemented. respectively the code for sleep mode is put in comments
/* Set the desired sleep mode. */
/ / pm_set_wakeup_mode(真正的);
// pm_set_sleep_mode(pm_mode_extended_sleep);
So the device should be in active mode all the time, right?
Yes, I checked the Bytes sent by the sensor with an terminal-tool and it sends definitively 10 Bytes, which consist of the 4 "standard-Bytes", I always receive and the 6 additional Bytes.
Is there maybe any other approach to realise this functionality?
Thanks!
Hi dx3gerst,
Yes, if you comment out those functions then the device will not go in sleep mode, although, what is suggested would be to set the pm_set_sleep_mode(pm_mode_active); and the pm_set_wakeup_mode(true) doesn't have to do with the sleeping of the device but with the waking up procedure, so it wont affect your code.
I dont see anything wrong with the code and i have also tried it on my side and i could start the BLE activity via waiting 10 bytes from UART using the code below in the system_init() function:
dev = ad_uart_open(SERIAL2);
char uart_buf[4];
char uart_buf_long[6];
ad_uart_read(dev, uart_buf, 4, OS_EVENT_FOREVER);
if(uart_buf[2] != 0 || uart_buf[3] !=0){
ad_uart_read(dev,uart_buf_long, 6, OS_EVENT_FOREVER);
}
Perhaps you could try taking the bytes from the senosr one by one and check if that works, but in any case you will have to debug it in order to check why that happens.
Thanks MT_dialog