blob: 097738ae8d3e592fa94b533c20fa3e7409793dac [file] [log] [blame]
w.denge87b5002025-08-20 10:43:03 +08001#include "apparms_config_example.h"
2#include "apparms_util.h"
3
4#ifdef ARMS_SUPPORT_ARGV
5#include "apparms_argv.h"
6#endif
7
8#ifdef ARMS_BOARD_EXAMPLE
9
10static ARMSCFGFUNLIST arms_example_cfgfun_pointer =
11{
12 arms_config_example_get_imei,
13 arms_config_example_get_sn,
14 arms_config_example_get_networkst,
15
16#ifdef ARMS_SUPPORT_DM
17 arms_config_example_get_dm_mode_cfg,
18 arms_config_example_get_dm_tlv_cfg,
19 arms_config_example_get_dm_push_rsp_tlv_cfg,
20 arms_config_example_get_dm_notification_tlv_cfg,
21#ifdef ARMS_DM_UDP
22 arms_config_example_get_dm_udp_cfg,
23#endif
24#ifdef ARMS_DM_MQTT
25 arms_config_example_get_dm_mqtt_cfg,
26#endif
27#ifdef ARMS_DM_LWM2M
28 arms_config_example_get_dm_lwm2m_cfg,
29#endif
30#ifdef ARMS_DM_IPC
31 arms_config_example_get_dm_ipc_cfg,
32#endif
33#ifdef ARMS_DM_RPC
34 arms_config_example_get_dm_rpc_cfg,
35#endif
36#endif
37
38#ifdef ARMS_SUPPORT_FOTA
39#ifdef ARMS_FOTA_HTTP
40 arms_config_example_get_http_cfg,
41#endif
42 arms_config_example_get_fota_mode_cfg,
43 arms_config_example_get_fota_tlv_cfg,
44#endif
45
46#ifdef ARMS_SUPPORT_EC2
47 arms_config_example_get_ec2_cfg,
48#endif
49
50 arms_config_example_init,
51 arms_config_example_uninit
52};
53
54PARMSCFGFUNLIST arms_config_example_get_cfgfun_pointer(void)
55{
56 return &arms_example_cfgfun_pointer;
57}
58
59int arms_config_example_get_imei(unsigned char *pDMIMEI, unsigned char* pIMEI)
60{
61 char szIMEI[32] = {0};
62#if 0
63 #ifdef ARMS_SUPPORT_ARGV
64 if (arms_argv_get_imei(szIMEI, sizeof(szIMEI)) <= 0)
65 #endif
66 {
67 #if defined(ARMS_DM_MQTT)
68 #ifdef ARMS_AUTH_X509
69 strcpy(szIMEI, "920000000000051");
70 #else
71 strcpy(szIMEI, "990000000000053");
72 #endif
73 #elif defined(ARMS_DM_LWM2M)
74 strcpy(szIMEI, "930000000000151");
75 #else
76 strcpy(szIMEI, "998199055256418");
77 #endif
78 }
79#endif
80 cfg_get_item("imei", szIMEI, sizeof(szIMEI));
81 printf("****arms_config_example_get_imei imei=[%s]\n", szIMEI);
82 if (pDMIMEI != NULL)
83 {
84 strcpy((char *)pDMIMEI, "0");
85 strcat((char *)pDMIMEI, szIMEI);
86 }
87
88 if (pIMEI != NULL)
89 {
90 strcpy((char *)pIMEI, szIMEI);
91 }
92
93 return 0;
94}
95
96int arms_config_example_get_sn(unsigned char *pSN)
97{
98 char szSN[32] = {0};
99
100 strcpy(szSN, "123456789012345");
101
102 if (pSN != NULL)
103 {
104 strcpy((char *)pSN, szSN);
105 }
106
107 return 0;
108}
109
110int arms_config_example_get_networkst(char *pIPAddr)
111{
112 int ret = -3;
113 char buf[32] = {0};
114 char wan_ipaddr[32] = {0};
115
116 if (pIPAddr == NULL)
117 return -1;
118#if 0
119 #ifdef ARMS_SUPPORT_ARGV
120 if (arms_argv_get_intf(szIntf, sizeof(szIntf)) <= 0)
121 #endif
122 {
123 strcpy(szIntf, ARMS_DM_WAN_IF);
124 }
125
126 ret = arms_util_get_if_ip(szIntf, pIPAddr);
127 if ((ret >= 0) && (strcmp(pIPAddr, "0.0.0.0") == 0))
128 {
129 ret = -3;
130 }
131
132#endif
133 cfg_get_item("ppp_status", buf, sizeof(buf));
134 if (0 == strcmp(buf, "ppp_connected"))
135 {
136 cfg_get_item("wan_ipaddr", wan_ipaddr, sizeof(wan_ipaddr));
137 strcpy(pIPAddr, wan_ipaddr);
138 ret = 0;
139 }
140
141 return ret;
142}
143
144int arms_config_example_init(void)
145{
146 return 0;
147}
148
149int arms_config_example_uninit(void)
150{
151 return 0;
152}
153
154
155#ifdef ARMS_SUPPORT_DM
156int arms_config_example_get_dm_mode_cfg(PDMCOMMCFG pDMCommCfg)
157{
158 if (pDMCommCfg == NULL)
159 return -1;
160
161#if defined(ARMS_DM_MQTT)
162 pDMCommCfg->emCommMode = ARMS_DM_COMM_MQTT;
163 #ifdef ARMS_AUTH_X509
164 pDMCommCfg->emAuthMode = ARMS_DM_AUTH_CERT;
165 #else
166 pDMCommCfg->emAuthMode = ARMS_DM_AUTH_KEY;
167 #endif
168#elif defined(ARMS_DM_LWM2M)
169 pDMCommCfg->emCommMode = ARMS_DM_COMM_LWM2M;
170#else
171 pDMCommCfg->emCommMode = ARMS_DM_COMM_UDP;
172#endif
173
174 pDMCommCfg->nReportPeriod = ARMS_DM_REPORT_INTERVAL; //Report DM telemetry for every 60 seconds
175
176 #ifdef ARMS_SUPPORT_ARGV
177 if (arms_argv_get_dm(&pDMCommCfg->unHWId, (char *)pDMCommCfg->szKey, sizeof(pDMCommCfg->szKey)) <= 0)
178 #endif
179 {
180 #if defined(ARMS_DM_MQTT)
181 #ifdef ARMS_AUTH_X509
182 pDMCommCfg->unHWId = 5168;
183 strcpy((char *)pDMCommCfg->szKey, "feb3aed743e74f45b718de349f0774e1");
184 #else
185 pDMCommCfg->unHWId = ARMS_DM_ACCESS_ID_MQTT;
186 strcpy((char *)pDMCommCfg->szKey, ARMS_DM_ACCESS_PW_MQTT);
187 #endif
188 #elif defined(ARMS_DM_LWM2M)
189 pDMCommCfg->unHWId = ARMS_DM_ACCESS_ID_LWM2M;
190 strcpy((char *)pDMCommCfg->szKey, ARMS_DM_ACCESS_PW_LWM2M);
191 #else
192 pDMCommCfg->unHWId = ARMS_DM_ACCESS_ID_UDP;
193 strcpy((char *)pDMCommCfg->szKey, ARMS_DM_ACCESS_PW_UDP);
194 #endif
195 }
196
197 return 0;
198}
199
200int arms_config_example_get_dm_tlv_cfg(PDMTLVCFG pDMTLVCfg)
201{
202 if (pDMTLVCfg == NULL)
203 return -1;
204
205 //pDMTLVCfg->emDMTLVMask = 0xFFFFF & ~ARMS_DM_TLV_COMM_RSPMSG & ~ARMS_DM_TLV_COMM_WARNMSG;
206 pDMTLVCfg->emDMTLVMask = ARMS_DM_TLV_COMM_VERSION | ARMS_DM_TLV_COMM_TOKEN;
207 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA1; //SW Ver
208 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA2; //Inner Ver
209 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA3; //RSRP
210 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA4; //RSRQ
211 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA5; //RSSI
212 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA6; //SINR
213 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA7; //Carrier
214 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA8; //GCI
215
216 pDMTLVCfg->emDMTLVGenMask = 0x1FFFF;
217 pDMTLVCfg->emDMTLVVerMask = ARMS_DM_TLV_VER_HID | ARMS_DM_TLV_VER_MCU;
218 pDMTLVCfg->emDMTLVEXTVerMask = ARMS_DM_TLV_EXTVER_MCU2;
219 pDMTLVCfg->emDMTLVDMReportMask = 0x7F;
220
221 return 0;
222}
223
224int arms_config_example_get_dm_push_rsp_tlv_cfg(PDMTLVCFG pDMTLVCfg)
225{
226 if (pDMTLVCfg == NULL)
227 return -1;
228
229 pDMTLVCfg->emDMTLVMask = ARMS_DM_TLV_COMM_VERSION | ARMS_DM_TLV_COMM_TOKEN | ARMS_DM_TLV_COMM_RSPMSG;
230 pDMTLVCfg->emDMTLVGenMask = 0x00000;
231 pDMTLVCfg->emDMTLVVerMask = ARMS_DM_TLV_VER_HID;
232 pDMTLVCfg->emDMTLVEXTVerMask = 0x00;
233 pDMTLVCfg->emDMTLVDMReportMask = 0x00;
234
235 return 0;
236}
237
238int arms_config_example_get_dm_notification_tlv_cfg(PDMTLVCFG pDMTLVCfg)
239{
240 if (pDMTLVCfg == NULL)
241 return -1;
242
243 pDMTLVCfg->emDMTLVMask = ARMS_DM_TLV_COMM_VERSION | ARMS_DM_TLV_COMM_TOKEN | ARMS_DM_TLV_COMM_WARNMSG;
244
245 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA1; //SW Ver
246 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA2; //Inner Ver
247 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA3; //RSRP
248 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA4; //RSRQ
249 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA5; //RSSI
250 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA6; //SINR
251 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA7; //Carrier
252 pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA8; //GCI
253
254 pDMTLVCfg->emDMTLVGenMask = 0x00000;
255 pDMTLVCfg->emDMTLVVerMask = ARMS_DM_TLV_VER_HID;
256 pDMTLVCfg->emDMTLVEXTVerMask = 0x00;
257 pDMTLVCfg->emDMTLVDMReportMask = 0x00;
258
259 return 0;
260}
261
262#ifdef ARMS_DM_UDP
263int arms_config_example_get_dm_udp_cfg(PUDPCFG pUDPCfg)
264{
265 if (pUDPCfg == NULL)
266 return -1;
267
268 pUDPCfg->nUDPPort = 9000;
269
270 #ifdef ARMS_SUPPORT_ARGV
271 if (arms_argv_get_udp_url(pUDPCfg->szUDPAddr, sizeof(pUDPCfg->szUDPAddr)) <= 0)
272 #endif
273 {
274 strcpy(pUDPCfg->szUDPAddr, ARMS_DM_SRV_UDP_ADDR);
275 }
276
277 return 0;
278}
279#endif
280
281#ifdef ARMS_DM_MQTT
282int arms_config_example_get_dm_mqtt_cfg(PMQTTCFG pMQTTCfg,PDMCOMMCFG pDMCommCfg)
283{
284 unsigned char *p = NULL;
285 if (pMQTTCfg == NULL)
286 return -1;
287
288 #ifdef ARMS_SUPPORT_ARGV
289 if (arms_argv_get_mqtt_url(pMQTTCfg->szMQTTAddr, sizeof(pMQTTCfg->szMQTTAddr)) <= 0)
290 #endif
291 {
292 strcpy(pMQTTCfg->szMQTTAddr,ARMS_DM_SRV_MQTT_ADDR);
293 }
294
295 pMQTTCfg->nMQTTLiveTM = 180;
296#ifdef ARMS_AUTH_X509
297 pMQTTCfg->nMQTTPort = 8099;
298#else
299 pMQTTCfg->nMQTTPort = 8089;
300#endif
301 p = pDMCommCfg->szIMEI + 1;
302 sprintf(pMQTTCfg->szUserName,"%ld_%s",pDMCommCfg->unHWId,p);
303#ifdef ARMS_AUTH_X509
304 strcpy(pMQTTCfg->szPassWord,"123456");
305 strcpy(pMQTTCfg->szCaCert,"./certs/ca-cert.pem");
306 strcpy(pMQTTCfg->szClientCert,"./certs/client-cert.pem");
307 strcpy(pMQTTCfg->szClientKey,"./certs/client-key.pem");
308#else
309 strcpy(pMQTTCfg->szPassWord,(char *)pDMCommCfg->szKey);
310#endif
311
312 return 0;
313}
314#endif
315
316#ifdef ARMS_DM_LWM2M
317int arms_config_example_get_dm_lwm2m_cfg(PLWM2MCFG pLWM2MCfg,PDMCOMMCFG pDMCommCfg)
318{
319 unsigned char *p = NULL;
320 if (pLWM2MCfg == NULL)
321 return -1;
322
323
324 #ifdef ARMS_SUPPORT_ARGV
325 if (arms_argv_get_lwm2m_url(pLWM2MCfg->szLwM2MAddr, sizeof(pLWM2MCfg->szLwM2MAddr)) <= 0)
326 #endif
327 {
328 strcpy(pLWM2MCfg->szLwM2MAddr,ARMS_DM_SRV_LWM2M_ADDR);
329 }
330
331 pLWM2MCfg->nLwM2MPort = 5683;
332 p = pDMCommCfg->szIMEI + 1;
333 sprintf(pLWM2MCfg->szEndpointName,"%s",p);
334
335 return 0;
336}
337#endif
338
339#ifdef ARMS_DM_IPC
340int arms_config_example_get_dm_ipc_cfg(PDMIPCCFG pIPCCfg)
341{
342 memset(pIPCCfg, 0, sizeof(DMIPCCFG));
343 pIPCCfg->enable = 1;
344 strcpy(pIPCCfg->intf[0], ARMS_DM_WAN_IF);
345 pIPCCfg->nPort = ARMS_DM_IPC_LISTEN_PORT;
346 pIPCCfg->uMaxclient = ARMS_DM_IPC_MAX_CLIENT;
347 pIPCCfg->mtimeout = ARMS_DM_IPC_CLOSE_TIME;
348 pIPCCfg->bUnixMode = 0;
349 pIPCCfg->bDynamicOpen = 1;
350
351 return 0;
352}
353#endif
354
355#ifdef ARMS_DM_RPC
356int arms_config_example_get_dm_rpc_cfg(PDMRPCCFG pRPCCfg)
357{
358 memset(pRPCCfg, 0, sizeof(DMRPCCFG));
359 pRPCCfg->bRPC = 1;
360 #ifdef ARMS_DM_RPC_UNX_MODE
361 pRPCCfg->bRPCUnixMode = 1;
362 strcpy(pRPCCfg->szRPCUnix, ARMS_DM_RPC_UNIX_PATH);
363 #else
364 pRPCCfg->bRPCUnixMode = 0;
365 strcpy(pRPCCfg->szRPCTCPSrv, "127.0.0.1");
366 pRPCCfg->nRPCTCPPort = ARMS_DM_RPC_TCP_PORT;
367 #endif
368
369 pRPCCfg->mRPCTimeout = 300*1000;
370
371 return 0;
372}
373#endif
374#endif
375
376#ifdef ARMS_SUPPORT_FOTA
377int arms_config_example_get_fota_mode_cfg(PFOTACOMMCFG pFOTACommCfg)
378{
379 if (pFOTACommCfg == NULL)
380 return -1;
381
382#if defined(ARMS_FOTA_HTTP)
383 pFOTACommCfg->emCommMode = ARMS_FOTA_COMM_HTTP_HTTPS;
384#endif
385
386 pFOTACommCfg->nCheckPeriod = ARMS_FOTA_CHECK_INTERVAL; //Check fota for every 30 seconds
387
388 return 0;
389}
390
391int arms_config_example_get_fota_tlv_cfg(PFOTATLVCFG pFOTATLVCfg)
392{
393 if (pFOTATLVCfg == NULL)
394 return -1;
395
396
397 return 0;
398}
399
400
401#ifdef ARMS_FOTA_HTTP
402int arms_config_example_get_http_cfg(PHTTPCFG pHTTPCfg)
403{
404 if (pHTTPCfg == NULL)
405 return -1;
406
407#ifdef ARMS_FOTA_HTTPS
408 #ifdef ARMS_SUPPORT_ARGV
409 if (arms_argv_get_fota_url(1, pHTTPCfg->szAddr, sizeof(pHTTPCfg->szAddr)) <= 0)
410 #endif
411 {
412 strcpy(pHTTPCfg->szAddr,ARMS_FOTA_SRV_HTTPS_ADDR);
413 }
414 pHTTPCfg->nPort = 443;
415#else
416 #ifdef ARMS_SUPPORT_ARGV
417 if (arms_argv_get_fota_url(0, pHTTPCfg->szAddr, sizeof(pHTTPCfg->szAddr)) <= 0)
418 #endif
419 {
420 strcpy(pHTTPCfg->szAddr,ARMS_FOTA_SRV_HTTP_ADDR);
421 }
422 pHTTPCfg->nPort = 80;
423#endif
424 strcpy(pHTTPCfg->szDownFilePath,ARMS_FOTA_DOWNLOAD_PATH);
425
426 #ifdef ARMS_SUPPORT_ARGV
427 if (arms_argv_get_fota(pHTTPCfg->szProdID, sizeof(pHTTPCfg->szProdID),
428 pHTTPCfg->szPassword, sizeof(pHTTPCfg->szPassword)) <= 0)
429 #endif
430 {
431 strcpy(pHTTPCfg->szProdID,ARMS_FOTA_ACCESS_ID);
432 strcpy(pHTTPCfg->szPassword,ARMS_FOTA_ACCESS_PW);
433 }
434
435 return 0;
436}
437#endif
438#endif
439
440#ifdef ARMS_SUPPORT_EC2
441int arms_config_example_get_ec2_cfg(PEC2CFG pEC2Cfg)
442{
443 if (pEC2Cfg == NULL)
444 return -1;
445
446 strcpy(pEC2Cfg->stHttpCfg.szAddr,ARMS_EC2_SRV_HTTP_ADDR);
447 pEC2Cfg->stHttpCfg.nPort = 80;
448 sprintf(pEC2Cfg->stHttpCfg.szProdID,"%d",ARMS_EC2_ACCESS_ID);
449 strcpy(pEC2Cfg->szHttpRspPath,ARMS_EC2_HTTP_RSP_PATH);
450
451 return 0;
452}
453#endif
454
455#endif
456