Commit 5775e0702985731797f1dee1d727a5063f58e398

Authored by Imanol-Mikel Barba Sabariego
1 parent 57df708f

--no commit message

BlinkerSchema/Em/Blinker-STUBS.c 0 โ†’ 100644
  1 +/**** DO NOT EDIT -- this file has been automatically generated from @emmoco.com.Blinker on 2014-05-14T16:24:37T ****/
  2 +/**** protocolLevel = 13, toolsVersion = 13.4.1.201311121909 ****/
  3 +
  4 +#include "Blinker.h"
  5 +
  6 +#ifdef Blinker_STUBS_ /* enables optional inclusion of application stubs */
  7 +
  8 +/* Copy the function skeletons below into your own application source file */
  9 +
  10 +void Blinker_connectHandler(void) {
  11 + /* TODO: application is now connected */
  12 +}
  13 +
  14 +void Blinker_disconnectHandler(void) {
  15 + /* TODO: application is now disconnected */
  16 +}
  17 +
  18 +void Blinker_cmd_store(Blinker_cmd_t* input) {
  19 + /* TODO: write resource 'cmd' from 'input' */
  20 +}
  21 +
  22 +void Blinker_count_fetch(Blinker_count_t* output) {
  23 + /* TODO: read resource 'count' into 'output' */
  24 +}
  25 +
  26 +void Blinker_count_store(Blinker_count_t* input) {
  27 + /* TODO: write resource 'count' from 'input' */
  28 +}
  29 +
  30 +void Blinker_delay_fetch(Blinker_delay_t* output) {
  31 + /* TODO: read resource 'delay' into 'output' */
  32 +}
  33 +
  34 +void Blinker_delay_store(Blinker_delay_t* input) {
  35 + /* TODO: write resource 'delay' from 'input' */
  36 +}
  37 +
  38 +void Blinker_ledState_fetch(Blinker_ledState_t* output) {
  39 + /* TODO: read resource 'ledState' into 'output' */
  40 +}
  41 +
  42 +#endif /* application stubs */
