[Feature][S300][task-view-1900][arms] Docking with ARMS platform,basic documents

Change-Id: I89df7b9e3685d6f6205bd2a4ff00ac67c8f447cb
diff --git a/lynq/S300/ap/app/apparms/apparms_config_example.c b/lynq/S300/ap/app/apparms/apparms_config_example.c
new file mode 100755
index 0000000..097738a
--- /dev/null
+++ b/lynq/S300/ap/app/apparms/apparms_config_example.c
@@ -0,0 +1,456 @@
+#include "apparms_config_example.h"

+#include "apparms_util.h"

+

+#ifdef ARMS_SUPPORT_ARGV

+#include "apparms_argv.h"

+#endif

+

+#ifdef ARMS_BOARD_EXAMPLE

+

+static ARMSCFGFUNLIST arms_example_cfgfun_pointer =

+{

+	arms_config_example_get_imei,

+	arms_config_example_get_sn,

+	arms_config_example_get_networkst,

+	

+#ifdef ARMS_SUPPORT_DM

+	arms_config_example_get_dm_mode_cfg,

+	arms_config_example_get_dm_tlv_cfg,

+	arms_config_example_get_dm_push_rsp_tlv_cfg,

+	arms_config_example_get_dm_notification_tlv_cfg,

+#ifdef ARMS_DM_UDP

+	arms_config_example_get_dm_udp_cfg,

+#endif

+#ifdef ARMS_DM_MQTT

+	arms_config_example_get_dm_mqtt_cfg,

+#endif

+#ifdef ARMS_DM_LWM2M

+	arms_config_example_get_dm_lwm2m_cfg,

+#endif

+#ifdef ARMS_DM_IPC

+	arms_config_example_get_dm_ipc_cfg,

+#endif

+#ifdef ARMS_DM_RPC

+	arms_config_example_get_dm_rpc_cfg,

+#endif

+#endif

+

+#ifdef ARMS_SUPPORT_FOTA

+#ifdef ARMS_FOTA_HTTP	

+	arms_config_example_get_http_cfg,

+#endif	

+	arms_config_example_get_fota_mode_cfg,

+	arms_config_example_get_fota_tlv_cfg,

+#endif

+

+#ifdef ARMS_SUPPORT_EC2

+	arms_config_example_get_ec2_cfg,

+#endif

+

+	arms_config_example_init,

+	arms_config_example_uninit

+};

+

+PARMSCFGFUNLIST arms_config_example_get_cfgfun_pointer(void)

+{

+	return &arms_example_cfgfun_pointer;

+}

+

+int arms_config_example_get_imei(unsigned char *pDMIMEI, unsigned char* pIMEI)

+{

+	char szIMEI[32] = {0};

+#if 0

+	#ifdef ARMS_SUPPORT_ARGV

+	if (arms_argv_get_imei(szIMEI, sizeof(szIMEI)) <= 0)

+	#endif

+	{

+		#if defined(ARMS_DM_MQTT)

+			#ifdef ARMS_AUTH_X509

+			strcpy(szIMEI, "920000000000051");

+			#else

+			strcpy(szIMEI, "990000000000053");

+			#endif

+		#elif defined(ARMS_DM_LWM2M)

+			strcpy(szIMEI, "930000000000151");

+		#else

+			strcpy(szIMEI, "998199055256418");

+		#endif

+	}

+#endif

+	cfg_get_item("imei", szIMEI, sizeof(szIMEI));

+	printf("****arms_config_example_get_imei imei=[%s]\n", szIMEI);

+	if (pDMIMEI != NULL)

+	{

+		strcpy((char *)pDMIMEI, "0");

+		strcat((char *)pDMIMEI, szIMEI);

+	}

+

+	if (pIMEI != NULL)

+	{

+		strcpy((char *)pIMEI, szIMEI);

+	}

+

+	return 0;

+}

+

+int arms_config_example_get_sn(unsigned char *pSN)

