From abfb82180a6addee0cbb6fd56c73fa716094c015 Mon Sep 17 00:00:00 2001 From: Ran Bao Date: Sat, 17 Aug 2024 21:09:45 +1200 Subject: [PATCH 1/3] remove the use of extra buffer --- src/and_scale.c | 8 ++++---- src/gng_scale.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/and_scale.c b/src/and_scale.c index eae7e8a..2fcf63f 100644 --- a/src/and_scale.c +++ b/src/and_scale.c @@ -21,7 +21,7 @@ typedef union { char unit[3]; char terminator[2]; }; - char packet[17]; + char bytes[17]; } scale_standard_data_format_t; @@ -56,20 +56,20 @@ static float _decode_measurement_msg(scale_standard_data_format_t * msg) { void _and_scale_listener_task(void *p) { - char string_buf[20]; uint8_t string_buf_idx = 0; + scale_standard_data_format_t frame; while (true) { // Read all data while (uart_is_readable(SCALE_UART)) { char ch = uart_getc(SCALE_UART); - string_buf[string_buf_idx++] = ch; + frame.bytes[string_buf_idx++] = ch; // If we have received 17 bytes then we can decode the message if (string_buf_idx == sizeof(scale_standard_data_format_t)) { // Data is ready, send to decode - scale_config.current_scale_measurement = _decode_measurement_msg((scale_standard_data_format_t *) string_buf); + scale_config.current_scale_measurement = _decode_measurement_msg(&frame); // Signal the data is ready if (scale_config.scale_measurement_ready) { diff --git a/src/gng_scale.c b/src/gng_scale.c index 29a4b7e..c2290f0 100644 --- a/src/gng_scale.c +++ b/src/gng_scale.c @@ -28,7 +28,7 @@ typedef union { char unit[3]; char terminator[2]; }; - char packet[14]; + char bytes[14]; } gngscale_standard_data_format_t; @@ -72,8 +72,8 @@ static float _decode_measurement_msg(gngscale_standard_data_format_t * msg) { //read UART void _gng_scale_listener_task(void *p) { - char string_buf[20]; uint8_t string_buf_idx = 0; + gngscale_standard_data_format_t frame; while (true) { // Request for a data transfer (ESC p) @@ -82,12 +82,12 @@ void _gng_scale_listener_task(void *p) { // Read all data while (uart_is_readable(SCALE_UART)) { char ch = uart_getc(SCALE_UART); - string_buf[string_buf_idx++] = ch; + frame.bytes[string_buf_idx++] = ch; // If we have received 14 bytes then we can decode the message if (string_buf_idx == sizeof(gngscale_standard_data_format_t)) { // Data is ready, send to decode - scale_config.current_scale_measurement = _decode_measurement_msg((gngscale_standard_data_format_t *) string_buf); + scale_config.current_scale_measurement = _decode_measurement_msg(&frame); // Signal the data is ready if (scale_config.scale_measurement_ready) { xSemaphoreGive(scale_config.scale_measurement_ready); From b777c304234aa0a5db0bd3ff00a12ceb0c0e792b Mon Sep 17 00:00:00 2001 From: Ran Bao Date: Sat, 17 Aug 2024 21:11:29 +1200 Subject: [PATCH 2/3] Update USSOLID scale --- src/ussolid_scale.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ussolid_scale.c b/src/ussolid_scale.c index d7db88b..260c421 100644 --- a/src/ussolid_scale.c +++ b/src/ussolid_scale.c @@ -34,7 +34,7 @@ typedef union { char unit[3]; // GN (or something else) char terminator[2]; // \r\n (carriage return and newline) }; - char packet[15]; + char bytes[15]; } ussolid_jfdbs_data_format_t ; // Forward declaration @@ -72,21 +72,21 @@ static float _decode_measurement_msg(ussolid_jfdbs_data_format_t * msg) { } void _ussolid_scale_listener_task(void *p) { - char string_buf[20]; uint8_t string_buf_idx = 0; + ussolid_jfdbs_data_format_t frame; while (true) { // Read all data while (uart_is_readable(SCALE_UART)) { char ch = uart_getc(SCALE_UART); - string_buf[string_buf_idx++] = ch; + frame.bytes[string_buf_idx++] = ch; // If we have received 15 bytes then we can decode the message if (string_buf_idx == sizeof(ussolid_jfdbs_data_format_t)) { // Data is ready, send to decode - float weight = _decode_measurement_msg((ussolid_jfdbs_data_format_t *) string_buf); + float weight = _decode_measurement_msg(&frame); scale_config.current_scale_measurement = weight; From ca0912b445bcdbbf08f7b6323ec474a30e6fc207 Mon Sep 17 00:00:00 2001 From: Ran Bao Date: Sat, 17 Aug 2024 21:12:43 +1200 Subject: [PATCH 3/3] Update Steinberg scale --- src/steinberg_scale.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/steinberg_scale.c b/src/steinberg_scale.c index 63d70fa..9fb6d48 100644 --- a/src/steinberg_scale.c +++ b/src/steinberg_scale.c @@ -27,7 +27,7 @@ typedef union { char unit[2]; // GN (or something else) char terminator[2]; // \r\n (carriage return) }; - char packet[16]; + char bytes[16]; } steinberg_sbs_data_format_t ; // Forward declaration @@ -57,20 +57,20 @@ static float _decode_measurement_msg(steinberg_sbs_data_format_t * msg) { void _steinberg_scale_listener_task(void *p) { - char string_buf[20]; uint8_t string_buf_idx = 0; + steinberg_sbs_data_format_t frame; while (true) { // Read all data while (uart_is_readable(SCALE_UART)) { char ch = uart_getc(SCALE_UART); - string_buf[string_buf_idx++] = ch; + frame.bytes[string_buf_idx++] = ch; // If we have received 16 bytes then we can decode the message if (string_buf_idx == sizeof(steinberg_sbs_data_format_t)) { // Data is ready, send to decode - scale_config.current_scale_measurement = _decode_measurement_msg((steinberg_sbs_data_format_t *) string_buf); + scale_config.current_scale_measurement = _decode_measurement_msg(&frame); // Signal the data is ready if (scale_config.scale_measurement_ready) {