From: Nathael Pajani Date: Sun, 5 Feb 2023 02:43:22 +0000 (+0100) Subject: Add comments and a buffer size check. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=fd3896a26e44dc2965bf163bf0a837faa10d440e;p=soft%2Flpc122x%2Frfsub1GHz Add comments and a buffer size check. --- diff --git a/rf_hopping/main.c b/rf_hopping/main.c index 049543a..a7176b9 100644 --- a/rf_hopping/main.c +++ b/rf_hopping/main.c @@ -1,6 +1,5 @@ /**************************************************************************** - * apps/dev/rf_hopping/main.c - * + * rf_hopping/main.c * * * Copyright 2013-2014 Nathael Pajani @@ -150,6 +149,10 @@ void rf_config(void) } #define RF_BUFF_LEN 64 + +/* Note that this example application does not really handle data. + * Only display a message indicating that we received data. + */ void handle_rf_rx_data(void) { uint8_t data[RF_BUFF_LEN]; @@ -215,7 +218,7 @@ int user_flash_update(void* data, int size) /******************************************************************************/ -/* Handle packets */ +/* Handle packets received on UART */ void handle_data(uint8_t* data, int len) { uint8_t cc_tx_data[RF_BUFF_LEN]; @@ -226,7 +229,7 @@ void handle_data(uint8_t* data, int len) /* Note : Packets will not respect the sequence numbers, do not check. */ status_led(green_on); - if (data[0] == 'a') { + if (data[0] == 'a') { /* Set our address */ struct board_data tmp_bdata __attribute__ ((__aligned__(4))) = {}; bdata->addr = strtoul((char*)&data[2], NULL, 10); memcpy(&tmp_bdata, bdata, sizeof(struct board_data)); @@ -237,7 +240,7 @@ void handle_data(uint8_t* data, int len) return; } - if (data[0] == 'C') { + if (data[0] == 'C') { /* RF Config */ struct board_data tmp_bdata __attribute__ ((__aligned__(4))) = {}; bdata->rx_channel = (uint8_t)strtoul((char*)&data[2], NULL, 10); bdata->tx_channel = (uint8_t)strtoul((char*)&data[5], NULL, 10); @@ -259,9 +262,9 @@ void handle_data(uint8_t* data, int len) return; } - if (data[0] == 's') { + if (data[0] == 's') { /* Send data */ uint8_t send_len = 0; - if (data[1] == 'v') { /* Send to one vehicule, raw */ + if (data[1] == 'v') { /* Send to one peer, raw */ cc_tx_data[0] = (len - 2); memcpy((cc_tx_data + 1), (data + 2), (len - 2)); send_len = len - 1; @@ -356,6 +359,9 @@ void uart_decode(uint8_t c) new_packet = idx; idx = 0; } + if (idx >= UART_BUFF_SIZE) { + idx = 0; + } } /******************************************************************************/