... ...
BlinkerSchema/Em/Blinker.c 0 โ†’ 100644
  1 +/**** DO NOT EDIT -- this file has been automatically generated from @emmoco.com.Blinker on 2014-05-14T16:24:37T ****/
  2 +/**** protocolLevel = 13, toolsVersion = 13.4.1.201311121909 ****/
  3 +
  4 +#include "Em_Message.h"
  5 +#include "Blinker.h"
  6 +
  7 +#ifdef __cplusplus
  8 +extern "C" {
  9 +#endif
  10 +
  11 +#define Em_Message_protocolLevel 13
  12 +
  13 +typedef struct Em_App_Message {
  14 + uint8_t dummy[3];
  15 + uint8_t sot;
  16 + Em_Message_Header hdr;
  17 + uint8_t data[20];
  18 +} Em_App_Message;
  19 +
  20 +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))};
  21 +
  22 +const uint8_t Em_App_build[] = {24, 231, 30, 251, 69, 1, 0, 0};
  23 +
  24 +#define Em_App_APP_RESOURCE_COUNT 4
  25 +#define Em_App_SYS_RESOURCE_COUNT 9
  26 +
  27 +#define Em_App_ACCEPT Blinker_accept
  28 +#define Em_App_ACTIVATEPARAMETERS Blinker_activateParameters
  29 +#define Em_App_BROADCASTOFF Blinker_broadcastOff
  30 +#define Em_App_DISCONNECT Blinker_disconnect
  31 +#define Em_App_PAIRINGON Blinker_pairingOn
  32 +#define Em_App_PAIRINGOFF Blinker_pairingOff
  33 +#define Em_App_RESET Blinker_reset
  34 +#define Em_App_SETDEVICENAME Blinker_setDeviceName
  35 +#define Em_App_START Blinker_start
  36 +
  37 +#define Em_App_CONNECTHANDLER Blinker_connectHandler
  38 +#define Em_App_DISCONNECTHANDLER Blinker_disconnectHandler
  39 +
  40 +#define Em_App_MAX_INDICATOR 2
  41 +
  42 +/* BEGIN common code */
  43 +
  44 +enum {Em_App_IDLE, Em_App_STARTING, Em_App_DISCONNECTED, Em_App_CONNECTED};
  45 +
  46 +typedef struct Em_App_Indicator {
  47 + uint8_t dummy[3];
  48 + uint8_t sot;
  49 + Em_Message_Header hdr;
  50 + uint8_t data[Em_Message_INDSIZE];
  51 +} Em_App_Indicator;
  52 +
  53 +union { uint32_t align; Em_App_Message msg; } Em_App_msg_u;
  54 +union { uint32_t align; Em_App_Indicator ind; } Em_App_ind_u;
  55 +#define Em_App_msg Em_App_msg_u.msg
  56 +#define Em_App_ind Em_App_ind_u.ind
  57 +
  58 +void (*Em_App_pdHdlr)(void);
  59 +
  60 +const uint16_t Em_App_endian = 0x0100;
  61 +
  62 +Em_Message_Size Em_App_recvIdx;
  63 +Em_Message_Size Em_App_recvSize;
  64 +Em_Message_Size Em_App_xmitIdx;
  65 +Em_Message_Size Em_App_xmitSize;
  66 +
  67 +uint8_t Em_App_state = Em_App_IDLE;
  68 +int32_t Em_App_fileIndex = 0;
  69 +uint32_t Em_App_xmitMask = 0;
  70 +
  71 +uint8_t* Em_App_valp;
  72 +uint8_t* Em_App_bufp;
  73 +const char* Em_App_desc;
  74 +
  75 +uint8_t* Em_App_inBuf = (uint8_t*)&Em_App_msg.hdr;
  76 +uint8_t* Em_App_outBuf = 0;
  77 +
  78 +uint8_t* _Em_Message_rxBuf = 0;
  79 +uint8_t _Em_Message_rxCnt = 0;
  80 +
  81 +uint8_t* _Em_Message_txBuf = 0;
  82 +uint8_t _Em_Message_txCnt = 0;
  83 +
  84 +#define Em_App_DEVNAME_LEN 9
  85 +const char* Em_App_devName = 0;
  86 +
  87 +void Em_App_fetchDispatch(void);
  88 +void Em_Message_marshallToBuf(uint8_t* valp, uint8_t* bufp, const char* desc);
  89 +void Em_Message_marshallToVal(uint8_t* valp, uint8_t* bufp, const char* desc);
  90 +void Em_App_storeDispatch(void);
  91 +void Em_App_sendIndicator(Em_Message_ResId indId);
  92 +void Em_App_sendResponse(Em_Message_Kind kind, Em_Message_Size size);
  93 +void Em_App_startIndSend(void);
  94 +void Em_App_startResSend(void);
  95 +void Em_App_sysFetchDispatch(void);
  96 +void Em_App_sysStoreDispatch(void);
  97 +bool Em_App_xmitReady(Em_Message_ResId indId);
  98 +
  99 +void Em_Message_nextXmit(void) {
  100 + uint8_t key = Em_Hal_lock();
  101 + if (Em_App_xmitMask != 0) {
  102 + uint8_t i;
  103 + uint32_t m;
  104 + for (i = 0, m = 0x1; i < Em_App_MAX_INDICATOR; i++, m <<= 1) {
  105 + if (Em_App_xmitMask & m) {
  106 + Em_App_xmitMask &= ~m;
  107 + if (i == 0) {
  108 + Em_App_startResSend();
  109 + }
  110 + else {
  111 + Em_App_sendIndicator(i - 1);
  112 + }
  113 + break;
  114 + }
  115 + }
  116 + }
  117 + Em_Hal_unlock(key);
  118 +}
  119 +
  120 +void Em_Message_restart(void) {
  121 + Em_App_START();
  122 +}
  123 +
  124 +void Em_App_ACCEPT(bool enable) {
  125 + if (Em_App_state == Em_App_CONNECTED) {
  126 + return;
  127 + }
  128 + Em_App_ind.sot = 0;
  129 + Em_App_ind.hdr.kind = Em_Message_ACCEPT;
  130 + Em_App_ind.hdr.size = sizeof (Em_Message_Header);
  131 + Em_App_ind.hdr.resId = enable;
  132 + Em_App_startIndSend();
  133 +}
  134 +
  135 +void Em_App_ACTIVATEPARAMETERS(uint8_t group) {
  136 + if (Em_App_state == Em_App_IDLE || Em_App_state == Em_App_STARTING) {
  137 + return;
  138 + }
  139 + Em_App_ind.sot = 0;
  140 + Em_App_ind.hdr.kind = Em_Message_ACTIVE_PARAMS;
  141 + Em_App_ind.hdr.size = sizeof (Em_Message_Header);
  142 + Em_App_ind.hdr.resId = group;
  143 + Em_App_startIndSend();
  144 +}
  145 +
  146 +void Em_App_BROADCASTOFF(void) {
  147 + Em_App_ind.sot = 0;
  148 + Em_App_ind.hdr.kind = Em_Message_INDICATOR;
  149 + Em_App_ind.hdr.size = sizeof (Em_Message_Header);
  150 + Em_App_ind.hdr.resId = 0;
  151 + Em_App_startIndSend();
  152 +}
  153 +
  154 +void Em_App_DISCONNECT(void) {
  155 + if (Em_App_state != Em_App_CONNECTED) {
  156 + return;
  157 + }
  158 + Em_App_state = Em_App_DISCONNECTED;
  159 + Em_App_ind.sot = 0;
  160 + Em_App_ind.hdr.kind = Em_Message_DISCONNECT;
  161 + Em_App_ind.hdr.size = sizeof (Em_Message_Header);
  162 + Em_App_ind.hdr.resId = 0;
  163 + Em_App_startIndSend();
  164 +}
  165 +
  166 +void Em_Message_dispatch(void) {
  167 + if (Em_App_state == Em_App_IDLE) {
  168 + return;
  169 + }
  170 + switch (Em_App_msg.hdr.kind) {
  171 + case Em_Message_CONNECT:
  172 + Em_App_state = Em_App_CONNECTED;
  173 + Em_App_CONNECTHANDLER();
  174 + break;
  175 + case Em_Message_DISCONNECT:
  176 + Em_App_state = Em_App_DISCONNECTED;
  177 + Em_App_DISCONNECTHANDLER();
  178 + break;
  179 + case Em_Message_PAIRING_DONE:
  180 + if (Em_App_pdHdlr) {
  181 + (*Em_App_pdHdlr)();
  182 + }
  183 + break;
  184 + case Em_Message_FETCH:
  185 + if (Em_App_msg.hdr.resId < 0x80) {
  186 + Em_App_fetchDispatch();
  187 + }
  188 + else {
  189 + Em_App_sysFetchDispatch();
  190 + }
  191 + break;
  192 + case Em_Message_STORE:
  193 + if (Em_App_msg.hdr.resId < 0x80) {
  194 + Em_App_storeDispatch();
  195 + }
  196 + else {
  197 + Em_App_sysStoreDispatch();
  198 + }
  199 + break;
  200 + }
  201 +}
  202 +
  203 +void Em_App_marshallToBuf() {
  204 + char ch;
  205 + while ((ch = *Em_App_desc++)) {
  206 + switch (ch) {
  207 + case '0' : {
  208 + *Em_App_bufp++ = 0;
  209 + break;
  210 + }
  211 + case '1' : {
  212 + *Em_App_bufp++ = *Em_App_valp & 0xFF;
  213 + break;
  214 + }
  215 + case '2' : {
  216 + uint16_t v16 = *(uint16_t*)Em_App_valp;
  217 + *Em_App_bufp++ = v16 & 0xFF;
  218 + *Em_App_bufp++ = (v16 >> 8) & 0xFF;
  219 + break;
  220 + }
  221 + case '4' : {
  222 + if (((uint32_t)Em_App_valp & 0x1)) Em_App_valp++;
  223 + uint32_t v32 = *(uint32_t*)Em_App_valp++;
  224 + *Em_App_bufp++ = v32 & 0xFF;
  225 + *Em_App_bufp++ = (v32 >> 8) & 0xFF;
  226 + *Em_App_bufp++ = (v32 >> 16) & 0xFF;
  227 + *Em_App_bufp++ = (v32 >> 24) & 0xFF;
  228 + break;
  229 + }
  230 + }
  231 + Em_App_valp += 1;
  232 + }
  233 +}
  234 +
  235 +void Em_App_marshallToVal() {
  236 + char ch;
  237 + while ((ch = *Em_App_desc++)) {
  238 + switch (ch) {
  239 + case '0' : {
  240 + *Em_App_valp = 0;
  241 + Em_App_bufp += 1;
  242 + break;
  243 + }
  244 + case '1' : {
  245 + *Em_App_valp = *Em_App_bufp++ & 0xFF;
  246 + break;
  247 + }
  248 + case '2' : {
  249 + uint16_t v16 = *Em_App_bufp++ & 0xFF;
  250 + v16 |= (*Em_App_bufp++ << 8);
  251 + *(uint16_t*)Em_App_valp = v16;
  252 + break;
  253 + }
  254 + case '4' : {
  255 + if (((uint32_t)Em_App_valp & 0x1)) Em_App_valp++;
  256 + uint32_t v32 = (uint32_t)*Em_App_bufp++ & 0xFF;
  257 + v32 |= ((uint32_t)*Em_App_bufp++ << 8);
  258 + v32 |= ((uint32_t)*Em_App_bufp++ << 16);
  259 + v32 |= ((uint32_t)*Em_App_bufp++ << 24);
  260 + *(uint32_t*)Em_App_valp++ = v32;
  261 + break;
  262 + }
  263 + }
  264 + Em_App_valp += 1;
  265 + }
  266 +}
  267 +
  268 +void Em_App_PAIRINGOFF(void(*handler)(void)) {
  269 + Em_App_PAIRINGON(0, handler);
  270 +}
  271 +
  272 +void Em_App_PAIRINGON(uint8_t secs, void(*handler)(void)) {
  273 + if (Em_App_state != Em_App_DISCONNECTED) {
  274 + return;
  275 + }
  276 + Em_App_pdHdlr = handler;
  277 + Em_App_ind.sot = 0;
  278 + Em_App_ind.hdr.kind = Em_Message_PAIRING;
  279 + Em_App_ind.hdr.size = sizeof (Em_Message_Header);
  280 + Em_App_ind.hdr.resId = secs;
  281 + Em_App_startIndSend();
  282 +}
  283 +
  284 +void Em_App_RESET(void) {
  285 + Em_Hal_reset();
  286 + _Em_Message_rxBuf = _Em_Message_txBuf = 0;
  287 + _Em_Message_rxCnt = _Em_Message_txCnt = 0;
  288 + Em_App_recvIdx = Em_App_recvSize = Em_App_xmitIdx = Em_App_xmitSize = 0;
  289 + Em_App_state = Em_App_IDLE;
  290 + Em_App_fileIndex = 0;
  291 + Em_App_xmitMask = 0;
  292 +}
  293 +
  294 +void Em_App_SETDEVICENAME(const char* name) {
  295 + Em_App_devName = name;
  296 +}
  297 +
  298 +void Em_App_START(void) {
  299 + Em_App_RESET();
  300 + Em_App_state = Em_App_STARTING;
  301 +}
  302 +
  303 +void Em_App_sendResponse(Em_Message_Kind kind, Em_Message_Size size) {
  304 + if (Em_App_state != Em_App_IDLE) {
  305 + Em_App_msg.sot = 0;
  306 + Em_App_msg.hdr.kind = kind;
  307 + Em_App_msg.hdr.size = size + sizeof (Em_Message_Header);
  308 + if (Em_App_xmitReady(0)) {
  309 + Em_App_startResSend();
  310 + }
  311 + }
  312 +}
  313 +
  314 +void Em_App_startIndSend(void) {
  315 + Em_App_outBuf = (uint8_t*)&Em_App_ind.sot;
  316 + Em_App_xmitSize = Em_App_ind.hdr.size + 1;
  317 + Em_App_xmitIdx = 0;
  318 + Em_Hal_startSend();
  319 +}
  320 +
  321 +void Em_App_startResSend(void) {
  322 + Em_App_outBuf = (uint8_t*)&Em_App_msg.sot;
  323 + Em_App_xmitSize = Em_App_msg.hdr.size + 1;
  324 + Em_App_xmitIdx = 0;
  325 + Em_Hal_startSend();
  326 +}
  327 +
  328 +void Em_App_sysFetchDispatch(void) {
  329 + uint8_t size = 0;
  330 + int i, j;
  331 + switch (Em_App_msg.hdr.resId) {
  332 + case Em_Message_SYS_SCHEMA_HASH:
  333 + for (i = 0; i < sizeof (Em_App_hash); i++) {
  334 + Em_App_msg.data[i] = Em_App_hash[i];
  335 + }
  336 + Em_App_msg.data[sizeof (Em_App_hash)] = *((uint8_t*)&Em_App_endian);
  337 + size = sizeof (Em_App_hash) + 1;
  338 + break;
  339 + case Em_Message_SYS_MCM_NAME:
  340 + if (Em_App_devName) {
  341 + for (i = 0; i < Em_App_DEVNAME_LEN; i++) {
  342 + if ((Em_App_msg.data[i] = Em_App_devName[i]) == 0) {
  343 + break;
  344 + }
  345 + }
  346 + for (j = i; j < Em_App_DEVNAME_LEN; j++) {
  347 + Em_App_msg.data[j] = 0;
  348 + }
  349 + size = Em_App_DEVNAME_LEN;
  350 + }
  351 + break;
  352 + case Em_Message_SYS_EAP_PROTOCOL_LEVEL:
  353 + *((Em_Message_protocolLevel_t*)Em_App_msg.data) = Em_Message_protocolLevel;
  354 + size = sizeof (Em_Message_protocolLevel_t);
  355 + break;
  356 + case Em_Message_SYS_EAP_BUILD_DATE:
  357 + for (i = 0; i < sizeof (Em_App_build); i++) {
  358 + Em_App_msg.data[i] = Em_App_build[i];
  359 + }
  360 + size = sizeof (Em_App_build);
  361 + break;
  362 + case Em_Message_SYS_RESOURCE_COUNT:
  363 + Em_App_msg.data[0] = Em_App_APP_RESOURCE_COUNT;
  364 + Em_App_msg.data[1] = Em_App_SYS_RESOURCE_COUNT;
  365 + size = 2;
  366 + break;
  367 + }
  368 + Em_App_sendResponse(Em_Message_FETCH_DONE, size);
  369 +}
  370 +
  371 +void Em_App_sysStoreDispatch(void) {
  372 + switch (Em_App_msg.hdr.resId) {
  373 + case Em_Message_SYS_FILE_INDEX_RESET:
  374 + Em_App_fileIndex = 0;
  375 + break;
  376 + }
  377 + Em_App_sendResponse(Em_Message_STORE_DONE, 0);
  378 +}
  379 +
  380 +bool Em_App_xmitReady(Em_Message_ResId indId) {
  381 + uint8_t key = Em_Hal_lock();
  382 + bool res = _Em_Message_txBuf == 0 && Em_App_xmitMask == 0;
  383 + if (!res) {
  384 + Em_App_xmitMask |= (1 << indId);
  385 + }
  386 + Em_Hal_unlock(key);
  387 + return res;
  388 +}
  389 +
  390 +/* END common code */
  391 +
  392 +void Em_App_fetchDispatch(void) {
  393 + uint8_t size = 0;
  394 + switch (Em_App_msg.hdr.resId) {
  395 + case 0: {
  396 + break;
  397 + }
  398 + case 2: {
  399 +#ifdef Em_16BIT
  400 + Blinker_count_t val;
  401 + Em_App_valp = (uint8_t*)&val;
  402 + Em_App_bufp = Em_App_msg.data;
  403 + Em_App_desc = "2";
  404 + Blinker_count_fetch(&val);
  405 + Em_App_marshallToBuf();
  406 +#else
  407 + Blinker_count_fetch((void*)Em_App_msg.data);
  408 +#endif
  409 + size = 2;
  410 + break;
  411 + }
  412 + case 3: {
  413 +#ifdef Em_16BIT
  414 + Blinker_delay_t val;
  415 + Em_App_valp = (uint8_t*)&val;
  416 + Em_App_bufp = Em_App_msg.data;
  417 + Em_App_desc = "2";
  418 + Blinker_delay_fetch(&val);
  419 + Em_App_marshallToBuf();
  420 +#else
  421 + Blinker_delay_fetch((void*)Em_App_msg.data);
  422 +#endif
  423 + size = 2;
  424 + break;
  425 + }
  426 + case 4: {
  427 +#ifdef Em_16BIT
  428 + Blinker_ledState_t val;
  429 + Em_App_valp = (uint8_t*)&val;
  430 + Em_App_bufp = Em_App_msg.data;
  431 + Em_App_desc = "1";
  432 + Blinker_ledState_fetch(&val);
  433 + Em_App_marshallToBuf();
  434 +#else
  435 + Blinker_ledState_fetch((void*)Em_App_msg.data);
  436 +#endif
  437 + size = 1;
  438 + break;
  439 + }
  440 + }
  441 + Em_App_sendResponse(Em_Message_FETCH_DONE, size);
  442 +}
  443 +
  444 +void Em_App_storeDispatch(void) {
  445 + switch (Em_App_msg.hdr.resId) {
  446 + case 0: {
  447 + break;
  448 + }
  449 + case 1: {
  450 +#ifdef Em_16BIT
  451 + Blinker_cmd_t val;
  452 + Em_App_valp = (uint8_t*)&val;
  453 + Em_App_bufp = Em_App_msg.data;
  454 + Em_App_desc = "1";
  455 + Em_App_marshallToVal();
  456 + Blinker_cmd_store(&val);
  457 +#else
  458 + Blinker_cmd_store((void*)Em_App_msg.data);
  459 +#endif
  460 + break;
  461 + }
  462 + case 2: {
  463 +#ifdef Em_16BIT
  464 + Blinker_count_t val;
  465 + Em_App_valp = (uint8_t*)&val;
  466 + Em_App_bufp = Em_App_msg.data;
  467 + Em_App_desc = "2";
  468 + Em_App_marshallToVal();
  469 + Blinker_count_store(&val);
  470 +#else
  471 + Blinker_count_store((void*)Em_App_msg.data);
  472 +#endif
  473 + break;
  474 + }
  475 + case 3: {
  476 +#ifdef Em_16BIT
  477 + Blinker_delay_t val;
  478 + Em_App_valp = (uint8_t*)&val;
  479 + Em_App_bufp = Em_App_msg.data;
  480 + Em_App_desc = "2";
  481 + Em_App_marshallToVal();
  482 + Blinker_delay_store(&val);
  483 +#else
  484 + Blinker_delay_store((void*)Em_App_msg.data);
  485 +#endif
  486 + break;
  487 + }
  488 + }
  489 + Em_App_sendResponse(Em_Message_STORE_DONE, 0);
  490 +}
  491 +
  492 +void Em_App_sendIndicator(Em_Message_ResId indId) {
  493 + Em_Message_Size resId = 0;
  494 + Em_Message_Size size = 0;
  495 + switch (indId) {
  496 + case 1: {
  497 +#ifdef Em_16BIT
  498 + Blinker_ledState_t val;
  499 + Em_App_valp = (uint8_t*)&val;
  500 + Em_App_bufp = Em_App_ind.data;
  501 + Em_App_desc = "1";
  502 + Blinker_ledState_fetch(&val);
  503 + Em_App_marshallToBuf();
  504 +#else
  505 + Blinker_ledState_fetch((Blinker_ledState_t*)&Em_App_ind.data);
  506 +#endif
  507 + resId = 4;
  508 + size = 1;
  509 + break;
  510 + }
  511 + }
  512 + Em_App_ind.sot = 0;
  513 + Em_App_ind.hdr.kind = Em_Message_INDICATOR;
  514 + Em_App_ind.hdr.size = sizeof (Em_Message_Header) + size;
  515 + Em_App_ind.hdr.resId = resId;
  516 + Em_App_startIndSend();
  517 +}
  518 +
  519 +void Blinker_ledState_indicate(void) {
  520 + if (Em_App_state == Em_App_CONNECTED && Em_App_xmitReady(1 + 1)) Em_App_sendIndicator(1);
  521 +}
  522 +
  523 +#ifdef __cplusplus
  524 +}
  525 +#endif
  526 +
