Changeset - 5b244673cf7f
[Not reviewed]
default
0 2 0
matthewreed - 7 years ago 2017-07-04 21:45:12

Implemented internal get data function and updated protocol definition
2 files changed with 27 insertions and 2 deletions:
0 comments (0 inline, 0 general)
inc/protocol.h
Show inline comments
 
@@ -46,26 +46,27 @@ typedef enum {
 
    PWM_OUTPUT = 0x0005,
 
    ANALOG_OUTPUT = 0x0006,
 
    AIR_TEMP = 0x0007,
 
    AIR_HUMIDITY = 0x0008,
 
    AIR_PRESSURE = 0x0009,
 
    AMBIENT_LIGHT = 0x000A,
 
    WATER_TEMP = 0x000B,
 
    WATER_LEVEL = 0x000C,
 
    WATER_CONDUCTIVITY = 0x000D,
 
    WATER_PH = 0x000E,
 
    CAN_ID = 0x0100,
 
    DATA_RATE = 0x0101,
 
    GPIO = 0x0102,
 
    LED_BRIGHTNESS = 0x0103,
 
    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);
 
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_test();
 
bool _protocol_config(protocol_message_t* message);
 
 
bool protocol_estop(bool value);
src/protocol.c
Show inline comments
 
@@ -115,24 +115,48 @@ 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_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);
 
    }
 
    else if (message->key == LED_BRIGHTNESS)
 
    {
 
        protocol_send_data(message->key, message->sensor, protocol_settings.val.led_brightness);
 
    }
 
    else
 
    {
 
        //call config weak function
 
        result = protocol_get_data(message);
 
    }
 
    return result;
 
}
 
 
bool _protocol_config(protocol_message_t* message)
 
{
 
    bool result = false;
 
 
    if (message->key == CAN_ID)
 
    {
 
        uint32_t can_id = (uint16_t) message->data.float_data;
 
        protocol_settings.val.can_id = can_id;
 
        flash_save(&protocol_settings);
 
    }
 
    else if (message->key == DATA_RATE)
 
    {
0 comments (0 inline, 0 general)