eliminate some compiler warnings
This commit is contained in:
parent
18f6d62c7b
commit
3f8e1290fa
@ -52,6 +52,7 @@ static uint8_t calculateCommandPEC(uint8_t* data, uint8_t datalen) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
[[maybe_unused]]
|
||||
static uint8_t checkCommandPEC(const uint8_t* data, uint8_t datalen) {
|
||||
if (datalen <= 3) { return 255; }
|
||||
const uint16_t pec = computeCRC15(data, datalen - 2);
|
||||
|
@ -127,7 +127,7 @@ typedef struct {
|
||||
} isotp_validation_result_t;
|
||||
|
||||
// Internal helper function to validate message parameters and find available slot
|
||||
[[gnu::access(none, 2, 3)]]
|
||||
ACCESS(none, 2, 3)
|
||||
static isotp_validation_result_t isotp_validate_message(isotp_conn_id_t conn_id, const uint8_t *data, size_t datalen) {
|
||||
isotp_validation_result_t result = {.status = ISOTP_ERROR, .index = 0};
|
||||
|
||||
@ -169,7 +169,7 @@ static isotp_validation_result_t isotp_validate_message(isotp_conn_id_t conn_id,
|
||||
}
|
||||
|
||||
isotp_status_t isotp_add_message(isotp_conn_id_t conn_id, const uint8_t * data, size_t datalen) {
|
||||
isotp_validation_result_t result = isotp_validate_message(conn_id, data, datalen);
|
||||
const isotp_validation_result_t result = isotp_validate_message(conn_id, data, datalen);
|
||||
|
||||
if (result.status == ISOTP_OK) {
|
||||
// Add message to the queue at the found index
|
||||
@ -187,7 +187,7 @@ isotp_status_t isotp_add_message(isotp_conn_id_t conn_id, const uint8_t * data,
|
||||
|
||||
isotp_status_t isotp_try_add_message(isotp_conn_id_t conn_id, const uint8_t * data, size_t datalen) {
|
||||
// Just validate without adding to the queue
|
||||
isotp_validation_result_t result = isotp_validate_message(conn_id, data, datalen);
|
||||
const isotp_validation_result_t result = isotp_validate_message(conn_id, data, datalen);
|
||||
return result.status;
|
||||
}
|
||||
|
||||
@ -199,8 +199,8 @@ isotp_status_t isotp_try_add_message(isotp_conn_id_t conn_id, const uint8_t * da
|
||||
}
|
||||
|
||||
isotp_status_t isotp_update() {
|
||||
uint32_t now = isotp_get_time();
|
||||
uint32_t delta = now - last_called;
|
||||
const uint32_t now = isotp_get_time();
|
||||
const uint32_t delta = now - last_called;
|
||||
for (size_t i = 0; i < MAX_ISOTP_MESSAGES_IN_FLIGHT; i++) {
|
||||
|
||||
isotp_message msg = {};
|
||||
@ -228,15 +228,14 @@ isotp_status_t isotp_update() {
|
||||
tx_queue[i].data += MAX_ISOTP_DATA_FIRST;
|
||||
|
||||
// Check if we're in broadcast mode - don't wait for flow control
|
||||
isotp_conn_id_t conn_id = tx_queue[i].conn_id;
|
||||
|
||||
// Connection ID was already validated during isotp_add_message
|
||||
if (check_flag(conn_id, ISOTP_FLAGS_BROADCAST)) {
|
||||
if (check_flag(tx_queue[i].conn_id, ISOTP_FLAGS_BROADCAST)) {
|
||||
// In broadcast mode, assume we can send directly
|
||||
tx_queue[i].flow_control.state = ISOTP_CONTINUE;
|
||||
tx_queue[i].flow_control.block_size = 0; // No block size limit
|
||||
tx_queue[i].flow_control.st_min = 0; // No separation time
|
||||
tx_queue[i].flow_control.st_min_counter = 0;
|
||||
tx_queue[i].state = ISOTP_READY;
|
||||
goto ISOTP_SEND_AGAIN; // Send all frames immediately
|
||||
} else {
|
||||
tx_queue[i].timestamp = now; // Set timestamp when entering WAITING_FLOW_CONTROL state
|
||||
tx_queue[i].state = ISOTP_WAITING_FLOW_CONTROL;
|
||||
@ -374,7 +373,7 @@ static isotp_status_t isotp_handle_first_frame(isotp_conn_id_t conn_id, const ui
|
||||
return ISOTP_INVALID_FRAME;
|
||||
}
|
||||
|
||||
uint16_t length = ((data[0] & 0x0F) << 8) | data[1];
|
||||
const uint16_t length = ((data[0] & 0x0F) << 8) | data[1];
|
||||
if (length > MAX_ISOTP_DATA_SIZE_MESSAGE) {
|
||||
return ISOTP_INVALID_FRAME;
|
||||
}
|
||||
@ -415,7 +414,7 @@ static isotp_status_t isotp_handle_consecutive_frame(isotp_conn_id_t conn_id, co
|
||||
return ISOTP_INVALID_FRAME;
|
||||
}
|
||||
|
||||
uint8_t seq_n = data[0] & 0x0F;
|
||||
const uint8_t seq_n = data[0] & 0x0F;
|
||||
|
||||
for (size_t i = 0; i < MAX_ISOTP_MESSAGES_IN_FLIGHT; i++) {
|
||||
if (rx_queue[i].state == ISOTP_DONE || rx_queue[i].state == ISOTP_FAILED || rx_queue[i].conn_id != conn_id) {
|
||||
@ -432,7 +431,7 @@ static isotp_status_t isotp_handle_consecutive_frame(isotp_conn_id_t conn_id, co
|
||||
rx_queue[i].seq_n++;
|
||||
rx_queue[i].seq_n &= 0x0F; // Wrap around sequence number
|
||||
|
||||
size_t bytes_to_copy = rx_queue[i].remaining <= MAX_ISOTP_DATA_CONSECUTIVE ? rx_queue[i].remaining : MAX_ISOTP_DATA_CONSECUTIVE;
|
||||
const size_t bytes_to_copy = rx_queue[i].remaining <= MAX_ISOTP_DATA_CONSECUTIVE ? rx_queue[i].remaining : MAX_ISOTP_DATA_CONSECUTIVE;
|
||||
memcpy(rx_queue[i].data, data + 1, bytes_to_copy);
|
||||
rx_queue[i].data += bytes_to_copy;
|
||||
rx_queue[i].remaining -= bytes_to_copy;
|
||||
@ -456,7 +455,7 @@ static isotp_status_t isotp_handle_single_frame(isotp_conn_id_t conn_id, const u
|
||||
return ISOTP_INVALID_FRAME;
|
||||
}
|
||||
|
||||
uint8_t length = data[0] & 0x0F;
|
||||
const uint8_t length = data[0] & 0x0F;
|
||||
if (length > MAX_ISOTP_DATA_SINGLE) {
|
||||
return ISOTP_INVALID_FRAME;
|
||||
}
|
||||
@ -480,9 +479,9 @@ static isotp_status_t isotp_handle_flow_control(isotp_conn_id_t conn_id, const u
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t status = data[0] & 0x0F;
|
||||
uint8_t block_size = data[1];
|
||||
uint8_t st_min = data[2];
|
||||
const uint8_t status = data[0] & 0x0F;
|
||||
const uint8_t block_size = data[1];
|
||||
const uint8_t st_min = data[2];
|
||||
|
||||
switch (status) {
|
||||
case ISOTP_FC_CTS: // Continue
|
||||
@ -529,7 +528,7 @@ isotp_status_t isotp_handle_incoming(uint16_t id, const uint8_t * data, size_t d
|
||||
return ISOTP_CONNECTION_NOT_FOUND;
|
||||
}
|
||||
|
||||
uint8_t type = data[0] & 0xF0;
|
||||
const uint8_t type = data[0] & 0xF0;
|
||||
|
||||
switch (type) {
|
||||
#if ISOTP_RX
|
||||
|
@ -11,7 +11,7 @@
|
||||
#define ISOTP_RX false // enable RX support
|
||||
#define ISOTP_RX_TIMEOUT 1000 // Timeout for incoming messages (ms)
|
||||
#define ISOTP_RX_MIN_ST 0 // Minimum ST for flow control (ms)
|
||||
//#define ISOTP_PADDING 0xAA // optional padding byte
|
||||
//#define ISOTP_PADDING 0xAA // optional padding byte
|
||||
|
||||
typedef enum isotp_status {
|
||||
ISOTP_OK = 0,
|
||||
@ -50,7 +50,19 @@ static inline const char *isotp_status_to_string(isotp_status_t status) {
|
||||
}
|
||||
}
|
||||
|
||||
typedef enum [[clang::flag_enum]] {
|
||||
#if __has_attribute(flag_enum)
|
||||
#define FLAG_ENUM [[clang::flag_enum]]
|
||||
#else
|
||||
#define FLAG_ENUM
|
||||
#endif
|
||||
|
||||
#if __has_attribute(access)
|
||||
#define ACCESS(access_type, ...) [[gnu::access(access_type, __VA_ARGS__)]]
|
||||
#else
|
||||
#define ACCESS(access_type, ...)
|
||||
#endif
|
||||
|
||||
typedef enum FLAG_ENUM {
|
||||
ISOTP_FLAGS_NONE = 0,
|
||||
ISOTP_FLAGS_LISTEN_ONLY = 1 << 0, // do not send flow control frames
|
||||
ISOTP_FLAGS_BROADCAST = 1 << 1, // linux socketcan broadcast (do not wait for flow control)
|
||||
@ -61,7 +73,7 @@ typedef uint16_t isotp_conn_id_t;
|
||||
|
||||
isotp_status_t isotp_init();
|
||||
isotp_status_t isotp_update();
|
||||
[[gnu::access(read_only, 2, 3)]] isotp_status_t isotp_handle_incoming(uint16_t id, const uint8_t *data, size_t datalen);
|
||||
ACCESS(read_only, 2, 3) isotp_status_t isotp_handle_incoming(uint16_t id, const uint8_t *data, size_t datalen);
|
||||
/**
|
||||
* @brief Add a new connection to the isotp stack.
|
||||
* @param them The CAN ID of the remote device.
|
||||
@ -71,7 +83,7 @@ isotp_status_t isotp_update();
|
||||
* On failure: One of the negative isotp_status_t error codes.
|
||||
*/
|
||||
int isotp_add_connection(uint16_t them, uint16_t us, isotp_flags_t flags);
|
||||
[[gnu::access(read_only, 2, 3)]] isotp_status_t isotp_add_message(isotp_conn_id_t conn_id, const uint8_t * data, size_t datalen);
|
||||
[[gnu::access(none, 2, 3)]] isotp_status_t isotp_try_add_message(isotp_conn_id_t conn_id, const uint8_t * data, size_t datalen);
|
||||
ACCESS(read_only, 2, 3) isotp_status_t isotp_add_message(isotp_conn_id_t conn_id, const uint8_t * data, size_t datalen);
|
||||
ACCESS(none, 2, 3) isotp_status_t isotp_try_add_message(isotp_conn_id_t conn_id, const uint8_t * data, size_t datalen);
|
||||
|
||||
#endif // ISOTP_H
|
Loading…
x
Reference in New Issue
Block a user