User API
This section presents a set of user-defined functions implemented in the unican_ard.h library.
Functions
Initialization
uint8_t UCanArd.Init();
``
_ Returns 0 if executed successfully._
### Changing your own UniCAN ID
```cpp
uint8_t UCanArd.ChangeSelfId(uint8_t self_id);
A new ID in the range from 0x1 to 0x1F is passed as an argument. It is not recommended to use ID=0x1 or an identifier that can be used by other devices. Default value: 0x1A.
Returns 0 if successful.
Changing the UniCAN ID of the head unit
uint8_t UCanArd.ChangeMasterId(uint8_t master_id);
A new ID in the range from 0x1 to 0x1F is passed as an argument. It is not recommended to use ID=0x1 or an identifier that can be used by other devices. The default value is 0x05.
Returns 0 if successful.
Deinitialization
uint8_t UCanArd.DeInit();
``
_ Returns 0 if executed successfully._
### Receiving a CAN message
```cpp
uint8_t UCanArd.ReceiveTask();
``
:::infofunction must be executed in a loop. Receiving UniCAN messages consisting of several frames is possible only with a short cycle period (on the order of several ms or less). When creating a protocol, it is recommended to limit yourself to single-frame incoming messages.
:::
_ Returns 0 if successful._
### Sending a UniCAN message:
``cpp
uint8_t UCanArd.SendMessage(uint8_t receiver_id, uint16_t msg_id, uint8_t* data, uint8_t length);
Arguments:
- Recipient's UniCAN ID;
- MSGid;
- a pointer to the first byte of data and the size of the data in bytes.
Returns 0 if successful.
Sending a UniCAN message to the head unit
uint8_t UCanArd.SendMessageToMaster(uint16_t msg_id, uint8_t* data, uint8_t length);
Arguments:
- MSGid;
- a pointer to the first byte of data and the size of the data in bytes.
Returns 0 if successful.
Read the last saved message
uint8_t UCanArd.ReadMessage(uint8_t* sender_id, uint16_t* msg_id, uint8_t* data, uint8_t* length);
Arguments:
- pointer to variables for the recipient's UniCAN ID;
- MSGid;
- a pointer to the first byte of data and a pointer to a variable for the size of the data in bytes.
Returns 0 if successful, 1 if there is no new message._
Reply with confirmation
uint8_t UCanArd.SendAck(uint8_t receiver_id);
The standard MSGid 0x0118 is used.
Arguments:
- UniCAN ID of the recipient.
Returns 0 if successful.
Reply with a refusal
uint8_t UCanArd.SendNack(uint8_t receiver_id);
The standard MSGid 0x0119 is used.
Arguments:
- UniCAN ID of the recipient.
Returns 0 if successful.