blob: f1d72ddb74d0e969b3bdee92a4dd5d7982d47088 [file] [log] [blame]
w.denge87b5002025-08-20 10:43:03 +08001#include "apparms_data_example.h"
2#include "apparms_util.h"
3
4#ifdef ARMS_BOARD_EXAMPLE
5static ARMSDATAFUNLIST arms_example_datafun_pointer =
6{
7#ifdef ARMS_SUPPORT_DM
8 arms_data_example_get_dm_header_tag,
9 arms_data_example_get_dm_header_event,
10 arms_data_example_get_dm_generic_pid,
11 arms_data_example_get_dm_generic_gps,
12 arms_data_example_get_dm_generic_battchg,
13 arms_data_example_get_dm_generic_network,
14 arms_data_example_get_dm_generic_gpio,
15 arms_data_example_get_dm_generic_odometer,
16 arms_data_example_get_dm_version,
17 arms_data_example_get_dm_extver,
18 arms_data_example_get_dm_dmreport_pricell,
19 arms_data_example_get_dm_dmreport_nbcell,
20 arms_data_example_get_dm_dmreport_light,
21 arms_data_example_get_dm_dmreport_macsim,
22 arms_data_example_get_dm_cusdata,
23 arms_data_example_handle_dm_ack_pushmsg,
24 arms_data_example_handle_dm_ack_ok,
25 arms_data_example_handle_dm_ack_fail,
26#endif
27
28#ifdef ARMS_SUPPORT_FOTA
29 arms_data_example_get_fota_ret,
30 arms_data_example_get_fota_ver_fw,
31 arms_data_example_get_fota_ver_cfg,
32 arms_data_example_get_fota_ver_mcu,
33 arms_data_example_get_fota_net_status,
34 arms_data_example_get_fota_task_id,
35 arms_data_example_save_fota_task_id,
36 arms_data_example_get_fota_device_id,
37 arms_data_example_save_fota_device_id,
38 arms_data_example_get_fota_device_sec,
39 arms_data_example_save_fota_device_sec,
40 arms_data_example_get_fota_deviceid_md5,
41 arms_data_example_save_fota_deviceid_md5,
42 arms_data_example_get_fota_pre_version_fw,
43 arms_data_example_save_fota_pre_version_fw,
44 arms_data_example_get_fota_pre_version_cfg,
45 arms_data_example_save_fota_pre_version_cfg,
46 arms_data_example_get_fota_pre_version_mcu,
47 arms_data_example_save_fota_pre_version_mcu,
48 arms_data_example_get_fota_backup,
49 arms_data_example_save_fota_backup,
50 arms_data_example_get_fota_down_size,
51 arms_data_example_save_fota_down_size,
52 arms_data_example_upgrade,
53 arms_data_example_get_region_size,
54 arms_data_example_get_log,
55#endif
56
57 arms_data_example_set_waketime,
58 arms_data_example_get_suspend,
59 arms_data_example_get_timestamp
60};
61
62PARMSDATAFUNLIST arms_data_example_get_cfgfun_pointer(void)
63{
64 return &arms_example_datafun_pointer;
65}
66
67int arms_data_example_set_waketime(unsigned long uHWId, long long nNowInSec, unsigned short nIntervalInSec)
68{
69 //TODO: request to wake up the device with nTimeInSec by platform wake mechanism.
70
71 return 0;
72}
73
74int arms_data_example_get_suspend(unsigned long uHWId, int* pSuspend)
75{
76 if (pSuspend == NULL)
77 return -1;
78
79 *pSuspend = 0;
80
81 return 0;
82}
83
84int arms_data_example_get_timestamp(unsigned long* pTimeStamp)
85{
86 if (pTimeStamp == NULL)
87 return -1;
88
89#ifdef EXAMPLE_REF_VALUE
90 struct tm *p_tm;
91 time_t now = time(NULL);
92 p_tm = localtime(&now);
93
94 *pTimeStamp = ((p_tm->tm_year + 1900) - 2000) * 12;
95 *pTimeStamp = (*pTimeStamp + p_tm->tm_mon) * 31;
96 *pTimeStamp = (*pTimeStamp + p_tm->tm_mday - 1) * 24;
97 *pTimeStamp = ((*pTimeStamp + p_tm->tm_hour) * 60 + p_tm->tm_min) * 60 + p_tm->tm_sec;
98#endif
99
100 return 0;
101}
102
103#ifdef ARMS_SUPPORT_DM
104int arms_data_example_get_dm_header_tag(unsigned char* pTag)
105{
106 if (pTag == NULL)
107 return -1;
108
109 *pTag = 0;
110
111#ifdef EXAMPLE_REF_VALUE
112 *pTag = 1;
113#endif
114
115 return 0;
116}
117
118int arms_data_example_get_dm_header_event(unsigned short* pEvent)
119{
120 if (pEvent == NULL)
121 return -1;
122
123 *pEvent = 0;
124
125#ifdef EXAMPLE_REF_VALUE
126 *pEvent = 0x22;
127#endif
128
129 return 0;
130}
131
132int arms_data_example_get_dm_generic_pid(unsigned char* pID)
133{
134 if (pID == NULL)
135 return -1;
136
137 *pID = 0;
138
139#ifdef EXAMPLE_REF_VALUE
140 *pID = 5;
141#endif
142
143 return 0;
144}
145
146int arms_data_example_get_dm_generic_gps(PDMGPSDATA pGPS)
147{
148 if (pGPS == NULL)
149 return -1;
150
151#ifdef EXAMPLE_REF_VALUE
152 pGPS->gps_lat = 31.19435;
153 pGPS->gps_lon = 121.5827;
154 pGPS->gps_speed = 100;
155 pGPS->gps_heading = 128;
156 pGPS->gps_altitude = 25;
157 pGPS->gps_status = 1;
158 pGPS->gps_sat_count = 5;
159 pGPS->gps_HOP = 1.1;
160#endif
161
162 return 0;
163}
164
165int arms_data_example_get_dm_generic_battchg(PDMBATTCHGDATA pBattChg)
166{
167 if (pBattChg == NULL)
168 return -1;
169
170#ifdef EXAMPLE_REF_VALUE
171 pBattChg->main_voltage = 1735;
172 pBattChg->batt_voltage = 2967;
173 pBattChg->aux_voltage = 3527;
174 pBattChg->solar_voltage = 4560;
175 pBattChg->tempeature = 75;
176 pBattChg->percentage = 99;
177 pBattChg->charge = 4321;
178#endif
179
180 return 0;
181}
182
183int arms_data_example_get_dm_generic_network(PDMNETWORKDATA pNetwork)
184{
185 if (pNetwork == NULL)
186 return -1;
187
188#ifdef EXAMPLE_REF_VALUE
189 pNetwork->roaming = 1;
190 pNetwork->srvtype = 2;
191 pNetwork->nw_mcc = 460;
192 pNetwork->nw_mnc = 0;
193 pNetwork->nw_rssi = 22;
194#endif
195
196 return 0;
197}
198
199int arms_data_example_get_dm_generic_gpio(PDMGPIODATA pGpio)
200{
201 if (pGpio == NULL)
202 return -1;
203
204#ifdef EXAMPLE_REF_VALUE
205 pGpio->GPIOADir=1;
206 pGpio->GPIOAValue=0;
207 pGpio->GPIOBDir=1;
208 pGpio->GPIOBValue=0;
209 pGpio->GPIOCDir=0;
210 pGpio->GPIOCValue=0;
211 pGpio->GPIODDir=1;
212 pGpio->GPIODValue=1;
213
214 pGpio->GPIOEDir=0;
215 pGpio->GPIOEValue=0;
216 pGpio->GPIOFDir=0;
217 pGpio->GPIOFValue=0;
218 pGpio->GPIOGDir=0;
219 pGpio->GPIOGValue=0;
220 pGpio->GPIOHDir=0;
221 pGpio->GPIOHValue=0;
222#endif
223
224 return 0;
225}
226
227int arms_data_example_get_dm_generic_odometer(unsigned long* pOdometer)
228{
229 if (pOdometer == NULL)
230 return -1;
231
232#ifdef EXAMPLE_REF_VALUE
233 *pOdometer = 123;
234#endif
235
236 return 0;
237}
238
239int arms_data_example_get_dm_version(PDMVERSIONDATA pVersion)
240{
241 if (pVersion == NULL)
242 return -1;
243
244#ifdef EXAMPLE_REF_VALUE
245 strcpy((char*)pVersion->main, "7.1.1.0");
246 strcpy((char*)pVersion->ext, "0");
247 strcpy((char*)pVersion->fw, "16.1.0.7.1");
248 strcpy((char*)pVersion->mcu, "1.0.8.1");
249 strcpy((char*)pVersion->cfg, "32789");
250#endif
251
252 return 0;
253}
254
255int arms_data_example_get_dm_extver(PDMEXTVERDATA pExtver)
256{
257 if (pExtver == NULL)
258 return -1;
259
260#ifdef EXAMPLE_REF_VALUE
261 strcpy((char*)pExtver->mcu2, "1.3.3.4");
262 strcpy((char*)pExtver->mcu3, "1.4.3.4");
263 strcpy((char*)pExtver->mcu4, "1.5.3.4");
264 strcpy((char*)pExtver->mcu5, "1.6.3.4");
265 strcpy((char*)pExtver->mcu6, "1.7.3.4");
266 strcpy((char*)pExtver->mcu7, "1.8.3.4");
267 strcpy((char*)pExtver->mcu8, "1.9.3.4");
268 strcpy((char*)pExtver->mcu9, "1.10.3.4");
269#endif
270
271
272 return 0;
273}
274
275int arms_data_example_get_dm_dmreport_pricell(PDMREPORTPRICELL pDMRptPriCell)
276{
277 if (pDMRptPriCell == NULL)
278 return -1;
279
280#ifdef EXAMPLE_REF_VALUE
281 pDMRptPriCell->mcc = 460;
282 pDMRptPriCell->mnc = 0;
283 pDMRptPriCell->eci = 0x1813A07;
284#endif
285
286 return 0;
287}
288
289int arms_data_example_get_dm_dmreport_nbcell(PDMREPORTNBCELL pDMRptNBCell)
290{
291 if (pDMRptNBCell == NULL)
292 return -1;
293
294#ifdef EXAMPLE_REF_VALUE
295 pDMRptNBCell[0].nb_mcc = 461;
296 pDMRptNBCell[0].nb_mnc = 01;
297 pDMRptNBCell[0].nb_eci = 45234;
298 pDMRptNBCell[0].nb_rssi = 21;
299 pDMRptNBCell[1].nb_mcc = 462;
300 pDMRptNBCell[1].nb_mnc = 02;
301 pDMRptNBCell[1].nb_eci = 12398;
302 pDMRptNBCell[1].nb_rssi = 22;
303 pDMRptNBCell[2].nb_mcc = 463;
304 pDMRptNBCell[2].nb_mnc = 03;
305 pDMRptNBCell[2].nb_eci = 12331;
306 pDMRptNBCell[2].nb_rssi = 23;
307#endif
308
309 return 0;
310}
311
312
313int arms_data_example_get_dm_dmreport_light(PDMREPORTLIGHTDATA pDMRptLight)
314{
315 if (pDMRptLight == NULL)
316 return -1;
317
318#ifdef EXAMPLE_REF_VALUE
319 pDMRptLight->lightlux = 60000;
320 pDMRptLight->lightontime = 500;
321 pDMRptLight->lightofftime = 500;
322 pDMRptLight->lightdurationtime = 12000;
323#endif
324
325 return 0;
326}
327
328int arms_data_example_get_dm_dmreport_macsim(PDMREPORTMACSIM pDMRptMacSim)
329{
330 if (pDMRptMacSim == NULL)
331 return -1;
332
333#ifdef EXAMPLE_REF_VALUE
334 //max len is 20
335 strcpy((char*)pDMRptMacSim->mdn, "008613511112222");
336
337 //max len is 20
338 strcpy((char*)pDMRptMacSim->iccid, "89860000000000000001");
339
340 //max len is 12
341 strcpy((char*)pDMRptMacSim->macaddr, "70B5E83A7507");
342#endif
343
344 return 0;
345}
346
347
348int arms_data_example_get_dm_cusdata(unsigned char index, int* pLen, unsigned char* pData)
349{
350 int nValueLen = 0;
351 char szTemp[256] = {0};
352
353 if (pLen == NULL || pData == NULL )
354 return -1;
355
356 if (index > 10)
357 return -2;
358
359#ifdef EXAMPLE_REF_VALUE
360 switch(index+1)
361 {
362 case 1:
363#if 0
364#ifndef ARMS_SUPPORT_TEST_MULTI_INSTANCE
365 if (1 == arms_util_readConfigValue(ARMS_SW_VERSION_FILE_PATH, "SW Ver", (char *)pData))
366 {
367 *pLen = strlen((char *)pData);
368 }
369 else
370 {
371 *pLen = 3;
372 strcpy((char*)pData, "N/A");
373 }
374#else
375 strcpy((char*)pData, "1.1.2.1");
376 *pLen = strlen((char*)pData);
377#endif
378#endif
379 memset(szTemp, 0, sizeof(szTemp));
380 cfg_get_item("wa_version", szTemp, sizeof(szTemp));
381 strcpy((char*)pData, szTemp);
382 *pLen = strlen((char*)pData);
383 break;
384
385 case 2:
386#if 0
387 if (1 == arms_util_readConfigValue(ARMS_SW_VERSION_FILE_PATH, "Inner Ver", (char *)pData))
388 {
389 *pLen = strlen((char *)pData);
390 }
391 else
392 {
393 *pLen = 3;
394 strcpy((char*)pData, "N/A");
395 }
396#endif
397 memset(szTemp, 0, sizeof(szTemp));
398 cfg_get_item("cr_inner_version", szTemp, sizeof(szTemp));
399 strcpy((char*)pData, szTemp);
400 *pLen = strlen((char*)pData);
401 break;
402
403 case 3:
404 if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "RSRP", (char *)szTemp))
405 {
406 nValueLen = strlen(szTemp);
407 *pLen = nValueLen;
408 if ((strstr(szTemp, "dBm") != NULL) && (nValueLen > 3))
409 {
410 szTemp[nValueLen - 3] = '\0';
411 *pLen = nValueLen - 3;
412 }
413 strcpy((char *)pData, szTemp);
414 }
415
416 if (nValueLen <= 0)
417 {
418 *pLen = 3;
419 strcpy((char*)pData, "N/A");
420 }
421 break;
422
423 case 4:
424 if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "RSRQ", (char *)szTemp))
425 {
426 nValueLen = strlen(szTemp);
427 *pLen = nValueLen;
428 if ((strstr(szTemp, "dB") != NULL) && (nValueLen > 2))
429 {
430 szTemp[nValueLen - 2] = '\0';
431 *pLen = nValueLen - 2;
432 }
433 strcpy((char *)pData, szTemp);
434 }
435
436 if (nValueLen <= 0)
437 {
438 *pLen = 3;
439 strcpy((char*)pData, "N/A");
440 }
441 break;
442
443 case 5:
444#if 0
445 if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "RSSI", (char *)szTemp))
446 {
447 nValueLen = strlen(szTemp);
448 *pLen = nValueLen;
449 if ((strstr(szTemp, "dBm") != NULL) && (nValueLen > 3))
450 {
451 szTemp[nValueLen - 3] = '\0';
452 *pLen = nValueLen - 3;
453 }
454 strcpy((char *)pData, szTemp);
455 }
456
457 if (nValueLen <= 0)
458 {
459 *pLen = 3;
460 strcpy((char*)pData, "N/A");
461 }
462#endif
463 memset(szTemp, 0, sizeof(szTemp));
464 cfg_get_item("rssi", szTemp, sizeof(szTemp));
465 strcpy((char*)pData, szTemp);
466 *pLen = strlen((char*)pData);
467 break;
468
469 case 6:
470 if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "SINR", (char *)szTemp))
471 {
472 nValueLen = strlen(szTemp);
473 *pLen = nValueLen;
474 if ((strstr(szTemp, "dB") != NULL) && (nValueLen > 2))
475 {
476 szTemp[nValueLen - 2] = '\0';
477 *pLen = nValueLen - 2;
478 }
479 strcpy((char *)pData, szTemp);
480 }
481
482 if (nValueLen <= 0)
483 {
484 *pLen = 3;
485 strcpy((char*)pData, "N/A");
486 }
487 break;
488
489 case 7:
490 if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "Carrier", (char *)pData))
491 {
492 *pLen = strlen((char *)pData);
493 }
494 else
495 {
496 *pLen = 3;
497 strcpy((char*)pData, "N/A");
498 }
499 break;
500
501 case 8:
502 if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "GCI", (char *)pData))
503 {
504 *pLen = strlen((char *)pData);
505 }
506 else
507 {
508 *pLen = 3;
509 strcpy((char*)pData, "N/A");
510 }
511 break;
512
513 case 9:
514 {
515 *pLen = 3;
516 strcpy((char*)pData, "N/A");
517 }
518 break;
519 case 10:
520 {
521 *pLen = 3;
522 strcpy((char*)pData, "N/A");
523 }
524 break;
525 default:
526 break;
527 }
528
529#endif
530
531 return 0;
532}
533
534int arms_data_example_handle_dm_ack_pushmsg(unsigned char* pInData, int nInLen,unsigned char* pOutData, int *pOutLen)
535{
536#ifdef EXAMPLE_REF_VALUE
537 time_t timep;
538 struct tm *p;
539 char curren_time[64] = {0};
540 int nTimeLen = 0;
541
542 time(&timep);
543 p=localtime(&timep);
544 if(p != NULL)
545 {
546 sprintf(curren_time,"[%02d-%02d %02d:%02d:%02d] ",
547 (1+p->tm_mon),p->tm_mday, p->tm_hour,
548 p->tm_min, p->tm_sec);
549
550 strcpy((char *)pOutData, curren_time);
551 strcat((char *)pOutData, " ");
552 nTimeLen = strlen(curren_time) + 1;
553 }
554
555 strcat((char *)pOutData, (char *)pInData);
556 *pOutLen = nInLen + nTimeLen;
557#endif
558 return 0;
559}
560
561int arms_data_example_handle_dm_ack_ok(void)
562{
563 return 0;
564}
565
566int arms_data_example_handle_dm_ack_fail(int nType)
567{
568 return 0;
569}
570
571#endif
572
573#ifdef ARMS_SUPPORT_FOTA
574#ifdef EXAMPLE_REF_VALUE
575FOTADATA g_stFotaData = {{0}};
576#endif
577
578int arms_data_example_get_fota_ret(PFOTARET pFOTRet)
579{
580 if (pFOTRet == NULL)
581 return -1;
582
583#ifdef EXAMPLE_REF_VALUE
584 memset(&g_stFotaData.stFOTARet,0,sizeof(g_stFotaData.stFOTARet));
585 memcpy(pFOTRet,&g_stFotaData.stFOTARet,sizeof(FOTARET));
586#endif
587
588 return 0;
589}
590
591int arms_data_example_get_fota_ver_fw(PFOTADATAFW pVerFW)
592{
593 if (pVerFW == NULL)
594 return -1;
595#if 0
596#ifdef EXAMPLE_REF_VALUE
597 memset(g_stFotaData.stFWVerArr,0,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM);
598 if (1 != arms_util_readConfigValue(ARMS_SW_VERSION_FILE_PATH, "Project Rev", g_stFotaData.stFWVerArr[0].szFOTAFwVer))
599 {
600 strcpy(g_stFotaData.stFWVerArr[0].szFOTAFwVer,"N/A");
601 }
602
603 if (1 != arms_util_readConfigValue(ARMS_SW_VERSION_FILE_PATH, "Cute Rev", g_stFotaData.stFWVerArr[1].szFOTAFwVer))
604 {
605 strcpy(g_stFotaData.stFWVerArr[1].szFOTAFwVer,"N/A");
606 }
607
608 memcpy(pVerFW,g_stFotaData.stFWVerArr,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM);
609#endif
610#endif
611 char buf[64] = {0};
612 cfg_get_item("wa_version", buf, sizeof(buf));
613 memset(g_stFotaData.stFWVerArr,0,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM);
614 strcpy(g_stFotaData.stFWVerArr[0].szFOTAFwVer, buf);
615 strcpy(g_stFotaData.stFWVerArr[1].szFOTAFwVer, buf);
616 memcpy(pVerFW, g_stFotaData.stFWVerArr, sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM);
617 printf("****arms_data_example_get_fota_ver_fw version:%s\n", pVerFW->szFOTAFwVer);
618
619 return 0;
620}
621
622int arms_data_example_get_fota_ver_cfg(PFOTADATAFCFG pVerCfg)
623{
624 if (pVerCfg == NULL)
625 return -1;
626
627#ifdef EXAMPLE_REF_VALUE
628 memset(g_stFotaData.stCFGVerArr,0,sizeof(FOTADATAFCFG)*ARMS_FOTA_CFG_VER_NUM);
629 memcpy(pVerCfg,g_stFotaData.stCFGVerArr,sizeof(FOTADATAFCFG)*ARMS_FOTA_CFG_VER_NUM);
630#endif
631
632 return 0;
633}
634
635int arms_data_example_get_fota_ver_mcu(PFOTADATAMCU pVerMCU)
636{
637 if (pVerMCU == NULL)
638 return -1;
639
640#ifdef EXAMPLE_REF_VALUE
641 memset(g_stFotaData.stMCUVerArry,0,sizeof(FOTADATAMCU)*ARMS_FOTA_MCU_VER_NUM);
642 memcpy(pVerMCU,g_stFotaData.stMCUVerArry,sizeof(FOTADATAMCU)*ARMS_FOTA_MCU_VER_NUM);
643#endif
644
645 return 0;
646}
647
648int arms_data_example_get_fota_net_status(void)
649{
650 int ret = 0;
651
652#ifdef EXAMPLE_REF_VALUE
653 ret = 1;
654#endif
655
656 return ret;
657}
658
659int arms_data_example_get_fota_task_id(unsigned int *pTaskId)
660{
661 if (pTaskId == NULL)
662 return -1;
663
664#ifdef EXAMPLE_REF_VALUE
665 *pTaskId = g_stFotaData.nTaskId;
666#endif
667 char buf[16] = {0};
668 cfg_get_item("arms_task_id", buf, sizeof(buf));
669 *pTaskId = atoi(buf);
670
671 return 0;
672}
673
674int arms_data_example_save_fota_task_id(unsigned int nTaskId)
675{
676#ifdef EXAMPLE_REF_VALUE
677 g_stFotaData.nTaskId = nTaskId;
678#endif
679 printf("******task id:%u\n", nTaskId);
680 char buf[16] = {0};
681 sprintf(buf, "%u", nTaskId);
682 cfg_set("arms_task_id", buf);
683 cfg_save();
684
685 return 0;
686}
687
688int arms_data_example_get_fota_device_id(char *pDevId)
689{
690 if (pDevId == NULL)
691 return -1;
692
693#ifdef EXAMPLE_REF_VALUE
694 strcpy(pDevId,g_stFotaData.cDeviceId);
695#endif
696 char buf[ARMS_FOTA_DEVICE_ID_BUF_SIZE] = {0};
697 cfg_get_item("arms_device_id", buf, sizeof(buf));
698 strcpy(pDevId, buf);
699
700 return 0;
701}
702
703int arms_data_example_save_fota_device_id(char *pDevId)
704{
705 if (pDevId == NULL)
706 return -1;
707
708#ifdef EXAMPLE_REF_VALUE
709 memset(g_stFotaData.cDeviceId,0,sizeof(g_stFotaData.cDeviceId));
710 strcpy(g_stFotaData.cDeviceId,pDevId);
711#endif
712 printf("******device_id:%s\n", pDevId);
713 cfg_set("arms_device_id", pDevId);
714 cfg_save();
715
716 return 0;
717}
718
719int arms_data_example_get_fota_device_sec(char *pDevSec)
720{
721 if (pDevSec == NULL)
722 return -1;
723
724#ifdef EXAMPLE_REF_VALUE
725 strcpy(pDevSec,g_stFotaData.cDeviceSec);
726#endif
727 char buf[ARMS_FOTA_DEVICE_SEC_BUF_SIZE] = {0};
728 cfg_get_item("arms_device_sec", buf, sizeof(buf));
729 strcpy(pDevSec, buf);
730
731 return 0;
732}
733
734int arms_data_example_save_fota_device_sec(char *pDevSec)
735{
736 if (pDevSec == NULL)
737 return -1;
738
739#ifdef EXAMPLE_REF_VALUE
740 memset(g_stFotaData.cDeviceSec,0,sizeof(g_stFotaData.cDeviceSec));
741 strcpy(g_stFotaData.cDeviceSec,pDevSec);
742#endif
743 printf("******device_sec:%s\n", pDevSec);
744 cfg_set("arms_device_sec", pDevSec);
745 cfg_save();
746
747 return 0;
748}
749
750int arms_data_example_get_fota_deviceid_md5(char *pDevIdMD5)
751{
752 if (pDevIdMD5 == NULL)
753 return -1;
754
755#ifdef EXAMPLE_REF_VALUE
756 strcpy(pDevIdMD5,g_stFotaData.cDeviceidMD5);
757#endif
758 char buf[ARMS_FOTA_DEVICEID_MD5_BUF_SIZE] = {0};
759 cfg_get_item("arms_device_md5", buf, sizeof(buf));
760 strcpy(pDevIdMD5, buf);
761
762 return 0;
763}
764
765int arms_data_example_save_fota_deviceid_md5(char *pDevIdMD5)
766{
767 if (pDevIdMD5 == NULL)
768 return -1;
769
770#ifdef EXAMPLE_REF_VALUE
771 memset(g_stFotaData.cDeviceidMD5,0,sizeof(g_stFotaData.cDeviceidMD5));
772 strcpy(g_stFotaData.cDeviceidMD5,pDevIdMD5);
773#endif
774 printf("******deviceid_md5:%s\n", pDevIdMD5);
775 cfg_set("arms_device_md5", pDevIdMD5);
776 cfg_save();
777
778 return 0;
779}
780
781int arms_data_example_get_fota_pre_version_fw(PFOTADATAFW pPreVerFW)
782{
783 if (pPreVerFW == NULL)
784 return -1;
785
786#ifdef EXAMPLE_REF_VALUE
787 memcpy(pPreVerFW,g_stFotaData.stFWPreVerArr,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM);
788#endif
789 char buf[64] = {0};
790 cfg_get_item("arms_fota_version", buf, sizeof(buf));
791 strcpy(pPreVerFW->szFOTAFwVer, buf);
792
793 return 0;
794}
795
796int arms_data_example_save_fota_pre_version_fw(PFOTADATAFW pPreVerFW)
797{
798 if (pPreVerFW == NULL)
799 return -1;
800
801#ifdef EXAMPLE_REF_VALUE
802 memset(g_stFotaData.stFWPreVerArr,0,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM);
803 memcpy(g_stFotaData.stFWPreVerArr,pPreVerFW,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM);
804#endif
805 printf("******pPreVerFW version:%s, nFOTAFwRet:%d\n", pPreVerFW->szFOTAFwVer, pPreVerFW->nFOTAFwRet);
806 cfg_set("arms_fota_version", pPreVerFW->szFOTAFwVer);
807 cfg_save();
808
809 return 0;
810}
811
812int arms_data_example_get_fota_pre_version_cfg(PFOTADATAFCFG pPreVerCFG)
813{
814 if (pPreVerCFG == NULL)
815 return -1;
816
817#ifdef EXAMPLE_REF_VALUE
818 memcpy(pPreVerCFG,g_stFotaData.stCFGPreVerArr,sizeof(FOTADATAFCFG)*ARMS_FOTA_CFG_VER_NUM);
819#endif
820
821 return 0;
822}
823
824int arms_data_example_save_fota_pre_version_cfg(PFOTADATAFCFG pPreVerCFG)
825{
826 if (pPreVerCFG == NULL)
827 return -1;
828
829#ifdef EXAMPLE_REF_VALUE
830 memset(g_stFotaData.stCFGPreVerArr,0,sizeof(FOTADATAFCFG)*ARMS_FOTA_CFG_VER_NUM);
831 memcpy(g_stFotaData.stCFGPreVerArr,pPreVerCFG,sizeof(FOTADATAFCFG)*ARMS_FOTA_CFG_VER_NUM);
832#endif
833
834 return 0;
835}
836
837int arms_data_example_get_fota_pre_version_mcu(PFOTADATAMCU pPreVerMCU)
838{
839 if (pPreVerMCU == NULL)
840 return -1;
841
842#ifdef EXAMPLE_REF_VALUE
843 memcpy(pPreVerMCU,g_stFotaData.stMCUPreVerArry,sizeof(PFOTADATAMCU)*ARMS_FOTA_MCU_VER_NUM);
844#endif
845
846 return 0;
847}
848
849int arms_data_example_save_fota_pre_version_mcu(PFOTADATAMCU pPreVerMCU)
850{
851 if (pPreVerMCU == NULL)
852 return -1;
853
854#ifdef EXAMPLE_REF_VALUE
855 memset(g_stFotaData.stMCUPreVerArry,0,sizeof(PFOTADATAMCU)*ARMS_FOTA_MCU_VER_NUM);
856 memcpy(g_stFotaData.stMCUPreVerArry,pPreVerMCU,sizeof(PFOTADATAMCU)*ARMS_FOTA_MCU_VER_NUM);
857#endif
858
859 return 0;
860}
861
862int arms_data_example_get_fota_backup(char *pBackup)
863{
864 if (pBackup == NULL)
865 return -1;
866
867#ifdef EXAMPLE_REF_VALUE
868 memcpy(pBackup,g_stFotaData.cBackup,ARMS_FOTA_BACKUP_BUF_SIZE);
869#endif
870
871 return 0;
872}
873
874int arms_data_example_save_fota_backup(char *pBackup)
875{
876 if (pBackup == NULL)
877 return -1;
878
879#ifdef EXAMPLE_REF_VALUE
880 memset(g_stFotaData.cBackup,0,sizeof(g_stFotaData.cBackup));
881 memcpy(g_stFotaData.cBackup,pBackup,sizeof(g_stFotaData.cBackup));
882#endif
883
884 return 0;
885}
886
887int arms_data_example_get_fota_down_size(unsigned int *pDownSize)
888{
889 if (pDownSize == NULL)
890 return -1;
891
892#ifdef EXAMPLE_REF_VALUE
893 *pDownSize = g_stFotaData.nDownSize;
894#endif
895
896 return 0;
897}
898
899int arms_data_example_save_fota_down_size(unsigned int nDownSize)
900{
901#ifdef EXAMPLE_REF_VALUE
902 g_stFotaData.nDownSize = nDownSize;
903#endif
904
905 return 0;
906}
907
908#define FOTA_UPDATE_STATUS_FILE "/cache/zte_fota/update_status"
909
910int fota_is_file_exist(const char* path)
911{
912 if ( (path == NULL) || (*path == '\0') )
913 return 0;
914 if (access(path, R_OK) != 0)
915 return 0;
916
917 return 1;
918}
919
920int fota_read_file(const char*path, char*buf, size_t sz)
921{
922 int fd = -1;
923 size_t cnt;
924
925 fd = open(path, O_RDONLY, 0);
926 if(fd < 0)
927 {
928 printf("fota_read_file failed to open %s\n", path);
929 cnt = -1;
930 return cnt;
931 }
932 cnt = read(fd, buf, sz - 1);
933 if(cnt <= 0)
934 {
935 printf("failed to read %s\n", path);
936 close(fd);
937 cnt = -1;
938 return cnt;
939 }
940 buf[cnt] = '\0';
941 if(buf[cnt - 1] == '\n')
942 {
943 cnt--;
944 buf[cnt] = '\0';
945 }
946 close(fd);
947
948 return cnt;
949}
950
951int fota_read_file_int(const char* path, int *val)
952{
953 char buf[32];
954 char *end;
955 int ret;
956 int tmp;
957
958 ret = fota_read_file(path, buf, sizeof(buf));
959 if(ret < 0)
960 return -1;
961
962 tmp = strtol(buf, &end, 0);
963 if ((end == buf) || ((end < buf + sizeof(buf)) && (*end != '\0')))
964 {
965 return -1;
966 }
967
968 *val = tmp;
969
970 return 0;
971}
972
973int fota_get_update_status(int *fota_status)
974{
975
976 int status = 0;
977 int ret = 0;
978 if(!fota_is_file_exist(FOTA_UPDATE_STATUS_FILE))
979 {
980 printf("fota_get_update_status file not exist\n");
981 *fota_status = -1;
982 return -1;
983 }
984 ret = fota_read_file_int(FOTA_UPDATE_STATUS_FILE, &status);
985 if(ret < 0) {
986 printf("fota_get_update_status read update_status error\n");
987 *fota_status = -1;
988 return -1;
989 }
990 printf("fota_get_update_status read status:%d\n", status);
991 *fota_status = status;
992
993 return 0;
994}
995
996int arms_data_example_upgrade(char *pPath)
997{
998 if (pPath == NULL)
999 return -1;
1000
1001 int upgradeStatus = 0;
1002 int result = 0;
1003
1004 printf("arms_data_example_upgrade upgrade file path:[%s]\n");
1005 system("fota_upi -u verify");
1006 result = fota_get_update_status(&upgradeStatus);
1007 if(result < 0)
1008 {
1009 printf("arms_data_example_upgrade failed to read the update_status file\n");
1010 return -1;
1011 }
1012 else if(upgradeStatus != 0)
1013 {
1014 printf("arms_data_example_upgrade verify failed\n");
1015 return -1;
1016 }
1017 else
1018 {
1019 printf("arms_data_example_upgrade verify success, start upgrade!\n");
1020 system("fota_upi -u recovery");
1021 }
1022
1023#ifdef EXAMPLE_REF_VALUE
1024 //remove(pPath);
1025#endif
1026
1027 return 0;
1028}
1029
1030int arms_data_example_get_region_size(unsigned int* pRegionSize)
1031{
1032 if (pRegionSize == NULL)
1033 return -1;
1034
1035 *pRegionSize = 20*1024*1024;
1036
1037 return 0;
1038}
1039
1040int arms_data_example_get_log(char *pPath, int *pPathLen, char *pFileName, int *pFileNameLen)
1041{
1042 if ((pPath == NULL) || (pPathLen == NULL) || (pFileName == NULL) || (pFileNameLen == NULL))
1043 return ARMS_DATA_POINT_NULL_ERROR;
1044
1045
1046 if (strlen(ARMS_LOG_FILE_PATH) >= *pPathLen)
1047 return -1;
1048
1049 if (strlen(ARMS_LOG_FILE_NAME) >= *pFileNameLen)
1050 return -1;
1051
1052 strcpy(pPath, ARMS_LOG_FILE_PATH);
1053 strcpy(pFileName, ARMS_LOG_FILE_NAME);
1054
1055 return 0;
1056}
1057
1058#endif
1059
1060
1061#endif
1062