123
Dependencies: MQTTSN
Sensor/sensor.cpp@15:8c473836feba, 2019-08-06 (annotated)
- Committer:
- m_ahsan
- Date:
- Tue Aug 06 05:32:43 2019 +0000
- Revision:
- 15:8c473836feba
123
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m_ahsan | 15:8c473836feba | 1 | #include "sensor.h" |
m_ahsan | 15:8c473836feba | 2 | #include "MbedJSONValue.h" |
m_ahsan | 15:8c473836feba | 3 | |
m_ahsan | 15:8c473836feba | 4 | void process_rsc(MbedJSONValue &MSG); |
m_ahsan | 15:8c473836feba | 5 | |
m_ahsan | 15:8c473836feba | 6 | struct Resource RES; |
m_ahsan | 15:8c473836feba | 7 | struct regularResource regRES; |
m_ahsan | 15:8c473836feba | 8 | struct announceableResource ancRES; |
m_ahsan | 15:8c473836feba | 9 | struct announcedResource ancdRES; |
m_ahsan | 15:8c473836feba | 10 | struct subordinateResource subRES; |
m_ahsan | 15:8c473836feba | 11 | struct announceableSubordinateResource ancsubRES; |
m_ahsan | 15:8c473836feba | 12 | struct announcedSubordinateResource ancdsubRES; |
m_ahsan | 15:8c473836feba | 13 | |
m_ahsan | 15:8c473836feba | 14 | struct CreateAE CAE; |
m_ahsan | 15:8c473836feba | 15 | struct CreateCIN CIN; |
m_ahsan | 15:8c473836feba | 16 | struct CreateSub CSub; |
m_ahsan | 15:8c473836feba | 17 | struct respAE RAE; |
m_ahsan | 15:8c473836feba | 18 | struct respCnt RCnt; |
m_ahsan | 15:8c473836feba | 19 | struct respCin RCin; |
m_ahsan | 15:8c473836feba | 20 | struct respSub RSub; |
m_ahsan | 15:8c473836feba | 21 | |
m_ahsan | 15:8c473836feba | 22 | //extern const char* CSE_ID; |
m_ahsan | 15:8c473836feba | 23 | extern char* AE_ID; |
m_ahsan | 15:8c473836feba | 24 | extern bool lcl; |
m_ahsan | 15:8c473836feba | 25 | |
m_ahsan | 15:8c473836feba | 26 | ////////////////////////////////////////////// |
m_ahsan | 15:8c473836feba | 27 | // Func: Create_Req // |
m_ahsan | 15:8c473836feba | 28 | // returns a json string // |
m_ahsan | 15:8c473836feba | 29 | // input parameters Class Request // |
m_ahsan | 15:8c473836feba | 30 | ////////////////////////////////////////////// |
m_ahsan | 15:8c473836feba | 31 | const char* Create_Req(Request Req) |
m_ahsan | 15:8c473836feba | 32 | { |
m_ahsan | 15:8c473836feba | 33 | MbedJSONValue demo, demo2, demo3, demo4; |
m_ahsan | 15:8c473836feba | 34 | |
m_ahsan | 15:8c473836feba | 35 | std::string s; |
m_ahsan | 15:8c473836feba | 36 | switch(Req.Resource_Type){ |
m_ahsan | 15:8c473836feba | 37 | case 0: |
m_ahsan | 15:8c473836feba | 38 | break; |
m_ahsan | 15:8c473836feba | 39 | case 1: |
m_ahsan | 15:8c473836feba | 40 | break; |
m_ahsan | 15:8c473836feba | 41 | case 2: |
m_ahsan | 15:8c473836feba | 42 | demo3["api"] = CAE.App_ID; |
m_ahsan | 15:8c473836feba | 43 | demo3["rn"] = CAE.resourceName; |
m_ahsan | 15:8c473836feba | 44 | demo3["rr"] = CAE.requestReachability; |
m_ahsan | 15:8c473836feba | 45 | demo2["m2m:ae"] = demo3; |
m_ahsan | 15:8c473836feba | 46 | break; |
m_ahsan | 15:8c473836feba | 47 | case 3: |
m_ahsan | 15:8c473836feba | 48 | demo3["rn"] = CAE.resourceName; |
m_ahsan | 15:8c473836feba | 49 | demo2["m2m:cnt"] = demo3; |
m_ahsan | 15:8c473836feba | 50 | break; |
m_ahsan | 15:8c473836feba | 51 | case 4: |
m_ahsan | 15:8c473836feba | 52 | demo3["cnf"] = CIN.contentInfo; |
m_ahsan | 15:8c473836feba | 53 | demo3["con"] = CIN.content; |
m_ahsan | 15:8c473836feba | 54 | demo2["m2m:cin"] = demo3; |
m_ahsan | 15:8c473836feba | 55 | break; |
m_ahsan | 15:8c473836feba | 56 | case 23: |
m_ahsan | 15:8c473836feba | 57 | demo3["rn"] = CSub.resourceName; |
m_ahsan | 15:8c473836feba | 58 | demo4["net"] = CSub.notificationEventType; |
m_ahsan | 15:8c473836feba | 59 | demo3["enc"] = demo4; |
m_ahsan | 15:8c473836feba | 60 | demo3["nu"] = CSub.notificationURI; |
m_ahsan | 15:8c473836feba | 61 | demo3["nct"] = CSub.notificationContentType; |
m_ahsan | 15:8c473836feba | 62 | demo2["m2m:sub"] = demo3; |
m_ahsan | 15:8c473836feba | 63 | break; |
m_ahsan | 15:8c473836feba | 64 | } |
m_ahsan | 15:8c473836feba | 65 | demo["fr"] = Req.From; |
m_ahsan | 15:8c473836feba | 66 | demo["op"] = Req.Operation; |
m_ahsan | 15:8c473836feba | 67 | demo["pc"] = demo2; |
m_ahsan | 15:8c473836feba | 68 | demo["rqi"] = Req.Request_Identifier; |
m_ahsan | 15:8c473836feba | 69 | demo["to"] = Req.To; |
m_ahsan | 15:8c473836feba | 70 | demo["ty"] = Req.Resource_Type; |
m_ahsan | 15:8c473836feba | 71 | demo["lcl"] = lcl; |
m_ahsan | 15:8c473836feba | 72 | |
m_ahsan | 15:8c473836feba | 73 | //serialize it into a JSON string |
m_ahsan | 15:8c473836feba | 74 | s = demo.serialize(); |
m_ahsan | 15:8c473836feba | 75 | printf("\nMSG SIZE: %d\n", s.length()); |
m_ahsan | 15:8c473836feba | 76 | printf("Req JSON: %s\r\n", s.c_str()); |
m_ahsan | 15:8c473836feba | 77 | |
m_ahsan | 15:8c473836feba | 78 | return s.c_str(); |
m_ahsan | 15:8c473836feba | 79 | } |
m_ahsan | 15:8c473836feba | 80 | ////////////////////////////////////////////// |
m_ahsan | 15:8c473836feba | 81 | // Func: Delete_Req // |
m_ahsan | 15:8c473836feba | 82 | // returns a json string // |
m_ahsan | 15:8c473836feba | 83 | // input parameters Class Request // |
m_ahsan | 15:8c473836feba | 84 | ////////////////////////////////////////////// |
m_ahsan | 15:8c473836feba | 85 | const char* Delete_Req(Request Req) |
m_ahsan | 15:8c473836feba | 86 | { |
m_ahsan | 15:8c473836feba | 87 | MbedJSONValue demo, demo2, demo3, demo4; |
m_ahsan | 15:8c473836feba | 88 | |
m_ahsan | 15:8c473836feba | 89 | std::string s; |
m_ahsan | 15:8c473836feba | 90 | |
m_ahsan | 15:8c473836feba | 91 | demo["fr"] = Req.From; |
m_ahsan | 15:8c473836feba | 92 | demo["op"] = Req.Operation; |
m_ahsan | 15:8c473836feba | 93 | demo["rqi"] = Req.Request_Identifier; |
m_ahsan | 15:8c473836feba | 94 | demo["to"] = Req.To; |
m_ahsan | 15:8c473836feba | 95 | demo["lcl"] = lcl; |
m_ahsan | 15:8c473836feba | 96 | |
m_ahsan | 15:8c473836feba | 97 | //serialize it into a JSON string |
m_ahsan | 15:8c473836feba | 98 | s = demo.serialize(); |
m_ahsan | 15:8c473836feba | 99 | printf("\nMSG SIZE: %d\n", s.length()); |
m_ahsan | 15:8c473836feba | 100 | printf("Req JSON: %s\r\n", s.c_str()); |
m_ahsan | 15:8c473836feba | 101 | |
m_ahsan | 15:8c473836feba | 102 | return s.c_str(); |
m_ahsan | 15:8c473836feba | 103 | } |
m_ahsan | 15:8c473836feba | 104 | ////////////////////////////////////////////// |
m_ahsan | 15:8c473836feba | 105 | // Func: Create_Resp // |
m_ahsan | 15:8c473836feba | 106 | // returns a json string // |
m_ahsan | 15:8c473836feba | 107 | // input parameters Class Response // |
m_ahsan | 15:8c473836feba | 108 | ////////////////////////////////////////////// |
m_ahsan | 15:8c473836feba | 109 | const char* Create_Resp(Response Resp) |
m_ahsan | 15:8c473836feba | 110 | { |
m_ahsan | 15:8c473836feba | 111 | MbedJSONValue demo, demo2, demo3, demo4; |
m_ahsan | 15:8c473836feba | 112 | demo3["ty"] = RES.Resource_Type; |
m_ahsan | 15:8c473836feba | 113 | demo3["ri"] = RES.resourceID; |
m_ahsan | 15:8c473836feba | 114 | demo3["pi"] = RES.parentID; |
m_ahsan | 15:8c473836feba | 115 | demo3["ct"] = RES.creationTime; //ct 1 |
m_ahsan | 15:8c473836feba | 116 | demo3["lt"] = RES.lastModifiedTime; //lt 1 |
m_ahsan | 15:8c473836feba | 117 | demo3["rn"] = RES.resourceName; |
m_ahsan | 15:8c473836feba | 118 | std::string s; |
m_ahsan | 15:8c473836feba | 119 | printf("RES.Resource_Type = %d",RES.Resource_Type); |
m_ahsan | 15:8c473836feba | 120 | switch(RES.Resource_Type){ |
m_ahsan | 15:8c473836feba | 121 | case 0: |
m_ahsan | 15:8c473836feba | 122 | demo3["api"] = RAE.App_ID; |
m_ahsan | 15:8c473836feba | 123 | demo3["rr"] = RAE.requestReachability; |
m_ahsan | 15:8c473836feba | 124 | demo3["aei"] = RAE.AE_ID; |
m_ahsan | 15:8c473836feba | 125 | demo3["poa"] = RAE.pointOfAccess; |
m_ahsan | 15:8c473836feba | 126 | demo2["m2m:ae"] = demo3; |
m_ahsan | 15:8c473836feba | 127 | break; |
m_ahsan | 15:8c473836feba | 128 | case 1: |
m_ahsan | 15:8c473836feba | 129 | break; |
m_ahsan | 15:8c473836feba | 130 | case 2: |
m_ahsan | 15:8c473836feba | 131 | demo3["api"] = RAE.App_ID; |
m_ahsan | 15:8c473836feba | 132 | demo3["rr"] = RAE.requestReachability; |
m_ahsan | 15:8c473836feba | 133 | demo3["aei"] = RAE.AE_ID; |
m_ahsan | 15:8c473836feba | 134 | demo3["poa"] = RAE.pointOfAccess; |
m_ahsan | 15:8c473836feba | 135 | demo2["m2m:ae"] = demo3; |
m_ahsan | 15:8c473836feba | 136 | break; |
m_ahsan | 15:8c473836feba | 137 | case 3: |
m_ahsan | 15:8c473836feba | 138 | demo3["st"] = RCnt.stateTag; |
m_ahsan | 15:8c473836feba | 139 | demo3["cni"] = RCnt.CurrentNrOfInstances; |
m_ahsan | 15:8c473836feba | 140 | demo3["cbs"] = RCnt.CurrentByteSize; |
m_ahsan | 15:8c473836feba | 141 | demo2["m2m:cnt"] = demo3; |
m_ahsan | 15:8c473836feba | 142 | break; |
m_ahsan | 15:8c473836feba | 143 | case 4: |
m_ahsan | 15:8c473836feba | 144 | demo3["et"] = ancsubRES.expirationTime; |
m_ahsan | 15:8c473836feba | 145 | demo3["st"] = RCin.stateTag; |
m_ahsan | 15:8c473836feba | 146 | demo3["cnf"] = RCin.contentInfo; |
m_ahsan | 15:8c473836feba | 147 | demo3["cs"] = RCin.contentSize; |
m_ahsan | 15:8c473836feba | 148 | demo3["con"] = RCin.content; |
m_ahsan | 15:8c473836feba | 149 | demo2["m2m:cin"] = demo3; |
m_ahsan | 15:8c473836feba | 150 | break; |
m_ahsan | 15:8c473836feba | 151 | case 23: |
m_ahsan | 15:8c473836feba | 152 | demo3["et"] = ancsubRES.expirationTime; |
m_ahsan | 15:8c473836feba | 153 | demo4["net"] = RSub.notificationEventType; |
m_ahsan | 15:8c473836feba | 154 | demo3["enc"] = demo4; |
m_ahsan | 15:8c473836feba | 155 | demo3["nct"] = RSub.notificationContentType; |
m_ahsan | 15:8c473836feba | 156 | demo3["nu"] = RSub.notificationURI; |
m_ahsan | 15:8c473836feba | 157 | demo2["m2m:sub"] = demo3; |
m_ahsan | 15:8c473836feba | 158 | break; |
m_ahsan | 15:8c473836feba | 159 | |
m_ahsan | 15:8c473836feba | 160 | } |
m_ahsan | 15:8c473836feba | 161 | demo["rsc"] = Resp.responseStatusCode; |
m_ahsan | 15:8c473836feba | 162 | demo["rqi"] = Resp.Request_Identifier; |
m_ahsan | 15:8c473836feba | 163 | demo["pc"] = demo2; |
m_ahsan | 15:8c473836feba | 164 | demo["to"] = Resp.To; |
m_ahsan | 15:8c473836feba | 165 | demo["fr"] = Resp.From; |
m_ahsan | 15:8c473836feba | 166 | demo["lcl"] = lcl; |
m_ahsan | 15:8c473836feba | 167 | |
m_ahsan | 15:8c473836feba | 168 | //serialize it into a JSON string |
m_ahsan | 15:8c473836feba | 169 | s = demo.serialize(); |
m_ahsan | 15:8c473836feba | 170 | printf("\nMSG SIZE: %d\n", s.length()); |
m_ahsan | 15:8c473836feba | 171 | printf("RESP JSON: %s\r\n", s.c_str()); |
m_ahsan | 15:8c473836feba | 172 | return s.c_str(); |
m_ahsan | 15:8c473836feba | 173 | } |
m_ahsan | 15:8c473836feba | 174 | |
m_ahsan | 15:8c473836feba | 175 | const char* Notify_Resp(Response Resp) |
m_ahsan | 15:8c473836feba | 176 | { |
m_ahsan | 15:8c473836feba | 177 | MbedJSONValue demo; |
m_ahsan | 15:8c473836feba | 178 | std::string s; |
m_ahsan | 15:8c473836feba | 179 | demo["rsc"] = Resp.responseStatusCode; |
m_ahsan | 15:8c473836feba | 180 | demo["rqi"] = Resp.Request_Identifier; |
m_ahsan | 15:8c473836feba | 181 | demo["fr"] = Resp.From; |
m_ahsan | 15:8c473836feba | 182 | demo["to"] = Resp.To; |
m_ahsan | 15:8c473836feba | 183 | demo["lcl"] = lcl; |
m_ahsan | 15:8c473836feba | 184 | //serialize it into a JSON string |
m_ahsan | 15:8c473836feba | 185 | s = demo.serialize(); |
m_ahsan | 15:8c473836feba | 186 | printf("\nMSG SIZE: %d\n", s.length()); |
m_ahsan | 15:8c473836feba | 187 | printf("RESP JSON: %s\r\n", s.c_str()); |
m_ahsan | 15:8c473836feba | 188 | return s.c_str(); |
m_ahsan | 15:8c473836feba | 189 | } |
m_ahsan | 15:8c473836feba | 190 | |
m_ahsan | 15:8c473836feba | 191 | void process_msg(const char* Buffer) |
m_ahsan | 15:8c473836feba | 192 | { |
m_ahsan | 15:8c473836feba | 193 | MbedJSONValue MSG; |
m_ahsan | 15:8c473836feba | 194 | |
m_ahsan | 15:8c473836feba | 195 | parse(MSG, Buffer); |
m_ahsan | 15:8c473836feba | 196 | |
m_ahsan | 15:8c473836feba | 197 | ////////////////////////Local Parameter (Additional parameter)////////////////////// |
m_ahsan | 15:8c473836feba | 198 | if(MSG.hasMember("lcl")) |
m_ahsan | 15:8c473836feba | 199 | { |
m_ahsan | 15:8c473836feba | 200 | local = MSG["lcl"].get<bool>(); |
m_ahsan | 15:8c473836feba | 201 | printf("Local: %s\r\n", local? "true" : "false"); |
m_ahsan | 15:8c473836feba | 202 | } |
m_ahsan | 15:8c473836feba | 203 | |
m_ahsan | 15:8c473836feba | 204 | ////////////////////////resource Type Parameter (Mendatory parameter)////////////////////// |
m_ahsan | 15:8c473836feba | 205 | if(MSG.hasMember("rsc")) |
m_ahsan | 15:8c473836feba | 206 | { |
m_ahsan | 15:8c473836feba | 207 | rsc = MSG["rsc"].get<int>(); |
m_ahsan | 15:8c473836feba | 208 | printf("Response Status Code: %d\r\n", rsc); |
m_ahsan | 15:8c473836feba | 209 | Response_Type(); |
m_ahsan | 15:8c473836feba | 210 | printf("Response Status: %s\r\n", response.c_str()); |
m_ahsan | 15:8c473836feba | 211 | process_rsc(MSG); |
m_ahsan | 15:8c473836feba | 212 | return; |
m_ahsan | 15:8c473836feba | 213 | } |
m_ahsan | 15:8c473836feba | 214 | |
m_ahsan | 15:8c473836feba | 215 | ////////////////////////From parameter (Mendatory parameter[optional for Create AE])////////// |
m_ahsan | 15:8c473836feba | 216 | if(MSG.hasMember("fr")) |
m_ahsan | 15:8c473836feba | 217 | { |
m_ahsan | 15:8c473836feba | 218 | From = MSG["fr"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 219 | printf("From: %s\r\n", From.c_str()); |
m_ahsan | 15:8c473836feba | 220 | } |
m_ahsan | 15:8c473836feba | 221 | else { |
m_ahsan | 15:8c473836feba | 222 | //add Response Status Code for no mendatory parameter BAD_REQUEST |
m_ahsan | 15:8c473836feba | 223 | return; } |
m_ahsan | 15:8c473836feba | 224 | |
m_ahsan | 15:8c473836feba | 225 | ////////////////////////Operation Parameter (Mendatory parameter)////////////////////// |
m_ahsan | 15:8c473836feba | 226 | if(MSG.hasMember("op")) |
m_ahsan | 15:8c473836feba | 227 | { |
m_ahsan | 15:8c473836feba | 228 | op = MSG["op"].get<int>(); |
m_ahsan | 15:8c473836feba | 229 | printf("Operation: %d\r\n", op); |
m_ahsan | 15:8c473836feba | 230 | Operation_Type(); |
m_ahsan | 15:8c473836feba | 231 | printf("Operation: %s\r\n", operation.c_str()); |
m_ahsan | 15:8c473836feba | 232 | /* Process Notification*/ |
m_ahsan | 15:8c473836feba | 233 | if(op == 5) |
m_ahsan | 15:8c473836feba | 234 | { |
m_ahsan | 15:8c473836feba | 235 | MbedJSONValue &MSG_1 = MSG["pc"]["m2m:sgn"]; |
m_ahsan | 15:8c473836feba | 236 | sur = MSG_1["sur"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 237 | printf("Subscription Reference: %s\r\n", sur.c_str()); |
m_ahsan | 15:8c473836feba | 238 | MbedJSONValue &MSG_2 = MSG_1["m2m:sgn"]["nev"]; |
m_ahsan | 15:8c473836feba | 239 | net = MSG_2["net"].get<int>(); |
m_ahsan | 15:8c473836feba | 240 | printf("NotificationEventType: %d\r\n", net); |
m_ahsan | 15:8c473836feba | 241 | MbedJSONValue &MSG_3 = MSG_2["nev"]["rep"]["cin"]; |
m_ahsan | 15:8c473836feba | 242 | con = MSG_3["con"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 243 | printf("Content: %s\r\n", con.c_str()); |
m_ahsan | 15:8c473836feba | 244 | cnf = MSG_3["cnf"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 245 | printf("Content Info: %s\r\n", cnf.c_str()); |
m_ahsan | 15:8c473836feba | 246 | to = MSG["to"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 247 | printf("To: %s\r\n", to.c_str()); |
m_ahsan | 15:8c473836feba | 248 | rqi = MSG["rqi"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 249 | printf("Request Identifier: %s\r\n", rqi.c_str()); |
m_ahsan | 15:8c473836feba | 250 | MSG.~MbedJSONValue(); |
m_ahsan | 15:8c473836feba | 251 | MSG_1.~MbedJSONValue(); |
m_ahsan | 15:8c473836feba | 252 | MSG_2.~MbedJSONValue(); |
m_ahsan | 15:8c473836feba | 253 | MSG_3.~MbedJSONValue(); |
m_ahsan | 15:8c473836feba | 254 | return; |
m_ahsan | 15:8c473836feba | 255 | } |
m_ahsan | 15:8c473836feba | 256 | } |
m_ahsan | 15:8c473836feba | 257 | else { |
m_ahsan | 15:8c473836feba | 258 | //add response code for no mendatory parameter |
m_ahsan | 15:8c473836feba | 259 | return; } |
m_ahsan | 15:8c473836feba | 260 | |
m_ahsan | 15:8c473836feba | 261 | ////////////////////////To Parameter (Mendatory parameter)////////////////////// |
m_ahsan | 15:8c473836feba | 262 | if(MSG.hasMember("to")) |
m_ahsan | 15:8c473836feba | 263 | { |
m_ahsan | 15:8c473836feba | 264 | to = MSG["to"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 265 | printf("To: %s\r\n", to.c_str()); |
m_ahsan | 15:8c473836feba | 266 | } |
m_ahsan | 15:8c473836feba | 267 | else { |
m_ahsan | 15:8c473836feba | 268 | //add response code for no mendatory parameter |
m_ahsan | 15:8c473836feba | 269 | return; } |
m_ahsan | 15:8c473836feba | 270 | |
m_ahsan | 15:8c473836feba | 271 | ////////////////////////Request Identifier (Mendatory parameter)////////////////////// |
m_ahsan | 15:8c473836feba | 272 | if(MSG.hasMember("rqi")) |
m_ahsan | 15:8c473836feba | 273 | { |
m_ahsan | 15:8c473836feba | 274 | rqi = MSG["rqi"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 275 | printf("Request Identifier: %s\r\n", rqi.c_str()); |
m_ahsan | 15:8c473836feba | 276 | } |
m_ahsan | 15:8c473836feba | 277 | else { |
m_ahsan | 15:8c473836feba | 278 | //add response code for no mendatory parameter |
m_ahsan | 15:8c473836feba | 279 | return; } |
m_ahsan | 15:8c473836feba | 280 | |
m_ahsan | 15:8c473836feba | 281 | ////////////////////////resource Type Parameter (Mendatory parameter)////////////////////// |
m_ahsan | 15:8c473836feba | 282 | if(MSG.hasMember("ty")) |
m_ahsan | 15:8c473836feba | 283 | { |
m_ahsan | 15:8c473836feba | 284 | ty = MSG["ty"].get<int>(); |
m_ahsan | 15:8c473836feba | 285 | printf("ResourceType: %d\r\n", ty); |
m_ahsan | 15:8c473836feba | 286 | resource_type(); |
m_ahsan | 15:8c473836feba | 287 | printf("ResourceType: %s\r\n", resourceType.c_str()); |
m_ahsan | 15:8c473836feba | 288 | } |
m_ahsan | 15:8c473836feba | 289 | else { |
m_ahsan | 15:8c473836feba | 290 | //add response code for no mendatory parameter |
m_ahsan | 15:8c473836feba | 291 | return; } |
m_ahsan | 15:8c473836feba | 292 | |
m_ahsan | 15:8c473836feba | 293 | ////////////////////////Response Status Code |
m_ahsan | 15:8c473836feba | 294 | if(MSG.hasMember("rsc")) |
m_ahsan | 15:8c473836feba | 295 | { |
m_ahsan | 15:8c473836feba | 296 | rsc = MSG["rsc"].get<int>(); |
m_ahsan | 15:8c473836feba | 297 | printf("Response Status Code: %d\r\n", rsc); |
m_ahsan | 15:8c473836feba | 298 | Response_Type(); |
m_ahsan | 15:8c473836feba | 299 | printf("Response Status: %s\r\n", response.c_str()); |
m_ahsan | 15:8c473836feba | 300 | } |
m_ahsan | 15:8c473836feba | 301 | MbedJSONValue &MSG_1 = MSG["pc"][content]; //content value depends on the resource type e.g. m2m:ae for resource type 2 |
m_ahsan | 15:8c473836feba | 302 | |
m_ahsan | 15:8c473836feba | 303 | //////////////////////// Resource specific attributes CSE-ID |
m_ahsan | 15:8c473836feba | 304 | if(MSG_1.hasMember("csi")) |
m_ahsan | 15:8c473836feba | 305 | { |
m_ahsan | 15:8c473836feba | 306 | csi = MSG_1["csi"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 307 | printf("CSI: %s\r\n", csi.c_str()); |
m_ahsan | 15:8c473836feba | 308 | } |
m_ahsan | 15:8c473836feba | 309 | |
m_ahsan | 15:8c473836feba | 310 | //////////////////////// Resource specific attributes Point of Access |
m_ahsan | 15:8c473836feba | 311 | if(MSG_1.hasMember("poa")) |
m_ahsan | 15:8c473836feba | 312 | { |
m_ahsan | 15:8c473836feba | 313 | poa = MSG_1["poa"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 314 | printf("POA: %s\r\n", poa.c_str()); |
m_ahsan | 15:8c473836feba | 315 | } |
m_ahsan | 15:8c473836feba | 316 | |
m_ahsan | 15:8c473836feba | 317 | /////////////////////// Resource specific attributes CSE Type |
m_ahsan | 15:8c473836feba | 318 | if(MSG_1.hasMember("cst")) |
m_ahsan | 15:8c473836feba | 319 | { |
m_ahsan | 15:8c473836feba | 320 | cst = MSG_1["cst"].get<int>(); |
m_ahsan | 15:8c473836feba | 321 | printf("CSE Type: %d\r\n", cst); |
m_ahsan | 15:8c473836feba | 322 | CSE_Type(); |
m_ahsan | 15:8c473836feba | 323 | printf("CSE Type: %s\r\n", cseType.c_str()); |
m_ahsan | 15:8c473836feba | 324 | } |
m_ahsan | 15:8c473836feba | 325 | |
m_ahsan | 15:8c473836feba | 326 | /////////////////////// Resource specific attributes RequestReachability |
m_ahsan | 15:8c473836feba | 327 | if(MSG_1.hasMember("rr")) |
m_ahsan | 15:8c473836feba | 328 | { |
m_ahsan | 15:8c473836feba | 329 | RequestReachability = MSG_1["rr"].get<bool>(); |
m_ahsan | 15:8c473836feba | 330 | printf("RR: %s\r\n", RequestReachability? "true" : "false"); |
m_ahsan | 15:8c473836feba | 331 | } |
m_ahsan | 15:8c473836feba | 332 | |
m_ahsan | 15:8c473836feba | 333 | /////////////////////// Resource specific attributes App-ID |
m_ahsan | 15:8c473836feba | 334 | if(MSG_1.hasMember("api")) |
m_ahsan | 15:8c473836feba | 335 | { |
m_ahsan | 15:8c473836feba | 336 | api = MSG_1["api"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 337 | printf("App-ID: %s\r\n", api.c_str()); |
m_ahsan | 15:8c473836feba | 338 | } |
m_ahsan | 15:8c473836feba | 339 | /////////////////////// Resource specific attributes resourceName |
m_ahsan | 15:8c473836feba | 340 | if(MSG_1.hasMember("rn")) |
m_ahsan | 15:8c473836feba | 341 | { |
m_ahsan | 15:8c473836feba | 342 | rn = MSG_1["rn"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 343 | printf("resourceName : %s\r\n", rn.c_str()); |
m_ahsan | 15:8c473836feba | 344 | } |
m_ahsan | 15:8c473836feba | 345 | /////////////////////// Resource specific attributes Content |
m_ahsan | 15:8c473836feba | 346 | if(MSG_1.hasMember("con")) |
m_ahsan | 15:8c473836feba | 347 | { |
m_ahsan | 15:8c473836feba | 348 | con = MSG_1["con"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 349 | printf("Content: %s\r\n", con.c_str()); |
m_ahsan | 15:8c473836feba | 350 | } |
m_ahsan | 15:8c473836feba | 351 | /////////////////////// Resource specific attributes ContentInfo |
m_ahsan | 15:8c473836feba | 352 | if(MSG_1.hasMember("cnf")) |
m_ahsan | 15:8c473836feba | 353 | { |
m_ahsan | 15:8c473836feba | 354 | cnf = MSG_1["cnf"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 355 | printf("Content Info: %s\r\n", cnf.c_str()); |
m_ahsan | 15:8c473836feba | 356 | } |
m_ahsan | 15:8c473836feba | 357 | /////////////////////// Resource specific attributes NotificationURI nu |
m_ahsan | 15:8c473836feba | 358 | if(MSG_1.hasMember("nu")) |
m_ahsan | 15:8c473836feba | 359 | { |
m_ahsan | 15:8c473836feba | 360 | nu = MSG_1["nu"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 361 | printf("Notification URI: %s\r\n", nu.c_str()); |
m_ahsan | 15:8c473836feba | 362 | } |
m_ahsan | 15:8c473836feba | 363 | /////////////////////// Resource specific attributes NotificationContentType |
m_ahsan | 15:8c473836feba | 364 | if(MSG_1.hasMember("nct")) |
m_ahsan | 15:8c473836feba | 365 | { |
m_ahsan | 15:8c473836feba | 366 | nct = MSG_1["nct"].get<int>(); |
m_ahsan | 15:8c473836feba | 367 | printf("NotificationContentType: %d\r\n", nct); |
m_ahsan | 15:8c473836feba | 368 | MbedJSONValue &MSG_2 = MSG_1["m2m:sub"]["enc"]; |
m_ahsan | 15:8c473836feba | 369 | if(MSG_2.hasMember("net")) |
m_ahsan | 15:8c473836feba | 370 | { |
m_ahsan | 15:8c473836feba | 371 | net = MSG_2["net"].get<int>(); |
m_ahsan | 15:8c473836feba | 372 | printf("NotificationEventType: %d\r\n", net); |
m_ahsan | 15:8c473836feba | 373 | } |
m_ahsan | 15:8c473836feba | 374 | MSG_2.~MbedJSONValue(); |
m_ahsan | 15:8c473836feba | 375 | } |
m_ahsan | 15:8c473836feba | 376 | |
m_ahsan | 15:8c473836feba | 377 | MSG.~MbedJSONValue(); |
m_ahsan | 15:8c473836feba | 378 | MSG_1.~MbedJSONValue(); |
m_ahsan | 15:8c473836feba | 379 | return; |
m_ahsan | 15:8c473836feba | 380 | } |
m_ahsan | 15:8c473836feba | 381 | |
m_ahsan | 15:8c473836feba | 382 | void process_rsc(MbedJSONValue &MSG) |
m_ahsan | 15:8c473836feba | 383 | { |
m_ahsan | 15:8c473836feba | 384 | if(MSG.hasMember("rqi")) |
m_ahsan | 15:8c473836feba | 385 | { |
m_ahsan | 15:8c473836feba | 386 | rqi = MSG["rqi"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 387 | printf("Request Identifier: %s\r\n", rqi.c_str()); |
m_ahsan | 15:8c473836feba | 388 | } |
m_ahsan | 15:8c473836feba | 389 | else { |
m_ahsan | 15:8c473836feba | 390 | //add response code for no mendatory parameter |
m_ahsan | 15:8c473836feba | 391 | return; } |
m_ahsan | 15:8c473836feba | 392 | if(MSG.hasMember("to")) |
m_ahsan | 15:8c473836feba | 393 | { |
m_ahsan | 15:8c473836feba | 394 | to = MSG["to"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 395 | printf("To: %s\r\n", to.c_str()); |
m_ahsan | 15:8c473836feba | 396 | } |
m_ahsan | 15:8c473836feba | 397 | else { |
m_ahsan | 15:8c473836feba | 398 | //add response code for no mendatory parameter |
m_ahsan | 15:8c473836feba | 399 | return; } |
m_ahsan | 15:8c473836feba | 400 | if(MSG.hasMember("fr")) |
m_ahsan | 15:8c473836feba | 401 | { |
m_ahsan | 15:8c473836feba | 402 | From = MSG["fr"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 403 | printf("From: %s\r\n", From.c_str()); |
m_ahsan | 15:8c473836feba | 404 | } |
m_ahsan | 15:8c473836feba | 405 | else { |
m_ahsan | 15:8c473836feba | 406 | //add response code for no mendatory parameter |
m_ahsan | 15:8c473836feba | 407 | return; } |
m_ahsan | 15:8c473836feba | 408 | |
m_ahsan | 15:8c473836feba | 409 | MbedJSONValue &MSG_1 = MSG["pc"][content]; |
m_ahsan | 15:8c473836feba | 410 | |
m_ahsan | 15:8c473836feba | 411 | if(MSG_1.hasMember("ty")) |
m_ahsan | 15:8c473836feba | 412 | { |
m_ahsan | 15:8c473836feba | 413 | ty = MSG_1["ty"].get<int>(); |
m_ahsan | 15:8c473836feba | 414 | printf("ResourceType in response: %d\r\n", ty); |
m_ahsan | 15:8c473836feba | 415 | //resource_type(); |
m_ahsan | 15:8c473836feba | 416 | //printf("ResourceType in response: %s\r\n", resourceType.c_str()); |
m_ahsan | 15:8c473836feba | 417 | } |
m_ahsan | 15:8c473836feba | 418 | else { |
m_ahsan | 15:8c473836feba | 419 | //add response code for no mendatory parameter |
m_ahsan | 15:8c473836feba | 420 | return; } |
m_ahsan | 15:8c473836feba | 421 | |
m_ahsan | 15:8c473836feba | 422 | if(MSG_1.hasMember("rr")) |
m_ahsan | 15:8c473836feba | 423 | { |
m_ahsan | 15:8c473836feba | 424 | RequestReachability = MSG_1["rr"].get<bool>(); |
m_ahsan | 15:8c473836feba | 425 | printf("RR: %s\r\n", RequestReachability? "true" : "false"); |
m_ahsan | 15:8c473836feba | 426 | } |
m_ahsan | 15:8c473836feba | 427 | if(MSG_1.hasMember("aei")) |
m_ahsan | 15:8c473836feba | 428 | { |
m_ahsan | 15:8c473836feba | 429 | aei = MSG_1["aei"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 430 | printf("AE_ID: %s\r\n", aei.c_str()); |
m_ahsan | 15:8c473836feba | 431 | } |
m_ahsan | 15:8c473836feba | 432 | if(MSG_1.hasMember("poa")) |
m_ahsan | 15:8c473836feba | 433 | { |
m_ahsan | 15:8c473836feba | 434 | poa = MSG_1["poa"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 435 | printf("POA: %s\r\n", poa.c_str()); |
m_ahsan | 15:8c473836feba | 436 | } |
m_ahsan | 15:8c473836feba | 437 | if(MSG_1.hasMember("rn")) |
m_ahsan | 15:8c473836feba | 438 | { |
m_ahsan | 15:8c473836feba | 439 | rn = MSG_1["rn"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 440 | printf("Resource Name: %s\r\n", rn.c_str()); |
m_ahsan | 15:8c473836feba | 441 | } |
m_ahsan | 15:8c473836feba | 442 | if(MSG_1.hasMember("api")) |
m_ahsan | 15:8c473836feba | 443 | { |
m_ahsan | 15:8c473836feba | 444 | api = MSG_1["api"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 445 | printf("App-ID: %s\r\n", api.c_str()); |
m_ahsan | 15:8c473836feba | 446 | } |
m_ahsan | 15:8c473836feba | 447 | /////////////////////// Resource specific attributes Content |
m_ahsan | 15:8c473836feba | 448 | if(MSG_1.hasMember("con")) |
m_ahsan | 15:8c473836feba | 449 | { |
m_ahsan | 15:8c473836feba | 450 | con = MSG_1["con"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 451 | printf("Content: %s\r\n", con.c_str()); |
m_ahsan | 15:8c473836feba | 452 | } |
m_ahsan | 15:8c473836feba | 453 | /////////////////////// Resource specific attributes ContentInfo |
m_ahsan | 15:8c473836feba | 454 | if(MSG_1.hasMember("cnf")) |
m_ahsan | 15:8c473836feba | 455 | { |
m_ahsan | 15:8c473836feba | 456 | cnf = MSG_1["cnf"].get<std::string>(); |
m_ahsan | 15:8c473836feba | 457 | printf("Content Info: %s\r\n", cnf.c_str()); |
m_ahsan | 15:8c473836feba | 458 | } |
m_ahsan | 15:8c473836feba | 459 | |
m_ahsan | 15:8c473836feba | 460 | return; |
m_ahsan | 15:8c473836feba | 461 | } |