![](/media/cache/profiles/dcee66ccb49a492ae42c446c0cc01b3a.jpg.50x50_q85.jpg)
Axeda Ready Demo for Freescale FRDM-KL46Z as accident alert system
Dependencies: FRDM_MMA8451Q KL46Z-USBHost MAG3110 SocketModem TSI mbed FATFileSystem
Fork of AxedaGo-Freescal_FRDM-KL46Z by
AMMPC/axSerializer.c@0:65004368569c, 2014-07-01 (annotated)
- Committer:
- AxedaCorp
- Date:
- Tue Jul 01 21:31:54 2014 +0000
- Revision:
- 0:65004368569c
Made initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AxedaCorp | 0:65004368569c | 1 | /************************************************************************************/ |
AxedaCorp | 0:65004368569c | 2 | /* axSerializer.c */ |
AxedaCorp | 0:65004368569c | 3 | /* �2013 Axeda Corporation */ |
AxedaCorp | 0:65004368569c | 4 | /* */ |
AxedaCorp | 0:65004368569c | 5 | /* Defines methods for transposing the data in domain objects into a serialized */ |
AxedaCorp | 0:65004368569c | 6 | /* encoding for transmission to the Platform Endpoint. This is a platform independent*/ |
AxedaCorp | 0:65004368569c | 7 | /* implementation that can be applied to any device that supports ANSI C. */ |
AxedaCorp | 0:65004368569c | 8 | /* */ |
AxedaCorp | 0:65004368569c | 9 | /************************************************************************************/ |
AxedaCorp | 0:65004368569c | 10 | #include "axSerializer.h" |
AxedaCorp | 0:65004368569c | 11 | |
AxedaCorp | 0:65004368569c | 12 | #define REG_ID 0 |
AxedaCorp | 0:65004368569c | 13 | #define REG_MODEL_NUMBER 1 |
AxedaCorp | 0:65004368569c | 14 | #define REG_SERIAL_NUMBER 2 |
AxedaCorp | 0:65004368569c | 15 | #define REG_TENANT 3 |
AxedaCorp | 0:65004368569c | 16 | #define REG_PING 4 |
AxedaCorp | 0:65004368569c | 17 | #define REG_KEY 5 |
AxedaCorp | 0:65004368569c | 18 | |
AxedaCorp | 0:65004368569c | 19 | #define DATA_ALERTS 0 |
AxedaCorp | 0:65004368569c | 20 | #define DATA_EVENTS 1 |
AxedaCorp | 0:65004368569c | 21 | #define DATA_DATA 2 |
AxedaCorp | 0:65004368569c | 22 | #define DATA_LOCATIONS 3 |
AxedaCorp | 0:65004368569c | 23 | #define DATA_ITEMS 4 |
AxedaCorp | 0:65004368569c | 24 | |
AxedaCorp | 0:65004368569c | 25 | #define PKG_STATUS 0 |
AxedaCorp | 0:65004368569c | 26 | #define PKG_ERROR 1 |
AxedaCorp | 0:65004368569c | 27 | |
AxedaCorp | 0:65004368569c | 28 | #define ALERT_SEV 0 |
AxedaCorp | 0:65004368569c | 29 | #define ALERT_CAUSE 1 |
AxedaCorp | 0:65004368569c | 30 | #define ALERT_REASON 2 |
AxedaCorp | 0:65004368569c | 31 | |
AxedaCorp | 0:65004368569c | 32 | #define COM_TIME 0 |
AxedaCorp | 0:65004368569c | 33 | #define COM_PRIORITY 1 |
AxedaCorp | 0:65004368569c | 34 | #define COM_NAME 2 |
AxedaCorp | 0:65004368569c | 35 | #define COM_DESCRIPTION 3 |
AxedaCorp | 0:65004368569c | 36 | |
AxedaCorp | 0:65004368569c | 37 | //#define EVENT_NAME 1 |
AxedaCorp | 0:65004368569c | 38 | //#define EVENT_DESC 0 |
AxedaCorp | 0:65004368569c | 39 | |
AxedaCorp | 0:65004368569c | 40 | #define LOC_LAT 0 |
AxedaCorp | 0:65004368569c | 41 | #define LOC_LON 1 |
AxedaCorp | 0:65004368569c | 42 | #define LOC_ALT 2 |
AxedaCorp | 0:65004368569c | 43 | |
AxedaCorp | 0:65004368569c | 44 | int terse_enable=AX_TRUE; |
AxedaCorp | 0:65004368569c | 45 | |
AxedaCorp | 0:65004368569c | 46 | const char *commonKW[]= {"time", "priority", "name", "description" }; |
AxedaCorp | 0:65004368569c | 47 | const char *dataKW[]={ "alerts", "events", "data", "locations", "dataItems"}; |
AxedaCorp | 0:65004368569c | 48 | const char *registrationKW[]= {"id", "mn", "sn", "tn", "pingRate", "key"}; |
AxedaCorp | 0:65004368569c | 49 | const char *alertKW[]= {"severity","cause", "reason" }; |
AxedaCorp | 0:65004368569c | 50 | const char *locationKW[]= {"latitude", "longitude", "altitude"}; |
AxedaCorp | 0:65004368569c | 51 | const char *pkgStatusKW[]={"status", "error"}; |
AxedaCorp | 0:65004368569c | 52 | |
AxedaCorp | 0:65004368569c | 53 | const char *terse_commonKW[]= {"t", "dp", "n", "d"}; |
AxedaCorp | 0:65004368569c | 54 | const char *terse_dataKW[]={ "alerts", "events", "data", "locations", "di"}; |
AxedaCorp | 0:65004368569c | 55 | const char *terse_registrationKW[]= {"id", "mn", "sn", "tn", "pr", "k"}; |
AxedaCorp | 0:65004368569c | 56 | const char *terse_alertKW[]= {"sv", "cn", "cr" }; |
AxedaCorp | 0:65004368569c | 57 | const char *terse_locationKW[]= {"lat", "lon", "alt"}; |
AxedaCorp | 0:65004368569c | 58 | const char *terse_pkgStatusKW[]={"st", "err"}; |
AxedaCorp | 0:65004368569c | 59 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 60 | /*dataSet2JSON() */ |
AxedaCorp | 0:65004368569c | 61 | /* */ |
AxedaCorp | 0:65004368569c | 62 | /*Takes an array of ax_dataItem structs and creates JSON to represent them in the AMMP-json */ |
AxedaCorp | 0:65004368569c | 63 | /*protocol. The return type will be a CJSON pointer which can then be rendered into an actual */ |
AxedaCorp | 0:65004368569c | 64 | /*JSON string. The JSON pointer will need to be free'd when you're done. If there are zero data */ |
AxedaCorp | 0:65004368569c | 65 | /*items in the array then this method will return an empty JSON array pointer. */ |
AxedaCorp | 0:65004368569c | 66 | /* */ |
AxedaCorp | 0:65004368569c | 67 | /*NOTE: If any array spots are left empty they will only be ignored if theyre are NULL. Junk */ |
AxedaCorp | 0:65004368569c | 68 | /* values from left over data will cause seg faults. NULL your empty pointers!!! */ |
AxedaCorp | 0:65004368569c | 69 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 70 | //takes data item set, not longer just data item structs. |
AxedaCorp | 0:65004368569c | 71 | cJSON *dataSet2JSON(ax_dataSet *di[], int len, int terse_on) |
AxedaCorp | 0:65004368569c | 72 | { |
AxedaCorp | 0:65004368569c | 73 | cJSON *root, *child_obj, *dis=NULL; |
AxedaCorp | 0:65004368569c | 74 | int ctr=0; |
AxedaCorp | 0:65004368569c | 75 | |
AxedaCorp | 0:65004368569c | 76 | ax_dataSet *curr=NULL; |
AxedaCorp | 0:65004368569c | 77 | ax_dataNode *currNode; |
AxedaCorp | 0:65004368569c | 78 | root=cJSON_CreateArray(); |
AxedaCorp | 0:65004368569c | 79 | |
AxedaCorp | 0:65004368569c | 80 | for(ctr=0; ctr<len; ctr++) |
AxedaCorp | 0:65004368569c | 81 | { |
AxedaCorp | 0:65004368569c | 82 | curr=di[ctr]; |
AxedaCorp | 0:65004368569c | 83 | if((curr!=NULL)&&(curr->dataNode_ct>0)) //If this set doesn't have any data in it, don't include it. |
AxedaCorp | 0:65004368569c | 84 | { |
AxedaCorp | 0:65004368569c | 85 | cJSON_AddItemToArray(root, child_obj=cJSON_CreateObject()); |
AxedaCorp | 0:65004368569c | 86 | if(terse_on==AX_TRUE) { |
AxedaCorp | 0:65004368569c | 87 | cJSON_AddItemToObject(child_obj, terse_dataKW[DATA_ITEMS], dis=cJSON_CreateObject()); } |
AxedaCorp | 0:65004368569c | 88 | else { |
AxedaCorp | 0:65004368569c | 89 | cJSON_AddItemToObject(child_obj, dataKW[DATA_ITEMS], dis=cJSON_CreateObject()); |
AxedaCorp | 0:65004368569c | 90 | } |
AxedaCorp | 0:65004368569c | 91 | if((curr->acquisitionTime>=0)&&(curr->acquisitionTime)){ |
AxedaCorp | 0:65004368569c | 92 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 93 | cJSON_AddNumberToObject(child_obj, terse_commonKW[COM_TIME], curr->acquisitionTime); |
AxedaCorp | 0:65004368569c | 94 | } |
AxedaCorp | 0:65004368569c | 95 | else { |
AxedaCorp | 0:65004368569c | 96 | cJSON_AddNumberToObject(child_obj, commonKW[COM_TIME], curr->acquisitionTime); |
AxedaCorp | 0:65004368569c | 97 | } |
AxedaCorp | 0:65004368569c | 98 | } |
AxedaCorp | 0:65004368569c | 99 | if((curr->priority>=1)&&(curr->priority<=100)) { |
AxedaCorp | 0:65004368569c | 100 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 101 | cJSON_AddNumberToObject(child_obj, terse_commonKW[COM_PRIORITY], curr->priority); |
AxedaCorp | 0:65004368569c | 102 | } |
AxedaCorp | 0:65004368569c | 103 | else { |
AxedaCorp | 0:65004368569c | 104 | cJSON_AddNumberToObject(child_obj, commonKW[COM_PRIORITY], curr->priority); |
AxedaCorp | 0:65004368569c | 105 | } |
AxedaCorp | 0:65004368569c | 106 | } |
AxedaCorp | 0:65004368569c | 107 | currNode=curr->data_first; |
AxedaCorp | 0:65004368569c | 108 | while(currNode!=NULL) |
AxedaCorp | 0:65004368569c | 109 | { |
AxedaCorp | 0:65004368569c | 110 | if(currNode->type==AX_DIGITAL) { |
AxedaCorp | 0:65004368569c | 111 | if(currNode->dValue==1) { |
AxedaCorp | 0:65004368569c | 112 | cJSON_AddTrueToObject(dis, currNode->name); |
AxedaCorp | 0:65004368569c | 113 | } |
AxedaCorp | 0:65004368569c | 114 | else { |
AxedaCorp | 0:65004368569c | 115 | cJSON_AddFalseToObject(dis, currNode->name); |
AxedaCorp | 0:65004368569c | 116 | } |
AxedaCorp | 0:65004368569c | 117 | } |
AxedaCorp | 0:65004368569c | 118 | else if(currNode->type==AX_ANALOG) { |
AxedaCorp | 0:65004368569c | 119 | cJSON_AddNumberToObject(dis, currNode->name, currNode->dValue); |
AxedaCorp | 0:65004368569c | 120 | } |
AxedaCorp | 0:65004368569c | 121 | else { |
AxedaCorp | 0:65004368569c | 122 | cJSON_AddStringToObject(dis, currNode->name, currNode->sValue); |
AxedaCorp | 0:65004368569c | 123 | } |
AxedaCorp | 0:65004368569c | 124 | //advance to the next data item |
AxedaCorp | 0:65004368569c | 125 | currNode=currNode->next; |
AxedaCorp | 0:65004368569c | 126 | } |
AxedaCorp | 0:65004368569c | 127 | } |
AxedaCorp | 0:65004368569c | 128 | } |
AxedaCorp | 0:65004368569c | 129 | return root; |
AxedaCorp | 0:65004368569c | 130 | } |
AxedaCorp | 0:65004368569c | 131 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 132 | /* eventsToJSON() */ |
AxedaCorp | 0:65004368569c | 133 | /* */ |
AxedaCorp | 0:65004368569c | 134 | /*Takes an array of ax_event struct pointers and creates JSON to represent them in the AMMP-json */ |
AxedaCorp | 0:65004368569c | 135 | /*protocol. The return type will be a CJSON pointer which can then be rendered into an actual */ |
AxedaCorp | 0:65004368569c | 136 | /*JSON string. The JSON pointer will need to be free'd when you're done. If there are zero data */ |
AxedaCorp | 0:65004368569c | 137 | /*items in the array then this method will return an empty JSON array pointer. */ |
AxedaCorp | 0:65004368569c | 138 | /* */ |
AxedaCorp | 0:65004368569c | 139 | /*NOTE: If any array spots are left empty they will only be ignored if theyre are NULL. Junk */ |
AxedaCorp | 0:65004368569c | 140 | /* values from left over data will cause seg faults. NULL your empty pointers!!! */ |
AxedaCorp | 0:65004368569c | 141 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 142 | cJSON *eventsToJSON(ax_event *events[], int len, int terse_on) { |
AxedaCorp | 0:65004368569c | 143 | cJSON *root, *dis; |
AxedaCorp | 0:65004368569c | 144 | ax_event *curr; |
AxedaCorp | 0:65004368569c | 145 | int ctr=0; |
AxedaCorp | 0:65004368569c | 146 | root=cJSON_CreateArray(); |
AxedaCorp | 0:65004368569c | 147 | curr=events[0]; |
AxedaCorp | 0:65004368569c | 148 | for(ctr=0; ctr<len; ctr++) |
AxedaCorp | 0:65004368569c | 149 | { |
AxedaCorp | 0:65004368569c | 150 | curr=events[ctr]; |
AxedaCorp | 0:65004368569c | 151 | if(curr!=NULL) |
AxedaCorp | 0:65004368569c | 152 | { |
AxedaCorp | 0:65004368569c | 153 | cJSON_AddItemToArray(root, dis=cJSON_CreateObject()); |
AxedaCorp | 0:65004368569c | 154 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 155 | cJSON_AddStringToObject(dis, terse_commonKW[COM_NAME], curr->name); |
AxedaCorp | 0:65004368569c | 156 | cJSON_AddStringToObject(dis, terse_commonKW[COM_DESCRIPTION], curr->description); |
AxedaCorp | 0:65004368569c | 157 | } |
AxedaCorp | 0:65004368569c | 158 | else { |
AxedaCorp | 0:65004368569c | 159 | cJSON_AddStringToObject(dis, commonKW[COM_NAME], curr->name); |
AxedaCorp | 0:65004368569c | 160 | cJSON_AddStringToObject(dis, commonKW[COM_DESCRIPTION], curr->description); |
AxedaCorp | 0:65004368569c | 161 | } |
AxedaCorp | 0:65004368569c | 162 | |
AxedaCorp | 0:65004368569c | 163 | if((curr->dateAcquired>=0)&&(curr->dateAcquired)){ |
AxedaCorp | 0:65004368569c | 164 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 165 | cJSON_AddNumberToObject(dis, terse_commonKW[COM_TIME], curr->dateAcquired); |
AxedaCorp | 0:65004368569c | 166 | } |
AxedaCorp | 0:65004368569c | 167 | else { |
AxedaCorp | 0:65004368569c | 168 | cJSON_AddNumberToObject(dis, commonKW[COM_TIME], curr->dateAcquired); |
AxedaCorp | 0:65004368569c | 169 | } |
AxedaCorp | 0:65004368569c | 170 | } |
AxedaCorp | 0:65004368569c | 171 | if((curr->priority>=1)&&(curr->priority<=100)&&(curr->priority)) { |
AxedaCorp | 0:65004368569c | 172 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 173 | cJSON_AddNumberToObject(dis, terse_commonKW[COM_PRIORITY], curr->priority); |
AxedaCorp | 0:65004368569c | 174 | } |
AxedaCorp | 0:65004368569c | 175 | else { |
AxedaCorp | 0:65004368569c | 176 | cJSON_AddNumberToObject(dis, commonKW[COM_PRIORITY], curr->priority); |
AxedaCorp | 0:65004368569c | 177 | } |
AxedaCorp | 0:65004368569c | 178 | } |
AxedaCorp | 0:65004368569c | 179 | } |
AxedaCorp | 0:65004368569c | 180 | } |
AxedaCorp | 0:65004368569c | 181 | |
AxedaCorp | 0:65004368569c | 182 | return root; |
AxedaCorp | 0:65004368569c | 183 | } |
AxedaCorp | 0:65004368569c | 184 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 185 | /* locationsToJSON() */ |
AxedaCorp | 0:65004368569c | 186 | /* */ |
AxedaCorp | 0:65004368569c | 187 | /*Takes an array of ax_location struct pointers and creates JSON to represent them in the AMMP */ |
AxedaCorp | 0:65004368569c | 188 | /*protocol. The return type will be a CJSON pointer which can then be rendered into an actual */ |
AxedaCorp | 0:65004368569c | 189 | /*JSON string. The JSON pointer will need to be free'd when you're done. If there are zero data */ |
AxedaCorp | 0:65004368569c | 190 | /*items in the array then this method will return an empty JSON array pointer. */ |
AxedaCorp | 0:65004368569c | 191 | /* */ |
AxedaCorp | 0:65004368569c | 192 | /*NOTE: If any array spots are left empty they will only be ignored if theyre are NULL. Junk */ |
AxedaCorp | 0:65004368569c | 193 | /* values from left over data will cause seg faults. NULL your empty pointers!!! */ |
AxedaCorp | 0:65004368569c | 194 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 195 | cJSON *locationsToJSON(ax_location *locations[], int len, int terse_on) { |
AxedaCorp | 0:65004368569c | 196 | cJSON *root, *dis; |
AxedaCorp | 0:65004368569c | 197 | ax_location *curr; |
AxedaCorp | 0:65004368569c | 198 | int ctr=0; |
AxedaCorp | 0:65004368569c | 199 | root=cJSON_CreateArray(); |
AxedaCorp | 0:65004368569c | 200 | for(ctr=0; ctr<len; ctr++) |
AxedaCorp | 0:65004368569c | 201 | { |
AxedaCorp | 0:65004368569c | 202 | curr=locations[ctr]; |
AxedaCorp | 0:65004368569c | 203 | if(curr) |
AxedaCorp | 0:65004368569c | 204 | { |
AxedaCorp | 0:65004368569c | 205 | cJSON_AddItemToArray(root, dis=cJSON_CreateObject()); |
AxedaCorp | 0:65004368569c | 206 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 207 | cJSON_AddNumberToObject(dis, terse_locationKW[LOC_LAT], curr->latitude); |
AxedaCorp | 0:65004368569c | 208 | cJSON_AddNumberToObject(dis, terse_locationKW[LOC_LON], curr->longitude); |
AxedaCorp | 0:65004368569c | 209 | cJSON_AddNumberToObject(dis, terse_locationKW[LOC_ALT], curr->altitude); |
AxedaCorp | 0:65004368569c | 210 | } |
AxedaCorp | 0:65004368569c | 211 | else { |
AxedaCorp | 0:65004368569c | 212 | cJSON_AddNumberToObject(dis, locationKW[LOC_LAT], curr->latitude); |
AxedaCorp | 0:65004368569c | 213 | cJSON_AddNumberToObject(dis, locationKW[LOC_LON], curr->longitude); |
AxedaCorp | 0:65004368569c | 214 | cJSON_AddNumberToObject(dis, locationKW[LOC_ALT], curr->altitude); |
AxedaCorp | 0:65004368569c | 215 | } |
AxedaCorp | 0:65004368569c | 216 | if((curr->dateAcquired)&&(curr->dateAcquired>=0)){ |
AxedaCorp | 0:65004368569c | 217 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 218 | cJSON_AddNumberToObject(dis, terse_commonKW[COM_TIME], curr->dateAcquired); |
AxedaCorp | 0:65004368569c | 219 | } |
AxedaCorp | 0:65004368569c | 220 | else { |
AxedaCorp | 0:65004368569c | 221 | cJSON_AddNumberToObject(dis, commonKW[COM_TIME], curr->dateAcquired); |
AxedaCorp | 0:65004368569c | 222 | } |
AxedaCorp | 0:65004368569c | 223 | } |
AxedaCorp | 0:65004368569c | 224 | if((curr->priority>=1)&&(curr->priority<=100)&&(curr->priority)) { |
AxedaCorp | 0:65004368569c | 225 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 226 | cJSON_AddNumberToObject(dis, terse_commonKW[COM_PRIORITY], curr->priority); |
AxedaCorp | 0:65004368569c | 227 | } |
AxedaCorp | 0:65004368569c | 228 | else { |
AxedaCorp | 0:65004368569c | 229 | cJSON_AddNumberToObject(dis, commonKW[COM_PRIORITY], curr->priority); |
AxedaCorp | 0:65004368569c | 230 | } |
AxedaCorp | 0:65004368569c | 231 | } |
AxedaCorp | 0:65004368569c | 232 | } |
AxedaCorp | 0:65004368569c | 233 | } |
AxedaCorp | 0:65004368569c | 234 | |
AxedaCorp | 0:65004368569c | 235 | return root; |
AxedaCorp | 0:65004368569c | 236 | } |
AxedaCorp | 0:65004368569c | 237 | |
AxedaCorp | 0:65004368569c | 238 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 239 | /* alarmsToJSON() */ |
AxedaCorp | 0:65004368569c | 240 | /* */ |
AxedaCorp | 0:65004368569c | 241 | /*Takes an array of ax_alarm struct pointers and creates JSON to represent them in the AMMP-json */ |
AxedaCorp | 0:65004368569c | 242 | /*protocol. The return type will be a CJSON pointer which can then be rendered into an actual */ |
AxedaCorp | 0:65004368569c | 243 | /*JSON string. The JSON pointer will need to be free'd when you're done. If there are zero data */ |
AxedaCorp | 0:65004368569c | 244 | /*items in the array then this method will return an empty JSON array pointer. */ |
AxedaCorp | 0:65004368569c | 245 | /* */ |
AxedaCorp | 0:65004368569c | 246 | /*NOTE: If any array spots are left empty they will only be ignored if theyre are NULL. Junk */ |
AxedaCorp | 0:65004368569c | 247 | /* values from left over data will cause seg faults. NULL your empty pointers!!! */ |
AxedaCorp | 0:65004368569c | 248 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 249 | cJSON *AlarmsToJSON(ax_alarm *alarms[], int len, int terse_on) |
AxedaCorp | 0:65004368569c | 250 | { |
AxedaCorp | 0:65004368569c | 251 | cJSON *root, *dis; |
AxedaCorp | 0:65004368569c | 252 | int ctr=0; |
AxedaCorp | 0:65004368569c | 253 | ax_alarm *curr; |
AxedaCorp | 0:65004368569c | 254 | root=cJSON_CreateArray(); |
AxedaCorp | 0:65004368569c | 255 | curr=alarms[0]; |
AxedaCorp | 0:65004368569c | 256 | for(ctr=0; ctr<len; ctr++) { |
AxedaCorp | 0:65004368569c | 257 | curr=alarms[ctr]; |
AxedaCorp | 0:65004368569c | 258 | if(curr!=NULL) |
AxedaCorp | 0:65004368569c | 259 | { |
AxedaCorp | 0:65004368569c | 260 | cJSON_AddItemToArray(root, dis=cJSON_CreateObject()); |
AxedaCorp | 0:65004368569c | 261 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 262 | cJSON_AddStringToObject(dis, terse_commonKW[COM_NAME], curr->alarmName); |
AxedaCorp | 0:65004368569c | 263 | cJSON_AddStringToObject(dis, terse_commonKW[COM_DESCRIPTION], curr->alarmDescription); |
AxedaCorp | 0:65004368569c | 264 | cJSON_AddNumberToObject(dis, terse_alertKW[ALERT_SEV], curr->alarmSeverity); |
AxedaCorp | 0:65004368569c | 265 | cJSON_AddStringToObject(dis, terse_alertKW[ALERT_CAUSE], curr->alarmCause); |
AxedaCorp | 0:65004368569c | 266 | cJSON_AddStringToObject(dis, terse_alertKW[ALERT_REASON], curr->alarmReason); |
AxedaCorp | 0:65004368569c | 267 | } |
AxedaCorp | 0:65004368569c | 268 | else { |
AxedaCorp | 0:65004368569c | 269 | cJSON_AddStringToObject(dis, commonKW[COM_NAME], curr->alarmName); |
AxedaCorp | 0:65004368569c | 270 | cJSON_AddStringToObject(dis, commonKW[COM_DESCRIPTION], curr->alarmDescription); |
AxedaCorp | 0:65004368569c | 271 | cJSON_AddNumberToObject(dis, alertKW[ALERT_SEV], curr->alarmSeverity); |
AxedaCorp | 0:65004368569c | 272 | cJSON_AddStringToObject(dis, alertKW[ALERT_CAUSE], curr->alarmCause); |
AxedaCorp | 0:65004368569c | 273 | cJSON_AddStringToObject(dis, alertKW[ALERT_REASON], curr->alarmReason); |
AxedaCorp | 0:65004368569c | 274 | } |
AxedaCorp | 0:65004368569c | 275 | |
AxedaCorp | 0:65004368569c | 276 | if((curr->dateAcquired)&&(curr->dateAcquired>=0)){ |
AxedaCorp | 0:65004368569c | 277 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 278 | cJSON_AddNumberToObject(dis, terse_commonKW[COM_TIME], curr->dateAcquired); |
AxedaCorp | 0:65004368569c | 279 | } |
AxedaCorp | 0:65004368569c | 280 | else { |
AxedaCorp | 0:65004368569c | 281 | cJSON_AddNumberToObject(dis, commonKW[COM_TIME], curr->dateAcquired); |
AxedaCorp | 0:65004368569c | 282 | } |
AxedaCorp | 0:65004368569c | 283 | } |
AxedaCorp | 0:65004368569c | 284 | if((curr->priority>=1)&&(curr->priority<=100)&&(curr->priority)) { |
AxedaCorp | 0:65004368569c | 285 | if(terse_on==AX_TRUE){ |
AxedaCorp | 0:65004368569c | 286 | cJSON_AddNumberToObject(dis, terse_commonKW[COM_PRIORITY], curr->priority); |
AxedaCorp | 0:65004368569c | 287 | } |
AxedaCorp | 0:65004368569c | 288 | else { |
AxedaCorp | 0:65004368569c | 289 | cJSON_AddNumberToObject(dis, commonKW[COM_PRIORITY], curr->priority); |
AxedaCorp | 0:65004368569c | 290 | } |
AxedaCorp | 0:65004368569c | 291 | } |
AxedaCorp | 0:65004368569c | 292 | } |
AxedaCorp | 0:65004368569c | 293 | } |
AxedaCorp | 0:65004368569c | 294 | |
AxedaCorp | 0:65004368569c | 295 | return root; |
AxedaCorp | 0:65004368569c | 296 | } |
AxedaCorp | 0:65004368569c | 297 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 298 | /* getRegistrationJSON() */ |
AxedaCorp | 0:65004368569c | 299 | /* */ |
AxedaCorp | 0:65004368569c | 300 | /*Takes a device and ping rate and will return a cJSON structure that represents a registration */ |
AxedaCorp | 0:65004368569c | 301 | /*message in the AMMP protocol. */ |
AxedaCorp | 0:65004368569c | 302 | /* */ |
AxedaCorp | 0:65004368569c | 303 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 304 | cJSON *getRegistrationJSON(ax_deviceID *device, int pingRate) |
AxedaCorp | 0:65004368569c | 305 | { |
AxedaCorp | 0:65004368569c | 306 | cJSON *root, *child; |
AxedaCorp | 0:65004368569c | 307 | |
AxedaCorp | 0:65004368569c | 308 | root=cJSON_CreateObject(); |
AxedaCorp | 0:65004368569c | 309 | |
AxedaCorp | 0:65004368569c | 310 | cJSON_AddItemToObject(root, registrationKW[REG_ID], child=cJSON_CreateObject()); |
AxedaCorp | 0:65004368569c | 311 | if(device->model) { |
AxedaCorp | 0:65004368569c | 312 | cJSON_AddStringToObject(child, registrationKW[REG_MODEL_NUMBER], device->model); |
AxedaCorp | 0:65004368569c | 313 | } |
AxedaCorp | 0:65004368569c | 314 | if(device->serial) { |
AxedaCorp | 0:65004368569c | 315 | cJSON_AddStringToObject(child, registrationKW[REG_SERIAL_NUMBER], device->serial); |
AxedaCorp | 0:65004368569c | 316 | } |
AxedaCorp | 0:65004368569c | 317 | if(strlen(device->tenant)>=1) |
AxedaCorp | 0:65004368569c | 318 | { |
AxedaCorp | 0:65004368569c | 319 | cJSON_AddStringToObject(child, registrationKW[REG_TENANT], device->tenant); |
AxedaCorp | 0:65004368569c | 320 | } |
AxedaCorp | 0:65004368569c | 321 | cJSON_AddNumberToObject(root, registrationKW[REG_PING], pingRate); |
AxedaCorp | 0:65004368569c | 322 | |
AxedaCorp | 0:65004368569c | 323 | |
AxedaCorp | 0:65004368569c | 324 | return root; |
AxedaCorp | 0:65004368569c | 325 | } |
AxedaCorp | 0:65004368569c | 326 | |
AxedaCorp | 0:65004368569c | 327 | //TODO: Fill out this description |
AxedaCorp | 0:65004368569c | 328 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 329 | /*getPKGStatusJSON() */ |
AxedaCorp | 0:65004368569c | 330 | /* */ |
AxedaCorp | 0:65004368569c | 331 | /* */ |
AxedaCorp | 0:65004368569c | 332 | /* */ |
AxedaCorp | 0:65004368569c | 333 | /*************************************************************************************************/ |
AxedaCorp | 0:65004368569c | 334 | cJSON *getPKGStatusJSON(int status, char *error, int priority, int time, int terse_on){ |
AxedaCorp | 0:65004368569c | 335 | cJSON *root; |
AxedaCorp | 0:65004368569c | 336 | root=cJSON_CreateObject(); |
AxedaCorp | 0:65004368569c | 337 | //STATUS |
AxedaCorp | 0:65004368569c | 338 | if(terse_on==AX_TRUE) { |
AxedaCorp | 0:65004368569c | 339 | cJSON_AddNumberToObject(root, pkgStatusKW[PKG_STATUS], status); |
AxedaCorp | 0:65004368569c | 340 | } |
AxedaCorp | 0:65004368569c | 341 | else { |
AxedaCorp | 0:65004368569c | 342 | cJSON_AddNumberToObject(root, pkgStatusKW[PKG_STATUS], status); |
AxedaCorp | 0:65004368569c | 343 | } |
AxedaCorp | 0:65004368569c | 344 | //TIME |
AxedaCorp | 0:65004368569c | 345 | if(time>=0) { |
AxedaCorp | 0:65004368569c | 346 | if(terse_on==AX_TRUE) { |
AxedaCorp | 0:65004368569c | 347 | cJSON_AddNumberToObject(root, terse_commonKW[COM_TIME], time); |
AxedaCorp | 0:65004368569c | 348 | } |
AxedaCorp | 0:65004368569c | 349 | else { |
AxedaCorp | 0:65004368569c | 350 | cJSON_AddNumberToObject(root, commonKW[COM_TIME], time); |
AxedaCorp | 0:65004368569c | 351 | } |
AxedaCorp | 0:65004368569c | 352 | } |
AxedaCorp | 0:65004368569c | 353 | //PRIORITY |
AxedaCorp | 0:65004368569c | 354 | if((priority>0)&&(priority<=100)) { |
AxedaCorp | 0:65004368569c | 355 | if(terse_on==AX_TRUE) { |
AxedaCorp | 0:65004368569c | 356 | cJSON_AddNumberToObject(root, terse_commonKW[COM_PRIORITY], priority); |
AxedaCorp | 0:65004368569c | 357 | } |
AxedaCorp | 0:65004368569c | 358 | else { |
AxedaCorp | 0:65004368569c | 359 | cJSON_AddNumberToObject(root, commonKW[COM_PRIORITY], priority); |
AxedaCorp | 0:65004368569c | 360 | } |
AxedaCorp | 0:65004368569c | 361 | } |
AxedaCorp | 0:65004368569c | 362 | //ERROR |
AxedaCorp | 0:65004368569c | 363 | if(error!=NULL) { |
AxedaCorp | 0:65004368569c | 364 | if(terse_on==AX_TRUE) { |
AxedaCorp | 0:65004368569c | 365 | cJSON_AddStringToObject(root, terse_pkgStatusKW[PKG_ERROR], error); |
AxedaCorp | 0:65004368569c | 366 | } |
AxedaCorp | 0:65004368569c | 367 | else { |
AxedaCorp | 0:65004368569c | 368 | cJSON_AddStringToObject(root, pkgStatusKW[PKG_ERROR], error); |
AxedaCorp | 0:65004368569c | 369 | } |
AxedaCorp | 0:65004368569c | 370 | } |
AxedaCorp | 0:65004368569c | 371 | return root; |
AxedaCorp | 0:65004368569c | 372 | } |
AxedaCorp | 0:65004368569c | 373 | |
AxedaCorp | 0:65004368569c | 374 |