+{

+	char szSN[32] = {0};

+

+	strcpy(szSN, "123456789012345");

+

+	if (pSN != NULL)

+	{

+		strcpy((char *)pSN, szSN);

+	}

+

+	return 0;

+}

+

+int arms_config_example_get_networkst(char *pIPAddr)

+{

+	int ret = -3;

+	char buf[32] = {0};

+	char wan_ipaddr[32] = {0};

+	

+	if (pIPAddr == NULL)

+		return -1;

+#if 0

+	#ifdef ARMS_SUPPORT_ARGV

+	if (arms_argv_get_intf(szIntf, sizeof(szIntf)) <= 0)

+	#endif

+	{

+		strcpy(szIntf, ARMS_DM_WAN_IF);

+	}

+

+	ret = arms_util_get_if_ip(szIntf, pIPAddr);

+	if ((ret >= 0) && (strcmp(pIPAddr, "0.0.0.0") == 0))

+	{

+		ret = -3;

+	}

+	

+#endif

+	cfg_get_item("ppp_status", buf, sizeof(buf));

+	if (0 == strcmp(buf, "ppp_connected"))

+	{

+		cfg_get_item("wan_ipaddr", wan_ipaddr, sizeof(wan_ipaddr));

+		strcpy(pIPAddr, wan_ipaddr);

+		ret = 0;

+	}

+

+	return ret;

+}

+

+int arms_config_example_init(void)

+{

+	return 0;

+}

+

+int arms_config_example_uninit(void)

+{

+	return 0;

+}

+

+

+#ifdef ARMS_SUPPORT_DM

+int arms_config_example_get_dm_mode_cfg(PDMCOMMCFG pDMCommCfg)

+{

+	if (pDMCommCfg == NULL)

+		return -1;	

+

+#if defined(ARMS_DM_MQTT)

+	pDMCommCfg->emCommMode = ARMS_DM_COMM_MQTT;

+	#ifdef ARMS_AUTH_X509

+		pDMCommCfg->emAuthMode = ARMS_DM_AUTH_CERT;

+	#else

+		pDMCommCfg->emAuthMode = ARMS_DM_AUTH_KEY;

+	#endif

+#elif defined(ARMS_DM_LWM2M)

+	pDMCommCfg->emCommMode = ARMS_DM_COMM_LWM2M;

+#else

+	pDMCommCfg->emCommMode = ARMS_DM_COMM_UDP;

+#endif

+

+	pDMCommCfg->nReportPeriod = ARMS_DM_REPORT_INTERVAL; //Report DM telemetry for every 60 seconds

+

+	#ifdef ARMS_SUPPORT_ARGV

+	if (arms_argv_get_dm(&pDMCommCfg->unHWId, (char *)pDMCommCfg->szKey, sizeof(pDMCommCfg->szKey)) <= 0)

+	#endif

+	{

+		#if defined(ARMS_DM_MQTT)

+			#ifdef ARMS_AUTH_X509

+				pDMCommCfg->unHWId = 5168;

+				strcpy((char *)pDMCommCfg->szKey, "feb3aed743e74f45b718de349f0774e1");

+			#else

+				pDMCommCfg->unHWId = ARMS_DM_ACCESS_ID_MQTT;

+				strcpy((char *)pDMCommCfg->szKey, ARMS_DM_ACCESS_PW_MQTT);

+			#endif

+		#elif defined(ARMS_DM_LWM2M)

+			pDMCommCfg->unHWId = ARMS_DM_ACCESS_ID_LWM2M;

+			strcpy((char *)pDMCommCfg->szKey, ARMS_DM_ACCESS_PW_LWM2M);

+		#else

+			pDMCommCfg->unHWId = ARMS_DM_ACCESS_ID_UDP;

+			strcpy((char *)pDMCommCfg->szKey, ARMS_DM_ACCESS_PW_UDP);

+		#endif

+	}

+

+	return 0;

+}