... ...
BlinkerSchema/Em/Blinker.h 0 โ†’ 100644
  1 +/**** DO NOT EDIT -- this file has been automatically generated from @emmoco.com.Blinker on 2014-05-14T16:24:37T ****/
  2 +/**** protocolLevel = 13, toolsVersion = 13.4.1.201311121909 ****/
  3 +
  4 +#ifndef Blinker__H
  5 +#define Blinker__H
  6 +
  7 +#include "Em_Types.h"
  8 +#include "Em_Message.h"
  9 +
  10 +#ifdef __cplusplus
  11 +extern "C" {
  12 +#endif
  13 +
  14 +/* -------- connection callback functions implemented by the application -------- */
  15 +
  16 +void Blinker_connectHandler(void);
  17 +void Blinker_disconnectHandler(void);
  18 +
  19 +/* -------- resource types defined in the schema -------- */
  20 +
  21 +/* enum Cmd */
  22 +typedef uint8_t Blinker_Cmd;
  23 +#define Blinker_START_CMD 0
  24 +#define Blinker_STOP_CMD 1
  25 +
  26 +/* enum LedState */
  27 +typedef uint8_t Blinker_LedState;
  28 +#define Blinker_LED_OFF 0
  29 +#define Blinker_LED_ON 1
  30 +
  31 +/* -------- resource callback functions implemented by the application -------- */
  32 +
  33 +/* resource cmd */
  34 +typedef Blinker_Cmd Blinker_cmd_t;
  35 +extern void Blinker_cmd_store(Blinker_cmd_t* input);
  36 +
  37 +/* resource count */
  38 +typedef int16_t Blinker_count_t;
  39 +extern void Blinker_count_fetch(Blinker_count_t* output);
  40 +extern void Blinker_count_store(Blinker_count_t* input);
  41 +
  42 +/* resource delay */
  43 +typedef uint16_t Blinker_delay_t;
  44 +#define Blinker_delay_min 500
  45 +#define Blinker_delay_max 2000
  46 +#define Blinker_delay_step 100
  47 +#define Blinker_delay_scale 1000
  48 +extern void Blinker_delay_fetch(Blinker_delay_t* output);
  49 +extern void Blinker_delay_store(Blinker_delay_t* input);
  50 +
  51 +/* resource ledState */
  52 +typedef Blinker_LedState Blinker_ledState_t;
  53 +extern void Blinker_ledState_fetch(Blinker_ledState_t* output);
  54 +extern void Blinker_ledState_indicate(void); /* called by the application */
  55 +
  56 +/* -------- application functions implemented in Blinker.c -------- */
  57 +
  58 +void Blinker_accept(bool enable);
  59 +void Blinker_activateParameters(uint8_t group);
  60 +void Blinker_broadcastOff(void);
  61 +void Blinker_disconnect(void);
  62 +void Blinker_pairingOn(uint8_t secs, void(*handler)(void));
  63 +void Blinker_pairingOff(void(*handler)(void));
  64 +void Blinker_reset(void);
  65 +void Blinker_setDeviceName(const char* name);
  66 +void Blinker_start(void);
  67 +
  68 +#ifdef __cplusplus
  69 +}
  70 +#endif
  71 +
  72 +#endif /* Blinker__H */
