ots-m2m / sew-lwm2m-reference-design

A reference implementation of the South East Water LWM2M water meter design
Mozilla Public License 2.0
7 stars 0 forks source link

Convert Event And Alarm to use definite cbor array markup #22

Closed mofosyne closed 7 years ago

mofosyne commented 7 years ago

  /*  Testing current state alarm
  ********************************/
  { // Verification
    uint8_t old_payload[] = {0x9f, 0x18, 0x7b, 0x01, 0x19, 0x02, 0x9a, 0x01, 0xff};
    uint8_t new_payload[] = {0x84, 0x18, 0x7b, 0x01, 0x19, 0x02, 0x9a, 0x01};
  }

  /*  Testing for timestamp overflow using current state alarm scenario
  **********************************************************************/
  { // Verification
    char old_payload[] = {0x9f, 0x18, 0x7b, 0x01, 0x1a, 0x58, 0xbc, 0xeb, 0x11, 0x01, 0xff};
    char new_payload[] = {0x84, 0x18, 0x7b, 0x01, 0x1a, 0x58, 0xbc, 0xeb, 0x11, 0x01};
  }

  /*  Alarm state change log scenario
  *************************************************************************/
  { // Verification
    char old_payload[] = {
                        0x9f, 0x18, 0x7b, 0x02, 0x9f, 0x9f, 0x1a, 0x58, 0xbc,
                        0xeb, 0x0f, 0x00, 0x01, 0xff, 0x9f, 0x1a, 0x58, 0xbc,
                        0xeb, 0x10, 0x18, 0xc8, 0x01, 0xff, 0x9f, 0x1a, 0x58,
                        0xbc, 0xeb, 0x11, 0x19, 0x01, 0x90, 0x01, 0xff, 0xff,
                        0xff
                      };
    char new_payload[] = {
                        0x83, 0x18, 0x7b, 0x02, 0x83, 0x82, 0x1a, 0x58, 0xbc,                                                                     
                        0xeb, 0x0f, 0x00, 0x82, 0x1a, 0x58, 0xbc, 0xeb, 0x10,                                                                     
                        0x18, 0xc8, 0x82, 0x1a, 0x58, 0xbc, 0xeb, 0x11, 0x19,                                                                     
                        0x01, 0x90
                      };
  }

  /*  Event log scenario
  *************************************************************************/

  { // Verification
    char old_payload[] = {
                        0x9f, 0x18, 0x7b, 0x03, 0x9f, 0x9f, 0x1a, 0x58, 0xbc,
                        0xeb, 0x0f, 0x00, 0x01, 0xff, 0x9f, 0x1a, 0x58, 0xbc,
                        0xeb, 0x10, 0x18, 0xc8, 0x01, 0xff, 0x9f, 0x1a, 0x58,
                        0xbc, 0xeb, 0x11, 0x19, 0x01, 0x90, 0x01, 0xff, 0xff,
                        0xff
                      };
    char new_payload[] = {
                        0x83, 0x18, 0x7b, 0x03, 0x83, 0x82, 0x1a, 0x58, 0xbc,                                                                     
                        0xeb, 0x0f, 0x00, 0x82, 0x1a, 0x58, 0xbc, 0xeb, 0x10,                                                                     
                        0x18, 0xc8, 0x82, 0x1a, 0x58, 0xbc, 0xeb, 0x11, 0x19,                                                                     
                        0x01, 0x90
                      };
  }
mofosyne commented 7 years ago

CBOR Payload Adjustments (10th Aug 2017)

Array marker now uses definite size (Confirmed via cbor.me )

Event And Alarm Base

Current State Change

Alarm State Change

Event Log

Interval Data Base

Single Block

Multi Block (skipped interval)


Above stats was generated by:

