diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/data.pb.c | 38 | ||||
| -rw-r--r-- | src/data.pb.h | 181 | ||||
| -rw-r--r-- | src/dataflow.h | 5 | ||||
| -rw-r--r-- | src/main-data.c | 14 |
4 files changed, 235 insertions, 3 deletions
diff --git a/src/data.pb.c b/src/data.pb.c new file mode 100644 index 0000000..fb1e203 --- /dev/null +++ b/src/data.pb.c @@ -0,0 +1,38 @@ +/* Automatically generated nanopb constant definitions */ +/* Generated by nanopb-0.4.2-dev */ + +#include "data.pb.h" +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +PB_BIND(m2s_SOR, m2s_SOR, AUTO) + + +PB_BIND(s2m_DOC, s2m_DOC, AUTO) + + +PB_BIND(m2s_CTS, m2s_CTS, AUTO) + + +PB_BIND(m2s_command, m2s_command, AUTO) + + +PB_BIND(s2m_command, s2m_command, AUTO) + + +PB_BIND(_datapoint, _datapoint, AUTO) + + +PB_BIND(s2m_data, s2m_data, AUTO) + + + +#ifndef PB_CONVERT_DOUBLE_FLOAT +/* On some platforms (such as AVR), double is really float. + * To be able to encode/decode double on these platforms, you need. + * to define PB_CONVERT_DOUBLE_FLOAT in pb.h or compiler command line. + */ +PB_STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES) +#endif + diff --git a/src/data.pb.h b/src/data.pb.h new file mode 100644 index 0000000..cc271a3 --- /dev/null +++ b/src/data.pb.h @@ -0,0 +1,181 @@ +/* Automatically generated nanopb header */ +/* Generated by nanopb-0.4.2-dev */ + +#ifndef PB_DATA_PB_H_INCLUDED +#define PB_DATA_PB_H_INCLUDED +#include <pb.h> + +#if PB_PROTO_HEADER_VERSION != 40 +#error Regenerate this file with the current version of nanopb generator. +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Struct definitions */ +typedef struct _s2m_data { + pb_callback_t datapoints; +} s2m_data; + +typedef struct __datapoint { + uint32_t entity_id; + double data; + bool has_channel_id; + uint32_t channel_id; + bool has_unit_id; + uint32_t unit_id; + bool has_timestamp; + int32_t timestamp; +} _datapoint; + +typedef struct _m2s_CTS { + uint32_t timeout; +} m2s_CTS; + +typedef struct _m2s_SOR { + uint32_t SOR_code; + bool has_rx_length; + uint32_t rx_length; +} m2s_SOR; + +typedef struct _m2s_command { + bool has_source_module_id; + uint32_t source_module_id; + bool has_source_i2c_address; + uint32_t source_i2c_address; + pb_callback_t cmd_bytes; + pb_callback_t cmd_str; +} m2s_command; + +typedef struct _s2m_DOC { + uint32_t DOC_code; + uint32_t tx_length; +} s2m_DOC; + +typedef struct _s2m_command { + bool has_dest_module_id; + uint32_t dest_module_id; + pb_callback_t dest_module_id_multicast; + pb_callback_t cmd_bytes; + pb_callback_t cmd_str; +} s2m_command; + + +/* Initializer values for message structs */ +#define m2s_SOR_init_default {1u, false, 0} +#define s2m_DOC_init_default {1u, 0u} +#define m2s_CTS_init_default {0} +#define m2s_command_init_default {false, 1u, false, 1u, {{NULL}, NULL}, {{NULL}, NULL}} +#define s2m_command_init_default {false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}} +#define _datapoint_init_default {0u, 0, false, 1u, false, 1u, false, 1} +#define s2m_data_init_default {{{NULL}, NULL}} +#define m2s_SOR_init_zero {0, false, 0} +#define s2m_DOC_init_zero {0, 0} +#define m2s_CTS_init_zero {0} +#define m2s_command_init_zero {false, 0, false, 0, {{NULL}, NULL}, {{NULL}, NULL}} +#define s2m_command_init_zero {false, 0, {{NULL}, NULL}, {{NULL}, NULL}, {{NULL}, NULL}} +#define _datapoint_init_zero {0, 0, false, 0, false, 0, false, 0} +#define s2m_data_init_zero {{{NULL}, NULL}} + +/* Field tags (for use in manual encoding/decoding) */ +#define s2m_data_datapoints_tag 1 +#define _datapoint_entity_id_tag 1 +#define _datapoint_data_tag 2 +#define _datapoint_channel_id_tag 3 +#define _datapoint_unit_id_tag 4 +#define _datapoint_timestamp_tag 5 +#define m2s_CTS_timeout_tag 1 +#define m2s_SOR_SOR_code_tag 1 +#define m2s_SOR_rx_length_tag 2 +#define m2s_command_source_module_id_tag 1 +#define m2s_command_source_i2c_address_tag 2 +#define m2s_command_cmd_bytes_tag 3 +#define m2s_command_cmd_str_tag 4 +#define s2m_DOC_DOC_code_tag 1 +#define s2m_DOC_tx_length_tag 2 +#define s2m_command_dest_module_id_tag 1 +#define s2m_command_dest_module_id_multicast_tag 2 +#define s2m_command_cmd_bytes_tag 3 +#define s2m_command_cmd_str_tag 4 + +/* Struct field encoding specification for nanopb */ +#define m2s_SOR_FIELDLIST(X, a) \ +X(a, STATIC, REQUIRED, UINT32, SOR_code, 1) \ +X(a, STATIC, OPTIONAL, UINT32, rx_length, 2) +#define m2s_SOR_CALLBACK NULL +#define m2s_SOR_DEFAULT (const pb_byte_t*)"\x08\x01\x00" + +#define s2m_DOC_FIELDLIST(X, a) \ +X(a, STATIC, REQUIRED, UINT32, DOC_code, 1) \ +X(a, STATIC, REQUIRED, UINT32, tx_length, 2) +#define s2m_DOC_CALLBACK NULL +#define s2m_DOC_DEFAULT (const pb_byte_t*)"\x08\x01\x10\x00\x00" + +#define m2s_CTS_FIELDLIST(X, a) \ +X(a, STATIC, REQUIRED, UINT32, timeout, 1) +#define m2s_CTS_CALLBACK NULL +#define m2s_CTS_DEFAULT NULL + +#define m2s_command_FIELDLIST(X, a) \ +X(a, STATIC, OPTIONAL, UINT32, source_module_id, 1) \ +X(a, STATIC, OPTIONAL, UINT32, source_i2c_address, 2) \ +X(a, CALLBACK, OPTIONAL, BYTES, cmd_bytes, 3) \ +X(a, CALLBACK, OPTIONAL, STRING, cmd_str, 4) +#define m2s_command_CALLBACK pb_default_field_callback +#define m2s_command_DEFAULT (const pb_byte_t*)"\x08\x01\x10\x01\x00" + +#define s2m_command_FIELDLIST(X, a) \ +X(a, STATIC, OPTIONAL, UINT32, dest_module_id, 1) \ +X(a, CALLBACK, REPEATED, UINT32, dest_module_id_multicast, 2) \ +X(a, CALLBACK, OPTIONAL, BYTES, cmd_bytes, 3) \ +X(a, CALLBACK, OPTIONAL, STRING, cmd_str, 4) +#define s2m_command_CALLBACK pb_default_field_callback +#define s2m_command_DEFAULT NULL + +#define _datapoint_FIELDLIST(X, a) \ +X(a, STATIC, REQUIRED, UINT32, entity_id, 1) \ +X(a, STATIC, REQUIRED, DOUBLE, data, 2) \ +X(a, STATIC, OPTIONAL, UINT32, channel_id, 3) \ +X(a, STATIC, OPTIONAL, UINT32, unit_id, 4) \ +X(a, STATIC, OPTIONAL, INT32, timestamp, 5) +#define _datapoint_CALLBACK NULL +#define _datapoint_DEFAULT (const pb_byte_t*)"\x08\x00\x11\x00\x00\x00\x00\x00\x00\x00\x00\x18\x01\x20\x01\x28\x01\x00" + +#define s2m_data_FIELDLIST(X, a) \ +X(a, CALLBACK, REPEATED, MESSAGE, datapoints, 1) +#define s2m_data_CALLBACK pb_default_field_callback +#define s2m_data_DEFAULT NULL +#define s2m_data_datapoints_MSGTYPE _datapoint + +extern const pb_msgdesc_t m2s_SOR_msg; +extern const pb_msgdesc_t s2m_DOC_msg; +extern const pb_msgdesc_t m2s_CTS_msg; +extern const pb_msgdesc_t m2s_command_msg; +extern const pb_msgdesc_t s2m_command_msg; +extern const pb_msgdesc_t _datapoint_msg; +extern const pb_msgdesc_t s2m_data_msg; + +/* Defines for backwards compatibility with code written before nanopb-0.4.0 */ +#define m2s_SOR_fields &m2s_SOR_msg +#define s2m_DOC_fields &s2m_DOC_msg +#define m2s_CTS_fields &m2s_CTS_msg +#define m2s_command_fields &m2s_command_msg +#define s2m_command_fields &s2m_command_msg +#define _datapoint_fields &_datapoint_msg +#define s2m_data_fields &s2m_data_msg + +/* Maximum encoded size of messages (where known) */ +#define m2s_SOR_size 12 +#define s2m_DOC_size 12 +#define m2s_CTS_size 6 +/* m2s_command_size depends on runtime parameters */ +/* s2m_command_size depends on runtime parameters */ +#define _datapoint_size 38 +/* s2m_data_size depends on runtime parameters */ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif diff --git a/src/dataflow.h b/src/dataflow.h new file mode 100644 index 0000000..15d15cd --- /dev/null +++ b/src/dataflow.h @@ -0,0 +1,5 @@ + +typedef enum dataflow_status { + DATA_SUCCESS = 0, + DATA_FAIL = 1 +} dataflow_status_t; diff --git a/src/main-data.c b/src/main-data.c index f228235..4314e9e 100644 --- a/src/main-data.c +++ b/src/main-data.c @@ -16,12 +16,13 @@ /* Library includes */ #include <pb_encode.h> #include <pb_decode.h> -#include "handshake.pb.h" /* Project includes */ +#include "main.h" #include "devices.h" #include "config.h" -#include "main.h" +#include "dataflow.h" +#include "handshake.pb.h" /* Private Macros */ #define device_MDR s2m_MDR_response @@ -53,6 +54,7 @@ static void MX_USART1_UART_Init(void); bool decode_subscriptions_callback(pb_istream_t *istream, const pb_field_t *field, void **args); hs_status_t handshake(uint32_t i2c_addr); +dataflow_status_t device_dataflow(uint8_t i2c_addr); bool todo_hs_or_not_todo_hs(uint8_t i2c_addr); state_t get_state_from_hs_status(uint16_t device_addr, hs_status_t hs_status); bool encode_subscription_callback(pb_ostream_t *ostream, const pb_field_t *field, void * const *arg); @@ -116,7 +118,6 @@ int main(void) device_info[dev_idx]->MDR = module_MDR; /* dataflow */ - #else /* Slave code*/ { @@ -429,6 +430,13 @@ __DEBUG_BLOCK_END: return hs_sts; } +dataflow_status_t device_dataflow(uint8_t i2c_addr) +{ + uint8_t dev_idx = GET_IDX_FROM_ADDR(i2c_addr); + dataflow_status_t status; + +} + bool decode_subscriptions_callback(pb_istream_t *istream, const pb_field_t *field, void **args) { _subscriptions subs; |
