From 5775e0702985731797f1dee1d727a5063f58e398 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Wed, 21 May 2014 13:26:01 +0000 Subject: [PATCH] --- BlinkerSchema/Em/Blinker-STUBS.c | 42 ++++++++++++++++++++++++++++++++++++++++++ BlinkerSchema/Em/Blinker.c | 526 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BlinkerSchema/Em/Blinker.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BlinkerSchema/Em/Em_Message.h | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BlinkerSchema/Em/Em_Types.h | 17 +++++++++++++++++ BlinkerSchema/Em/blinker.json | 262 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ BlinkerSchema/Schema-Imports/system@emmoco.com/System.ems | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1173 insertions(+), 0 deletions(-) create mode 100644 BlinkerSchema/Em/Blinker-STUBS.c create mode 100644 BlinkerSchema/Em/Blinker.c create mode 100644 BlinkerSchema/Em/Blinker.h create mode 100644 BlinkerSchema/Em/Em_Message.h create mode 100644 BlinkerSchema/Em/Em_Types.h create mode 100644 BlinkerSchema/Em/blinker.json create mode 100644 BlinkerSchema/Schema-Imports/system@emmoco.com/System.ems diff --git a/BlinkerSchema/Em/Blinker-STUBS.c b/BlinkerSchema/Em/Blinker-STUBS.c new file mode 100644 index 0000000..00ac639 --- /dev/null +++ b/BlinkerSchema/Em/Blinker-STUBS.c @@ -0,0 +1,42 @@ +/**** DO NOT EDIT -- this file has been automatically generated from @emmoco.com.Blinker on 2014-05-14T16:24:37T ****/ +/**** protocolLevel = 13, toolsVersion = 13.4.1.201311121909 ****/ + +#include "Blinker.h" + +#ifdef Blinker_STUBS_ /* enables optional inclusion of application stubs */ + +/* Copy the function skeletons below into your own application source file */ + +void Blinker_connectHandler(void) { + /* TODO: application is now connected */ +} + +void Blinker_disconnectHandler(void) { + /* TODO: application is now disconnected */ +} + +void Blinker_cmd_store(Blinker_cmd_t* input) { + /* TODO: write resource 'cmd' from 'input' */ +} + +void Blinker_count_fetch(Blinker_count_t* output) { + /* TODO: read resource 'count' into 'output' */ +} + +void Blinker_count_store(Blinker_count_t* input) { + /* TODO: write resource 'count' from 'input' */ +} + +void Blinker_delay_fetch(Blinker_delay_t* output) { + /* TODO: read resource 'delay' into 'output' */ +} + +void Blinker_delay_store(Blinker_delay_t* input) { + /* TODO: write resource 'delay' from 'input' */ +} + +void Blinker_ledState_fetch(Blinker_ledState_t* output) { + /* TODO: read resource 'ledState' into 'output' */ +} + +#endif /* application stubs */ diff --git a/BlinkerSchema/Em/Blinker.c b/BlinkerSchema/Em/Blinker.c new file mode 100644 index 0000000..1c19cf5 --- /dev/null +++ b/BlinkerSchema/Em/Blinker.c @@ -0,0 +1,526 @@ +/**** DO NOT EDIT -- this file has been automatically generated from @emmoco.com.Blinker on 2014-05-14T16:24:37T ****/ +/**** protocolLevel = 13, toolsVersion = 13.4.1.201311121909 ****/ + +#include "Em_Message.h" +#include "Blinker.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define Em_Message_protocolLevel 13 + +typedef struct Em_App_Message { + uint8_t dummy[3]; + uint8_t sot; + Em_Message_Header hdr; + uint8_t data[20]; +} Em_App_Message; + +const uint8_t Em_App_hash[] = {252, 123, 209, 86, 230, 104, 211, 8, 40, 191, 19, 28, 180, 183, 223, 192, 13, 0, ((sizeof(struct{uint8_t f1; uint16_t f2;}) - sizeof(uint16_t)) << 4) | (sizeof(struct{uint8_t f1; uint32_t f2;}) - sizeof(uint32_t))}; + +const uint8_t Em_App_build[] = {24, 231, 30, 251, 69, 1, 0, 0}; + +#define Em_App_APP_RESOURCE_COUNT 4 +#define Em_App_SYS_RESOURCE_COUNT 9 + +#define Em_App_ACCEPT Blinker_accept +#define Em_App_ACTIVATEPARAMETERS Blinker_activateParameters +#define Em_App_BROADCASTOFF Blinker_broadcastOff +#define Em_App_DISCONNECT Blinker_disconnect +#define Em_App_PAIRINGON Blinker_pairingOn +#define Em_App_PAIRINGOFF Blinker_pairingOff +#define Em_App_RESET Blinker_reset +#define Em_App_SETDEVICENAME Blinker_setDeviceName +#define Em_App_START Blinker_start + +#define Em_App_CONNECTHANDLER Blinker_connectHandler +#define Em_App_DISCONNECTHANDLER Blinker_disconnectHandler + +#define Em_App_MAX_INDICATOR 2 + +/* BEGIN common code */ + +enum {Em_App_IDLE, Em_App_STARTING, Em_App_DISCONNECTED, Em_App_CONNECTED}; + +typedef struct Em_App_Indicator { + uint8_t dummy[3]; + uint8_t sot; + Em_Message_Header hdr; + uint8_t data[Em_Message_INDSIZE]; +} Em_App_Indicator; + +union { uint32_t align; Em_App_Message msg; } Em_App_msg_u; +union { uint32_t align; Em_App_Indicator ind; } Em_App_ind_u; +#define Em_App_msg Em_App_msg_u.msg +#define Em_App_ind Em_App_ind_u.ind + +void (*Em_App_pdHdlr)(void); + +const uint16_t Em_App_endian = 0x0100; + +Em_Message_Size Em_App_recvIdx; +Em_Message_Size Em_App_recvSize; +Em_Message_Size Em_App_xmitIdx; +Em_Message_Size Em_App_xmitSize; + +uint8_t Em_App_state = Em_App_IDLE; +int32_t Em_App_fileIndex = 0; +uint32_t Em_App_xmitMask = 0; + +uint8_t* Em_App_valp; +uint8_t* Em_App_bufp; +const char* Em_App_desc; + +uint8_t* Em_App_inBuf = (uint8_t*)&Em_App_msg.hdr; +uint8_t* Em_App_outBuf = 0; + +uint8_t* _Em_Message_rxBuf = 0; +uint8_t _Em_Message_rxCnt = 0; + +uint8_t* _Em_Message_txBuf = 0; +uint8_t _Em_Message_txCnt = 0; + +#define Em_App_DEVNAME_LEN 9 +const char* Em_App_devName = 0; + +void Em_App_fetchDispatch(void); +void Em_Message_marshallToBuf(uint8_t* valp, uint8_t* bufp, const char* desc); +void Em_Message_marshallToVal(uint8_t* valp, uint8_t* bufp, const char* desc); +void Em_App_storeDispatch(void); +void Em_App_sendIndicator(Em_Message_ResId indId); +void Em_App_sendResponse(Em_Message_Kind kind, Em_Message_Size size); +void Em_App_startIndSend(void); +void Em_App_startResSend(void); +void Em_App_sysFetchDispatch(void); +void Em_App_sysStoreDispatch(void); +bool Em_App_xmitReady(Em_Message_ResId indId); + +void Em_Message_nextXmit(void) { + uint8_t key = Em_Hal_lock(); + if (Em_App_xmitMask != 0) { + uint8_t i; + uint32_t m; + for (i = 0, m = 0x1; i < Em_App_MAX_INDICATOR; i++, m <<= 1) { + if (Em_App_xmitMask & m) { + Em_App_xmitMask &= ~m; + if (i == 0) { + Em_App_startResSend(); + } + else { + Em_App_sendIndicator(i - 1); + } + break; + } + } + } + Em_Hal_unlock(key); +} + +void Em_Message_restart(void) { + Em_App_START(); +} + +void Em_App_ACCEPT(bool enable) { + if (Em_App_state == Em_App_CONNECTED) { + return; + } + Em_App_ind.sot = 0; + Em_App_ind.hdr.kind = Em_Message_ACCEPT; + Em_App_ind.hdr.size = sizeof (Em_Message_Header); + Em_App_ind.hdr.resId = enable; + Em_App_startIndSend(); +} + +void Em_App_ACTIVATEPARAMETERS(uint8_t group) { + if (Em_App_state == Em_App_IDLE || Em_App_state == Em_App_STARTING) { + return; + } + Em_App_ind.sot = 0; + Em_App_ind.hdr.kind = Em_Message_ACTIVE_PARAMS; + Em_App_ind.hdr.size = sizeof (Em_Message_Header); + Em_App_ind.hdr.resId = group; + Em_App_startIndSend(); +} + +void Em_App_BROADCASTOFF(void) { + Em_App_ind.sot = 0; + Em_App_ind.hdr.kind = Em_Message_INDICATOR; + Em_App_ind.hdr.size = sizeof (Em_Message_Header); + Em_App_ind.hdr.resId = 0; + Em_App_startIndSend(); +} + +void Em_App_DISCONNECT(void) { + if (Em_App_state != Em_App_CONNECTED) { + return; + } + Em_App_state = Em_App_DISCONNECTED; + Em_App_ind.sot = 0; + Em_App_ind.hdr.kind = Em_Message_DISCONNECT; + Em_App_ind.hdr.size = sizeof (Em_Message_Header); + Em_App_ind.hdr.resId = 0; + Em_App_startIndSend(); +} + +void Em_Message_dispatch(void) { + if (Em_App_state == Em_App_IDLE) { + return; + } + switch (Em_App_msg.hdr.kind) { + case Em_Message_CONNECT: + Em_App_state = Em_App_CONNECTED; + Em_App_CONNECTHANDLER(); + break; + case Em_Message_DISCONNECT: + Em_App_state = Em_App_DISCONNECTED; + Em_App_DISCONNECTHANDLER(); + break; + case Em_Message_PAIRING_DONE: + if (Em_App_pdHdlr) { + (*Em_App_pdHdlr)(); + } + break; + case Em_Message_FETCH: + if (Em_App_msg.hdr.resId < 0x80) { + Em_App_fetchDispatch(); + } + else { + Em_App_sysFetchDispatch(); + } + break; + case Em_Message_STORE: + if (Em_App_msg.hdr.resId < 0x80) { + Em_App_storeDispatch(); + } + else { + Em_App_sysStoreDispatch(); + } + break; + } +} + +void Em_App_marshallToBuf() { + char ch; + while ((ch = *Em_App_desc++)) { + switch (ch) { + case '0' : { + *Em_App_bufp++ = 0; + break; + } + case '1' : { + *Em_App_bufp++ = *Em_App_valp & 0xFF; + break; + } + case '2' : { + uint16_t v16 = *(uint16_t*)Em_App_valp; + *Em_App_bufp++ = v16 & 0xFF; + *Em_App_bufp++ = (v16 >> 8) & 0xFF; + break; + } + case '4' : { + if (((uint32_t)Em_App_valp & 0x1)) Em_App_valp++; + uint32_t v32 = *(uint32_t*)Em_App_valp++; + *Em_App_bufp++ = v32 & 0xFF; + *Em_App_bufp++ = (v32 >> 8) & 0xFF; + *Em_App_bufp++ = (v32 >> 16) & 0xFF; + *Em_App_bufp++ = (v32 >> 24) & 0xFF; + break; + } + } + Em_App_valp += 1; + } +} + +void Em_App_marshallToVal() { + char ch; + while ((ch = *Em_App_desc++)) { + switch (ch) { + case '0' : { + *Em_App_valp = 0; + Em_App_bufp += 1; + break; + } + case '1' : { + *Em_App_valp = *Em_App_bufp++ & 0xFF; + break; + } + case '2' : { + uint16_t v16 = *Em_App_bufp++ & 0xFF; + v16 |= (*Em_App_bufp++ << 8); + *(uint16_t*)Em_App_valp = v16; + break; + } + case '4' : { + if (((uint32_t)Em_App_valp & 0x1)) Em_App_valp++; + uint32_t v32 = (uint32_t)*Em_App_bufp++ & 0xFF; + v32 |= ((uint32_t)*Em_App_bufp++ << 8); + v32 |= ((uint32_t)*Em_App_bufp++ << 16); + v32 |= ((uint32_t)*Em_App_bufp++ << 24); + *(uint32_t*)Em_App_valp++ = v32; + break; + } + } + Em_App_valp += 1; + } +} + +void Em_App_PAIRINGOFF(void(*handler)(void)) { + Em_App_PAIRINGON(0, handler); +} + +void Em_App_PAIRINGON(uint8_t secs, void(*handler)(void)) { + if (Em_App_state != Em_App_DISCONNECTED) { + return; + } + Em_App_pdHdlr = handler; + Em_App_ind.sot = 0; + Em_App_ind.hdr.kind = Em_Message_PAIRING; + Em_App_ind.hdr.size = sizeof (Em_Message_Header); + Em_App_ind.hdr.resId = secs; + Em_App_startIndSend(); +} + +void Em_App_RESET(void) { + Em_Hal_reset(); + _Em_Message_rxBuf = _Em_Message_txBuf = 0; + _Em_Message_rxCnt = _Em_Message_txCnt = 0; + Em_App_recvIdx = Em_App_recvSize = Em_App_xmitIdx = Em_App_xmitSize = 0; + Em_App_state = Em_App_IDLE; + Em_App_fileIndex = 0; + Em_App_xmitMask = 0; +} + +void Em_App_SETDEVICENAME(const char* name) { + Em_App_devName = name; +} + +void Em_App_START(void) { + Em_App_RESET(); + Em_App_state = Em_App_STARTING; +} + +void Em_App_sendResponse(Em_Message_Kind kind, Em_Message_Size size) { + if (Em_App_state != Em_App_IDLE) { + Em_App_msg.sot = 0; + Em_App_msg.hdr.kind = kind; + Em_App_msg.hdr.size = size + sizeof (Em_Message_Header); + if (Em_App_xmitReady(0)) { + Em_App_startResSend(); + } + } +} + +void Em_App_startIndSend(void) { + Em_App_outBuf = (uint8_t*)&Em_App_ind.sot; + Em_App_xmitSize = Em_App_ind.hdr.size + 1; + Em_App_xmitIdx = 0; + Em_Hal_startSend(); +} + +void Em_App_startResSend(void) { + Em_App_outBuf = (uint8_t*)&Em_App_msg.sot; + Em_App_xmitSize = Em_App_msg.hdr.size + 1; + Em_App_xmitIdx = 0; + Em_Hal_startSend(); +} + +void Em_App_sysFetchDispatch(void) { + uint8_t size = 0; + int i, j; + switch (Em_App_msg.hdr.resId) { + case Em_Message_SYS_SCHEMA_HASH: + for (i = 0; i < sizeof (Em_App_hash); i++) { + Em_App_msg.data[i] = Em_App_hash[i]; + } + Em_App_msg.data[sizeof (Em_App_hash)] = *((uint8_t*)&Em_App_endian); + size = sizeof (Em_App_hash) + 1; + break; + case Em_Message_SYS_MCM_NAME: + if (Em_App_devName) { + for (i = 0; i < Em_App_DEVNAME_LEN; i++) { + if ((Em_App_msg.data[i] = Em_App_devName[i]) == 0) { + break; + } + } + for (j = i; j < Em_App_DEVNAME_LEN; j++) { + Em_App_msg.data[j] = 0; + } + size = Em_App_DEVNAME_LEN; + } + break; + case Em_Message_SYS_EAP_PROTOCOL_LEVEL: + *((Em_Message_protocolLevel_t*)Em_App_msg.data) = Em_Message_protocolLevel; + size = sizeof (Em_Message_protocolLevel_t); + break; + case Em_Message_SYS_EAP_BUILD_DATE: + for (i = 0; i < sizeof (Em_App_build); i++) { + Em_App_msg.data[i] = Em_App_build[i]; + } + size = sizeof (Em_App_build); + break; + case Em_Message_SYS_RESOURCE_COUNT: + Em_App_msg.data[0] = Em_App_APP_RESOURCE_COUNT; + Em_App_msg.data[1] = Em_App_SYS_RESOURCE_COUNT; + size = 2; + break; + } + Em_App_sendResponse(Em_Message_FETCH_DONE, size); +} + +void Em_App_sysStoreDispatch(void) { + switch (Em_App_msg.hdr.resId) { + case Em_Message_SYS_FILE_INDEX_RESET: + Em_App_fileIndex = 0; + break; + } + Em_App_sendResponse(Em_Message_STORE_DONE, 0); +} + +bool Em_App_xmitReady(Em_Message_ResId indId) { + uint8_t key = Em_Hal_lock(); + bool res = _Em_Message_txBuf == 0 && Em_App_xmitMask == 0; + if (!res) { + Em_App_xmitMask |= (1 << indId); + } + Em_Hal_unlock(key); + return res; +} + +/* END common code */ + +void Em_App_fetchDispatch(void) { + uint8_t size = 0; + switch (Em_App_msg.hdr.resId) { + case 0: { + break; + } + case 2: { +#ifdef Em_16BIT + Blinker_count_t val; + Em_App_valp = (uint8_t*)&val; + Em_App_bufp = Em_App_msg.data; + Em_App_desc = "2"; + Blinker_count_fetch(&val); + Em_App_marshallToBuf(); +#else + Blinker_count_fetch((void*)Em_App_msg.data); +#endif + size = 2; + break; + } + case 3: { +#ifdef Em_16BIT + Blinker_delay_t val; + Em_App_valp = (uint8_t*)&val; + Em_App_bufp = Em_App_msg.data; + Em_App_desc = "2"; + Blinker_delay_fetch(&val); + Em_App_marshallToBuf(); +#else + Blinker_delay_fetch((void*)Em_App_msg.data); +#endif + size = 2; + break; + } + case 4: { +#ifdef Em_16BIT + Blinker_ledState_t val; + Em_App_valp = (uint8_t*)&val; + Em_App_bufp = Em_App_msg.data; + Em_App_desc = "1"; + Blinker_ledState_fetch(&val); + Em_App_marshallToBuf(); +#else + Blinker_ledState_fetch((void*)Em_App_msg.data); +#endif + size = 1; + break; + } + } + Em_App_sendResponse(Em_Message_FETCH_DONE, size); +} + +void Em_App_storeDispatch(void) { + switch (Em_App_msg.hdr.resId) { + case 0: { + break; + } + case 1: { +#ifdef Em_16BIT + Blinker_cmd_t val; + Em_App_valp = (uint8_t*)&val; + Em_App_bufp = Em_App_msg.data; + Em_App_desc = "1"; + Em_App_marshallToVal(); + Blinker_cmd_store(&val); +#else + Blinker_cmd_store((void*)Em_App_msg.data); +#endif + break; + } + case 2: { +#ifdef Em_16BIT + Blinker_count_t val; + Em_App_valp = (uint8_t*)&val; + Em_App_bufp = Em_App_msg.data; + Em_App_desc = "2"; + Em_App_marshallToVal(); + Blinker_count_store(&val); +#else + Blinker_count_store((void*)Em_App_msg.data); +#endif + break; + } + case 3: { +#ifdef Em_16BIT + Blinker_delay_t val; + Em_App_valp = (uint8_t*)&val; + Em_App_bufp = Em_App_msg.data; + Em_App_desc = "2"; + Em_App_marshallToVal(); + Blinker_delay_store(&val); +#else + Blinker_delay_store((void*)Em_App_msg.data); +#endif + break; + } + } + Em_App_sendResponse(Em_Message_STORE_DONE, 0); +} + +void Em_App_sendIndicator(Em_Message_ResId indId) { + Em_Message_Size resId = 0; + Em_Message_Size size = 0; + switch (indId) { + case 1: { +#ifdef Em_16BIT + Blinker_ledState_t val; + Em_App_valp = (uint8_t*)&val; + Em_App_bufp = Em_App_ind.data; + Em_App_desc = "1"; + Blinker_ledState_fetch(&val); + Em_App_marshallToBuf(); +#else + Blinker_ledState_fetch((Blinker_ledState_t*)&Em_App_ind.data); +#endif + resId = 4; + size = 1; + break; + } + } + Em_App_ind.sot = 0; + Em_App_ind.hdr.kind = Em_Message_INDICATOR; + Em_App_ind.hdr.size = sizeof (Em_Message_Header) + size; + Em_App_ind.hdr.resId = resId; + Em_App_startIndSend(); +} + +void Blinker_ledState_indicate(void) { + if (Em_App_state == Em_App_CONNECTED && Em_App_xmitReady(1 + 1)) Em_App_sendIndicator(1); +} + +#ifdef __cplusplus +} +#endif + diff --git a/BlinkerSchema/Em/Blinker.h b/BlinkerSchema/Em/Blinker.h new file mode 100644 index 0000000..f829bca --- /dev/null +++ b/BlinkerSchema/Em/Blinker.h @@ -0,0 +1,72 @@ +/**** DO NOT EDIT -- this file has been automatically generated from @emmoco.com.Blinker on 2014-05-14T16:24:37T ****/ +/**** protocolLevel = 13, toolsVersion = 13.4.1.201311121909 ****/ + +#ifndef Blinker__H +#define Blinker__H + +#include "Em_Types.h" +#include "Em_Message.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* -------- connection callback functions implemented by the application -------- */ + +void Blinker_connectHandler(void); +void Blinker_disconnectHandler(void); + +/* -------- resource types defined in the schema -------- */ + +/* enum Cmd */ +typedef uint8_t Blinker_Cmd; +#define Blinker_START_CMD 0 +#define Blinker_STOP_CMD 1 + +/* enum LedState */ +typedef uint8_t Blinker_LedState; +#define Blinker_LED_OFF 0 +#define Blinker_LED_ON 1 + +/* -------- resource callback functions implemented by the application -------- */ + +/* resource cmd */ +typedef Blinker_Cmd Blinker_cmd_t; +extern void Blinker_cmd_store(Blinker_cmd_t* input); + +/* resource count */ +typedef int16_t Blinker_count_t; +extern void Blinker_count_fetch(Blinker_count_t* output); +extern void Blinker_count_store(Blinker_count_t* input); + +/* resource delay */ +typedef uint16_t Blinker_delay_t; +#define Blinker_delay_min 500 +#define Blinker_delay_max 2000 +#define Blinker_delay_step 100 +#define Blinker_delay_scale 1000 +extern void Blinker_delay_fetch(Blinker_delay_t* output); +extern void Blinker_delay_store(Blinker_delay_t* input); + +/* resource ledState */ +typedef Blinker_LedState Blinker_ledState_t; +extern void Blinker_ledState_fetch(Blinker_ledState_t* output); +extern void Blinker_ledState_indicate(void); /* called by the application */ + +/* -------- application functions implemented in Blinker.c -------- */ + +void Blinker_accept(bool enable); +void Blinker_activateParameters(uint8_t group); +void Blinker_broadcastOff(void); +void Blinker_disconnect(void); +void Blinker_pairingOn(uint8_t secs, void(*handler)(void)); +void Blinker_pairingOff(void(*handler)(void)); +void Blinker_reset(void); +void Blinker_setDeviceName(const char* name); +void Blinker_start(void); + +#ifdef __cplusplus +} +#endif + +#endif /* Blinker__H */ diff --git a/BlinkerSchema/Em/Em_Message.h b/BlinkerSchema/Em/Em_Message.h new file mode 100644 index 0000000..3bd0d58 --- /dev/null +++ b/BlinkerSchema/Em/Em_Message.h @@ -0,0 +1,182 @@ +#ifndef Em_Message_H_ +#define Em_Message_H_ + +#include "Em_Types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* -------- SRT FUNCTIONS CALLED BY HAL -------- */ + +static inline bool Em_Message_addByte(uint8_t b); +extern void Em_Message_dispatch(void); +static inline bool Em_Message_getByte(uint8_t* bp); +extern void Em_Message_restart(void); +static inline bool Em_Message_startRx(void); +static inline uint8_t Em_Message_startTx(void); + + +/* -------- HAL FUNCTIONS CALLED BY SRT -------- */ + +extern uint8_t Em_Hal_lock(void); +extern void Em_Hal_reset(void); +extern void Em_Hal_startSend(void); +extern void Em_Hal_unlock(uint8_t key); +extern void Em_Hal_watchOff(void); +extern void Em_Hal_watchOn(void); + + +/* -------- MESSAGE FORMAT -------- */ + +/* protocolLevel #4 */ +#define Em_Message_INDSIZE 4 + +typedef uint8_t Em_Message_Size; +typedef uint8_t Em_Message_Kind; +/* protocolLevel #12 -- split 16-bit resId into */ +typedef uint8_t Em_Message_ResId; +typedef uint8_t Em_Message_Chan; + +#define Em_Message_NOP 0 +#define Em_Message_FETCH 1 +#define Em_Message_FETCH_DONE 2 +#define Em_Message_STORE 3 +#define Em_Message_STORE_DONE 4 +#define Em_Message_INDICATOR 5 +#define Em_Message_CONNECT 6 +#define Em_Message_DISCONNECT 7 +#define Em_Message_ECHO 8 +/* protocolLevel #3 */ +/* protocolLevel #6 -- rename from BROADCAST to PAIRING */ +#define Em_Message_PAIRING 9 +#define Em_Message_PAIRING_DONE 10 +/* protocolLevel #7 */ +#define Em_Message_OFFLINE 11 +/* protocolLevel #8 */ +#define Em_Message_ACCEPT 12 +/* protocolLevel #13 */ +#define Em_Message_START 13 +#define Em_Message_ACTIVE_PARAMS 14 + +typedef struct Em_Message_Header { + Em_Message_Size size; + Em_Message_Kind kind; + Em_Message_ResId resId; + Em_Message_Chan chan; +} Em_Message_Header; + +typedef uint16_t Em_Message_protocolLevel_t; + +/* protocolLevel #1 */ + +/* protocolLevel #10 */ +/* #define Em_Message_SYS_SCHEMA_UUID 0xFF */ + +#define Em_Message_SYS_MCM_PROTOCOL_LEVEL 0xFE +#define Em_Message_SYS_EAP_PROTOCOL_LEVEL 0xFD +#define Em_Message_SYS_EAP_BUILD_DATE 0xFC + +/* protocolLevel #2 */ +#define Em_Message_SYS_FILE_INDEX_RESET 0xFB + +/* protocolLevel #5 */ +#define Em_Message_SYS_SCHEMA_HASH 0xFA + +/* protocolLevel #7 */ +#define Em_Message_SYS_RESOURCE_COUNT 0xF9 + +/* protocolLevel #9 */ +#define Em_Message_SYS_MOBILE_RSSI 0xF8 + +/* protocolLevel #11 */ +#define Em_Message_SYS_MCM_DISCONNECT 0xF7 + +/* protocolLevel #13a */ +#define Em_Message_SYS_MCM_NAME 0xF5 + + +/* -------- PRIVATE -------- */ + +extern void Em_Message_nextXmit(void); + +extern uint8_t* Em_App_inBuf; +extern uint8_t* Em_App_outBuf; +extern Em_Message_Size Em_App_xmitSize; + +extern uint8_t* _Em_Message_rxBuf; +extern uint8_t _Em_Message_rxCnt; + +extern uint8_t* _Em_Message_txBuf; +extern uint8_t _Em_Message_txCnt; + +static inline bool Em_Message_addByte(uint8_t b) { + if (_Em_Message_rxCnt == 0) { + if (b == 0) { + return false; + } + _Em_Message_rxCnt = b; + } + *_Em_Message_rxBuf++ = b; + if (--_Em_Message_rxCnt == 0) { + _Em_Message_rxBuf = 0; + if (_Em_Message_txBuf == 0) { + Em_Hal_watchOff(); + } + return true; + } + else { + return false; + } +} + +static inline bool Em_Message_getByte(uint8_t* bp) { + if (_Em_Message_txBuf == 0) { + return false; + } + if (_Em_Message_txCnt == 0) { + _Em_Message_txCnt = *_Em_Message_txBuf + 1; + } + if (--_Em_Message_txCnt > 0) { + *bp = *_Em_Message_txBuf++; + return true; + } + else { + _Em_Message_txBuf = 0; + Em_App_xmitSize = 0; + Em_Message_nextXmit(); + if (_Em_Message_rxBuf == 0) { + Em_Hal_watchOff(); + } + return false; + } +} + +static inline bool Em_Message_startRx(void) { + if (_Em_Message_rxBuf == 0) { + _Em_Message_rxBuf = Em_App_inBuf; + if (_Em_Message_txBuf == 0) { + Em_Hal_watchOn(); + } + return true; + } + else { + return false; + } +} + +static inline uint8_t Em_Message_startTx(void) { + _Em_Message_txBuf = Em_App_outBuf + 1; + _Em_Message_txCnt = 0; + if (_Em_Message_rxBuf == 0) { + Em_Hal_watchOn(); + } + return 0; +} + + +#ifdef __cplusplus +} +#endif + +#endif /*Em_Message_H_*/ diff --git a/BlinkerSchema/Em/Em_Types.h b/BlinkerSchema/Em/Em_Types.h new file mode 100644 index 0000000..d002306 --- /dev/null +++ b/BlinkerSchema/Em/Em_Types.h @@ -0,0 +1,17 @@ +#ifndef Em_Types_H_ +#define Em_Types_H_ + +#ifndef Em_NOSTDBOOL +#include +#endif + +#ifndef Em_NOSTDINT +#include +#endif + +#ifdef Em_16BIT +typedef signed char int8_t; +typedef unsigned char uint8_t; +#endif + +#endif /*Em_Types_H_*/ diff --git a/BlinkerSchema/Em/blinker.json b/BlinkerSchema/Em/blinker.json new file mode 100644 index 0000000..c806052 --- /dev/null +++ b/BlinkerSchema/Em/blinker.json @@ -0,0 +1,262 @@ +{ + "resources": { + "$eapProtocolLevel": { + "id": -3, + "align": 2, + "attributes": {"readonly": true}, + "type": "u2", + "access": "r", + "size": 2 + }, + "count": { + "id": 2, + "align": 2, + "attributes": {"readwrite": true}, + "type": "i2", + "access": "rw", + "size": 2 + }, + "$activeGroup": { + "id": -10, + "align": 1, + "pack": 1, + "attributes": {"readwrite": true}, + "type": "E:system@emmoco.com.System/ParameterGroup", + "access": "rw", + "size": 1 + }, + "$mcmDisconnect": { + "id": -9, + "align": 1, + "attributes": {"writeonly": true}, + "type": "u1", + "access": "w", + "size": 1 + }, + "$eapBuildDate": { + "dim": 8, + "id": -4, + "align": 1, + "attributes": {"readonly": true}, + "type": "A8:u1", + "access": "r", + "size": 8 + }, + "ledState": { + "id": 4, + "align": 1, + "pack": 1, + "attributes": { + "indicator": true, + "readonly": true + }, + "type": "E:@emmoco.com.Blinker/LedState", + "access": "ir", + "size": 1 + }, + "$resourceCount": { + "id": -7, + "align": 1, + "attributes": {"readonly": true}, + "type": "S:system@emmoco.com.System/ResourceCount", + "access": "r", + "size": 2 + }, + "$schemaHash": { + "dim": 20, + "id": -6, + "align": 1, + "attributes": {"readonly": true}, + "type": "A20:u1", + "access": "r", + "size": 20 + }, + "cmd": { + "id": 1, + "align": 1, + "pack": 1, + "attributes": {"writeonly": true}, + "type": "E:@emmoco.com.Blinker/Cmd", + "access": "w", + "size": 1 + }, + "$mcmProtocolLevel": { + "id": -2, + "align": 2, + "attributes": {"readonly": true}, + "type": "u2", + "access": "r", + "size": 2 + }, + "$mobileRssi": { + "id": -8, + "align": 1, + "attributes": {"readonly": true}, + "type": "i1", + "access": "r", + "size": 1 + }, + "delay": { + "id": 3, + "align": 2, + "pack": 4, + "attributes": {"readwrite": true}, + "type": "N:0.500000,2.000000,0.100000,3/u2/15", + "access": "rw", + "size": 2 + }, + "$fileIndexReset": { + "id": -5, + "align": 2, + "attributes": {"writeonly": true}, + "type": "i2", + "access": "w", + "size": 2 + } + }, + "resourceNamesSys": [ + "$activeGroup", + "$eapBuildDate", + "$eapProtocolLevel", + "$fileIndexReset", + "$mcmDisconnect", + "$mcmProtocolLevel", + "$mobileRssi", + "$resourceCount", + "$schemaHash" + ], + "manifest": { + "protocolLevel": 13, + "hash": [ + 252, + 123, + 209, + 86, + 230, + 104, + 211, + 8, + 40, + 191, + 19, + 28, + 180, + 183, + 223, + 192 + ], + "toolVersion": "13.4.1.201311121909", + "name": "Blinker", + "$$md5": "fc7bd156e668d30828bf131cb4b7dfc0", + "build": [ + 24, + 231, + 30, + 251, + 69, + 1, + 0, + 0 + ], + "date": "2014-05-14T16:24:37T", + "maxAlign": 2, + "maxSize": 20, + "version": "1.0.0" + }, + "resourceNames": [ + "cmd", + "count", + "delay", + "ledState", + "$mcmProtocolLevel", + "$eapProtocolLevel", + "$eapBuildDate", + "$fileIndexReset", + "$schemaHash", + "$resourceCount", + "$mobileRssi", + "$mcmDisconnect", + "$activeGroup" + ], + "attributes": { + "description": "Blinker, the hello world program for mobile control", + "version": "1.0.0" + }, + "resourceNamesApp": [ + "cmd", + "count", + "delay", + "ledState" + ], + "types": { + "@emmoco.com.Blinker/LedState": { + "values": [ + "LED_OFF", + "LED_ON" + ], + "align": 1, + "pack": 1, + "type": "E:@emmoco.com.Blinker/LedState", + "size": 1 + }, + "system@emmoco.com.System/ResourceCount": { + "packed": false, + "align": 1, + "type": "S:system@emmoco.com.System/ResourceCount", + "size": 2, + "fields": [ + { + "pad": 0, + "align": 1, + "name": "app", + "type": "u1", + "size": 1 + }, + { + "pad": 0, + "align": 1, + "name": "sys", + "type": "u1", + "size": 1 + } + ] + }, + "std:i2": { + "align": 2, + "size": 2 + }, + "std:i1": { + "align": 1, + "size": 1 + }, + "std:u1": { + "align": 1, + "size": 1 + }, + "system@emmoco.com.System/ParameterGroup": { + "values": [ + "GROUP_A", + "GROUP_B" + ], + "align": 1, + "pack": 1, + "type": "E:system@emmoco.com.System/ParameterGroup", + "size": 1 + }, + "@emmoco.com.Blinker/Cmd": { + "values": [ + "START_CMD", + "STOP_CMD" + ], + "align": 1, + "pack": 1, + "type": "E:@emmoco.com.Blinker/Cmd", + "size": 1 + }, + "std:u2": { + "align": 2, + "size": 2 + } + }, + "imports": {"@emmoco.com.Blinker": true} +} \ No newline at end of file diff --git a/BlinkerSchema/Schema-Imports/system@emmoco.com/System.ems b/BlinkerSchema/Schema-Imports/system@emmoco.com/System.ems new file mode 100644 index 0000000..9601635 --- /dev/null +++ b/BlinkerSchema/Schema-Imports/system@emmoco.com/System.ems @@ -0,0 +1,72 @@ +owner = "system@emmoco.com" + +schema System { + + // protocolLevel #13 + + enum ParameterGroup { + GROUP_A, GROUP_B + } + + // protocolLevel #1 + + uint8 $schemaUuid[16] { // protocolLevel #10 -- invisible to applications + readonly + } + + uint16 $mcmProtocolLevel { + readonly + } + + uint16 $eapProtocolLevel { + readonly + } + + uint8 $eapBuildDate[8] { // protocolLevel #5 -- rename from $eapBuildNumber + readonly + } + + // protocolLevel #2 + + int16 $fileIndexReset { + writeonly + } + + // protocolLevel #5 + + // protocolLevel #12 -- increase size to 20 + + uint8 $schemaHash[20] { + readonly + } + + // protocolLevel #7 + + struct ResourceCount { + uint8 app + uint8 sys + } + + ResourceCount $resourceCount { + readonly + } + + // protocolLevel #9 + + int8 $mobileRssi { + readonly + } + + // protocolLevel #11 + + uint8 $mcmDisconnect { + writeonly + } + + // protocolLevel #13 + + ParameterGroup $activeGroup { + readwrite + } + +} -- libgit2 0.22.2