+

+int arms_config_example_get_dm_tlv_cfg(PDMTLVCFG pDMTLVCfg)

+{

+	if (pDMTLVCfg == NULL)

+		return -1;

+	

+	//pDMTLVCfg->emDMTLVMask = 0xFFFFF & ~ARMS_DM_TLV_COMM_RSPMSG & ~ARMS_DM_TLV_COMM_WARNMSG;

+	pDMTLVCfg->emDMTLVMask = ARMS_DM_TLV_COMM_VERSION | ARMS_DM_TLV_COMM_TOKEN; 

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA1; //SW Ver

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA2; //Inner Ver

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA3; //RSRP

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA4; //RSRQ

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA5; //RSSI

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA6; //SINR

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA7; //Carrier

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA8; //GCI

+

+	pDMTLVCfg->emDMTLVGenMask = 0x1FFFF;

+	pDMTLVCfg->emDMTLVVerMask = ARMS_DM_TLV_VER_HID | ARMS_DM_TLV_VER_MCU;

+	pDMTLVCfg->emDMTLVEXTVerMask = ARMS_DM_TLV_EXTVER_MCU2;

+	pDMTLVCfg->emDMTLVDMReportMask = 0x7F;

+

+	return 0;	

+}

+

+int arms_config_example_get_dm_push_rsp_tlv_cfg(PDMTLVCFG pDMTLVCfg)

+{

+	if (pDMTLVCfg == NULL)

+		return -1;

+

+	pDMTLVCfg->emDMTLVMask = ARMS_DM_TLV_COMM_VERSION | ARMS_DM_TLV_COMM_TOKEN | ARMS_DM_TLV_COMM_RSPMSG;

+	pDMTLVCfg->emDMTLVGenMask = 0x00000;

+	pDMTLVCfg->emDMTLVVerMask = ARMS_DM_TLV_VER_HID;

+	pDMTLVCfg->emDMTLVEXTVerMask = 0x00;

+	pDMTLVCfg->emDMTLVDMReportMask = 0x00;

+	

+	return 0;	

+}

+

+int arms_config_example_get_dm_notification_tlv_cfg(PDMTLVCFG pDMTLVCfg)

+{

+	if (pDMTLVCfg == NULL)

+		return -1;

+	

+	pDMTLVCfg->emDMTLVMask = ARMS_DM_TLV_COMM_VERSION | ARMS_DM_TLV_COMM_TOKEN | ARMS_DM_TLV_COMM_WARNMSG;

+

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA1; //SW Ver

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA2; //Inner Ver

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA3; //RSRP

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA4; //RSRQ

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA5; //RSSI

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA6; //SINR

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA7; //Carrier

+	pDMTLVCfg->emDMTLVMask |= ARMS_DM_TLV_COMM_CUSDATA8; //GCI

+

+	pDMTLVCfg->emDMTLVGenMask = 0x00000;

+	pDMTLVCfg->emDMTLVVerMask = ARMS_DM_TLV_VER_HID;

+	pDMTLVCfg->emDMTLVEXTVerMask = 0x00;

+	pDMTLVCfg->emDMTLVDMReportMask = 0x00;

+

+	return 0;	

+}

+

+#ifdef ARMS_DM_UDP

+int arms_config_example_get_dm_udp_cfg(PUDPCFG pUDPCfg)

+{

+	if (pUDPCfg == NULL)

+		return -1;

+

+	pUDPCfg->nUDPPort = 9000;

+

+	#ifdef ARMS_SUPPORT_ARGV

+	if (arms_argv_get_udp_url(pUDPCfg->szUDPAddr, sizeof(pUDPCfg->szUDPAddr)) <= 0)

+	#endif

+	{

+		strcpy(pUDPCfg->szUDPAddr, ARMS_DM_SRV_UDP_ADDR);

+	}

+	

+	return 0;	

+}

+#endif

+

+#ifdef ARMS_DM_MQTT

