diff --git a/NetX/inc/u_nx_ethernet.h b/NetX/inc/u_nx_ethernet.h index bf5a816a..6c26c386 100644 --- a/NetX/inc/u_nx_ethernet.h +++ b/NetX/inc/u_nx_ethernet.h @@ -14,7 +14,7 @@ /* CONFIG */ #define ETH_UDP_PORT 2006 /* UDP port for communication */ -#define ETH_MESSAGE_SIZE 8 /* Maximum ethernet message size in bytes. */ +#define ETH_MESSAGE_SIZE 60 /* Maximum ethernet message size in bytes. */ #define ETH_MAX_PACKETS 10 /* Maximum number of packets we wanna handle simultaneously */ #define ETH_NUMBER_OF_NODES 8 /* Number of nodes in the network. */ @@ -51,7 +51,7 @@ typedef enum { } plca_node_id_t; /* END CONFIG */ -typedef struct { +typedef struct __attribute__((__packed__)) { uint8_t sender_id; uint8_t recipient_id; uint8_t message_id; diff --git a/NetX/src/u_nx_ethernet.c b/NetX/src/u_nx_ethernet.c index 54a28bd9..d1a6ee38 100644 --- a/NetX/src/u_nx_ethernet.c +++ b/NetX/src/u_nx_ethernet.c @@ -4,6 +4,7 @@ #include "nxd_ptp_client.h" #include "u_nx_debug.h" #include "u_tx_debug.h" +#include "c_utils.h" #include "nx_api.h" #include #include @@ -113,20 +114,15 @@ static void _receive_message(NX_UDP_SOCKET *socket) { } /* Extract message from packet */ - status = nx_packet_data_extract_offset( - packet, // Packet to extract from - 0, // Offset (start of packet) - &message, // Message buffer - sizeof(ethernet_message_t), // Size to extract - &bytes_copied // Stores how many bytes were actually copied to &message - ); - if(bytes_copied < sizeof(ethernet_message_t)) { - PRINTLN_WARNING("Received ethernet message was smaller than expected (only received %lu of %u expected bytes).", bytes_copied, sizeof(ethernet_message_t)); + ULONG bytes_copied = 0; + status = nx_packet_data_retrieve(packet, &message, &bytes_copied); + if(status != NX_SUCCESS) { + PRINTLN_ERROR("Failed to call nx_packet_data_retrieve() (Status: %d/%s).", status, nx_status_toString(status)); } /* Process received message */ if(status == NX_SUCCESS) { - PRINTLN_INFO("Received ethernet message! (Sender ID: %d, Message ID: %d).", message.sender_id, message.message_id); + PRINTLN_INFO("Received ethernet message! (Sender ID: %d, Message ID: %d, bytes_copied: %d).", message.sender_id, message.message_id, bytes_copied); device.on_recieve(message); } } @@ -356,7 +352,7 @@ uint8_t ethernet_send_message(ethernet_message_t *message) { /* Append message data to packet */ status = nx_packet_data_append( packet, // Packet - &message, // Data to append + message, // Data to append sizeof(ethernet_message_t), // Size of data &device.packet_pool, // Packet pool TX_WAIT_FOREVER // Wait indefinitely