Commit d894bea3 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

more defines added to avoid the use of 'magic' constants in the code

parent af0d49f7
......@@ -48,11 +48,12 @@
/* max. message length (header + payload + CRC), limited by the COM module */
#define DPP_MSG_PKT_LEN 126 /* uint8_t (max. 255) */
#define DPP_MSG_HDR_LEN 16
#define DPP_MSG_CRC_LEN 2 /* CRC-16-IBM / ANSI */
/* max. message payload length */
#define DPP_MSG_PAYLOAD_LEN (DPP_MSG_PKT_LEN - DPP_MSG_HDR_LEN - 2)
#define DPP_MSG_PAYLOAD_LEN (DPP_MSG_PKT_LEN - DPP_MSG_HDR_LEN - DPP_MSG_CRC_LEN)
/* actual message length incl. CRC */
#define DPP_MSG_LEN(msg) \
((msg)->header.payload_len + DPP_MSG_HDR_LEN + 2)
((msg)->header.payload_len + DPP_MSG_HDR_LEN + DPP_MSG_CRC_LEN)
/* minimal message type with smaller header (set last bit of message type to
* indicate an minimal message) */
......@@ -60,9 +61,9 @@
#define DPP_MSG_MIN_PKT_LEN 126 /* uint8_t (max. 255) */
#define DPP_MSG_MIN_HDR_LEN 4
#define DPP_MSG_MIN_PAYLOAD_LEN \
(DPP_MSG_MIN_PKT_LEN - DPP_MSG_MIN_HDR_LEN - 2)
(DPP_MSG_MIN_PKT_LEN - DPP_MSG_MIN_HDR_LEN - DPP_MSG_CRC_LEN)
#define DPP_MSG_MIN_LEN(msg) \
((msg)->header.payload_len + DPP_MSG_MIN_HDR_LEN + 2)
((msg)->header.payload_len + DPP_MSG_MIN_HDR_LEN + DPP_MSG_CRC_LEN)
/* special (reserved) device IDs */
......@@ -158,9 +159,9 @@ typedef struct {
typedef struct {
dpp_command_type_t type; /* command ID */
union {
uint8_t arg[DPP_MSG_PAYLOAD_LEN - 2]; /* arguments (length depends on command) */
uint16_t arg16[(DPP_MSG_PAYLOAD_LEN - 2) / 2];
uint32_t arg32[(DPP_MSG_PAYLOAD_LEN - 2) / 4];
uint8_t arg[DPP_MSG_PAYLOAD_LEN - DPP_COMMAND_HDR_LEN]; /* arguments (length depends on command) */
uint16_t arg16[(DPP_MSG_PAYLOAD_LEN - DPP_COMMAND_HDR_LEN) / 2];
uint32_t arg32[(DPP_MSG_PAYLOAD_LEN - DPP_COMMAND_HDR_LEN) / 4];
};
} dpp_command_t;
......@@ -210,30 +211,37 @@ typedef struct {
/* helper structs for dpp_data_aggr_t to create tuples of node ID and some other struct */
#define DPP_DATA_AGGR_HEALTH_MIN_LEN (2 + DPP_HEALTH_MIN_LEN)
typedef struct {
uint16_t node_id;
dpp_health_min_t health_min;
} dpp_data_aggr_health_min_t;
#define DPP_DATA_AGGR_GEO_ACQ_MIN_LEN (2 + DPP_HEALTH_MIN_LEN)
typedef struct {
uint16_t node_id;
dpp_geophone_acq_min_t geo_acq_min;
} dpp_data_aggr_geo_acq_min_t;
/* for general data aggregation (several 'blocks' of the same type of data sequentialized) */
#define DPP_DATA_AGGR_HDR_LEN 2
#define DPP_DATA_AGGR_LEN(aggr) (((aggr)->block_cnt * (aggr)->block_size) + 2)
typedef struct {
uint8_t block_cnt;
uint8_t block_size;
union {
dpp_data_aggr_health_min_t health_blocks[(DPP_MSG_PAYLOAD_LEN - 2) / (DPP_HEALTH_MIN_LEN + 2)];
dpp_data_aggr_geo_acq_min_t geo_acq_blocks[(DPP_MSG_PAYLOAD_LEN - 2) / (DPP_GEOPHONE_ACQ_MIN_LEN + 2)];
dpp_data_aggr_health_min_t health_blocks[(DPP_MSG_PAYLOAD_LEN - DPP_DATA_AGGR_HDR_LEN) / DPP_DATA_AGGR_HEALTH_MIN_LEN];
dpp_data_aggr_geo_acq_min_t geo_acq_blocks[(DPP_MSG_PAYLOAD_LEN - DPP_DATA_AGGR_HDR_LEN) / DPP_DATA_AGGR_GEO_ACQ_MIN_LEN];
};
} dpp_data_aggr_t;
#define DPP_FW_HDR_LEN 4
#define DPP_FW_BLOCK_SIZE 96 /* must be a multiple of 8 */
#define DPP_FW_HDR_LEN 4
#define DPP_FW_BLOCK_SIZE 96 /* must be a multiple of 8 */
#define DPP_FW_INFO_LEN (DPP_FW_HDR_LEN + 8)
#define DPP_FW_DATA_LEN (DPP_FW_HDR_LEN + 2 + DPP_FW_BLOCK_SIZE)
#define DPP_FW_REQ_LEN(n) (DPP_FW_HDR_LEN + 2 + 2 * (n))
#define DPP_FW_REQ_MAX_BLOCKS ((DPP_MSG_PAYLOAD_LEN - 2 - DPP_FW_HDR_LEN) / 2)
typedef struct {
dpp_fw_type_t type : 8;
......@@ -250,7 +258,7 @@ typedef struct {
} data;
struct {
uint16_t num; /* 16-bit to avoid alignment issues */
uint16_t block_ids[(DPP_MSG_PAYLOAD_LEN - 2 - DPP_FW_HDR_LEN) / 2];
uint16_t block_ids[DPP_FW_REQ_MAX_BLOCKS];
} req;
};
} dpp_fw_t;
......
......@@ -37,7 +37,7 @@
/* Label ----------------------- | #No. | Description ---------------------- | Value ---*/
EVENT_SX1262_CMD_EXECUTED, /* 0x01 | command executed (ACK) | cmd type (16-bit) + argument (16-bit) */
EVENT_SX1262_CMD_EXECUTED, /* 0x01 | command executed (ACK) | cmd type without component ID (16-bit) + argument (16-bit) */
EVENT_SX1262_TIME_UPDATED, /* 0x02 | local time has been adjusted | time delta / jump in ms (32-bit signed) */
EVENT_SX1262_QUEUE_FULL, /* 0x03 | queue full, message dropped | queue ID (32-bit) */
EVENT_SX1262_INV_MSG, /* 0x04 | invalid message received | sender device ID (16-bit) + message length in bytes (16-bit) */
......@@ -51,8 +51,8 @@ EVENT_SX1262_SCHED_MISSED, /* 0x0b | schedule packet missed | e
EVENT_SX1262_MUTEX_ERROR, /* 0x0c | error related to mutual exclusion (semaphores, critical sections) | error code (32-bit) */
EVENT_SX1262_TSYNC_ERROR, /* 0x0d | error or warning related to time synchronization | error code (32-bit) */
EVENT_SX1262_TSYNC_DRIFT, /* 0x0e | high drift warning | drift in ppm (signed 32-bit) */
EVENT_SX1262_RTC_ERROR, /* 0x0f | error related to the RTC | error code */
EVENT_SX1262_TIMEOUT, /* 0x10 | generic timeout error | error code */
EVENT_SX1262_RTC_ERROR, /* 0x0f | error related to the RTC | error code (32-bit) */
EVENT_SX1262_TIMEOUT, /* 0x10 | generic timeout error | error code (32-bit) */
EVENT_SX1262_RESET, /* 0x11 | device reset occurred | reset cause (16-bit) + counter (16-bit) */
EVENT_SX1262_TX_FAILED, /* 0x12 | transmission failed (e.g. due to channel busy or no ACK received) | error code (32-bit) */
EVENT_SX1262_FW_OTA_STATUS, /* 0x13 | firmware update status | progress in percent (32-bit) */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment