Skip to content

Commit

Permalink
Merge pull request #51 from eamars/fix_scale_data_buffer
Browse files Browse the repository at this point in the history
Remove the use of extra buffer
  • Loading branch information
eamars authored Aug 17, 2024
2 parents d87afaf + ca0912b commit 462c7f7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/and_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef union {
char unit[3];
char terminator[2];
};
char packet[17];
char bytes[17];
} scale_standard_data_format_t;


Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/gng_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef union {
char unit[3];
char terminator[2];
};
char packet[14];
char bytes[14];
} gngscale_standard_data_format_t;


Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/steinberg_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/ussolid_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 462c7f7

Please sign in to comment.