Fixes related to dtplug protocol for hostside udpbridge
authorNathael Pajani <nathael.pajani@ed3l.fr>
Fri, 12 Jun 2020 10:35:25 +0000 (12:35 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Thu, 9 Feb 2023 23:36:08 +0000 (00:36 +0100)
host/udpbridge/dtplug_protocol_host.c

index b891269..1505d31 100644 (file)
 #include <stdint.h>
 #include <string.h>
 #include <unistd.h>
+
+#undef DEBUG
+
+#ifdef DEBUG
+#include <stdio.h>
+#endif
+
 #include "dtplug_protocol_host.h"
 
 
@@ -114,8 +121,12 @@ next_packet:
                                rx_data->packet_rx_count, rx_data->errors_count);
        if (rx_data->rx_ptr >= sizeof(struct header)) {
                struct header* h = info;
-               printf("Pkt: type: %d, seq: %d, err: %d, quick: %d\n", h->type, h->seq_num,
+               printf("Pkt: type: %d, seq: %d, err: %d, quick: %d\n", h->type, (h->seq_num & 0x1F),
                                                (h->seq_num & PACKET_IS_ERROR), (h->seq_num & QUICK_DATA_PACKET));
+               if (!(h->seq_num & QUICK_DATA_PACKET) && !(h->seq_num & PACKET_IS_ERROR)) {
+                       printf("Pkt: data_size: %d, data_cksum: 0x%02x\n", h->data.size, h->data.checksum);
+                       printf("rx_data_cksum: 0x%02x\n", rx_data->sum);
+               }
        }
 #endif
        /* Wether the packet was OK or not doesn't matter, go on for a new one :) */
@@ -140,6 +151,7 @@ int host_send_packet(struct line_transceiver* slave, uint8_t type, uint32_t size
 
        /* Loop to send all data, possibly split in several packets */
        do {
+               memset(&cmd, 0, sizeof(struct packet));
                if (data_send_size > PACKET_DATA_SIZE) {
                        data_send_size = PACKET_DATA_SIZE;
                }
@@ -157,7 +169,10 @@ int host_send_packet(struct line_transceiver* slave, uint8_t type, uint32_t size
                        if (size && (size <= 2)) {
                                cmd_info->seq_num |= QUICK_DATA_PACKET;
                                cmd_info->quick_data[0] = data[0];
-                               cmd_info->quick_data[1] = data[1];
+                               if (size == 2) {
+                                       cmd_info->seq_num |= QUICK_DATA_PACKET_TWO_BYTES;
+                                       cmd_info->quick_data[1] = data[1];
+                               }
                        } else {
                                /* Copy data, compute checksum (also OK for a data_send_size of 0) */
                                for (i = 0; i < data_send_size; i++) {