28#define E12_MAX_PKT_SIZE 128
34#define E12_MAX_DATA_PAYLOAD (E12_MAX_PKT_SIZE - sizeof(e12_onwire_head_t) - 8)
143#define E12_MAX_LOG_BUFFERS 1
144#define MAX_S_LOG_DATA 16
145typedef struct __attribute__((packed, aligned(4))) e12_log_evt {
176typedef struct __attribute__((packed, aligned(4))) e12_wakeup_data {
180typedef struct __attribute__((packed, aligned(4))) e12_debug_blink {
186typedef struct __attribute__((packed, aligned(4))) e12_node_properties {
191 uint8_t FACTORY_RESET : 1;
192 uint8_t DISABLE_SLEEP : 1;
193 uint8_t REFRESH_CONFIG : 1;
194 uint8_t ACTIVATE_WIFI : 1;
195 uint8_t ACTIVATE_LTE : 1;
196 uint8_t ACTIVATE_LORA : 1;
197 uint8_t ACTIVATE_WIFI_CAPTIVE_PORTAL : 1;
199 uint8_t TRANSMIT : 1;
212#define MAX_SSID_LEN 32
213#define MAX_PWD_LEN 32
214typedef struct __attribute__((packed, aligned(4))) e12_auth_data {
216 uint8_t AUTH_WIFI : 1;
217 uint8_t AUTH_LTE_AP : 1;
227typedef struct __attribute__((packed, aligned(4))) e12_node_state {
230 uint8_t CONFIGURED : 1;
231 uint8_t CONNECTED : 1;
234 uint16_t next_connection_in_sec;
238 uint32_t node_wake_up_ms;
243#define MAX_LOG_SIZE (sizeof(e12_log_evt_t))
245typedef struct __attribute__((packed, aligned(4))) e12_header {
249 uint8_t RESP_EXPECTED : 1;
250 uint8_t IS_RESPONSE : 1;
256#define E12_MAGIC_MARKER_LEN 2
257#define E12_MAGIC_MARKER_1 (0xEC)
258#define E12_MAGIC_MARKER_2 (0xEC ^ 0xCE)
259typedef union __attribute__((packed, aligned(4))) e12_onwire_head {
268#define E12_MAX_CMD_DATA_PAYLOAD (E12_MAX_DATA_PAYLOAD - sizeof(e12_header_t))
269#define E12_MAX_FIRMWARE_VERSION_LEN 32
278 uint8_t response : 1;
289typedef union __attribute__((packed, aligned(4))) e12_packet {
318 } msg_auth_credentials;
325 uint32_t release_type;
334 bool flashing_enabled;
359typedef union __attribute__((packed, aligned(4))) e12_onwire {
364 uint8_t resp_pending : 1;
382typedef struct __attribute__((packed, aligned(4))) e12_device {
409 uint32_t _pin_io_mask;
411 uint32_t _mcu_fwr_version;
414 bool _mcu_flashing_enabled;
474 e12(uint32_t vid, uint32_t pid);
531 _mcu_fwr_version = fwr_version;
533 _protocol = protocol;
534 _mcu_flashing_enabled = enabled;
566 bool set_pin_in(uint8_t pin_number,
bool is_analog =
false);
573 bool set_pin_out(uint8_t pin_number,
bool is_analog =
false);
619 _pin_mask = pin_mask;
620 _pin_io_mask = io_mask;
656 static uint8_t
get_checksum(
const char* data, uint8_t len);
700 virtual int begin(
void* bus, uint8_t e12_addr = 0) = 0;
705 virtual int sleep(uint32_t ms,
void* data) = 0;
706 virtual int log(uint8_t type, uint8_t status, uint32_t ts,
void* data) = 0;
This class represents the base class for the e12 protocol.
Definition e12_protocol.h:403
virtual bool on_ctl_write(uint8_t pin, uint32_t val)
Validates a WRITE request (PIN <- IN only)
Definition e12_protocol.cpp:543
virtual int set_node_auth_credentials(e12_auth_data_t *auth)=0
virtual int on_wakeup()=0
uint32_t _timeout
Timeout value in milliseconds.
Definition e12_protocol.h:421
virtual int sleep(uint32_t ms, void *data)=0
void set_version(uint32_t v)
Sets the version of the e12 protocol.
Definition e12_protocol.h:609
bool is_configured()
Checks if the e12 endpoint is configured.
Definition e12_protocol.h:591
e12_packet_t * decode(e12_onwire_t *pkt, uint8_t data)
Decodes the given data into a packet.
Definition e12_protocol.cpp:450
uint32_t get_fwr_version()
Get the fwr version object.
Definition e12_protocol.h:542
virtual int on_config(const char *s, int len)=0
void set_node_properties(e12_node_properties_t *props)
Sets the properties of the e12 node.
Definition e12_protocol.cpp:143
void flush_buffer(e12_onwire_t *buf)
Flushes the given buffer.
Definition e12_protocol.cpp:298
virtual e12_log_evt_t * get_log_evt()=0
virtual e12_packet_t * get_response(e12_packet_t *p)
Gets a response packet for the given packet.
Definition e12_protocol.cpp:313
void set_product_info(uint32_t vid, uint32_t pid)
Sets the product information.
Definition e12_protocol.h:517
e12_onwire_t * get_encode_buffer()
Gets the buffer for encoding packets.
Definition e12_protocol.h:428
virtual int send(e12_packet_t *buf, bool retry=true)=0
bool get_message(e12_packet_t *data)
Gets a message from the e12 protocol.
Definition e12_protocol.cpp:282
void set_e12_device(e12_device_t *p)
Sets the e12 device.
Definition e12_protocol.h:510
virtual int log(uint8_t type, uint8_t status, uint32_t ts, void *data)=0
e12_node_op_status_t set_node_status(e12_node_op_status_t status, uint32_t data)
Sets the status of the e12 node.
Definition e12_protocol.cpp:513
static uint8_t get_checksum(const char *data, uint8_t len)
Get the checksum object.
Definition e12_protocol.cpp:267
virtual int begin(void *bus, uint8_t e12_addr=0)=0
void set_pin_mask(uint32_t pin_mask, uint32_t io_mask)
Sets the bit mask for pin and io. Recommended to be used by advanced user or else use set_pin_in and ...
Definition e12_protocol.h:618
e12_node_op_status_t get_node_status()
Gets the status of the e12 node.
Definition e12_protocol.cpp:504
int publish_info()
Publish info e.g fwr version, arch, protocol etc.
Definition e12_protocol.cpp:58
uint32_t get_pin_mask()
Get the pin io mask object. top 16bit for analog, lower 16bit for digital.
Definition e12_protocol.cpp:129
e12_onwire_t * get_decode_buffer()
Gets the buffer for decoding packets.
Definition e12_protocol.h:434
virtual uint32_t get_time_ms()=0
~e12()
Destructor for the e12 class.
Definition e12_protocol.cpp:51
virtual int on_get_state(char *s, int len, void *ctx)=0
void set_fwr_details(uint32_t fwr_version, mcu_arch_t arch, mcu_flashing_protocol_t protocol, bool enabled)
Set the vmcu firmware details object.
Definition e12_protocol.h:529
bool set_pin_out(uint8_t pin_number, bool is_analog=false)
Sets the pin as output and type (analog/digital)
Definition e12_protocol.cpp:108
virtual int wakeup_e12_node()
Wakes up the e12 node.
Definition e12_protocol.h:669
bool on_ctl(ctl_op_t op, uint8_t pin, uint32_t val)
function doing basic sanity and scheduling return cmds
Definition e12_protocol.cpp:410
e12_onwire_t * encode(e12_packet_t *data)
Encodes the given data into a packet.
Definition e12_protocol.cpp:73
e12_packet_t * e12_get_packet()
Gets a new packet for the e12 protocol.
Definition e12_protocol.cpp:493
uint32_t get_version()
Gets the version of the e12 protocol.
Definition e12_protocol.h:603
virtual e12_packet_t * get_request(e12_cmd_t cmd, bool response=true, void *data=0)
Gets a request packet for the given command.
Definition e12_protocol.cpp:159
void set_configured(bool status)
Set the configured status for e12 endpoint.
Definition e12_protocol.h:597
virtual int on_receive(e12_packet_t *p)
Handles the received packet.
Definition e12_protocol.cpp:375
virtual int on_ctl_read(uint8_t pin)
allows READ state of any valid pin
Definition e12_protocol.cpp:533
virtual int on_restore_state(const char *s, int len)=0
uint8_t _seq
Sequence number for packets.
Definition e12_protocol.h:422
bool set_pin_in(uint8_t pin_number, bool is_analog=false)
Sets the pin as input and type (analog/digital)
Definition e12_protocol.cpp:89
virtual int print_buffer(e12_onwire_t *buf)
Prints the contents of the buffer.
Definition e12_protocol.h:678
virtual e12_packet_t * read()=0
void set_timeout(uint32_t ms)
Sets the timeout value.
Definition e12_protocol.h:585
uint32_t get_pin_io_mask()
Get the pin io mask object. top 16bit for analog, lower 16bit for digital.
Definition e12_protocol.cpp:137
int publish_profile()
Publish profile info e.g pin configuration.
Definition e12_protocol.cpp:65
struct __attribute__((packed, aligned(4))) e12_log_evt
Definition e12_protocol.h:145
#define MAX_S_LOG_DATA
Definition e12_protocol.h:144
ctl_op_t
Definition e12_protocol.h:89
#define E12_MAX_PKT_SIZE
e12 on wire max packet size
Definition e12_protocol.h:28
#define E12_MAX_CMD_DATA_PAYLOAD
Definition e12_protocol.h:268
e12_release_t
Definition e12_protocol.h:80
@ DEV
Development release.
e12_auth_data_t
Definition e12_protocol.h:225
#define E12_MAX_DATA_PAYLOAD
e12 max payload size in bytes in a e12 packet
Definition e12_protocol.h:34
e12_cmd_t
e12 commands
Definition e12_protocol.h:40
@ CMD_INFO
used to send current VMCU firmware version
@ CMD_NODE_SLEEP
typically sent by e12 node intending to go to sleep
@ CMD_NODE_AWAKE
typically sent by e12 node when it powers on or wake up from sleep
@ CMD_PING
typical ping cmd. responded with a "pong" string
@ CMD_DEBUG_BLINK
initiate a debug blink of led on e12 node
@ CMD_VMCU_OTA
request initiation of VMCU OTA
@ CMD_STATE
used to either send or request vendor state from e12 node
@ CMD_TIME
request current time in ms from e12 node
@ CMD_LOG
used to log a vendor event to e12 node for store and forward
@ CMD_CONFIG
used to request vendor specific configuration
@ CMD_SET_NODE_PROPERTIES
@ CMD_PROFILE
used to send device profile info e.g pins (digital/analog), in/out etc
@ CMD_OTA
request initiation of OTA
@ CMD_AUTH
used to pass authentication credential for e.g WiFi or LTE etc
@ CMD_STATUS
asked to query the e12 node for various status information
@ CMD_SCHEDULE_WAKEUP
request e12 node to wake vendor mcu after certain ms
e12_debug_blink_t
Definition e12_protocol.h:184
e12_err_t
Used to indicate the error status of an operation.
Definition e12_protocol.h:100
e12_onwire_t
Definition e12_protocol.h:371
e12_evt_status_t
Used to indicate the status of an event. This information is typically carried in a log event.
Definition e12_protocol.h:110
#define MAX_PWD_LEN
Definition e12_protocol.h:213
e12_device_t
Definition e12_protocol.h:386
e12_node_properties_t
Definition e12_protocol.h:210
e12_node_op_status_t
Used to indicate the operation status of an e12 node e.g active, sleep, ota etc.
Definition e12_protocol.h:121
e12_data_t
Definition e12_protocol.h:380
#define E12_MAGIC_MARKER_LEN
Definition e12_protocol.h:256
#define MAX_SSID_LEN
Definition e12_protocol.h:212
mcu_arch_t
Supported MCU architecture.
Definition e12_protocol.h:132
e12_ctl_msg_t
Definition e12_protocol.h:284
mcu_flashing_protocol_t
Supported MCU flashing protocols architecture.
Definition e12_protocol.h:137
e12_node_state_t
Definition e12_protocol.h:241
e12_wakeup_data_t
Definition e12_protocol.h:178
e12_header_t
Definition e12_protocol.h:254
#define E12_MAX_FIRMWARE_VERSION_LEN
Definition e12_protocol.h:269
e12_onwire_head_t
Definition e12_protocol.h:266
e12_log_evt_t
Definition e12_protocol.h:174
e12_packet_t
Definition e12_protocol.h:357
ctl_log_t
Definition e12_protocol.h:392