File mock_can.c¶
FileList > examples > python_api > src > mock_can.c
Go to the source code of this file
#include "mock_can.h"#include "can_driver.h"#include <string.h>#include <unistd.h>
Classes¶
| Type | Name |
|---|---|
| struct | can_frame_t Structure representing a CAN frame in the mock driver. |
Public Static Attributes¶
| Type | Name |
|---|---|
| int | delay_ms = 0Artificial delay in milliseconds for send operations (0 for no delay) |
| int | disable_fc = 0Flag to disable FlowControl frames in the mock driver. |
| int | drop_enabled = 0Flag to enable or disable frame dropping in the mock driver. |
| int | head = 0Index of the head of the queue (next frame to receive) |
| can_frame_t | queue Internal queue to hold CAN frames for simulation. |
| int | tail = 0Index of the tail of the queue (next position to send a frame) |
Public Functions¶
| Type | Name |
|---|---|
| void | mock_can_disable_fc (int enable) Disables sending FlowControl frames in the mock CAN driver. |
| void | mock_can_enable_drop (int enable) Enables or disables frame dropping in the mock CAN driver. |
| void | mock_can_init (void) Initializes the mock CAN driver and sets it as the active driver. |
| void | mock_can_set_delay_ms (int delay) Sets the artificial delay for the mock CAN driver. |
Public Static Functions¶
| Type | Name |
|---|---|
| int | mock_receive (uint32_t * id, uint8_t * data, uint8_t * len) Mock implementation of CAN receive function. |
| int | mock_send (uint32_t id, const uint8_t * data, uint8_t len) Mock implementation of CAN send function. |
| void | sleep_ms (int ms) Sleep for a specified number of milliseconds. |
Macros¶
| Type | Name |
|---|---|
| define | CAN_MAX_DLEN 8Maximum data length for CAN frames. |
| define | MOCK_QUEUE_SIZE 256Size of the internal queue for simulating CAN frames. |
Public Static Attributes Documentation¶
variable delay_ms¶
Artificial delay in milliseconds for send operations (0 for no delay)
int delay_ms;
variable disable_fc¶
Flag to disable FlowControl frames in the mock driver.
int disable_fc;
variable drop_enabled¶
Flag to enable or disable frame dropping in the mock driver.
int drop_enabled;
variable head¶
Index of the head of the queue (next frame to receive)
int head;
variable queue¶
Internal queue to hold CAN frames for simulation.
can_frame_t queue[MOCK_QUEUE_SIZE];
variable tail¶
Index of the tail of the queue (next position to send a frame)
int tail;
Public Functions Documentation¶
function mock_can_disable_fc¶
Disables sending FlowControl frames in the mock CAN driver.
void mock_can_disable_fc (
int enable
)
Parameters:
enable- 1 to disable FlowControl frames, 0 to allow them.
function mock_can_enable_drop¶
Enables or disables frame dropping in the mock CAN driver.
void mock_can_enable_drop (
int enable
)
Parameters:
enable- 1 to enable frame dropping, 0 to disable.
function mock_can_init¶
Initializes the mock CAN driver and sets it as the active driver.
void mock_can_init (
void
)
function mock_can_set_delay_ms¶
Sets the artificial delay for the mock CAN driver.
void mock_can_set_delay_ms (
int delay
)
Parameters:
delay- Delay in milliseconds.
Public Static Functions Documentation¶
function mock_receive¶
Mock implementation of CAN receive function.
static int mock_receive (
uint32_t * id,
uint8_t * data,
uint8_t * len
)
Parameters:
idPointer to store the received CAN ID.dataPointer to store the received CAN data.lenPointer to store the length of the received CAN data.
Returns:
int 0 on success, -1 if the queue is empty.
function mock_send¶
Mock implementation of CAN send function.
static int mock_send (
uint32_t id,
const uint8_t * data,
uint8_t len
)
Parameters:
idCAN ID to send.dataPointer to the CAN data to send.lenLength of the CAN data to send.
Returns:
int 0 on success (including when drop is enabled and a frame is discarded), -1 if the queue is full.
function sleep_ms¶
Sleep for a specified number of milliseconds.
static void sleep_ms (
int ms
)
Parameters:
msNumber of milliseconds to sleep.
Macro Definition Documentation¶
define CAN_MAX_DLEN¶
Maximum data length for CAN frames.
#define CAN_MAX_DLEN `8`
define MOCK_QUEUE_SIZE¶
Size of the internal queue for simulating CAN frames.
#define MOCK_QUEUE_SIZE `256`
The documentation for this class was generated from the following file examples/python_api/src/mock_can.c