Skip to content

Commit

Permalink
Windows: update after protocol change
Browse files Browse the repository at this point in the history
  • Loading branch information
jgressmann committed Sep 7, 2020
1 parent 6fff3f9 commit c93f2fd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
39 changes: 39 additions & 0 deletions Windows/app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,45 @@ int main(int argc, char** argv)
}
fprintf(stdout, "\n");
} break;
case SC_MSG_CAN_ERROR: {
struct sc_msg_can_error const* error_msg = (struct sc_msg_can_error const*)msg;
if (msg->len < sizeof(*error_msg)) {
fprintf(stderr, "malformed sc_msg_can_error\n");
break;
}

uint32_t timestamp_us = dev->dev_to_host32(error_msg->timestamp_us);
if (SC_CAN_ERROR_NONE != error_msg->error) {
fprintf(
stdout, "%s %s ",
(error_msg->flags & SC_CAN_ERROR_FLAG_RXTX_TX) ? "tx" : "rx",
(error_msg->flags& SC_CAN_ERROR_FLAG_NMDT_DT) ? "data" : "arbitration");
switch (error_msg->error) {
case SC_CAN_ERROR_STUFF:
fprintf(stdout, "stuff ");
break;
case SC_CAN_ERROR_FORM:
fprintf(stdout, "form ");
break;
case SC_CAN_ERROR_ACK:
fprintf(stdout, "ack ");
break;
case SC_CAN_ERROR_BIT1:
fprintf(stdout, "bit1 ");
break;
case SC_CAN_ERROR_BIT0:
fprintf(stdout, "bit0 ");
break;
case SC_CAN_ERROR_CRC:
fprintf(stdout, "crc ");
break;
default:
fprintf(stdout, "<unknown> ");
break;
}
fprintf(stdout, "error\n");
}
} break;
case SC_MSG_CAN_RX: {
struct sc_msg_can_rx const *rx = (struct sc_msg_can_rx const*)msg;
uint32_t can_id = dev->dev_to_host32(rx->can_id);
Expand Down
25 changes: 18 additions & 7 deletions Windows/inc/supercan.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ extern "C" {
#define SC_MSG_CAN_RX 0x21 ///< Device -> Host. Received CAN frame.
#define SC_MSG_CAN_TX 0x22 ///< Host -> Device. Send CAN frame.
#define SC_MSG_CAN_TXR 0x23 ///< Device -> Host. CAN frame transmission receipt.
#define SC_MSG_CAN_ERROR 0x24 ///< Device -> Host. CAN frame error.

#define SC_MSG_USER_OFFSET 0x80 ///< Custom device messages

Expand Down Expand Up @@ -129,6 +130,9 @@ extern "C" {
#define SC_CAN_ERROR_BIT0 0x5 ///< Bit0 Error: During the transmission of a message (or acknowledge bit, or active error flag, or overload flag), the device wanted to send a dominant level (data or identifier bit logical value ‘0’), but the monitored bus value was recessive. During Bus_Off recovery this status is set each time a sequence of 11 recessive bits have been monitored. This enables the CPU to monitor the proceeding of the Bus_Off recovery sequence (indicating the bus is not stuck at dominant or continuously disturbed).
#define SC_CAN_ERROR_CRC 0x6 ///< CRC Error: The CRC checksum of a received message was incorrect. The CRC of an incoming message does not match with the CRC calculated from the received data.

#define SC_CAN_ERROR_FLAG_RXTX_TX 0x1 ///< Error on transmit, if unset on receive.
#define SC_CAN_ERROR_FLAG_NMDT_DT 0x2 ///< Error during data, if unset during arbitration.


#define SC_CAN_STATE_SYNC 0x0 ///< Node is synchronizing on CAN communication.
#define SC_CAN_STATE_IDLE 0x1 ///< Node is neither receiver nor transmitter.
Expand All @@ -139,6 +143,8 @@ extern "C" {


#define SC_CAN_STATUS_FLAG_TXR_DESYNC 0x1 ///< no USB buffer space to queue TXR message
#define SC_CAN_STATUS_FLAG_IRQ_QUEUE_FULL 0x2 ///< no space in interrupt -> task queue



/**
Expand Down Expand Up @@ -266,19 +272,23 @@ struct sc_msg_bittiming {
struct sc_msg_can_status {
uint8_t id;
uint8_t len;
uint8_t unused;
uint8_t flags; ///< CAN bus status flags
uint8_t bus_status;
uint32_t timestamp_us;
uint16_t rx_lost; ///< messages CAN -> USB lost since last time due to full rx fifo
uint16_t tx_dropped; ///< messages USB -> CAN dropped since last time due of full tx fifo
uint8_t arbt_phase_error;
uint8_t data_phase_error;
uint8_t node_state;
uint8_t flags; ///< CAN bus status flags
uint8_t rx_errors; ///< CAN rx error counter
uint8_t tx_errors; ///< CAN tx error counter
uint8_t tx_fifo_size;
uint8_t rx_fifo_size;
uint8_t rx_fifo_size; ///< CAN rx fifo fill state
uint8_t tx_fifo_size; ///< CAN tx fifo fill state
} SC_PACKED;

struct sc_msg_can_error {
uint8_t id;
uint8_t len;
uint8_t error;
uint8_t flags;
uint32_t timestamp_us;
} SC_PACKED;

struct sc_msg_can_rx {
Expand Down Expand Up @@ -322,6 +332,7 @@ enum {
sc_static_assert_sc_msg_config_is_a_multiple_of_4 = sizeof(int[(sizeof(struct sc_msg_config) & 0x3) == 0 ? 1 : -1]),
sc_static_assert_sc_msg_can_info_is_a_multiple_of_4 = sizeof(int[(sizeof(struct sc_msg_can_info) & 0x3) == 0 ? 1 : -1]),
sc_static_assert_sc_msg_features_is_a_multiple_of_4 = sizeof(int[(sizeof(struct sc_msg_features) & 0x3) == 0 ? 1 : -1]),
sc_static_assert_sc_msg_can_error_is_a_multiple_of_4 = sizeof(int[(sizeof(struct sc_msg_can_error) & 0x3) == 0 ? 1 : -1]),
};

#ifdef __cplusplus
Expand Down

0 comments on commit c93f2fd

Please sign in to comment.