Skip to content

Commit f51daef

Browse files
authored
Merge branch 'main' into feature/hdc2021debr
2 parents 93e9b79 + e11e8ee commit f51daef

14 files changed

Lines changed: 195 additions & 76 deletions

File tree

NetX/inc/u_nx_ethernet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/* CONFIG */
1616
#define ETH_UDP_PORT 2006 /* UDP port for communication */
17-
#define ETH_MESSAGE_SIZE 8 /* Maximum ethernet message size in bytes. */
17+
#define ETH_MESSAGE_SIZE 128 /* Maximum ethernet message size in bytes. */
1818
#define ETH_MAX_PACKETS 10 /* Maximum number of packets we wanna handle simultaneously */
1919
#define ETH_NUMBER_OF_NODES 8 /* Number of nodes in the network. */
2020

@@ -51,7 +51,7 @@ typedef enum {
5151
} plca_node_id_t;
5252
/* END CONFIG */
5353

54-
typedef struct {
54+
typedef struct __attribute__((__packed__)) {
5555
uint8_t sender_id;
5656
uint8_t recipient_id;
5757
uint8_t message_id;

NetX/src/u_nx_ethernet.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "nxd_ptp_client.h"
55
#include "u_nx_debug.h"
66
#include "u_tx_debug.h"
7+
#include "c_utils.h"
78
#include "nx_api.h"
89
#include <string.h>
910
#include <stdio.h>
@@ -113,20 +114,15 @@ static void _receive_message(NX_UDP_SOCKET *socket) {
113114
}
114115

115116
/* Extract message from packet */
116-
status = nx_packet_data_extract_offset(
117-
packet, // Packet to extract from
118-
0, // Offset (start of packet)
119-
&message, // Message buffer
120-
sizeof(ethernet_message_t), // Size to extract
121-
&bytes_copied // Stores how many bytes were actually copied to &message
122-
);
123-
if(bytes_copied < sizeof(ethernet_message_t)) {
124-
PRINTLN_WARNING("Received ethernet message was smaller than expected (only received %lu of %u expected bytes).", bytes_copied, sizeof(ethernet_message_t));
117+
ULONG bytes_copied = 0;
118+
status = nx_packet_data_retrieve(packet, &message, &bytes_copied);
119+
if(status != NX_SUCCESS) {
120+
PRINTLN_ERROR("Failed to call nx_packet_data_retrieve() (Status: %d/%s).", status, nx_status_toString(status));
125121
}
126122

127123
/* Process received message */
128124
if(status == NX_SUCCESS) {
129-
PRINTLN_INFO("Received ethernet message! (Sender ID: %d, Message ID: %d).", message.sender_id, message.message_id);
125+
PRINTLN_INFO("Received ethernet message! (Sender ID: %d, Message ID: %d, bytes_copied: %d).", message.sender_id, message.message_id, bytes_copied);
130126
device.on_recieve(message);
131127
}
132128
}
@@ -356,7 +352,7 @@ uint8_t ethernet_send_message(ethernet_message_t *message) {
356352
/* Append message data to packet */
357353
status = nx_packet_data_append(
358354
packet, // Packet
359-
&message, // Data to append
355+
message, // Data to append
360356
sizeof(ethernet_message_t), // Size of data
361357
&device.packet_pool, // Packet pool
362358
TX_WAIT_FOREVER // Wait indefinitely

Testing/cmock-config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
:cmock:
33
:mock_prefix: mock_
4-
:includes:
5-
- stubs.h
64
:plugins:
75
- :ignore
86
- :ignore_arg

general/include/mcp23008.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <stdint.h>
55

6-
typedef int (*write_ptr)(uint8_t addr, const uint8_t *data, uint8_t len);
6+
typedef int (*write_ptr)(uint8_t addr, uint8_t *data, uint8_t len);
77
typedef int (*read_ptr)(uint8_t addr, uint8_t *data, uint8_t len);
88
typedef struct {
99
write_ptr write;

general/include/p3t1755.h

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55

66
#ifndef p3t1755_H
77
#define p3t1755_H
8-
#include <stdint.h>
98
#include <math.h>
9+
#include <stdint.h>
1010

1111
// REGISTERS
12-
// Temperature register: contains two 8-bit data bytes; to store the measured Temp data.
12+
// Temperature register: contains two 8-bit data bytes; to store the measured
13+
// Temp data.
1314
#define p3t1755_TEMPERATURE 0x00 // read only
14-
// Configuration register: contains a single 8-bit data byte; to set the device operating condition
15+
// Configuration register: contains a single 8-bit data byte; to set the device
16+
// operating condition
1517
#define p3t1755_CONFIGURATION 0x01
16-
// T_low register: Hysteresis register, it contains two 8-bit data bytes to store the hysteresis T_low limit; default = 75 °C.
18+
// T_low register: Hysteresis register, it contains two 8-bit data bytes to
19+
// store the hysteresis T_low limit; default = 75 °C.
1720
#define p3t1755_T_LOW 0x02
18-
// T_high register: Overtemperature shut down threshold register, it contains two 8-bit data bytes to
19-
// store the overtemperature shutdown T_high limit; default = 80 °C.
21+
// T_high register: Overtemperature shut down threshold register, it contains
22+
// two 8-bit data bytes to store the overtemperature shutdown T_high limit;
23+
// default = 80 °C.
2024
#define p3t1755_T_HIGH 0x03
2125

2226
// TEMPERATURE REGISTER FORMAT
@@ -50,20 +54,26 @@
5054
#define p3t1755_220MS_CONVERSION_TIME 0x60
5155

5256
// Function Pointers
53-
typedef int (*WritePtr)(uint16_t dev_addr, uint16_t reg, uint16_t *data);
54-
typedef int (*ReadPtr)(uint16_t dev_addr, uint16_t reg, uint16_t *data);
57+
typedef int32_t (*WritePtr)(uint16_t dev_addr, uint16_t reg, uint8_t *data,
58+
uint8_t length);
59+
typedef int32_t (*ReadPtr)(uint16_t dev_addr, uint16_t reg, uint8_t *data,
60+
uint8_t length);
5561

5662
typedef struct {
5763
uint16_t dev_addr;
5864
WritePtr write;
5965
ReadPtr read;
6066
} p3t1755_t;
6167

68+
float p3t1755_raw_to_celsius(uint16_t raw);
69+
6270
void p3t1755_init(p3t1755_t *p3t, WritePtr write, ReadPtr read,
6371
uint16_t dev_addr);
6472

65-
int p3t1755_read_reg(p3t1755_t *p3t, uint16_t reg, uint16_t *data);
66-
int p3t1755_write_reg(p3t1755_t *p3t, uint16_t reg, uint16_t *data);
73+
int p3t1755_read_reg(p3t1755_t *p3t, uint16_t reg, uint8_t *data,
74+
uint8_t length);
75+
int p3t1755_write_reg(p3t1755_t *p3t, uint16_t reg, uint8_t *data,
76+
uint8_t length);
6777

6878
// Reads current temp in celcius
6979
int p3t1755_read_temperature(p3t1755_t *p3t, float *temp_c);
@@ -86,4 +96,4 @@ int p3t1755_read_low_temp(p3t1755_t *p3t, float *temp_c);
8696
int p3t1755_set_high_temp(p3t1755_t *p3t, float temp_c);
8797
int p3t1755_set_low_temp(p3t1755_t *p3t, float temp_c);
8898

89-
#endif
99+
#endif

0 commit comments

Comments
 (0)