#include "apparms_data_example.h" | |
#include "apparms_util.h" | |
#ifdef ARMS_BOARD_EXAMPLE | |
static ARMSDATAFUNLIST arms_example_datafun_pointer = | |
{ | |
#ifdef ARMS_SUPPORT_DM | |
arms_data_example_get_dm_header_tag, | |
arms_data_example_get_dm_header_event, | |
arms_data_example_get_dm_generic_pid, | |
arms_data_example_get_dm_generic_gps, | |
arms_data_example_get_dm_generic_battchg, | |
arms_data_example_get_dm_generic_network, | |
arms_data_example_get_dm_generic_gpio, | |
arms_data_example_get_dm_generic_odometer, | |
arms_data_example_get_dm_version, | |
arms_data_example_get_dm_extver, | |
arms_data_example_get_dm_dmreport_pricell, | |
arms_data_example_get_dm_dmreport_nbcell, | |
arms_data_example_get_dm_dmreport_light, | |
arms_data_example_get_dm_dmreport_macsim, | |
arms_data_example_get_dm_cusdata, | |
arms_data_example_handle_dm_ack_pushmsg, | |
arms_data_example_handle_dm_ack_ok, | |
arms_data_example_handle_dm_ack_fail, | |
#endif | |
#ifdef ARMS_SUPPORT_FOTA | |
arms_data_example_get_fota_ret, | |
arms_data_example_get_fota_ver_fw, | |
arms_data_example_get_fota_ver_cfg, | |
arms_data_example_get_fota_ver_mcu, | |
arms_data_example_get_fota_net_status, | |
arms_data_example_get_fota_task_id, | |
arms_data_example_save_fota_task_id, | |
arms_data_example_get_fota_device_id, | |
arms_data_example_save_fota_device_id, | |
arms_data_example_get_fota_device_sec, | |
arms_data_example_save_fota_device_sec, | |
arms_data_example_get_fota_deviceid_md5, | |
arms_data_example_save_fota_deviceid_md5, | |
arms_data_example_get_fota_pre_version_fw, | |
arms_data_example_save_fota_pre_version_fw, | |
arms_data_example_get_fota_pre_version_cfg, | |
arms_data_example_save_fota_pre_version_cfg, | |
arms_data_example_get_fota_pre_version_mcu, | |
arms_data_example_save_fota_pre_version_mcu, | |
arms_data_example_get_fota_backup, | |
arms_data_example_save_fota_backup, | |
arms_data_example_get_fota_down_size, | |
arms_data_example_save_fota_down_size, | |
arms_data_example_upgrade, | |
arms_data_example_get_region_size, | |
arms_data_example_get_log, | |
#endif | |
arms_data_example_set_waketime, | |
arms_data_example_get_suspend, | |
arms_data_example_get_timestamp | |
}; | |
PARMSDATAFUNLIST arms_data_example_get_cfgfun_pointer(void) | |
{ | |
return &arms_example_datafun_pointer; | |
} | |
int arms_data_example_set_waketime(unsigned long uHWId, long long nNowInSec, unsigned short nIntervalInSec) | |
{ | |
//TODO: request to wake up the device with nTimeInSec by platform wake mechanism. | |
return 0; | |
} | |
int arms_data_example_get_suspend(unsigned long uHWId, int* pSuspend) | |
{ | |
if (pSuspend == NULL) | |
return -1; | |
*pSuspend = 0; | |
return 0; | |
} | |
int arms_data_example_get_timestamp(unsigned long* pTimeStamp) | |
{ | |
if (pTimeStamp == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
struct tm *p_tm; | |
time_t now = time(NULL); | |
p_tm = localtime(&now); | |
*pTimeStamp = ((p_tm->tm_year + 1900) - 2000) * 12; | |
*pTimeStamp = (*pTimeStamp + p_tm->tm_mon) * 31; | |
*pTimeStamp = (*pTimeStamp + p_tm->tm_mday - 1) * 24; | |
*pTimeStamp = ((*pTimeStamp + p_tm->tm_hour) * 60 + p_tm->tm_min) * 60 + p_tm->tm_sec; | |
#endif | |
return 0; | |
} | |
#ifdef ARMS_SUPPORT_DM | |
int arms_data_example_get_dm_header_tag(unsigned char* pTag) | |
{ | |
if (pTag == NULL) | |
return -1; | |
*pTag = 0; | |
#ifdef EXAMPLE_REF_VALUE | |
*pTag = 1; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_header_event(unsigned short* pEvent) | |
{ | |
if (pEvent == NULL) | |
return -1; | |
*pEvent = 0; | |
#ifdef EXAMPLE_REF_VALUE | |
*pEvent = 0x22; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_generic_pid(unsigned char* pID) | |
{ | |
if (pID == NULL) | |
return -1; | |
*pID = 0; | |
#ifdef EXAMPLE_REF_VALUE | |
*pID = 5; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_generic_gps(PDMGPSDATA pGPS) | |
{ | |
if (pGPS == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
pGPS->gps_lat = 31.19435; | |
pGPS->gps_lon = 121.5827; | |
pGPS->gps_speed = 100; | |
pGPS->gps_heading = 128; | |
pGPS->gps_altitude = 25; | |
pGPS->gps_status = 1; | |
pGPS->gps_sat_count = 5; | |
pGPS->gps_HOP = 1.1; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_generic_battchg(PDMBATTCHGDATA pBattChg) | |
{ | |
if (pBattChg == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
pBattChg->main_voltage = 1735; | |
pBattChg->batt_voltage = 2967; | |
pBattChg->aux_voltage = 3527; | |
pBattChg->solar_voltage = 4560; | |
pBattChg->tempeature = 75; | |
pBattChg->percentage = 99; | |
pBattChg->charge = 4321; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_generic_network(PDMNETWORKDATA pNetwork) | |
{ | |
if (pNetwork == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
pNetwork->roaming = 1; | |
pNetwork->srvtype = 2; | |
pNetwork->nw_mcc = 460; | |
pNetwork->nw_mnc = 0; | |
pNetwork->nw_rssi = 22; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_generic_gpio(PDMGPIODATA pGpio) | |
{ | |
if (pGpio == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
pGpio->GPIOADir=1; | |
pGpio->GPIOAValue=0; | |
pGpio->GPIOBDir=1; | |
pGpio->GPIOBValue=0; | |
pGpio->GPIOCDir=0; | |
pGpio->GPIOCValue=0; | |
pGpio->GPIODDir=1; | |
pGpio->GPIODValue=1; | |
pGpio->GPIOEDir=0; | |
pGpio->GPIOEValue=0; | |
pGpio->GPIOFDir=0; | |
pGpio->GPIOFValue=0; | |
pGpio->GPIOGDir=0; | |
pGpio->GPIOGValue=0; | |
pGpio->GPIOHDir=0; | |
pGpio->GPIOHValue=0; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_generic_odometer(unsigned long* pOdometer) | |
{ | |
if (pOdometer == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
*pOdometer = 123; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_version(PDMVERSIONDATA pVersion) | |
{ | |
if (pVersion == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
strcpy((char*)pVersion->main, "7.1.1.0"); | |
strcpy((char*)pVersion->ext, "0"); | |
strcpy((char*)pVersion->fw, "16.1.0.7.1"); | |
strcpy((char*)pVersion->mcu, "1.0.8.1"); | |
strcpy((char*)pVersion->cfg, "32789"); | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_extver(PDMEXTVERDATA pExtver) | |
{ | |
if (pExtver == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
strcpy((char*)pExtver->mcu2, "1.3.3.4"); | |
strcpy((char*)pExtver->mcu3, "1.4.3.4"); | |
strcpy((char*)pExtver->mcu4, "1.5.3.4"); | |
strcpy((char*)pExtver->mcu5, "1.6.3.4"); | |
strcpy((char*)pExtver->mcu6, "1.7.3.4"); | |
strcpy((char*)pExtver->mcu7, "1.8.3.4"); | |
strcpy((char*)pExtver->mcu8, "1.9.3.4"); | |
strcpy((char*)pExtver->mcu9, "1.10.3.4"); | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_dmreport_pricell(PDMREPORTPRICELL pDMRptPriCell) | |
{ | |
if (pDMRptPriCell == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
pDMRptPriCell->mcc = 460; | |
pDMRptPriCell->mnc = 0; | |
pDMRptPriCell->eci = 0x1813A07; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_dmreport_nbcell(PDMREPORTNBCELL pDMRptNBCell) | |
{ | |
if (pDMRptNBCell == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
pDMRptNBCell[0].nb_mcc = 461; | |
pDMRptNBCell[0].nb_mnc = 01; | |
pDMRptNBCell[0].nb_eci = 45234; | |
pDMRptNBCell[0].nb_rssi = 21; | |
pDMRptNBCell[1].nb_mcc = 462; | |
pDMRptNBCell[1].nb_mnc = 02; | |
pDMRptNBCell[1].nb_eci = 12398; | |
pDMRptNBCell[1].nb_rssi = 22; | |
pDMRptNBCell[2].nb_mcc = 463; | |
pDMRptNBCell[2].nb_mnc = 03; | |
pDMRptNBCell[2].nb_eci = 12331; | |
pDMRptNBCell[2].nb_rssi = 23; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_dmreport_light(PDMREPORTLIGHTDATA pDMRptLight) | |
{ | |
if (pDMRptLight == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
pDMRptLight->lightlux = 60000; | |
pDMRptLight->lightontime = 500; | |
pDMRptLight->lightofftime = 500; | |
pDMRptLight->lightdurationtime = 12000; | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_dmreport_macsim(PDMREPORTMACSIM pDMRptMacSim) | |
{ | |
if (pDMRptMacSim == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
//max len is 20 | |
strcpy((char*)pDMRptMacSim->mdn, "008613511112222"); | |
//max len is 20 | |
strcpy((char*)pDMRptMacSim->iccid, "89860000000000000001"); | |
//max len is 12 | |
strcpy((char*)pDMRptMacSim->macaddr, "70B5E83A7507"); | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_dm_cusdata(unsigned char index, int* pLen, unsigned char* pData) | |
{ | |
int nValueLen = 0; | |
char szTemp[256] = {0}; | |
if (pLen == NULL || pData == NULL ) | |
return -1; | |
if (index > 10) | |
return -2; | |
#ifdef EXAMPLE_REF_VALUE | |
switch(index+1) | |
{ | |
case 1: | |
#if 0 | |
#ifndef ARMS_SUPPORT_TEST_MULTI_INSTANCE | |
if (1 == arms_util_readConfigValue(ARMS_SW_VERSION_FILE_PATH, "SW Ver", (char *)pData)) | |
{ | |
*pLen = strlen((char *)pData); | |
} | |
else | |
{ | |
*pLen = 3; | |
strcpy((char*)pData, "N/A"); | |
} | |
#else | |
strcpy((char*)pData, "1.1.2.1"); | |
*pLen = strlen((char*)pData); | |
#endif | |
#endif | |
memset(szTemp, 0, sizeof(szTemp)); | |
cfg_get_item("wa_version", szTemp, sizeof(szTemp)); | |
strcpy((char*)pData, szTemp); | |
*pLen = strlen((char*)pData); | |
break; | |
case 2: | |
#if 0 | |
if (1 == arms_util_readConfigValue(ARMS_SW_VERSION_FILE_PATH, "Inner Ver", (char *)pData)) | |
{ | |
*pLen = strlen((char *)pData); | |
} | |
else | |
{ | |
*pLen = 3; | |
strcpy((char*)pData, "N/A"); | |
} | |
#endif | |
memset(szTemp, 0, sizeof(szTemp)); | |
cfg_get_item("cr_inner_version", szTemp, sizeof(szTemp)); | |
strcpy((char*)pData, szTemp); | |
*pLen = strlen((char*)pData); | |
break; | |
case 3: | |
if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "RSRP", (char *)szTemp)) | |
{ | |
nValueLen = strlen(szTemp); | |
*pLen = nValueLen; | |
if ((strstr(szTemp, "dBm") != NULL) && (nValueLen > 3)) | |
{ | |
szTemp[nValueLen - 3] = '\0'; | |
*pLen = nValueLen - 3; | |
} | |
strcpy((char *)pData, szTemp); | |
} | |
if (nValueLen <= 0) | |
{ | |
*pLen = 3; | |
strcpy((char*)pData, "N/A"); | |
} | |
break; | |
case 4: | |
if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "RSRQ", (char *)szTemp)) | |
{ | |
nValueLen = strlen(szTemp); | |
*pLen = nValueLen; | |
if ((strstr(szTemp, "dB") != NULL) && (nValueLen > 2)) | |
{ | |
szTemp[nValueLen - 2] = '\0'; | |
*pLen = nValueLen - 2; | |
} | |
strcpy((char *)pData, szTemp); | |
} | |
if (nValueLen <= 0) | |
{ | |
*pLen = 3; | |
strcpy((char*)pData, "N/A"); | |
} | |
break; | |
case 5: | |
#if 0 | |
if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "RSSI", (char *)szTemp)) | |
{ | |
nValueLen = strlen(szTemp); | |
*pLen = nValueLen; | |
if ((strstr(szTemp, "dBm") != NULL) && (nValueLen > 3)) | |
{ | |
szTemp[nValueLen - 3] = '\0'; | |
*pLen = nValueLen - 3; | |
} | |
strcpy((char *)pData, szTemp); | |
} | |
if (nValueLen <= 0) | |
{ | |
*pLen = 3; | |
strcpy((char*)pData, "N/A"); | |
} | |
#endif | |
memset(szTemp, 0, sizeof(szTemp)); | |
cfg_get_item("rssi", szTemp, sizeof(szTemp)); | |
strcpy((char*)pData, szTemp); | |
*pLen = strlen((char*)pData); | |
break; | |
case 6: | |
if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "SINR", (char *)szTemp)) | |
{ | |
nValueLen = strlen(szTemp); | |
*pLen = nValueLen; | |
if ((strstr(szTemp, "dB") != NULL) && (nValueLen > 2)) | |
{ | |
szTemp[nValueLen - 2] = '\0'; | |
*pLen = nValueLen - 2; | |
} | |
strcpy((char *)pData, szTemp); | |
} | |
if (nValueLen <= 0) | |
{ | |
*pLen = 3; | |
strcpy((char*)pData, "N/A"); | |
} | |
break; | |
case 7: | |
if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "Carrier", (char *)pData)) | |
{ | |
*pLen = strlen((char *)pData); | |
} | |
else | |
{ | |
*pLen = 3; | |
strcpy((char*)pData, "N/A"); | |
} | |
break; | |
case 8: | |
if (1 == arms_util_readConfigValue(ARMS_NW_STATUS_FILE_PATH, "GCI", (char *)pData)) | |
{ | |
*pLen = strlen((char *)pData); | |
} | |
else | |
{ | |
*pLen = 3; | |
strcpy((char*)pData, "N/A"); | |
} | |
break; | |
case 9: | |
{ | |
*pLen = 3; | |
strcpy((char*)pData, "N/A"); | |
} | |
break; | |
case 10: | |
{ | |
*pLen = 3; | |
strcpy((char*)pData, "N/A"); | |
} | |
break; | |
default: | |
break; | |
} | |
#endif | |
return 0; | |
} | |
int arms_data_example_handle_dm_ack_pushmsg(unsigned char* pInData, int nInLen,unsigned char* pOutData, int *pOutLen) | |
{ | |
#ifdef EXAMPLE_REF_VALUE | |
time_t timep; | |
struct tm *p; | |
char curren_time[64] = {0}; | |
int nTimeLen = 0; | |
time(&timep); | |
p=localtime(&timep); | |
if(p != NULL) | |
{ | |
sprintf(curren_time,"[%02d-%02d %02d:%02d:%02d] ", | |
(1+p->tm_mon),p->tm_mday, p->tm_hour, | |
p->tm_min, p->tm_sec); | |
strcpy((char *)pOutData, curren_time); | |
strcat((char *)pOutData, " "); | |
nTimeLen = strlen(curren_time) + 1; | |
} | |
strcat((char *)pOutData, (char *)pInData); | |
*pOutLen = nInLen + nTimeLen; | |
#endif | |
return 0; | |
} | |
int arms_data_example_handle_dm_ack_ok(void) | |
{ | |
return 0; | |
} | |
int arms_data_example_handle_dm_ack_fail(int nType) | |
{ | |
return 0; | |
} | |
#endif | |
#ifdef ARMS_SUPPORT_FOTA | |
#ifdef EXAMPLE_REF_VALUE | |
FOTADATA g_stFotaData = {{0}}; | |
#endif | |
int arms_data_example_get_fota_ret(PFOTARET pFOTRet) | |
{ | |
if (pFOTRet == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memset(&g_stFotaData.stFOTARet,0,sizeof(g_stFotaData.stFOTARet)); | |
memcpy(pFOTRet,&g_stFotaData.stFOTARet,sizeof(FOTARET)); | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_fota_ver_fw(PFOTADATAFW pVerFW) | |
{ | |
if (pVerFW == NULL) | |
return -1; | |
#if 0 | |
#ifdef EXAMPLE_REF_VALUE | |
memset(g_stFotaData.stFWVerArr,0,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM); | |
if (1 != arms_util_readConfigValue(ARMS_SW_VERSION_FILE_PATH, "Project Rev", g_stFotaData.stFWVerArr[0].szFOTAFwVer)) | |
{ | |
strcpy(g_stFotaData.stFWVerArr[0].szFOTAFwVer,"N/A"); | |
} | |
if (1 != arms_util_readConfigValue(ARMS_SW_VERSION_FILE_PATH, "Cute Rev", g_stFotaData.stFWVerArr[1].szFOTAFwVer)) | |
{ | |
strcpy(g_stFotaData.stFWVerArr[1].szFOTAFwVer,"N/A"); | |
} | |
memcpy(pVerFW,g_stFotaData.stFWVerArr,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM); | |
#endif | |
#endif | |
char buf[64] = {0}; | |
cfg_get_item("wa_version", buf, sizeof(buf)); | |
memset(g_stFotaData.stFWVerArr,0,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM); | |
strcpy(g_stFotaData.stFWVerArr[0].szFOTAFwVer, buf); | |
strcpy(g_stFotaData.stFWVerArr[1].szFOTAFwVer, buf); | |
memcpy(pVerFW, g_stFotaData.stFWVerArr, sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM); | |
printf("****arms_data_example_get_fota_ver_fw version:%s\n", pVerFW->szFOTAFwVer); | |
return 0; | |
} | |
int arms_data_example_get_fota_ver_cfg(PFOTADATAFCFG pVerCfg) | |
{ | |
if (pVerCfg == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memset(g_stFotaData.stCFGVerArr,0,sizeof(FOTADATAFCFG)*ARMS_FOTA_CFG_VER_NUM); | |
memcpy(pVerCfg,g_stFotaData.stCFGVerArr,sizeof(FOTADATAFCFG)*ARMS_FOTA_CFG_VER_NUM); | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_fota_ver_mcu(PFOTADATAMCU pVerMCU) | |
{ | |
if (pVerMCU == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memset(g_stFotaData.stMCUVerArry,0,sizeof(FOTADATAMCU)*ARMS_FOTA_MCU_VER_NUM); | |
memcpy(pVerMCU,g_stFotaData.stMCUVerArry,sizeof(FOTADATAMCU)*ARMS_FOTA_MCU_VER_NUM); | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_fota_net_status(void) | |
{ | |
int ret = 0; | |
#ifdef EXAMPLE_REF_VALUE | |
ret = 1; | |
#endif | |
return ret; | |
} | |
int arms_data_example_get_fota_task_id(unsigned int *pTaskId) | |
{ | |
if (pTaskId == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
*pTaskId = g_stFotaData.nTaskId; | |
#endif | |
char buf[16] = {0}; | |
cfg_get_item("arms_task_id", buf, sizeof(buf)); | |
*pTaskId = atoi(buf); | |
return 0; | |
} | |
int arms_data_example_save_fota_task_id(unsigned int nTaskId) | |
{ | |
#ifdef EXAMPLE_REF_VALUE | |
g_stFotaData.nTaskId = nTaskId; | |
#endif | |
printf("******task id:%u\n", nTaskId); | |
char buf[16] = {0}; | |
sprintf(buf, "%u", nTaskId); | |
cfg_set("arms_task_id", buf); | |
cfg_save(); | |
return 0; | |
} | |
int arms_data_example_get_fota_device_id(char *pDevId) | |
{ | |
if (pDevId == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
strcpy(pDevId,g_stFotaData.cDeviceId); | |
#endif | |
char buf[ARMS_FOTA_DEVICE_ID_BUF_SIZE] = {0}; | |
cfg_get_item("arms_device_id", buf, sizeof(buf)); | |
strcpy(pDevId, buf); | |
return 0; | |
} | |
int arms_data_example_save_fota_device_id(char *pDevId) | |
{ | |
if (pDevId == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memset(g_stFotaData.cDeviceId,0,sizeof(g_stFotaData.cDeviceId)); | |
strcpy(g_stFotaData.cDeviceId,pDevId); | |
#endif | |
printf("******device_id:%s\n", pDevId); | |
cfg_set("arms_device_id", pDevId); | |
cfg_save(); | |
return 0; | |
} | |
int arms_data_example_get_fota_device_sec(char *pDevSec) | |
{ | |
if (pDevSec == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
strcpy(pDevSec,g_stFotaData.cDeviceSec); | |
#endif | |
char buf[ARMS_FOTA_DEVICE_SEC_BUF_SIZE] = {0}; | |
cfg_get_item("arms_device_sec", buf, sizeof(buf)); | |
strcpy(pDevSec, buf); | |
return 0; | |
} | |
int arms_data_example_save_fota_device_sec(char *pDevSec) | |
{ | |
if (pDevSec == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memset(g_stFotaData.cDeviceSec,0,sizeof(g_stFotaData.cDeviceSec)); | |
strcpy(g_stFotaData.cDeviceSec,pDevSec); | |
#endif | |
printf("******device_sec:%s\n", pDevSec); | |
cfg_set("arms_device_sec", pDevSec); | |
cfg_save(); | |
return 0; | |
} | |
int arms_data_example_get_fota_deviceid_md5(char *pDevIdMD5) | |
{ | |
if (pDevIdMD5 == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
strcpy(pDevIdMD5,g_stFotaData.cDeviceidMD5); | |
#endif | |
char buf[ARMS_FOTA_DEVICEID_MD5_BUF_SIZE] = {0}; | |
cfg_get_item("arms_device_md5", buf, sizeof(buf)); | |
strcpy(pDevIdMD5, buf); | |
return 0; | |
} | |
int arms_data_example_save_fota_deviceid_md5(char *pDevIdMD5) | |
{ | |
if (pDevIdMD5 == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memset(g_stFotaData.cDeviceidMD5,0,sizeof(g_stFotaData.cDeviceidMD5)); | |
strcpy(g_stFotaData.cDeviceidMD5,pDevIdMD5); | |
#endif | |
printf("******deviceid_md5:%s\n", pDevIdMD5); | |
cfg_set("arms_device_md5", pDevIdMD5); | |
cfg_save(); | |
return 0; | |
} | |
int arms_data_example_get_fota_pre_version_fw(PFOTADATAFW pPreVerFW) | |
{ | |
if (pPreVerFW == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memcpy(pPreVerFW,g_stFotaData.stFWPreVerArr,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM); | |
#endif | |
char buf[64] = {0}; | |
cfg_get_item("arms_fota_version", buf, sizeof(buf)); | |
strcpy(pPreVerFW->szFOTAFwVer, buf); | |
return 0; | |
} | |
int arms_data_example_save_fota_pre_version_fw(PFOTADATAFW pPreVerFW) | |
{ | |
if (pPreVerFW == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memset(g_stFotaData.stFWPreVerArr,0,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM); | |
memcpy(g_stFotaData.stFWPreVerArr,pPreVerFW,sizeof(FOTADATAFW)*ARMS_FOTA_FW_VER_NUM); | |
#endif | |
printf("******pPreVerFW version:%s, nFOTAFwRet:%d\n", pPreVerFW->szFOTAFwVer, pPreVerFW->nFOTAFwRet); | |
cfg_set("arms_fota_version", pPreVerFW->szFOTAFwVer); | |
cfg_save(); | |
return 0; | |
} | |
int arms_data_example_get_fota_pre_version_cfg(PFOTADATAFCFG pPreVerCFG) | |
{ | |
if (pPreVerCFG == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memcpy(pPreVerCFG,g_stFotaData.stCFGPreVerArr,sizeof(FOTADATAFCFG)*ARMS_FOTA_CFG_VER_NUM); | |
#endif | |
return 0; | |
} | |
int arms_data_example_save_fota_pre_version_cfg(PFOTADATAFCFG pPreVerCFG) | |
{ | |
if (pPreVerCFG == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memset(g_stFotaData.stCFGPreVerArr,0,sizeof(FOTADATAFCFG)*ARMS_FOTA_CFG_VER_NUM); | |
memcpy(g_stFotaData.stCFGPreVerArr,pPreVerCFG,sizeof(FOTADATAFCFG)*ARMS_FOTA_CFG_VER_NUM); | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_fota_pre_version_mcu(PFOTADATAMCU pPreVerMCU) | |
{ | |
if (pPreVerMCU == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memcpy(pPreVerMCU,g_stFotaData.stMCUPreVerArry,sizeof(PFOTADATAMCU)*ARMS_FOTA_MCU_VER_NUM); | |
#endif | |
return 0; | |
} | |
int arms_data_example_save_fota_pre_version_mcu(PFOTADATAMCU pPreVerMCU) | |
{ | |
if (pPreVerMCU == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memset(g_stFotaData.stMCUPreVerArry,0,sizeof(PFOTADATAMCU)*ARMS_FOTA_MCU_VER_NUM); | |
memcpy(g_stFotaData.stMCUPreVerArry,pPreVerMCU,sizeof(PFOTADATAMCU)*ARMS_FOTA_MCU_VER_NUM); | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_fota_backup(char *pBackup) | |
{ | |
if (pBackup == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memcpy(pBackup,g_stFotaData.cBackup,ARMS_FOTA_BACKUP_BUF_SIZE); | |
#endif | |
return 0; | |
} | |
int arms_data_example_save_fota_backup(char *pBackup) | |
{ | |
if (pBackup == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
memset(g_stFotaData.cBackup,0,sizeof(g_stFotaData.cBackup)); | |
memcpy(g_stFotaData.cBackup,pBackup,sizeof(g_stFotaData.cBackup)); | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_fota_down_size(unsigned int *pDownSize) | |
{ | |
if (pDownSize == NULL) | |
return -1; | |
#ifdef EXAMPLE_REF_VALUE | |
*pDownSize = g_stFotaData.nDownSize; | |
#endif | |
return 0; | |
} | |
int arms_data_example_save_fota_down_size(unsigned int nDownSize) | |
{ | |
#ifdef EXAMPLE_REF_VALUE | |
g_stFotaData.nDownSize = nDownSize; | |
#endif | |
return 0; | |
} | |
#define FOTA_UPDATE_STATUS_FILE "/cache/zte_fota/update_status" | |
int fota_is_file_exist(const char* path) | |
{ | |
if ( (path == NULL) || (*path == '\0') ) | |
return 0; | |
if (access(path, R_OK) != 0) | |
return 0; | |
return 1; | |
} | |
int fota_read_file(const char*path, char*buf, size_t sz) | |
{ | |
int fd = -1; | |
size_t cnt; | |
fd = open(path, O_RDONLY, 0); | |
if(fd < 0) | |
{ | |
printf("fota_read_file failed to open %s\n", path); | |
cnt = -1; | |
return cnt; | |
} | |
cnt = read(fd, buf, sz - 1); | |
if(cnt <= 0) | |
{ | |
printf("failed to read %s\n", path); | |
close(fd); | |
cnt = -1; | |
return cnt; | |
} | |
buf[cnt] = '\0'; | |
if(buf[cnt - 1] == '\n') | |
{ | |
cnt--; | |
buf[cnt] = '\0'; | |
} | |
close(fd); | |
return cnt; | |
} | |
int fota_read_file_int(const char* path, int *val) | |
{ | |
char buf[32]; | |
char *end; | |
int ret; | |
int tmp; | |
ret = fota_read_file(path, buf, sizeof(buf)); | |
if(ret < 0) | |
return -1; | |
tmp = strtol(buf, &end, 0); | |
if ((end == buf) || ((end < buf + sizeof(buf)) && (*end != '\0'))) | |
{ | |
return -1; | |
} | |
*val = tmp; | |
return 0; | |
} | |
int fota_get_update_status(int *fota_status) | |
{ | |
int status = 0; | |
int ret = 0; | |
if(!fota_is_file_exist(FOTA_UPDATE_STATUS_FILE)) | |
{ | |
printf("fota_get_update_status file not exist\n"); | |
*fota_status = -1; | |
return -1; | |
} | |
ret = fota_read_file_int(FOTA_UPDATE_STATUS_FILE, &status); | |
if(ret < 0) { | |
printf("fota_get_update_status read update_status error\n"); | |
*fota_status = -1; | |
return -1; | |
} | |
printf("fota_get_update_status read status:%d\n", status); | |
*fota_status = status; | |
return 0; | |
} | |
int arms_data_example_upgrade(char *pPath) | |
{ | |
if (pPath == NULL) | |
return -1; | |
int upgradeStatus = 0; | |
int result = 0; | |
printf("arms_data_example_upgrade upgrade file path:[%s]\n"); | |
system("fota_upi -u verify"); | |
result = fota_get_update_status(&upgradeStatus); | |
if(result < 0) | |
{ | |
printf("arms_data_example_upgrade failed to read the update_status file\n"); | |
return -1; | |
} | |
else if(upgradeStatus != 0) | |
{ | |
printf("arms_data_example_upgrade verify failed\n"); | |
return -1; | |
} | |
else | |
{ | |
printf("arms_data_example_upgrade verify success, start upgrade!\n"); | |
system("fota_upi -u recovery"); | |
} | |
#ifdef EXAMPLE_REF_VALUE | |
//remove(pPath); | |
#endif | |
return 0; | |
} | |
int arms_data_example_get_region_size(unsigned int* pRegionSize) | |
{ | |
if (pRegionSize == NULL) | |
return -1; | |
*pRegionSize = 20*1024*1024; | |
return 0; | |
} | |
int arms_data_example_get_log(char *pPath, int *pPathLen, char *pFileName, int *pFileNameLen) | |
{ | |
if ((pPath == NULL) || (pPathLen == NULL) || (pFileName == NULL) || (pFileNameLen == NULL)) | |
return ARMS_DATA_POINT_NULL_ERROR; | |
if (strlen(ARMS_LOG_FILE_PATH) >= *pPathLen) | |
return -1; | |
if (strlen(ARMS_LOG_FILE_NAME) >= *pFileNameLen) | |
return -1; | |
strcpy(pPath, ARMS_LOG_FILE_PATH); | |
strcpy(pFileName, ARMS_LOG_FILE_NAME); | |
return 0; | |
} | |
#endif | |
#endif | |