Changeset - 01ed20819369
[Not reviewed]
default
0 2 0
matthewreed - 6 years ago 2018-08-29 23:20:05

Added send bytes function to protocol
2 files changed with 20 insertions and 0 deletions:
0 comments (0 inline, 0 general)
inc/protocol.h
Show inline comments
 
@@ -58,21 +58,22 @@ typedef enum {
 
    LED_BRIGHTNESS = 0x0102,
 
    INPUT = 0x0103,
 
    OUTPUT = 0x0104,
 
} protocol_data_key_t;
 
 
void protocol_init(protocol_device_t device);
 
flash_settings_t* protocol_get_settings(void);
 
void protocol_save_settings(void);
 
bool protocol_receive_message(CanRxMsgTypeDef* can_message);
 
bool protocol_send_message(protocol_message_t* message);
 
bool protocol_process_message(protocol_message_t* message);
 
bool protocol_send_data(protocol_data_key_t key, uint8_t sensor, float data);
 
bool protocol_send_data_bytes(protocol_data_key_t key, uint8_t sensor, uint8_t* data);
 
bool protocol_send_test();
 
bool _protocol_config(protocol_message_t* message);
 
 
bool protocol_estop(bool value);
 
bool protocol_set_output(protocol_message_t* message);
 
bool protocol_get_data(protocol_message_t* message);
 
bool protocol_config(protocol_message_t* message);
 
 
#endif //_PROTOCOL_H_
src/protocol.c
Show inline comments
 
@@ -120,24 +120,43 @@ bool protocol_send_data(protocol_data_ke
 
    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;
 
}
 
 
bool protocol_send_data_bytes(protocol_data_key_t key, uint8_t sensor, uint8_t* data)
 
{
 
    bool result = true;
 
 
    protocol_message_t message;
 
    message.command = false;
 
    message.id = protocol_device;
 
    message.key = key;
 
    message.sensor = sensor;
 
    message.data.byte_data[0] = data[0];
 
    message.data.byte_data[1] = data[1];
 
    message.data.byte_data[2] = data[2];
 
    message.data.byte_data[3] = data[3];
 
 
    result = protocol_send_message(&message);
 
 
    return result;
 
}
 
 
bool _protocol_get_data(protocol_message_t* message)
 
{
 
    bool result = false;
 
 
    if (message->key == CAN_ID)
 
    {
 
        protocol_send_data(message->key, message->sensor, protocol_settings.val.can_id);
 
    }
 
    else if (message->key == DATA_RATE)
 
    {
 
        protocol_send_data(message->key, message->sensor, ((float)protocol_settings.val.data_rate)/1000);
 
    }
0 comments (0 inline, 0 general)