... ...
BlinkerSchema/Em/Em_Message.h 0 โ†’ 100644
  1 +#ifndef Em_Message_H_
  2 +#define Em_Message_H_
  3 +
  4 +#include "Em_Types.h"
  5 +
  6 +#ifdef __cplusplus
  7 +extern "C" {
  8 +#endif
  9 +
  10 +/* -------- SRT FUNCTIONS CALLED BY HAL -------- */
  11 +
  12 +static inline bool Em_Message_addByte(uint8_t b);
  13 +extern void Em_Message_dispatch(void);
  14 +static inline bool Em_Message_getByte(uint8_t* bp);
  15 +extern void Em_Message_restart(void);
  16 +static inline bool Em_Message_startRx(void);
  17 +static inline uint8_t Em_Message_startTx(void);
  18 +
  19 +
  20 +/* -------- HAL FUNCTIONS CALLED BY SRT -------- */
  21 +
  22 +extern uint8_t Em_Hal_lock(void);
  23 +extern void Em_Hal_reset(void);
  24 +extern void Em_Hal_startSend(void);
  25 +extern void Em_Hal_unlock(uint8_t key);
  26 +extern void Em_Hal_watchOff(void);
  27 +extern void Em_Hal_watchOn(void);
  28 +
  29 +
  30 +/* -------- MESSAGE FORMAT -------- */
  31 +
  32 +/* protocolLevel #4 */
  33 +#define Em_Message_INDSIZE 4
  34 +
  35 +typedef uint8_t Em_Message_Size;
  36 +typedef uint8_t Em_Message_Kind;
  37 +/* protocolLevel #12 -- split 16-bit resId into <resId, chan> */
  38 +typedef uint8_t Em_Message_ResId;
  39 +typedef uint8_t Em_Message_Chan;
  40 +
  41 +#define Em_Message_NOP 0
  42 +#define Em_Message_FETCH 1
  43 +#define Em_Message_FETCH_DONE 2
  44 +#define Em_Message_STORE 3
  45 +#define Em_Message_STORE_DONE 4
  46 +#define Em_Message_INDICATOR 5
  47 +#define Em_Message_CONNECT 6
  48 +#define Em_Message_DISCONNECT 7
  49 +#define Em_Message_ECHO 8
  50 +/* protocolLevel #3 */
  51 +/* protocolLevel #6 -- rename from BROADCAST to PAIRING */
  52 +#define Em_Message_PAIRING 9
  53 +#define Em_Message_PAIRING_DONE 10
  54 +/* protocolLevel #7 */
  55 +#define Em_Message_OFFLINE 11
  56 +/* protocolLevel #8 */
  57 +#define Em_Message_ACCEPT 12
  58 +/* protocolLevel #13 */
  59 +#define Em_Message_START 13
  60 +#define Em_Message_ACTIVE_PARAMS 14
  61 +
  62 +typedef struct Em_Message_Header {
  63 + Em_Message_Size size;
  64 + Em_Message_Kind kind;
  65 + Em_Message_ResId resId;
  66 + Em_Message_Chan chan;
  67 +} Em_Message_Header;
  68 +
  69 +typedef uint16_t Em_Message_protocolLevel_t;
  70 +
  71 +/* protocolLevel #1 */
  72 +
  73 +/* protocolLevel #10 */
  74 +/* #define Em_Message_SYS_SCHEMA_UUID 0xFF */
  75 +
  76 +#define Em_Message_SYS_MCM_PROTOCOL_LEVEL 0xFE
  77 +#define Em_Message_SYS_EAP_PROTOCOL_LEVEL 0xFD
  78 +#define Em_Message_SYS_EAP_BUILD_DATE 0xFC
  79 +
  80 +/* protocolLevel #2 */
  81 +#define Em_Message_SYS_FILE_INDEX_RESET 0xFB
  82 +
  83 +/* protocolLevel #5 */
  84 +#define Em_Message_SYS_SCHEMA_HASH 0xFA
  85 +
  86 +/* protocolLevel #7 */
  87 +#define Em_Message_SYS_RESOURCE_COUNT 0xF9
  88 +
  89 +/* protocolLevel #9 */
  90 +#define Em_Message_SYS_MOBILE_RSSI 0xF8
  91 +
  92 +/* protocolLevel #11 */
  93 +#define Em_Message_SYS_MCM_DISCONNECT 0xF7
  94 +
  95 +/* protocolLevel #13a */
  96 +#define Em_Message_SYS_MCM_NAME 0xF5
  97 +
  98 +
  99 +/* -------- PRIVATE -------- */
  100 +
  101 +extern void Em_Message_nextXmit(void);
  102 +
  103 +extern uint8_t* Em_App_inBuf;
  104 +extern uint8_t* Em_App_outBuf;
  105 +extern Em_Message_Size Em_App_xmitSize;
  106 +
  107 +extern uint8_t* _Em_Message_rxBuf;
  108 +extern uint8_t _Em_Message_rxCnt;
  109 +
  110 +extern uint8_t* _Em_Message_txBuf;
  111 +extern uint8_t _Em_Message_txCnt;
  112 +
  113 +static inline bool Em_Message_addByte(uint8_t b) {
  114 + if (_Em_Message_rxCnt == 0) {
  115 + if (b == 0) {
  116 + return false;
  117 + }
  118 + _Em_Message_rxCnt = b;
  119 + }
  120 + *_Em_Message_rxBuf++ = b;
  121 + if (--_Em_Message_rxCnt == 0) {
  122 + _Em_Message_rxBuf = 0;
  123 + if (_Em_Message_txBuf == 0) {
  124 + Em_Hal_watchOff();
  125 + }
  126 + return true;
  127 + }
  128 + else {
  129 + return false;
  130 + }
  131 +}
  132 +
  133 +static inline bool Em_Message_getByte(uint8_t* bp) {
  134 + if (_Em_Message_txBuf == 0) {
  135 + return false;
  136 + }
  137 + if (_Em_Message_txCnt == 0) {
  138 + _Em_Message_txCnt = *_Em_Message_txBuf + 1;
  139 + }
  140 + if (--_Em_Message_txCnt > 0) {
  141 + *bp = *_Em_Message_txBuf++;
  142 + return true;
  143 + }
  144 + else {
  145 + _Em_Message_txBuf = 0;
  146 + Em_App_xmitSize = 0;
  147 + Em_Message_nextXmit();
  148 + if (_Em_Message_rxBuf == 0) {
  149 + Em_Hal_watchOff();
  150 + }
  151 + return false;
  152 + }
  153 +}
  154 +
  155 +static inline bool Em_Message_startRx(void) {
  156 + if (_Em_Message_rxBuf == 0) {
  157 + _Em_Message_rxBuf = Em_App_inBuf;
  158 + if (_Em_Message_txBuf == 0) {
  159 + Em_Hal_watchOn();
  160 + }
  161 + return true;
  162 + }
  163 + else {
  164 + return false;
  165 + }
  166 +}
  167 +
  168 +static inline uint8_t Em_Message_startTx(void) {
  169 + _Em_Message_txBuf = Em_App_outBuf + 1;
  170 + _Em_Message_txCnt = 0;
  171 + if (_Em_Message_rxBuf == 0) {
  172 + Em_Hal_watchOn();
  173 + }
  174 + return 0;
  175 +}
  176 +
  177 +
  178 +#ifdef __cplusplus
  179 +}
  180 +#endif
  181 +
  182 +#endif /*Em_Message_H_*/