+int arms_config_example_get_dm_mqtt_cfg(PMQTTCFG pMQTTCfg,PDMCOMMCFG pDMCommCfg)

+{

+	unsigned char *p = NULL;

+	if (pMQTTCfg == NULL)

+		return -1;

+

+	#ifdef ARMS_SUPPORT_ARGV

+	if (arms_argv_get_mqtt_url(pMQTTCfg->szMQTTAddr, sizeof(pMQTTCfg->szMQTTAddr)) <= 0)

+	#endif

+	{

+		strcpy(pMQTTCfg->szMQTTAddr,ARMS_DM_SRV_MQTT_ADDR);

+	}

+

+	pMQTTCfg->nMQTTLiveTM = 180;

+#ifdef ARMS_AUTH_X509

+	pMQTTCfg->nMQTTPort = 8099;

+#else

+	pMQTTCfg->nMQTTPort = 8089;

+#endif

+	p = pDMCommCfg->szIMEI + 1;

+	sprintf(pMQTTCfg->szUserName,"%ld_%s",pDMCommCfg->unHWId,p);

+#ifdef ARMS_AUTH_X509

+	strcpy(pMQTTCfg->szPassWord,"123456");

+	strcpy(pMQTTCfg->szCaCert,"./certs/ca-cert.pem");

+	strcpy(pMQTTCfg->szClientCert,"./certs/client-cert.pem");

+	strcpy(pMQTTCfg->szClientKey,"./certs/client-key.pem");

+#else

+	strcpy(pMQTTCfg->szPassWord,(char *)pDMCommCfg->szKey);

+#endif

+

+	return 0;	

+}

+#endif

+

+#ifdef ARMS_DM_LWM2M

+int arms_config_example_get_dm_lwm2m_cfg(PLWM2MCFG pLWM2MCfg,PDMCOMMCFG pDMCommCfg)

+{

+	unsigned char *p = NULL;

+	if (pLWM2MCfg == NULL)

+		return -1;

+

+	

+	#ifdef ARMS_SUPPORT_ARGV

+	if (arms_argv_get_lwm2m_url(pLWM2MCfg->szLwM2MAddr, sizeof(pLWM2MCfg->szLwM2MAddr)) <= 0)

+	#endif

+	{

+		strcpy(pLWM2MCfg->szLwM2MAddr,ARMS_DM_SRV_LWM2M_ADDR);

+	}

+

+	pLWM2MCfg->nLwM2MPort = 5683;

+	p = pDMCommCfg->szIMEI + 1;

+	sprintf(pLWM2MCfg->szEndpointName,"%s",p);

+

+	return 0;	

+}

+#endif

+

+#ifdef ARMS_DM_IPC

+int arms_config_example_get_dm_ipc_cfg(PDMIPCCFG pIPCCfg)

+{

+	memset(pIPCCfg, 0, sizeof(DMIPCCFG));

+	pIPCCfg->enable = 1;

+	strcpy(pIPCCfg->intf[0], ARMS_DM_WAN_IF);

+	pIPCCfg->nPort = ARMS_DM_IPC_LISTEN_PORT;

+	pIPCCfg->uMaxclient = ARMS_DM_IPC_MAX_CLIENT;

+	pIPCCfg->mtimeout = ARMS_DM_IPC_CLOSE_TIME;

+	pIPCCfg->bUnixMode = 0;

+	pIPCCfg->bDynamicOpen = 1;

+	

+	return 0;

+}

+#endif

+

+#ifdef ARMS_DM_RPC

+int arms_config_example_get_dm_rpc_cfg(PDMRPCCFG pRPCCfg)

