Files @ 01ed20819369
Branch filter:

Location: HydroBot/hydrobot-sharedlibs/inc/protocol.h

matthewreed
Added send bytes function to protocol
#ifndef _PROTOCOL_H_
#define _PROTOCOL_H_

#include <stdbool.h>

#include "config.h"
#include "can.h"
#include "flash.h"

#define DEFAULT_BROADCAST_ID 0x00000000

typedef struct {
    bool command;
    uint8_t id;
    uint16_t key;
    uint8_t sensor;
    union {
        float float_data;
        uint8_t byte_data[4];
    } data;
}  protocol_message_t;

typedef enum {
    ESTOP = 0x00,
    SILENCE_BUS = 0x01,
    SET_OUTPUT = 0X10,
    GET_DATA = 0x11,
    CONFIG = 0x12,
    CALIBRATE = 0x13,
} protocol_command_t;

typedef enum {
    MASTER = 0x00,
    AIRSENSE = 0x01,
    RELAYDRIVE = 0X02,
    WATERSENSE = 0x03,
    PROTOMODULE = 0x04,
} protocol_device_t;

typedef enum {
    NONE = 0x0000,
    DIGITAL_INPUT = 0x0001,
    FREQ_INPUT = 0x0002,
    ANALOG_INPUT = 0x0003,
    DIGITAL_OUTPUT = 0x0004,
    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,
    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_