... ...
BlinkerSchema/Em/Em_Types.h 0 โ†’ 100644
  1 +#ifndef Em_Types_H_
  2 +#define Em_Types_H_
  3 +
  4 +#ifndef Em_NOSTDBOOL
  5 +#include <stdbool.h>
  6 +#endif
  7 +
  8 +#ifndef Em_NOSTDINT
  9 +#include <stdint.h>
  10 +#endif
  11 +
  12 +#ifdef Em_16BIT
  13 +typedef signed char int8_t;
  14 +typedef unsigned char uint8_t;
  15 +#endif
  16 +
  17 +#endif /*Em_Types_H_*/
... ...
BlinkerSchema/Em/blinker.json 0 โ†’ 100644
  1 +{
  2 + "resources": {
  3 + "$eapProtocolLevel": {
  4 + "id": -3,
  5 + "align": 2,
  6 + "attributes": {"readonly": true},
  7 + "type": "u2",
  8 + "access": "r",
  9 + "size": 2
  10 + },
  11 + "count": {
  12 + "id": 2,
  13 + "align": 2,
  14 + "attributes": {"readwrite": true},
  15 + "type": "i2",
  16 + "access": "rw",
  17 + "size": 2
  18 + },
  19 + "$activeGroup": {
  20 + "id": -10,
  21 + "align": 1,
  22 + "pack": 1,
  23 + "attributes": {"readwrite": true},
  24 + "type": "E:system@emmoco.com.System/ParameterGroup",
  25 + "access": "rw",
  26 + "size": 1
  27 + },
  28 + "$mcmDisconnect": {
  29 + "id": -9,
  30 + "align": 1,
  31 + "attributes": {"writeonly": true},
  32 + "type": "u1",
  33 + "access": "w",
  34 + "size": 1
  35 + },
  36 + "$eapBuildDate": {
  37 + "dim": 8,
  38 + "id": -4,
  39 + "align": 1,
  40 + "attributes": {"readonly": true},
  41 + "type": "A8:u1",
  42 + "access": "r",
  43 + "size": 8
  44 + },
  45 + "ledState": {
  46 + "id": 4,
  47 + "align": 1,
  48 + "pack": 1,
  49 + "attributes": {
  50 + "indicator": true,
  51 + "readonly": true
  52 + },
  53 + "type": "E:@emmoco.com.Blinker/LedState",
  54 + "access": "ir",
  55 + "size": 1
  56 + },
  57 + "$resourceCount": {
  58 + "id": -7,
  59 + "align": 1,
  60 + "attributes": {"readonly": true},
  61 + "type": "S:system@emmoco.com.System/ResourceCount",
  62 + "access": "r",
  63 + "size": 2
  64 + },
  65 + "$schemaHash": {
  66 + "dim": 20,
  67 + "id": -6,
  68 + "align": 1,
  69 + "attributes": {"readonly": true},
  70 + "type": "A20:u1",
  71 + "access": "r",
  72 + "size": 20
  73 + },
  74 + "cmd": {
  75 + "id": 1,
  76 + "align": 1,
  77 + "pack": 1,
  78 + "attributes": {"writeonly": true},
  79 + "type": "E:@emmoco.com.Blinker/Cmd",
  80 + "access": "w",
  81 + "size": 1
  82 + },
  83 + "$mcmProtocolLevel": {
  84 + "id": -2,
  85 + "align": 2,
  86 + "attributes": {"readonly": true},
  87 + "type": "u2",
  88 + "access": "r",
  89 + "size": 2
  90 + },
  91 + "$mobileRssi": {
  92 + "id": -8,
  93 + "align": 1,
  94 + "attributes": {"readonly": true},
  95 + "type": "i1",
  96 + "access": "r",
  97 + "size": 1
  98 + },
  99 + "delay": {
  100 + "id": 3,
  101 + "align": 2,
  102 + "pack": 4,
  103 + "attributes": {"readwrite": true},
  104 + "type": "N:0.500000,2.000000,0.100000,3/u2/15",
  105 + "access": "rw",
  106 + "size": 2
  107 + },
  108 + "$fileIndexReset": {
  109 + "id": -5,
  110 + "align": 2,
  111 + "attributes": {"writeonly": true},
  112 + "type": "i2",
  113 + "access": "w",
  114 + "size": 2
  115 + }
  116 + },
  117 + "resourceNamesSys": [
  118 + "$activeGroup",
  119 + "$eapBuildDate",
  120 + "$eapProtocolLevel",
  121 + "$fileIndexReset",
  122 + "$mcmDisconnect",
  123 + "$mcmProtocolLevel",
  124 + "$mobileRssi",
  125 + "$resourceCount",
  126 + "$schemaHash"
  127 + ],
  128 + "manifest": {
  129 + "protocolLevel": 13,
  130 + "hash": [
  131 + 252,
  132 + 123,
  133 + 209,
  134 + 86,
  135 + 230,
  136 + 104,
  137 + 211,
  138 + 8,
  139 + 40,
  140 + 191,
  141 + 19,
  142 + 28,
  143 + 180,
  144 + 183,
  145 + 223,
  146 + 192
  147 + ],
  148 + "toolVersion": "13.4.1.201311121909",
  149 + "name": "Blinker",
  150 + "$$md5": "fc7bd156e668d30828bf131cb4b7dfc0",
  151 + "build": [
  152 + 24,
  153 + 231,
  154 + 30,
  155 + 251,
  156 + 69,
  157 + 1,
  158 + 0,
  159 + 0
  160 + ],
  161 + "date": "2014-05-14T16:24:37T",
  162 + "maxAlign": 2,
  163 + "maxSize": 20,
  164 + "version": "1.0.0"
  165 + },
  166 + "resourceNames": [
  167 + "cmd",
  168 + "count",
  169 + "delay",
  170 + "ledState",
  171 + "$mcmProtocolLevel",
  172 + "$eapProtocolLevel",
  173 + "$eapBuildDate",
  174 + "$fileIndexReset",
  175 + "$schemaHash",
  176 + "$resourceCount",
  177 + "$mobileRssi",
  178 + "$mcmDisconnect",
  179 + "$activeGroup"
  180 + ],
  181 + "attributes": {
  182 + "description": "Blinker, the hello world program for mobile control",
  183 + "version": "1.0.0"
  184 + },
  185 + "resourceNamesApp": [
  186 + "cmd",
  187 + "count",
  188 + "delay",
  189 + "ledState"
  190 + ],
  191 + "types": {
  192 + "@emmoco.com.Blinker/LedState": {
  193 + "values": [
  194 + "LED_OFF",
  195 + "LED_ON"
  196 + ],
  197 + "align": 1,
  198 + "pack": 1,
  199 + "type": "E:@emmoco.com.Blinker/LedState",
  200 + "size": 1
  201 + },
  202 + "system@emmoco.com.System/ResourceCount": {
  203 + "packed": false,
  204 + "align": 1,
  205 + "type": "S:system@emmoco.com.System/ResourceCount",
  206 + "size": 2,
  207 + "fields": [
  208 + {
  209 + "pad": 0,
  210 + "align": 1,
  211 + "name": "app",
  212 + "type": "u1",
  213 + "size": 1
  214 + },
  215 + {
  216 + "pad": 0,
  217 + "align": 1,
  218 + "name": "sys",
  219 + "type": "u1",
  220 + "size": 1
  221 + }
  222 + ]
  223 + },
  224 + "std:i2": {
  225 + "align": 2,
  226 + "size": 2
  227 + },
  228 + "std:i1": {
  229 + "align": 1,
  230 + "size": 1
  231 + },
  232 + "std:u1": {
  233 + "align": 1,
  234 + "size": 1
  235 + },
  236 + "system@emmoco.com.System/ParameterGroup": {
  237 + "values": [
  238 + "GROUP_A",
  239 + "GROUP_B"
  240 + ],
  241 + "align": 1,
  242 + "pack": 1,
  243 + "type": "E:system@emmoco.com.System/ParameterGroup",
  244 + "size": 1
  245 + },
  246 + "@emmoco.com.Blinker/Cmd": {
  247 + "values": [
  248 + "START_CMD",
  249 + "STOP_CMD"
  250 + ],
  251 + "align": 1,
  252 + "pack": 1,
  253 + "type": "E:@emmoco.com.Blinker/Cmd",
  254 + "size": 1
  255 + },
  256 + "std:u2": {
  257 + "align": 2,
  258 + "size": 2
  259 + }
  260 + },
  261 + "imports": {"@emmoco.com.Blinker": true}
  262 +}