+{

+	memset(pRPCCfg, 0, sizeof(DMRPCCFG));

+	pRPCCfg->bRPC = 1;

+	#ifdef ARMS_DM_RPC_UNX_MODE

+	pRPCCfg->bRPCUnixMode = 1;

+	strcpy(pRPCCfg->szRPCUnix, ARMS_DM_RPC_UNIX_PATH);

+	#else

+	pRPCCfg->bRPCUnixMode = 0;

+	strcpy(pRPCCfg->szRPCTCPSrv, "127.0.0.1");

+	pRPCCfg->nRPCTCPPort = ARMS_DM_RPC_TCP_PORT;

+	#endif

+

+	pRPCCfg->mRPCTimeout = 300*1000;

+	

+	return 0;

+}

+#endif

+#endif

+

+#ifdef ARMS_SUPPORT_FOTA

+int arms_config_example_get_fota_mode_cfg(PFOTACOMMCFG pFOTACommCfg)

+{

+	if (pFOTACommCfg == NULL)

+		return -1;	

+

+#if defined(ARMS_FOTA_HTTP)

+	pFOTACommCfg->emCommMode = ARMS_FOTA_COMM_HTTP_HTTPS;

+#endif

+

+	pFOTACommCfg->nCheckPeriod = ARMS_FOTA_CHECK_INTERVAL; //Check fota for every 30 seconds

+

+	return 0;

+}

+

+int arms_config_example_get_fota_tlv_cfg(PFOTATLVCFG pFOTATLVCfg)

+{

+	if (pFOTATLVCfg == NULL)

+		return -1;

+

+

+	return 0;	

+}

+

+

+#ifdef ARMS_FOTA_HTTP

+int arms_config_example_get_http_cfg(PHTTPCFG pHTTPCfg)

+{

+	if (pHTTPCfg == NULL)

+		return -1;

+	

+#ifdef ARMS_FOTA_HTTPS

+	#ifdef ARMS_SUPPORT_ARGV

+	if (arms_argv_get_fota_url(1, pHTTPCfg->szAddr, sizeof(pHTTPCfg->szAddr)) <= 0)

+	#endif

+	{

+		strcpy(pHTTPCfg->szAddr,ARMS_FOTA_SRV_HTTPS_ADDR);

+	}

+	pHTTPCfg->nPort = 443;

+#else

+	#ifdef ARMS_SUPPORT_ARGV

+	if (arms_argv_get_fota_url(0, pHTTPCfg->szAddr, sizeof(pHTTPCfg->szAddr)) <= 0)

+	#endif

+	{

+		strcpy(pHTTPCfg->szAddr,ARMS_FOTA_SRV_HTTP_ADDR);

+	}

+	pHTTPCfg->nPort = 80;

+#endif	

+	strcpy(pHTTPCfg->szDownFilePath,ARMS_FOTA_DOWNLOAD_PATH);

+

+	#ifdef ARMS_SUPPORT_ARGV

+	if (arms_argv_get_fota(pHTTPCfg->szProdID, sizeof(pHTTPCfg->szProdID), 

+								pHTTPCfg->szPassword, sizeof(pHTTPCfg->szPassword)) <= 0)

+	#endif

+	{

+		strcpy(pHTTPCfg->szProdID,ARMS_FOTA_ACCESS_ID);

+		strcpy(pHTTPCfg->szPassword,ARMS_FOTA_ACCESS_PW);

+	}

+

+	return 0;	

+}

+#endif

+#endif

+

+#ifdef ARMS_SUPPORT_EC2

+int arms_config_example_get_ec2_cfg(PEC2CFG pEC2Cfg)

+{

+	if (pEC2Cfg == NULL)

+		return -1;	

+

+	strcpy(pEC2Cfg->stHttpCfg.szAddr,ARMS_EC2_SRV_HTTP_ADDR);

+	pEC2Cfg->stHttpCfg.nPort = 80;

+	sprintf(pEC2Cfg->stHttpCfg.szProdID,"%d",ARMS_EC2_ACCESS_ID);

+	strcpy(pEC2Cfg->szHttpRspPath,ARMS_EC2_HTTP_RSP_PATH);

+

+	return 0;

+}

+#endif

+

+#endif

+