diff --git a/src/protocol.c b/src/protocol.c --- a/src/protocol.c +++ b/src/protocol.c @@ -1,5 +1,22 @@ #include "protocol.h" +protocol_device_t protocol_device; +flash_settings_t protocol_settings; + +void protocol_init(protocol_device_t device) +{ + protocol_device = device; + flash_restore(&protocol_settings); + + can_init(protocol_settings.val.can_id, DEFAULT_BROADCAST_ID); +} + +bool protocol_send_test() +{ + bool result = true; + can_send_test(protocol_settings.val.can_id | 0x00000001); + return result; +} bool protocol_receive_message(CanRxMsgTypeDef* can_message) { @@ -34,7 +51,7 @@ bool protocol_send_message(protocol_mess data[6] = (message->data.byte_data[2] >> 8) & 0xFF; data[7] = (message->data.byte_data[3] >> 0) & 0xFF; - can_send(CAN_SEND_ID, CAN_ID_STD, 8, data); + can_send(protocol_settings.val.can_id | 0x00000001, CAN_ID_STD, 8, data); return result; } @@ -83,6 +100,22 @@ bool protocol_process_message(protocol_m return result; } +bool protocol_send_data(protocol_data_key_t key, uint8_t sensor, float data) +{ + bool result = true; + + protocol_message_t message; + message.command = false; + message.id = protocol_device; + message.key = key; + message.sensor = sensor; + message.data.float_data = data; + + result = protocol_send_message(&message); + + return result; +} + __weak bool protocol_estop(bool value) { return false;