Changeset - 10c03b9c67e6
[Not reviewed]
default
0 1 0
matthewreed - 7 years ago 2017-07-20 14:23:43

Added protocol save settings function
1 file changed with 5 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/protocol.c
Show inline comments
 
#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);
 
    led_set_brightness(protocol_settings.val.led_brightness);
 
 
    can_init(protocol_settings.val.can_id, DEFAULT_BROADCAST_ID);
 
}
 
 
flash_settings_t* protocol_get_settings(void)
 
{
 
    return &protocol_settings;
 
}
 
 
void protocol_save_settings(void)
 
{
 
    flash_save(&protocol_settings);
 
}
 
 
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)
 
{
 
    bool result = true;
 
    
 
    protocol_message_t message;
 
    message.command = can_message->Data[0] & 0x80;
 
    message.id = can_message->Data[0] & 0x7F;
 
    message.key = (can_message->Data[1] << 8) | can_message->Data[2];
 
    message.sensor = can_message->Data[3];
 
    message.data.byte_data[0] = can_message->Data[4];
 
    message.data.byte_data[1] = can_message->Data[5];
 
    message.data.byte_data[2] = can_message->Data[6];
 
    message.data.byte_data[3] = can_message->Data[7];
 
    
 
    protocol_process_message(&message);
 
    
 
    return result;
0 comments (0 inline, 0 general)