0 263 \ No newline at end of file
... ...
BlinkerSchema/Schema-Imports/system@emmoco.com/System.ems 0 โ†’ 100644
  1 +owner = "system@emmoco.com"
  2 +
  3 +schema System {
  4 +
  5 + // protocolLevel #13
  6 +
  7 + enum ParameterGroup {
  8 + GROUP_A, GROUP_B
  9 + }
  10 +
  11 + // protocolLevel #1
  12 +
  13 + uint8 $schemaUuid[16] { // protocolLevel #10 -- invisible to applications
  14 + readonly
  15 + }
  16 +
  17 + uint16 $mcmProtocolLevel {
  18 + readonly
  19 + }
  20 +
  21 + uint16 $eapProtocolLevel {
  22 + readonly
  23 + }
  24 +
  25 + uint8 $eapBuildDate[8] { // protocolLevel #5 -- rename from $eapBuildNumber
  26 + readonly
  27 + }
  28 +
  29 + // protocolLevel #2
  30 +
  31 + int16 $fileIndexReset {
  32 + writeonly
  33 + }
  34 +
  35 + // protocolLevel #5
  36 +
  37 + // protocolLevel #12 -- increase size to 20
  38 +
  39 + uint8 $schemaHash[20] {
  40 + readonly
  41 + }
  42 +
  43 + // protocolLevel #7
  44 +
  45 + struct ResourceCount {
  46 + uint8 app
  47 + uint8 sys
  48 + }
  49 +
  50 + ResourceCount $resourceCount {
  51 + readonly
  52 + }
  53 +
  54 + // protocolLevel #9
  55 +
  56 + int8 $mobileRssi {
  57 + readonly
  58 + }
  59 +
  60 + // protocolLevel #11
  61 +
  62 + uint8 $mcmDisconnect {
  63 + writeonly
  64 + }
  65 +
  66 + // protocolLevel #13
  67 +
  68 + ParameterGroup $activeGroup {
  69 + readwrite
  70 + }
  71 +
  72 +}
... ...