``` #include // printf() #include // isprint() #include // strtok_r() #include // sscanf() /* clang hello.c -o hello && chmod +x hello && ./hello */ #define ARGTOINT(arg, var) if((argc-1) >= arg){sscanf(argv[arg], "%d", &var);} void payload_stat(int old, int new, char *desc); int main(int argc, char *argv[]) { for (int i = 0 ; i < argc ; i++) { printf("%s ",argv[i]); } printf("\n\n\n"); printf("CBOR Payload Adjustments (10th Aug 2017)\n"); printf("========================================\n"); printf("\n Array marker now uses definite size (Confirmed via cbor.me )\n"); printf("\n\n## Event And Alarm Base\n"); { /* Event And Alarm Base - Current State Change */ char old_payload[] = {0x9f, 0x18, 0x7b, 0x01, 0x1a, 0x58, 0xbc, 0xeb, 0x11, 0x01, 0xff}; char new_payload[] = {0x84, 0x18, 0x7b, 0x01, 0x1a, 0x58, 0xbc, 0xeb, 0x11, 0x01}; payload_stat(sizeof(old_payload), sizeof(new_payload), "Current State Change"); printf("- Old: `[123, 1, 1488775953, 1]`\n"); printf("- New: `[123, 1, 1488775953, 1]`\n"); } { /* Event And Alarm Base - Alarm State Change */ char old_payload[] = { 0x9f, 0x18, 0x7b, 0x02, 0x9f, 0x9f, 0x1a, 0x58, 0xbc, 0xeb, 0x0f, 0x00, 0x01, 0xff, 0x9f, 0x1a, 0x58, 0xbc, 0xeb, 0x10, 0x18, 0xc8, 0x01, 0xff, 0x9f, 0x1a, 0x58, 0xbc, 0xeb, 0x11, 0x19, 0x01, 0x90, 0x01, 0xff, 0xff, 0xff }; char new_payload[] = { 0x83, 0x18, 0x7b, 0x02, 0x83, 0x83, 0x1a, 0x58, 0xbc, 0xeb, 0x0f, 0x01, 0x00, 0x83, 0x1a, 0x58, 0xbc, 0xeb, 0x10, 0x01, 0x18, 0xc8, 0x83, 0x1a, 0x58, 0xbc, 0xeb, 0x11, 0x01, 0x19, 0x01, 0x90 }; payload_stat(sizeof(old_payload), sizeof(new_payload), "Alarm State Change"); printf("- Old: `[123, 2, [[1488775951, 0, 1], [1488775952, 200, 1], [1488775953, 400, 1]]]`\n"); printf("- New: `[123, 2, [[1488775951, 1, 0], [1488775952, 1, 200], [1488775953, 1, 400]]]`\n"); } { /* Event And Alarm Base - Event Log */ char old_payload[] = { 0x9f, 0x18, 0x7b, 0x03, 0x9f, 0x9f, 0x1a, 0x58, 0xbc, 0xeb, 0x0f, 0x00, 0x01, 0xff, 0x9f, 0x1a, 0x58, 0xbc, 0xeb, 0x10, 0x18, 0xc8, 0x01, 0xff, 0x9f, 0x1a, 0x58, 0xbc, 0xeb, 0x11, 0x19, 0x01, 0x90, 0x01, 0xff, 0xff, 0xff }; char new_payload[] = { 0x83, 0x18, 0x7b, 0x03, 0x83, 0x83, 0x1a, 0x58, 0xbc, 0xeb, 0x0f, 0x01, 0x00, 0x83, 0x1a, 0x58, 0xbc, 0xeb, 0x10, 0x01, 0x18, 0xc8, 0x83, 0x1a, 0x58, 0xbc, 0xeb, 0x11, 0x01, 0x19, 0x01, 0x90 }; payload_stat(sizeof(old_payload), sizeof(new_payload), "Event Log"); printf("- Old: `[123, 3, [[1488775951, 0, 1], [1488775952, 200, 1], [1488775953, 400, 1]]]`\n"); printf("- New: `[123, 3, [[1488775951, 1, 0], [1488775952, 1, 200], [1488775953, 1, 400]]]`\n"); } printf("\n\n## Interval Data Base\n"); { /* Interval Data Base - Single Block */ char old_payload[] = { 0x9f, 0x19, 0x1f, 0x4a, 0x00, 0x9f, 0x9f, 0x1a, 0x05, 0x26, 0x5c, 0x00, 0x1a, 0x00, 0x01, 0x51, 0x80, 0x9f, 0x9f, 0x01, 0xff, 0x9f, 0x02, 0xff, 0x9f, 0x03, 0xff, 0x9f, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff }; char new_payload[] = { 0x83, 0x19, 0x1f, 0x4a, 0x00, 0x83, 0x1a, 0x05, 0x26, 0x5c, 0x00, 0x1a, 0x00, 0x01, 0x51, 0x80, 0x84, 0x01, 0x02, 0x03, 0x04 }; payload_stat(sizeof(old_payload), sizeof(new_payload), "Single Block"); printf("- Old: `[8010, 0, [[86400000, 86400, [[1], [2], [3], [4]]]]]`\n"); printf("- New: `[8010, 0, [86400000, 86400, [1, 2, 3, 4]]]`\n"); } { /* Interval Data Base - Multi Block (skipped interval) */ char old_payload[] = { 0x9f, 0x19, 0x1f, 0x4a, 0x00, 0x9f, 0x9f, 0x1a, 0x05, 0x26, 0x5c, 0x00, 0x1a, 0x00, 0x01, 0x51, 0x80, 0x9f, 0x9f, 0x01, 0xff, 0x9f, 0x02, 0xff, 0xff, 0xff, 0x9f, 0x1a, 0x05, 0x2a, 0x50, 0x80, 0x1a, 0x00, 0x01, 0x51, 0x80, 0x9f, 0x9f, 0x03, 0xff, 0x9f, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff }; char new_payload[] = { 0x83, 0x19, 0x1f, 0x4a, 0x00, 0x82, 0x83, 0x1a, 0x05, 0x26, 0x5c, 0x00, 0x1a, 0x00, 0x01, 0x51, 0x80, 0x82, 0x01, 0x02, 0x83, 0x1a, 0x05, 0x2a, 0x50, 0x80, 0x1a, 0x00, 0x01, 0x51, 0x80, 0x82, 0x03, 0x04 }; payload_stat(sizeof(old_payload), sizeof(new_payload), "Multi Block (skipped interval) "); printf("- Old: `[8010, 0, [[86400000, 86400, [[1], [2]]], [86659200, 86400, [[3], [4]]]]]`\n"); printf("- New: `[8010, 0, [[86400000, 86400, [1, 2]], [86659200, 86400, [3, 4]]]]`\n"); } return 0; } void payload_stat(int old, int new, char *desc) { int bytesaved = old-new; float percent_reduction = ((float)bytesaved / (float)old) * 100; printf("\n### %s\n", desc); printf("- Old: %dB | New: %dB | Saved: %dB | **%0.2f%% reduction**\n", old, new, bytesaved, percent_reduction); } ```