Skip to content

Commit

Permalink
Assign intial checksum value for debug-link
Browse files Browse the repository at this point in the history
  • Loading branch information
shengwen-tw committed May 24, 2024
1 parent e63f008 commit ca83186
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions tools/rtplot/src/rtplot/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from .yaml_loader import TenokMsgManager

CHECKSUM_INIT_VAL = 63


class DataQueue:
def __init__(self, max_count):
Expand Down Expand Up @@ -273,6 +275,7 @@ def receive_msg(self):
buf = self.ser.read(payload_count + 1)

# Verify the checksum
checksum = CHECKSUM_INIT_VAL
for i in range(0, payload_count):
buffer.append(buf[i])
buffer_checksum = buffer[i]
Expand Down
11 changes: 6 additions & 5 deletions user/debug-link/debug_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

#include "debug_link.h"

#define DEBUG_LINK_HEADER_SIZE 3
#define DBGLINK_HEADER_SIZE 3
#define DBGLINK_CHECKSUM_INIT_VAL 63

void pack_debug_link_msg_header(debug_link_payload_t *payload, int message_id)
{
payload->size = DEBUG_LINK_HEADER_SIZE;
payload->size = DBGLINK_HEADER_SIZE;
payload->data[2] = message_id;
}

Expand Down Expand Up @@ -135,9 +136,9 @@ void pack_debug_link_msg_double(double *data,

void generate_debug_link_msg_checksum(debug_link_payload_t *payload)
{
uint8_t *data = payload->data + DEBUG_LINK_HEADER_SIZE;
size_t size = payload->size - DEBUG_LINK_HEADER_SIZE;
uint8_t checksum = 0;
uint8_t *data = payload->data + DBGLINK_HEADER_SIZE;
size_t size = payload->size - DBGLINK_HEADER_SIZE;
uint8_t checksum = DBGLINK_CHECKSUM_INIT_VAL;

for (int i = 0; i < size; i++)
checksum ^= data[i];
Expand Down

0 comments on commit ca83186

Please sign in to comment.