PV1_MakeProject/Example/main.c

2322 lines
69 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include <uv.h>
#include <dbus/dbus.h>
#include <readline/readline.h>
#include <uthash/utstring.h>
#include <linux/netlink.h>
#include <linux/socket.h>
#include <linux/nl80211.h>
#include <sys/socket.h>
#include "log.h"
#include "libuv_dbus.h"
#include "crypto.h"
#include "json_struct.h"
#include "config_engine.h"
#include "ota.h"
#include "skins.h"
#include "assistant.h"
#include "inet_api.h"
#include "skins_res.h"
#include "server_addr.h"
#include "boardlink_iot.h"
static MOD_INFO_TABLE g_ModInfo;
static uv_timer_t g_tmTest;
static uv_barrier_t g_tmSync;
static uv_loop_t* pUserLoop = NULL;
static int g_isExitLoop = 0;
static void test_task_new(uv_thread_cb pCallback, void* pParams);
static void OnCfgMsgCb(DBUS_CMD cmd, PCFG_ITEM pMsg, int err)
{
fprintf(stdout, "Cmd = %d, Cfg = %s\n", cmd, pMsg->pKeyName);
if(err != 0)
{
LOG_EX(LOG_Error, "Cmd %d Error: %d\n", cmd, err);
return;
}
switch(cmd)
{
case CMD_CFG_GET_RSP:
CfgItemPrint("Add Configure: ", pMsg);
break;
}
}
static void __dBusDeameonCb(MODULE_NAME modName, int status)
{
#if 1
if(status)
{
LOG_EX(LOG_Error, "Daemon(%d) Msg: [%s]\n", modName, status == 0 ? "Connect" : "Disconnect");
}
else
{
LOG_EX(LOG_Info, "Daemon(%d) Msg: [%s]\n", modName, status == 0 ? "Connect" : "Disconnect");
}
#endif
if(modName == MODULE_OTA && status == 0)
{
int ret = DBusSendToCommand(NULL,
g_pModInfoTable[MODULE_OTA].modAliase,
CMD_SYSTEM_STANDBY, "{\"status\" : 0}");
LOG_EX(LOG_Debug, "Send Standby Command: %d\n", ret);
}
LOG_EX(LOG_Debug, "Set Exit Loop\n");
g_isExitLoop = TRUE;
}
static void KeyEventCb(uint16_t uType, uint16_t uKey, int32_t iValue)
{
LOG_EX(LOG_Info, "type = %u, code = %u, value = %u\n", uType, uKey, iValue);
}
static void __uvThreadOTA(void *pParams)
{
OTA_DATA_INFO otaInfo;
POTA_DATA_INFO pInfo = NULL;
int ret;
int version = (int)(intptr_t)pParams;
memset(&otaInfo, 0, sizeof(OTA_DATA_INFO));
#if 0
if(version == 130)
{
otaInfo.version = 132;
strcpy(otaInfo.otaFileInfo.url, "http://10.241.0.70/tina/tina_r16_ota_132.tar.gz");
strcpy(otaInfo.otaFileInfo.md5, "3bda58a2eb4e90fbb35b0d33db44cf57");
otaInfo.otaFileInfo.size = 22966488;
}
else if(version == 132)
{
otaInfo.version = 133;
strcpy(otaInfo.otaFileInfo.url, "http://10.241.0.70/tina/tina_r16_ota_133.tar.gz");
strcpy(otaInfo.otaFileInfo.md5, "c4085cb33d6dbd5ae5fdae948365023c");
otaInfo.otaFileInfo.size = 22966524;
}
else
{
otaInfo.version = 4;
strcpy(otaInfo.otaFileInfo.url, "http://api.multimedia.netease.com/imgtest/ota/tina_r16_ota_133.tar.gz");
strcpy(otaInfo.otaFileInfo.md5, "c4085cb33d6dbd5ae5fdae948365023c");
otaInfo.otaFileInfo.size = 22963814;
}
#else
otaInfo.version = 0x00000004;
strcpy(otaInfo.otaFileInfo.url, "http://10.240.84.163/tina_r311_ota_34.tar.gz");
strcpy(otaInfo.otaFileInfo.md5, "34c06f79806be978a328194fd883365d");
otaInfo.otaFileInfo.size = 31581616;
#endif
otaInfo.otaCmd = OTA_CMD_DOWNLOAD;
otaInfo.otaMode = OTA_MODE_FORCE_NOW;
ret = DBusJsonSendToCommand(NULL,
g_pModInfoTable[MODULE_OTA].modAliase,
CMD_OTA_NOTIFY,
JSON_ENGINE_OTA_REQ,
&otaInfo, TRUE);
LOG_EX(LOG_Debug, "Send OTA Command: OTA_CMD_DOWNLOAD --> %d\n", ret);
}
#if 0
static void __radomAlarmItem(PASSISTANT_ITEM_INFO pInfo)
{
static unsigned int alarmId = 0;
time_t tmVal = time(NULL);
struct tm *pTmNow = localtime(&tmVal);
if(pInfo == NULL)
{
return;
}
memset(pInfo, 0, sizeof(ALARM_ITEM_INFO));
pInfo->alarmId = __sync_fetch_and_add(&alarmId, 1);
pInfo->itemType = (random() % 2 == 0) ? ALARM_TYPE_REMAIND : ALARM_TYPE_CLOCK;
pInfo->priority = random() % 10;
pInfo->repeatMode = random() % (REPEAT_MODE_EVERY_YEAR_DAY + 1);
pTmNow->tm_hour = random() % 24;
pTmNow->tm_min = random() % 60;
//strftime(pInfo->strDateTime, MAX_DT_LEN, "%Y-%m-%d %H:%M", pTmNow);
sprintf(pInfo->strTips, "TTS %llu", pInfo->itemId);
}
#endif
static PDBUS_MSG_PACK DBusOnMessage(uv_loop_t* pLoop, DBusConnection* pConn, PDBUS_MSG_PACK pMsg)
{
int i, ret, err;
uint32_t tm = LIBUV_CURRENT_TIME_US();
PCFG_API_RSP pRsp = NULL;
POTA_RSP_STATUS pOTAStatus = NULL;
//PALARM_RSP_STATUS pAlarmStatus = NULL;
//PALARM_SYNC_INFO pSyncInfo = NULL;
static unsigned int iCnt = 0;
if(!pMsg || !pLoop || !pConn)
{
return NULL;
}
#if 1
if(iCnt++ % 1000 == 0)
{
LOG_EX(LOG_Info, "Receive: %s\n", pMsg->pMsg);
}
#endif
//LOG_EX(LOG_Info, "Process Message(%u --> 0x%08X) at [%lu.%06lu]: cmd = %u, size = %u, key = %d, msg(%d) = [%s]\n",
// pMsg->msgSrc, pMsg->msgDests, tm / 1000000, tm % 1000000, pMsg->busCmd, pMsg->msgSize, pMsg->msgKey, pMsg->msgSize, pMsg->pMsg);
switch(pMsg->busCmd)
{
case CMD_CALL_DIAL:
LOG_EX(LOG_Debug, "Recv: %s\n", pMsg->pMsg);
break;
case CMD_MISC_OTA:
print_hex_dump_bytes("OTA", DUMP_PREFIX_ADDRESS, pMsg->pMsg, (pMsg->msgSize > 128) ? 128 : pMsg->msgSize);
break;
case CMD_CFG_GET_RSP:
pRsp = (PCFG_API_RSP)Json2Struct(pMsg->pMsg, JSON_ENGINE_CFG_RSP, TRUE, &err);
if(pRsp == NULL || err != 0)
{
LOG_EX(LOG_Error, "CMD_CFG_GET: pRsp = %p, err = %d\n", pRsp, err);
return (NULL);
}
LOG_EX(LOG_Debug, "Get Configure: [%s](%d) --> \"%s\"\n", pRsp->keyName, pRsp->keyType, pRsp->keyValue);
free(pRsp);
break;
case CMD_OTA_STATUS:
pOTAStatus = (POTA_RSP_STATUS)Json2Struct(pMsg->pMsg, JSON_ENGINE_OTA_RSP, TRUE, &err);
LOG_EX(LOG_Debug, "%s --> %d(0x%08X)\n", otaStatusName(pOTAStatus->status), pOTAStatus->val, pOTAStatus->val);
if(pOTAStatus->status == OTA_CURRENT_VERSION)
{
test_task_new(__uvThreadOTA, (void*)(intptr_t)pOTAStatus->val);
}
free(pOTAStatus);
break;
case CMD_ALARM_SYNC_REQ:
LOG_EX(LOG_Debug, "Receive CMD_ALARM_SYNC_REQ Command\n");
if(iCnt++ > 0)
{
break;
}
#if 0
const char *pAddCmd = "{\"data\":[{\"createTime\":1509419640000,\"id\":672,\"label\":1,\"type\":8,\"status\":1,"
"\"updateTime\":1509419640000,\"vboxDate\":{\"dayofMonth\":\"17\",\"dayofWeek\":"
"\"1,2,3,4,5\",\"hour\":\"0\",\"minute\":\"0\",\"month\":\"11\",\"second\":\"10\",\"year\":\"\"},"
"\"vboxid\":\"0-52AEDB2DF9F45FEB\",\"voiceName\":\"音效2\",\"voiceType\":2},"
"{\"createTime\":1509419547000,\"id\":671,\"label\":0,\"type\":1,\"status\":1,\"updateTime\":"
"1509419547000,\"vboxDate\":{\"dayofMonth\":\"\",\"dayofWeek\":\"\",\"hour\":\"0\","
"\"minute\":\"0\",\"month\":\"\",\"second\":\"10\",\"year\":\"\"},\"vboxid\":\"0-52AEDB2DF9F45FEB\","
"\"voiceName\":\"音效2\",\"voiceType\":2}]}";
#else
#if 0
const char *pAddCmd = "{\"data\":[{\"id\":6734,\"vboxid\":\"0-D04CDF28BB622AF7\",\"label\":0,"
"\"type\":1,\"voiceType\":1,\"voiceName\":\"音效1\",\"status\":2,"
"\"updateTime\":1515576709000,\"createTime\":1515576709000,"
"\"vboxDate\":{\"second\":\"0\",\"minute\":\"41\",\"hour\":\"18\","
"\"dayofMonth\":\"10\",\"month\":\"1\",\"dayofWeek\":\"3\",\"year\":"
"\"2018\"}},{\"id\":6733,\"vboxid\":\"0-D04CDF28BB622AF7\",\"label\":0,"
"\"type\":1,\"voiceType\":1,\"voiceName\":\"音效1\",\"status\":2,"
"\"updateTime\":1515576701000,\"createTime\":1515576701000,\"vboxDate\":"
"{\"second\":\"0\",\"minute\":\"42\",\"hour\":\"18\",\"dayofMonth\":\"10\","
"\"month\":\"1\",\"dayofWeek\":\"3\",\"year\":\"2018\"}}]}";
#else
const char *pAddCmd = "{\"data\":[{\"id\":8136,\"vboxid\":\"0-ADC8ED8631B2032D\",\"label\":0,"
"\"type\":3,\"voiceType\":1,\"voiceName\":\"音效1\",\"status\":2,"
"\"updateTime\":1520841240000,\"createTime\":1520841240000,"
"\"vboxDate\":{\"second\":\"\",\"minute\":\"56\",\"hour\":\"9\","
"\"dayofMonth\":\"13\",\"month\":\"3\",\"dayofWeek\":\"2\","
"\"year\":\"2018\"}}]}";
#endif
#endif
#if 0
ALARM_SYNC_INFO alarmInfo;
ALARM_REMOVE_INFO rmInfo;
memset(&alarmInfo, 0, sizeof(ALARM_SYNC_INFO));
memset(&rmInfo, 0, sizeof(ALARM_REMOVE_INFO));
alarmInfo.nItems = 10;
//alarmInfo.cmd = CMD_ALARM_SYNC_RSP;
alarmInfo.pAlarmInfo = (PALARM_ITEM_INFO)malloc(sizeof(ALARM_ITEM_INFO) * 10);
for(i = 0; i < 10; i++)
{
__radomAlarmItem(&alarmInfo.pAlarmInfo[i]);
}
ret = DBusJsonSendToCommand(NULL,
g_pModInfoTable[MODULE_ALARM].modAliase,
CMD_ALARM_SYNC_RSP,
JSON_ENGINE_ALARM_SYNC_RSP,
&alarmInfo, TRUE);
#endif
ret = DBusSendToCommand(NULL,
g_pModInfoTable[MODULE_ALARM].modAliase,
CMD_ALARM_SYNC_RSP,
pAddCmd);
LOG_EX(LOG_Debug, "Send Alarm Command: JSON_ENGINE_ALARM_SYNC_RSP --> %d\n", ret);
#if 0
rmInfo.nItems = 3;
for(i = 0; i < 3; i++)
{
// rmInfo.rmItemId[i] = alarmInfo.pAlarmInfo[i * 2].alarmId;
}
ret = DBusJsonSendToCommand(NULL,
g_pModInfoTable[MODULE_ALARM].modAliase,
CMD_ALARM_REMOVE,
JSON_ENGINE_ALARM_REMOVE,
&rmInfo, TRUE);
LOG_EX(LOG_Debug, "Send Alarm Command: JSON_ENGINE_ALARM_SYNC_RSP --> %d\n", ret);
free(alarmInfo.pAlarmInfo);
#endif
break;
#if 0
case CMD_ALARM_STATUS:
//LOG_EX(LOG_Debug, "CMD_ALARM_STATUS: %s\n", (const char *)pMsg->pMsg);
pAlarmStatus = (PALARM_RSP_STATUS)Json2Struct(pMsg->pMsg, JSON_ENGINE_ALARM_STATUS, TRUE, &err);
LOG_EX(LOG_Debug, "%s --> %d(0x%08X)\n", alarmStatusName(pAlarmStatus->cmd), pAlarmStatus->val, pAlarmStatus->val);
free(pAlarmStatus);
break;
case CMD_ALARM_NOTIFY_EVT:
//LOG_EX(LOG_Debug, "CMD_ALARM_NOTIFY_EVT: %s\n", (const char *)pMsg->pMsg);
pSyncInfo = (PALARM_SYNC_INFO)Json2Struct((const char *)pMsg->pMsg, JSON_ENGINE_ALARM_SYNC_RSP, TRUE, &err);
if(pSyncInfo)
{
__printAlarmSyncInfo("CMD_ALARM_NOTIFY_EVT", pSyncInfo);
free(pSyncInfo);
}
break;
#endif
default:
break;
}
return NULL;
}
static unsigned int g_Delay = 1000;
static void uvSndLessCb(uv_timer_t* pTimer)
{
#if 0
DBusConnection* pBus = (DBusConnection*)pTimer->data;
unsigned char* pData = (unsigned char*)malloc(2048);
memset(pData, 0x3f, 2048);
*pData = 0;
if(g_ModInfo.modName != MODULE_CONTROLLER)
{
DBusSendToCommand(pBus, g_pModInfoTable[MODULE_CONTROLLER].modAliase, CMD_MISC_OTA, pData, 2048);
}
free(pData);
#endif
LOG_EX(LOG_Info, "Timer Runing delay = %u ....\n", g_Delay);
uv_barrier_wait(&g_tmSync);
// AESEncrypto();
}
#define TEST_AES_LEN (93)
void test_evp_aes(void)
{
int i;
unsigned char enData[ALIGN_AES_BLOCK(TEST_AES_LEN)];
unsigned char* pData = (unsigned char*)malloc(ALIGN_AES_BLOCK(TEST_AES_LEN));
int outSize = 0;
char* pKey = "0123456789abcedf";
for(i = 0; i < TEST_AES_LEN; i++)
{
enData[i] = i % 0xFF;
}
strcpy(enData, "hello world");
fprintf(stdout, "EvpAESEncrypto: %s\n",
EvpAESEncrypto(enData, TEST_AES_LEN, pData, &outSize, (unsigned char*)pKey) == 0 ? "Success" : "Fail");
print_hex_dump_bytes("en_", 2, pData, outSize);
fprintf(stdout, "enc: %s --> %s\n",enData, EvpBase64EncodeNoAlignV2(pData, outSize));
memset(enData, 0, ALIGN_AES_BLOCK(TEST_AES_LEN));
fprintf(stdout, "EvpAESDecrypto: %s\n",
EvpAESDecrypto(pData, outSize, enData, &outSize, (unsigned char*)pKey) == 0 ? "Success" : "Fail");
fprintf(stdout, "dec:%s\n", (char*)enData);
free(pData);
}
static void uvTimeoutCb(uv_timer_t* pTimer)
{
PCFG_ITEM pItem = NULL;
int ret = 0;
if((ret = CfgGetKeyValue("Age", &pItem)) == 0)
{
CfgItemPrint("Get KeyValue: ", pItem);
}
else
{
LOG_EX(LOG_Error, "Get Key [Age] Error: %d\n", ret);
}
}
static void EVPEncryptCb(CRYPTO_TYPE type,
const unsigned char* pData,
int iSize,
const unsigned char* pSrcData,
int iError)
{
int i = 0;
if(iError == 0)
{
if(type == CRYPTO_AES_ENCRYPT)
{
char* pKey = "xajhuang12345678";
unsigned char* enData = (unsigned char*)malloc(ALIGN_AES_BLOCK(TEST_AES_LEN));
memset(enData, 0, ALIGN_AES_BLOCK(TEST_AES_LEN));
print_hex_dump_bytes("AES_Encrypt_", DUMP_PREFIX_ADDRESS, pData, iSize);
i = EvpAddCryptoTask(CRYPTO_AES_DECRYPT, (unsigned char*)pData, iSize, enData, pKey, EVPEncryptCb);
if(i != 0)
{
free(enData);
LOG_EX(LOG_Error, "EvpAddCryptoTask Error: %d\n", i);
}
}
else if(type == CRYPTO_AES_DECRYPT)
{
print_hex_dump_bytes("AES_Decrypt_", DUMP_PREFIX_ADDRESS, pData, iSize);
}
else if(type == CRYPTO_BASE64_ENCODE)
{
int ret = 0;
LOG_EX(LOG_Info, "Base64(%d):[\n%s]\n", iSize, (char*)pData);
ret = EvpAddCryptoTask(CRYPTO_BASE64_DECODE, (unsigned char*)pData, iSize, NULL, NULL, EVPEncryptCb);
if(ret != 0)
{
LOG_EX(LOG_Error, "EvpAddCryptoTask Error: %d\n", ret);
}
}
else if(type == CRYPTO_BASE64_DECODE)
{
LOG_EX(LOG_Info, "Base64(%d):[\n%s]\n", iSize, (char*)pData);
}
else if(type == CRYPTO_MD5_FILE)
{
LOG_EX(LOG_Info, "%s MD5 value [%s]\n", (char*)pSrcData, (char*)pData);
}
}
else
{
LOG_EX(LOG_Error, "pData = %p, iError = %d\n", pData, iError);
}
free((void*)pData);
}
static void test_aes_async(void)
{
int i;
unsigned char enData[ALIGN_AES_BLOCK(TEST_AES_LEN)];
unsigned char* pData = (unsigned char*)malloc(ALIGN_AES_BLOCK(TEST_AES_LEN));
int outSize = 0;
char* pKey = "xajhuang12345678";
for(i = 0; i < TEST_AES_LEN; i++)
{
enData[i] = i % 0xFF;
}
i = EvpAddCryptoTask(CRYPTO_BASE64_ENCODE, enData, TEST_AES_LEN, pData, pKey, EVPEncryptCb);
if(i != 0)
{
LOG_EX(LOG_Error, "EvpAddCryptoTask Error: %d\n", i);
free(pData);
}
}
static void test_base64_async(void)
{
int ret = 0;
#if 1
const char* pSrc = "Wikiversity is a Wikimedia Foundation project devoted to learning resources, learning projects, \
and research for use in all levels, types, and styles of education from pre-school to university, including professional \
training and informal learning. We invite teachers, students, and researchers to join us in creating open educational \
resources and collaborative learning communities. \
This page is an index of all Wikiversity help and maintenance pages. The following articles contain guidance and \
information about Editing, Policies and guidelines, and participating in the Wikiversity community. \
Having trouble finding out what you need to know? If it is not covered by the FAQ, try asking at the Colloquium.";
#else
const char *pSrc = "http://www.164.com";
#endif
const char *pBase64 = EvpBase64EncodeNoAlign(pSrc);
const char *pDecode = EvpBase64DecodeNoAlign(pBase64);
fprintf(stdout, "Encode:\n%s\n", pBase64);
fprintf(stdout, "Decode:\n%s\n", pDecode);
#if 0
ret = EvpAddCryptoTask(CRYPTO_BASE64_ENCODE, (unsigned char*)pSrc, strlen(pSrc), NULL, NULL, EVPEncryptCb);
if(ret != 0)
{
LOG_EX(LOG_Error, "EvpAddCryptoTask Error: %d\n", ret);
}
#endif
}
static void test_md5file_async(void)
{
int ret = 0;
const char* pFile = "/root/time.txt";
ret = EvpAddCryptoTask(CRYPTO_MD5_FILE, (unsigned char*)pFile, strlen(pFile), NULL, NULL, EVPEncryptCb);
if(ret != 0)
{
LOG_EX(LOG_Error, "EvpAddCryptoTask Error: %d\n", ret);
}
}
static void test_s2j_task(void)
{
PLAYER_TO_CTRL plyCtl;
PPLAYER_TO_CTRL pPlyCtl = NULL;
int err;
const char* pJson = NULL;
strcpy(plyCtl.musicUuid, "http://www.164.com");
plyCtl.plySt = 1;
plyCtl.curPos = 12133;
plyCtl.duration = 321000;
pJson = Struct2Json(&plyCtl, JSON_ENGINE_P2C, TRUE, &err);
if(pJson != NULL)
{
LOG_EX(LOG_Debug, "Json:\n %s\n", pJson);
pPlyCtl = (PPLAYER_TO_CTRL)Json2Struct(pJson, JSON_ENGINE_P2C, TRUE, &err);
if(pPlyCtl != NULL)
{
LOG_EX(LOG_Debug, "Struct:\nmusicUuid: %s\nplySt: %d\ncurPos: %d\nduration: %d\n",
pPlyCtl->musicUuid, pPlyCtl->plySt, pPlyCtl->curPos, pPlyCtl->duration);
free(pPlyCtl);
}
else
{
LOG_EX(LOG_Debug, "Json2Struct Test Error\n");
}
free((void*)pJson);
}
else
{
LOG_EX(LOG_Debug, "test error\n");
}
}
extern const char* __ota_Notify_REQ2Json(void *pData);
extern void* __json2OTA_Notify_REQ(const char *pJsonS);
static void __uvThreadTestOTA(void *pParam)
{
int err = 0, i = 0;
int ret;
const char *pMD5 = NULL;
char* strMenu[] = {
"Usage:\n",
"OTA Cmd download : download\n",
"OTA Cmd local : local\n",
"OTA Cmd exec : exec\n",
"Batch Test : batch\n",
"Set Config : ready\n",
"Exit : quit\n",
};
while(TRUE)
{
char *pInput = NULL;
char *pSub = NULL;
for(i = 0; i < sizeof(strMenu) / sizeof(strMenu[0]); i++)
{
fprintf(stdout, "%s", strMenu[i]);
}
pInput = readline("Please Choise:");
if(pInput == NULL)
{
continue;
}
pSub = strtok(pInput, " ");
i = 0;
while(pSub != NULL)
{
OTA_DATA_INFO otaInfo;
POTA_DATA_INFO pInfo = NULL;
memset(&otaInfo, 0, sizeof(OTA_DATA_INFO));
otaInfo.version = 1;
if(strcmp(pSub, "download") == 0)
{
otaInfo.otaCmd = OTA_CMD_DOWNLOAD;
otaInfo.otaMode = OTA_MODE_NORMAL;
otaInfo.otaFileInfo.size = 21484772;
strcpy(otaInfo.otaFileInfo.url, "http://10.241.0.70/tina/tina_r16_ota.tar.gz");
strcpy(otaInfo.otaFileInfo.md5, "2d58366a0846f6345730e28b021816d0");
ret = DBusJsonSendToCommand(NULL,
g_pModInfoTable[MODULE_OTA].modAliase,
CMD_OTA_NOTIFY,
JSON_ENGINE_OTA_REQ,
&otaInfo, TRUE);
LOG_EX(LOG_Debug, "Send OTA Command %s: %d\n", pSub, ret);
}
else if(strcmp(pSub, "local") == 0)
{
otaInfo.otaCmd = OTA_CMD_USED_LOCAL_IMAGE;
otaInfo.otaMode = OTA_MODE_FORCE_NOW;
ret = DBusJsonSendToCommand(NULL,
g_pModInfoTable[MODULE_OTA].modAliase,
CMD_OTA_NOTIFY,
JSON_ENGINE_OTA_REQ,
&otaInfo, TRUE);
LOG_EX(LOG_Debug, "Send OTA Command %s: %d\n", pSub, ret);
}
else if(strcmp(pSub, "exec") == 0)
{
otaInfo.otaCmd = OTA_CMD_EXEC;
otaInfo.otaMode = OTA_MODE_FORCE_NOW;
ret = DBusJsonSendToCommand(NULL,
g_pModInfoTable[MODULE_OTA].modAliase,
CMD_OTA_NOTIFY,
JSON_ENGINE_OTA_REQ,
&otaInfo, TRUE);
LOG_EX(LOG_Debug, "Send OTA Command %s: %d\n", pSub, ret);
}
else if(strcmp(pSub, "batch") == 0)
{
#if 0
int err;
POTA_DATA_INFO pInfo = NULL;
const char *pJson = NULL;
#endif
#if 0
pJson = Struct2Json(&otaInfo, JSON_ENGINE_OTA_REQ, TRUE, &err);
fprintf(stdout, "Json(%p->%d): \n%s\n", &otaInfo, err, pJson);
pInfo = (POTA_DATA_INFO)Json2Struct(pJson, JSON_ENGINE_OTA_REQ, TRUE, &err);
if(pInfo)
{
fprintf(stdout, "JsonInfo: \n%s\n", __ota_Notify_REQ2Json(pInfo));
}
#else
pMD5 = EvpMD5HashBufV2((const unsigned char *)&otaInfo, sizeof(OTA_DATA_INFO));
err = 0;
for(i = 0; i < 1000000; i++)
{
POTA_DATA_INFO pOInfo = (POTA_DATA_INFO)malloc(sizeof(OTA_DATA_INFO));
memcpy(pOInfo, &otaInfo, sizeof(OTA_DATA_INFO));
ret = DBusJsonSendToCommand(NULL,
g_pModInfoTable[MODULE_OTA].modAliase,
CMD_OTA_NOTIFY,
JSON_ENGINE_OTA_REQ,
pOInfo, TRUE);
free(pOInfo);
if(ret != 0)
{
err++;
break;
//fprintf(stderr, "ret = %d\n", ret);
}
//fprintf(stdout, "send [%d]: %d\n", i, err);
//LOG_EX(LOG_Debug, "Send OTA Command: %d\n", ret);
//usleep(1000);
}
fprintf(stdout, "%s\n", pMD5);
free((void*)pMD5);
//fprintf(stdout, "send [%d]: %d\n", i, err);
#endif
}
else if(strcmp(pSub, "ready") == 0)
{
ret = DBusSendToCommand(NULL,
g_pModInfoTable[MODULE_OTA].modAliase,
CMD_SYSTEM_STANDBY, "{\"status\" : 0}");
LOG_EX(LOG_Debug, "Send Standby Command: %d\n", ret);
}
else if(strcmp(pSub, "quit") == 0)
{
return;
}
pSub = strtok(NULL, " ");
}
free(pInput);
usleep(1000);
}
}
static void __uvThreadTimer(void *pParams)
{
while(TRUE)
{
uv_barrier_init(&g_tmSync, 2);
g_Delay += 1000;
uv_timer_stop(&g_tmTest);
LOG_EX(LOG_Info, "Re Start Timer %u...\n", g_Delay);
uv_timer_start(&g_tmTest, uvSndLessCb, g_Delay, 0);
uv_barrier_wait(&g_tmSync);
uv_barrier_destroy(&g_tmSync);
sleep(1);
}
}
static void __uvThreadTestConfigure(void *pParams)
{
int i = 0;
int ret;
char* g_Menu[] = {
"Usage:\n",
"Get Config : get <keyName>\n",
"Set Config : set <keyName> <keyType> <value> <savetoDb>\n",
"Change Config : change <keyName> <value> <savetoDb>\n",
"Exit: quit\n",
};
while(TRUE)
{
char *pInput = NULL;
char *pSub = NULL;
for(i = 0; i < sizeof(g_Menu) / sizeof(g_Menu[0]); i++)
{
fprintf(stdout, "%s", g_Menu[i]);
}
pInput = readline("Please Choise:");
if(pInput == NULL)
{
continue;
}
pSub = strtok(pInput, " ");
i = 0;
while(pSub != NULL)
{
if(strcmp(pSub, "get") == 0)
{
char* pKeyName = strtok(NULL, " ");
if(pKeyName != NULL && strlen(pKeyName) > 0)
{
CFG_ITEM* pCfg;
ret = CfgGetKeyValue(pKeyName, &pCfg);
if(ret == 0)
{
CfgItemPrint("GetLocalCfg: ", pCfg);
}
else if(ret == -ERR_CFG_WAIT_RSP)
{
LOG_EX(LOG_Debug, "Wait for server response\n");
}
else
{
LOG_EX(LOG_Error, "Get Configure [%s] Error: %d\n", pKeyName, ret);
}
}
}
else if(strcmp(pSub, "set") == 0)
{
char* pKeyName = strtok(NULL, " ");
char *pKeyType = strtok(NULL, " ");
char* pKeyValue = strtok(NULL, " ");
char* pSaveTo = strtok(NULL, " ");
if(pKeyName && pKeyValue && pKeyType && pSaveTo
&& strlen(pKeyName) > 0 && strlen(pKeyValue) > 0 && strlen(pKeyType) > 0 && strlen(pSaveTo) > 0)
{
CFG_ITEM item;
item.pKeyName = pKeyName;
item.keyType = strtoul(pKeyType, NULL, 10);
if(item.keyType == CFG_TYPE_STRING)
{
item.pStrValue = pKeyValue;
}
else if(item.keyType == CFG_TYPE_INT)
{
item.intValue = strtol(pKeyValue, NULL, 10);
}
else if(item.keyType == CFG_TYPE_DOUBLE)
{
item.doubleValue = strtod(pKeyValue, NULL);
}
ret = CfgAddKeyValue(pKeyName, &item, strtol(pSaveTo, NULL, 10));
if(ret == 0)
{
CfgItemPrint("Add Configure: ", &item);
}
else
{
LOG_EX(LOG_Error, "Add Configure [%s] Error: %d\n", pKeyName, ret);
}
}
}
else if(strcmp(pSub, "quit") == 0)
{
return;
}
pSub = strtok(NULL, " ");
}
usleep(1000);
}
}
static void test_task_new(uv_thread_cb pCallback, void* pParams)
{
uv_thread_t uvSyncThread;
uv_thread_create(&uvSyncThread, pCallback, pParams);
}
#define WAKE_CACHE_SIZE (10)
static unsigned char g_AudioCache[WAKE_CACHE_SIZE];
static unsigned int g_wtPos = 0;
static unsigned int g_tolCache = 0;
static void __cacheCAEAudio(unsigned char* pBuf, unsigned int iSize)
{
if(iSize > WAKE_CACHE_SIZE)
{
return;
}
memmove(g_AudioCache, g_AudioCache + iSize, WAKE_CACHE_SIZE - iSize);
memcpy(g_AudioCache + WAKE_CACHE_SIZE - iSize, pBuf, iSize);
}
static void test_move_data(void)
{
}
static void __onAlarmCb(unsigned int tmId, unsigned int status, void *pUserData)
{
LOG_EX(LOG_Debug, "Time %u On......\n", tmId);
}
static int g_isExitApp = FALSE;
static void uvExitLoopCb(uv_timer_t *pParams)
{
DEBUG_CODE_LINE();
uv_stop(GetDBusDefaultLoop());
}
static void __uvLoopExit(void *pParams)
{
int ret = 0;
uv_timer_t tmExit;
uv_loop_t* pLoop = GetDBusDefaultLoop();
DBusConnection* pBus = DBusWithLibuvInit(pLoop, g_ModInfo.modAliase,
DBusOnMessage,
__dBusDeameonCb,
NULL, //KeyEventCb,
&ret);
if(pBus == NULL)
{
fprintf(stderr, "DBusWithLibuvInit Error: %d\n", ret);
return;
}
DBusBoardcastCommand(NULL, 0x11, 10, "xajhuang");
//test_task_new(uvExitLoopCb, NULL);
uv_timer_init(pLoop, &tmExit);
uv_timer_start(&tmExit, uvExitLoopCb, 3000, 3000);
DEBUG_CODE_LINE();
//RunUVLoop(pLoop);
uv_run(pLoop, UV_RUN_DEFAULT);
//uv_loop_close(pLoop);
DEBUG_CODE_LINE();
g_isExitApp = TRUE;
return;
}
static void __fs_event_handle_cb(uv_fs_event_t *pEvent, const char *pFileName, int events, int status)
{
char path[MAX_PATH];
size_t pathSize = MAX_PATH - 1;
memset(path, 0, MAX_PATH);
uv_fs_event_getpath(pEvent, path, &pathSize);
fprintf(stdout, "%s: %d, %d\n", path, events, status);
}
static void __onPrgCb(const char *pReqUrl, const char *pTaskUuid, unsigned char uPercent, void *pUserData)
{
static unsigned char preCnt = 0;
if(preCnt != uPercent)
{
preCnt = uPercent;
LOG_EX(LOG_Debug, "[%s](%s): %u%%\n", pReqUrl, pTaskUuid, uPercent);
}
if(uPercent > 50)
{
//InetCancelDownload(pTaskUuid);
}
}
static unsigned int g_DlCount = 0;
static void __onDlCb(void *pData, unsigned int size, const char *pReqUrl, const char* pDlPath, const char *pTaskUuid, int iFinished, void *pUserData)
{
if(g_DlCount > 0)
{
g_DlCount--;
}
if(iFinished == 0)
{
LOG_EX(LOG_Debug, "Request(%s): [%s] --> [%s] Response: [%u] OK\n", pTaskUuid, pReqUrl, pDlPath, size);
}
else if(iFinished == 1)
{
LOG_EX(LOG_Error, "Request(%s): [%s] --> [%s] Response: [%u] Error\n", pTaskUuid, pReqUrl, pDlPath, size);
}
else
{
LOG_EX(LOG_Error, "Download Error Code: %d\n", iFinished);
}
#if 1
if(iFinished != 0)
{
const char* pId = InetHttpDlFileAsync(pReqUrl,
pDlPath,
__onDlCb,
NULL,//__onPrgCb,
NULL);
LOG_EX(LOG_Debug, "Download ID: %s\n", pId);
}
#endif
}
static void __uvTestSkin(void *pParams)
{
int tolItems = sizeof(g_SkinDefaultResTable) / sizeof(g_SkinDefaultResTable[0]);
#if 0
char *pUpg = "[ \
{ \
\"createTime\": 1510570174000, \
\"enable\": 1, \
\"id\": 3, \
\"md5\": \"af065860c3667ca2508c283d660990f7\", \
\"osType\": 0, \
\"remark\": \"音效1文件\", \
\"resourceName\": \"v111\", \
\"resourceType\": 1, \
\"resourceVersion\": \"v0.3.1\", \
\"size\": 164460, \
\"updateTime\": 1510570227000, \
\"url\": \"http://vbox-resource.nos.netease.com/d627159f-bccd-4364-bccc-f196c2b83ffd.mp3\", \
\"versionId\": 10, \
\"versionName\": \"0.0.9\", \
\"versionOsType\": \"0\" \
} ]";
#endif
#if 0
static int i = 0;
while(i++ < 100)
{
char *pKeyName = (char*)(g_SkinDefaultResTable[random() % tolItems].pKeyName);
char *pResPath = GetSkinsResource(pKeyName, NULL, NULL, NULL);
LOG_EX(LOG_Debug, "[%s] = {%s}\n", pKeyName, pResPath);
free(pResPath);
sleep(3);
}
#else
for(int i = 0; i < tolItems; i++)
{
int tmUsed = 0;
struct timeval tmStart, tmEnd;
char *pKeyName = (char*)(g_SkinDefaultResTable[i].pKeyName);
char *pResPath = NULL;
gettimeofday(&tmStart, NULL);
pResPath = GetSkinsResource(pKeyName, NULL, NULL, NULL);
gettimeofday(&tmEnd, NULL);
tmUsed = (tmEnd.tv_sec * 1000000 + tmEnd.tv_usec) - (tmStart.tv_sec * 1000000 + tmStart.tv_usec);
LOG_EX(LOG_Debug, "(%d):[%s] = {%s}\n", tmUsed, pKeyName, pResPath);
free(pResPath);
}
#if 0
fprintf(stdout, "-----------------------\n");
for(int i = 0; i < tolItems; i++)
{
int tmUsed = 0;
struct timeval tmStart, tmEnd;
char *pKeyName = (char*)(g_SkinDefaultResTable[i].pKeyName);
char *pResPath = NULL;
gettimeofday(&tmStart, NULL);
pResPath = GetSkinsResource(pKeyName, NULL, NULL, NULL);
gettimeofday(&tmEnd, NULL);
tmUsed = (tmEnd.tv_sec * 1000000 + tmEnd.tv_usec) - (tmStart.tv_sec * 1000000 + tmStart.tv_usec);
LOG_EX(LOG_Debug, "(%d):[%s] = {%s}\n", tmUsed, pKeyName, pResPath);
free(pResPath);
}
#endif
#endif
#if 0
SkinUpgrade(pUpg);
sleep(5);
GetSkinsResource("v111", NULL, NULL, NULL);
#endif
}
static LOG_LEVEL g_logLevelInfo[] = {
LOG_Fatal, LOG_Error, LOG_Warn, LOG_Debug, LOG_Info,
LOG_Test, LOG_Call, LOG_Devp, LOG_Step, LOG_Unknown, LOG_All, LOG_Close
};
static void __uvLogTestProc(void *pParams)
{
while(TRUE)
{
//SysPointMark("-----------------------------------------------------\n");
for(int i = 0; i < sizeof(g_logLevelInfo) / sizeof(g_logLevelInfo[0]); i++)
{
UT_string* pString = NULL;
utstring_new(pString);
utstring_printf(pString, "This is LogLevel %s\n", LogLeveToString(g_logLevelInfo[i]));
//SysPointMark(utstring_body(pString));
LOG_EX(g_logLevelInfo[i], "This is LogLevel %s\n", LogLeveToString(g_logLevelInfo[i]));
utstring_free(pString);
}
sleep(1);
}
}
static void __uvLogCtrlProc(void *pParams)
{
int i = 0;
int ret;
const char* g_Menu[] = {
"Usage: enable/disable <modName> <operation> [params1] [params2]\n"
" help\n",
" quit\n",
};
const char* pOptMenu[] = {
"\n operation:\n"
" |--------------------------------------------------------------------------|\n",
" | command | operation | params1 | params2 |\n",
" |--------------------------------------------------------------------------|\n",
" | enable | | | |\n",
" |----------| 0: Set log level | Log level | Unused |\n",
" | disable | | | |\n",
" |----------|---------------------|-----------------------|-----------------|\n",
" | enable | | | |\n",
" |----------| 1: Print to file | Unused | Unused |\n",
" | disable | | | |\n",
" |----------|---------------------|-----------------------|-----------------|\n",
" | enable | | | |\n",
" |----------| 2: Backup to email | Unused | Unused |\n",
" | disable | | | |\n",
" |----------|---------------------|-----------------------|-----------------|\n",
" | enable | | Log server ip address | Log server port |\n",
" |----------| 3: Send to network |-----------------------|-----------------|\n",
" | disable | | Unused | Unused |\n",
" |--------------------------------------------------------------------------|\n",
};
while(TRUE)
{
char *pInput = NULL;
char *pCmd = NULL;
for(i = 0; i < sizeof(g_Menu) / sizeof(g_Menu[0]); i++)
{
fprintf(stdout, "%s", g_Menu[i]);
}
pInput = readline("Enter Command:");
if(pInput == NULL)
{
continue;
}
#if 1
pCmd = strtok(pInput, " ");
i = 0;
while(pCmd != NULL)
{
if(strcmp(pCmd, "help") == 0)
{
for(i = 0; i < sizeof(g_pModInfoTable) / sizeof(g_pModInfoTable[0]); i++)
{
if(i == 0)
{
fprintf(stdout, " modName : %-2d --> %s\n",
i, ModuleNameToString(g_pModInfoTable[i].modName));
}
else
{
fprintf(stdout, "%15s%-2d --> %s\n", "",
i, ModuleNameToString(g_pModInfoTable[i].modName));
}
}
for(i = 0; i < sizeof(g_logLevelInfo) / sizeof(g_logLevelInfo[0]); i++)
{
if(i == 0)
{
fprintf(stdout, "\n Log Level: %-2d --> %s\n", i, LogLeveToString(g_logLevelInfo[i]));
}
else
{
fprintf(stdout, "%15s%-2d --> %s\n", "", i, LogLeveToString(g_logLevelInfo[i]));
}
}
for(i = 0; i < sizeof(pOptMenu) / sizeof(pOptMenu[0]); i++)
{
fprintf(stdout, "%s", pOptMenu[i]);
}
}
else if(strcmp(pCmd, "enable") == 0
|| strcmp(pCmd, "disable") == 0)
{
LOG_CFG_PROTOCOL logItem;
int iCmd, iMod;
char *pParams1 = NULL, *pParams2 = NULL;
char* pMod = strtok(NULL, " ");
char* pOperat = strtok(NULL, " ");
if(pMod == NULL || strlen(pMod) == 0)
{
LOG_EX(LOG_Error, "Input <modName> error, see help\n");
break;
}
if(pOperat == NULL || strlen(pOperat) == 0)
{
LOG_EX(LOG_Error, "Input <operation> error, see help\n");
break;
}
iMod = strtol(pMod, NULL, 10);
if(iMod < 0 || iMod >= MODULE_MAX)
{
LOG_EX(LOG_Error, "Input <modName> error: %s(%d)\n", pMod, iMod);
break;
}
iCmd = strtol(pOperat, NULL, 10);
memset(&logItem, 0, sizeof(LOG_CFG_PROTOCOL));
switch(iCmd)
{
case 0:
pParams1 = strtok(NULL, " ");
if(pParams1 && strlen(pParams1) > 0)
{
int logLevel = strtol(pParams1, NULL, 10);
if(logLevel >= 0 && logLevel < sizeof(g_logLevelInfo) / sizeof(g_logLevelInfo[0]))
{
fprintf(stdout, "%s %d 0x%08X\n", pCmd, iCmd, g_logLevelInfo[logLevel]);
logItem.cfgCmd = CMD_LOG_LEVEL;
logItem.iParams2 = (strcmp(pCmd, "disable") == 0) ? FALSE : TRUE;
logItem.iParams1 = g_logLevelInfo[logLevel];
DBusJsonSendToCommand(NULL,
g_pModInfoTable[iMod].modAliase,
CMD_LOG_CONFIG,
JSON_ENGINE_LOG_CFG_CMD,
&logItem, TRUE);
}
else
{
LOG_EX(LOG_Error, "Input <pParams1> error, see help\n");
}
}
else
{
LOG_EX(LOG_Error, "Input <pParams1> error, see help\n");
}
break;
case 1:
logItem.cfgCmd = CMD_LOG_FILE;
logItem.iParams1 = (strcmp(pCmd, "disable") == 0) ? FALSE : TRUE;
DBusJsonSendToCommand(NULL,
g_pModInfoTable[iMod].modAliase,
CMD_LOG_CONFIG,
JSON_ENGINE_LOG_CFG_CMD,
&logItem, TRUE);
break;
case 2:
logItem.cfgCmd = CMD_LOG_MAIL;
logItem.iParams1 = (strcmp(pCmd, "disable") == 0) ? FALSE : TRUE;
DBusJsonSendToCommand(NULL,
g_pModInfoTable[iMod].modAliase,
CMD_LOG_CONFIG,
JSON_ENGINE_LOG_CFG_CMD,
&logItem, TRUE);
break;
case 3:
pParams1 = strtok(NULL, " ");
logItem.cfgCmd = CMD_LOG_NETWORK;
if(pParams1 == NULL || strlen(pParams1) == 0)
{
logItem.iParams1 = 0;
DBusJsonSendToCommand(NULL,
g_pModInfoTable[iMod].modAliase,
CMD_LOG_CONFIG,
JSON_ENGINE_LOG_CFG_CMD,
&logItem, TRUE);
}
else
{
pParams2 = strtok(NULL, " ");
if(pParams2 != NULL && strlen(pParams2) > 0)
{
logItem.iParams1 = inet_addr(pParams1);
logItem.iParams2 = strtol(pParams2, NULL, 10);
DBusJsonSendToCommand(NULL,
g_pModInfoTable[iMod].modAliase,
CMD_LOG_CONFIG,
JSON_ENGINE_LOG_CFG_CMD,
&logItem, TRUE);
}
else
{
LOG_EX(LOG_Error, "Input <pParams> error, pParams2 = %s\n",
SAFE_STRING_VALUE(pParams2));
}
}
break;
default:
LOG_EX(LOG_Error, "Unknown operation(0-3) %s, see help\n", pOperat);
break;
}
#if 0
char* pKeyName = strtok(NULL, " ");
char *pKeyType = strtok(NULL, " ");
char* pKeyValue = strtok(NULL, " ");
char* pSaveTo = strtok(NULL, " ");
if(pKeyName && pKeyValue && pKeyType && pSaveTo
&& strlen(pKeyName) > 0 && strlen(pKeyValue) > 0 && strlen(pKeyType) > 0 && strlen(pSaveTo) > 0)
{
CFG_ITEM item;
item.pKeyName = pKeyName;
item.keyType = strtoul(pKeyType, NULL, 10);
if(item.keyType == CFG_TYPE_STRING)
{
item.pStrValue = pKeyValue;
}
else if(item.keyType == CFG_TYPE_INT)
{
item.intValue = strtol(pKeyValue, NULL, 10);
}
else if(item.keyType == CFG_TYPE_DOUBLE)
{
item.doubleValue = strtod(pKeyValue, NULL);
}
ret = CfgAddKeyValue(pKeyName, &item, strtol(pSaveTo, NULL, 10));
if(ret == 0)
{
CfgItemPrint("Add Configure: ", &item);
}
else
{
LOG_EX(LOG_Error, "Add Configure [%s] Error: %d\n", pKeyName, ret);
}
}
#endif
}
else if(strcmp(pCmd, "quit") == 0)
{
return;
}
pCmd = strtok(NULL, " ");
}
#endif
usleep(1000);
}
}
static void __uvMsgSendTestProc(void *pParams)
{
char buf[DBUS_MSG_MAX_PAD_SIZE];
unsigned int i = 0;
memset(buf, 'a', DBUS_MSG_MAX_PAD_SIZE - 1);
buf[DBUS_MSG_MAX_PAD_SIZE - 1] = 0;
while(TRUE)
{
// memset(buf, 0, 256);
// sprintf(buf, "%u", i);
fprintf(stdout, "Send Message: %u\n", i);
DBusSendToCommand(NULL, g_pModInfoTable[MODULE_CONTROLLER].modAliase, CMD_CALL_DIAL, buf);
i++;
sleep(3);
}
}
static void __uvMsgRecvProc(void *pParams)
{
while(TRUE)
{
PDBUS_MSG_PACK pMsg = DBusGetMessage();
PLIBUV_DBUS_PARAMS pInfo = DBusLibuvGetRuntime();
do
{
if(pMsg && pInfo)
{
//static PDBUS_MSG_PACK DBusOnMessage(uv_loop_t* pLoop, DBusConnection* pConn, PDBUS_MSG_PACK pMsg)
DBusOnMessage(pInfo->pLoop, pInfo->pBus, pMsg);
DBusMsgCleanup(pMsg);
}
pMsg = DBusGetMessage();
} while(pMsg && pInfo);
usleep(100);
}
}
void test_dbus(void)
{
DBusError error;
DBusConnection* pBus = NULL;
dbus_error_init(&error);
pBus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
if (dbus_error_is_set(&error))
{
fprintf(stdout, "dbus: Could not acquire the session bus\n");
dbus_error_free(&error);
return;
}
else
{
fprintf(stdout, "Create Session OK\n");
}
}
static unsigned int g_Count1 = 0;
static void __uvThreadRun(void *pParams)
{
g_Count1++;
usleep(10);
}
static void __uvThreadTestProc(void *pParams)
{
LOG_EX(LOG_Debug, "Test Create Thread\n");
for(int i = 0; i < 1000; i++)
{
test_task_new(__uvThreadRun, NULL);
usleep(1);
}
while(TRUE)
{
LOG_EX(LOG_Debug, "Current Cnt: %u\n", g_Count1);
sleep(1);
}
}
#include "fifo.h"
static DECLARE_KFIFO(g_TestFifo, unsigned char, 128);
static void __fifoPut(void *pParams)
{
int ret = 0;
static unsigned char val = 0;
while(TRUE)
{
for(int i = 0; i < 130; i++)
{
if(kfifo_avail(&g_TestFifo) < 1)
{
ret = kfifo_out(&g_TestFifo, NULL, 1);
}
ret = kfifo_in_locked(&g_TestFifo, &val, 1);
if(ret != 1)
{
LOG_EX(LOG_Error, "Add %d ret %d\n", val, ret);
}
val++;
}
usleep(10);
return;
}
}
static void __fifoGet(void *pParams)
{
unsigned char val[128];
while(TRUE)
{
int len = kfifo_len(&g_TestFifo);
if(len > 0)
{
len = kfifo_out_locked(&g_TestFifo, val, len);
print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, val, len);
fprintf(stdout, "Peek %d\n", len);
}
usleep(1000);
}
}
static void __uvThreadTestFifo(void *pParams)
{
INIT_KFIFO(g_TestFifo);
test_task_new(__fifoPut, NULL);
sleep(3);
test_task_new(__fifoGet, NULL);
}
#if 0
static inline int round_up_pow_of_two(unsigned long x)
{
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
return x + 1;
}
#define WAKE_CACHE_DATA_SIZE1 (1920000U)
#endif
typedef struct
{
char* mcuCmd;
} BYPASS_INFO, *PBYPASS_INFO;
typedef struct
{
BYPASS_INFO reported;
} SHADOW_STATE, *PSHADOW_STATE;
typedef struct
{
char* method;
int version;
SHADOW_STATE state;
} SHADOW_UPDATE, *PSHADOW_UPDATE;
static const char* __shadow2Json(PSHADOW_UPDATE pInfo)
{
cJSON *pRoot, *pStatus, *pReports;
const char* pJsonS;
pRoot = cJSON_CreateObject();
cJSON_AddNumberToObject(pRoot, "version", pInfo->version);
cJSON_AddItemToObject(pRoot, "method", cJSON_CreateString(pInfo->method));
pStatus = cJSON_CreateObject();
pReports = cJSON_CreateObject();
cJSON_AddItemToObject(pRoot, "status", pStatus);
cJSON_AddItemToObject(pStatus, "reports", pReports);
cJSON_AddItemToObject(pReports, "mcuCmd", cJSON_CreateString(pInfo->state.reported.mcuCmd));
pJsonS = cJSON_Print(pRoot);
cJSON_Delete(pRoot);
return pJsonS;
}
static void __dlThreadRuntimeCb(void *pParams)
{
pthread_detach(pthread_self());
pthread_exit(0);
}
static void __uvThreadTest(void *pParams)
{
#ifndef PLATFORM_CPU
for(int i = 0; i < 100; i++)
{
char buf[256];
memset(buf, 0, 256);
sprintf(buf, "Send %d times\n", i);
//BL_SendMessage(buf, strlen(buf));
sleep(1);
}
#endif
#if 0
for(int i = 0; i < 100000; i++)
{
uv_thread_t uvThread;
int err = uv_thread_create(&uvThread, __dlThreadRuntimeCb, NULL);
if(err != 0)
{
LOG_EX(LOG_Error, "Create Thread Error: %d(%d)\n", err, i);
return;
}
if(i % 1000 == 0)
{
LOG_EX(LOG_Debug, "Create Thread: %d\n", i);
}
usleep(1000);
}
#endif
}
static void __dlTestThread(void* p)
{
static char* testURL[] = {
"http://vbox-resource.nos.netease.com/20180309192932533Alianwang003.mp3",
"http://vbox-resource.nos.netease.com/20180309192932594Alianwang004.mp3",
"http://vbox-resource.nos.netease.com/20180309192932882Alianwang005.mp3",
"http://vbox-resource.nos.netease.com/20180309192933094Alianwang006.mp3",
"http://vbox-resource.nos.netease.com/20180309192933355Alianwang007.mp3",
"http://vbox-resource.nos.netease.com/20180309192933571Alianwang008.mp3",
"http://vbox-resource.nos.netease.com/20180309192933805Alianwang009.mp3",
"http://vbox-resource.nos.netease.com/20180309192934929Ashiyong002.mp3",
"http://vbox-resource.nos.netease.com/20180309192935659Ashiyong003.mp3",
"http://vbox-resource.nos.netease.com/20180309192935729Ashiyong004.mp3",
"http://vbox-resource.nos.netease.com/20180309192936130Ashiyong005.mp3",
"http://vbox-resource.nos.netease.com/20180309192936192Ashiyong006.mp3",
"http://vbox-resource.nos.netease.com/20180309192936289S001.mp3",
"http://vbox-resource.nos.netease.com/20180309192936471S002.mp3",
"http://vbox-resource.nos.netease.com/20180309192937566S006.mp3",
"http://vbox-resource.nos.netease.com/20180309192937735S007.mp3",
"http://vbox-resource.nos.netease.com/20180309192937793S008.mp3",
"http://vbox-resource.nos.netease.com/20180309192938129S009.mp3",
"http://vbox-resource.nos.netease.com/20180309192938262S010.mp3",
"http://vbox-resource.nos.netease.com/20180309192938975S011.mp3",
"http://vbox-resource.nos.netease.com/20180309192933845Alianwang010.mp3",
"http://vbox-resource.nos.netease.com/20180309192933937Alianwang011.mp3",
"http://vbox-resource.nos.netease.com/20180309192934678Ashiyong001.mp3",
"http://vbox-resource.nos.netease.com/20180605170040224Alianwang012.mp3",
"http://vbox-resource.nos.netease.com/20180605170146178Alianwang014.mp3",
"http://vbox-resource.nos.netease.com/20180605170324285Alianwang013.mp3",
"http://vbox-resource.nos.netease.com/20180605165854636Alianwang002.mp3",
"http://vbox-resource.nos.netease.com/20180607095314669S004-13DB.mp3",
"http://vbox-resource.nos.netease.com/20180607095347590S0053DB.mp3",
"https://vbox-resource.nos-hz.163yun.com/20180625120349098S003+3.mp3",
};
//while(TRUE)
{
for(int i = 0; i < sizeof(testURL) / sizeof(testURL[2]); i++)
{
char buf[256];
g_DlCount++;
memset(buf, 0, 256);
sprintf(buf, "./dl_%d.mp3", i);
InetHttpDlFileAsync(testURL[i],
buf,
__onDlCb,
NULL,//__onPrgCb,
NULL);
}
while(g_DlCount)
{
usleep(100000);
}
}
}
static void uvTimerTestCb(uv_timer_t* pTimer)
{
LOG_EX(LOG_Debug, "Timer On(%d)...............\n", pTimer->data);
}
static void __uvThreadTimerV2(uv_loop_t *pLoop)
{
static uv_timer_t uvTimer;
uv_timer_init(pLoop, &uvTimer);
LOG_EX(LOG_Debug, "Timer Begin\n");
uvTimer.data = (intptr_t*)1;
uv_timer_start(&uvTimer, uvTimerTestCb, 3000, 0);
sleep(10);
LOG_EX(LOG_Debug, "Timer Stop\n");
uv_timer_stop(&uvTimer);
LOG_EX(LOG_Debug, "Timer Begin\n");
uvTimer.data = (intptr_t*)2;
uv_update_time(pLoop);
uv_timer_start(&uvTimer, uvTimerTestCb, 6000, 0);
sleep(3);
LOG_EX(LOG_Debug, "Timer Stop\n");
uv_timer_stop(&uvTimer);
LOG_EX(LOG_Debug, "Timer Begin\n");
uvTimer.data = (intptr_t*)3;
uv_update_time(pLoop);
uv_timer_start(&uvTimer, uvTimerTestCb, 12000, 0);
}
#define MAX_PAYLOAD 1024 // maximum payload size
#define NETLINK_TEST 30 //自定义的协议
void test_netlink(void)
{
struct sockaddr_nl src_addr, dest_addr;
struct nlmsghdr *nlh = NULL; //Netlink数据包头
struct msghdr msg;
int sock_fd;
int retval;
struct iovec iov;
sock_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_TEST);
if(sock_fd == -1)
{
LOG_EX(LOG_Error, "Init socket error: %s\n", strerror(errno));
return;
}
// To prepare binding
memset(&src_addr, 0, sizeof(src_addr));
src_addr.nl_family = AF_NETLINK;
src_addr.nl_pid = getpid(); //A设置源端端口号
src_addr.nl_groups = 0;
//Bind
retval = bind(sock_fd, (struct sockaddr*)&src_addr, sizeof(src_addr));
if(retval < 0)
{
LOG_EX(LOG_Error, "bind failed: %s", strerror(errno));
close(sock_fd);
return;
}
// To orepare create mssage
nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD));
if(!nlh)
{
LOG_EX(LOG_Error, "malloc nlmsghdr error!\n");
close(sock_fd);
return;
}
memset(&dest_addr, 0, sizeof(dest_addr));
dest_addr.nl_family = AF_NETLINK;
dest_addr.nl_pid = 0; //B设置目的端口号
dest_addr.nl_groups = 0;
nlh->nlmsg_len = NLMSG_SPACE(MAX_PAYLOAD);
nlh->nlmsg_pid = getpid(); //C设置源端口
nlh->nlmsg_flags = 0;
strcpy(NLMSG_DATA(nlh),"Hello you!"); //设置消息体
iov.iov_base = (void *)nlh;
iov.iov_len = NLMSG_SPACE(MAX_PAYLOAD);
//Create mssage
memset(&msg, 0, sizeof(msg));
msg.msg_name = (void *)&dest_addr;
msg.msg_namelen = sizeof(dest_addr);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
retval = sendmsg(sock_fd, &msg, 0);
if(retval == -1)
{
LOG_EX(LOG_Error, "sendmsg failed: %s", strerror(errno));
}
memset(nlh,0,NLMSG_SPACE(MAX_PAYLOAD));
while(TRUE)
{
retval = recvmsg(sock_fd, &msg, 0);
if(retval < 0)
{
printf("state<1");
}
else
{
//LOG_EX(LOG_Debug, "Received message: %s\n",(char *) NLMSG_DATA(nlh));
print_hex_dump_bytes("Msg", 0, NLMSG_DATA(nlh), retval);
}
}
close(sock_fd);
}
static void __uvThreadSysPointUpload(void *pParams)
{
sleep(10);
while(TRUE)
{
printf("++++++++++++++++++++++++++++++++++\n");
SysPointMarkUpload();
printf("----------------------------------\n");
sleep(60);
}
}
#ifndef PLATFORM_CPU
static void __uvThreadNetlinkSend(void *pParams)
{
char* pData = "0123456789abcdef";
int lastSt = MSG_IN_DISCOVERY_MODE;
for(int i = 0; i < 100; i++)
{
BL_IOT_MSG blMsg;
memset(&blMsg, 0, sizeof(BL_IOT_MSG));
strcpy(blMsg.msgTags, BL_IOT_MSG_TAGS);
memcpy(blMsg.msgData, pData, strlen(pData));
blMsg.msglen = strlen(pData);
blMsg.msgType = MSG_BYPASS_MODE;
LOG_EX(LOG_Debug, "Send Message : %d\n", i);
BL_SendBLMsg(MSG_GET_WLAN_INFO, NULL, 0);
if(i % 10 == 0)
{
BL_SendBLMsg(lastSt, NULL, 0);
if(lastSt == MSG_IN_DISCOVERY_MODE)
{
lastSt = MSG_OUT_DISCOVERY_MODE;
}
else
{
lastSt = MSG_IN_DISCOVERY_MODE;
}
}
//BL_SendMessage((unsigned char*)&blMsg, BL_IOT_MSG_LEN(blMsg.msglen));
sleep(1);
}
}
#endif
static int expectedId;
static int nlCallback(void* msg, void* arg)
{
struct ucred * p = (struct ucred *)msg;
LOG_EX(LOG_Debug, "receive message\n");
}
#if 0
void test_nl80211(void)
{
int ret;
//allocate socket
nl_sock* sk = nl_socket_alloc();
//connect to generic netlink
genl_connect(sk);
//find the nl80211 driver ID
expectedId = genl_ctrl_resolve(sk, "nl80211");
//attach a callback
nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM,
nlCallback, NULL);
//allocate a message
nl_msg* msg = nlmsg_alloc();
nl80211_commands cmd = NL80211_CMD_GET_INTERFACE;
int ifIndex = if_nametoindex("wlan0");
int flags = 0;
// setup the message
genlmsg_put(msg, 0, 0, expectedId, 0, flags, cmd, 0);
//add message attributes
NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifIndex);
//send the messge (this frees it)
ret = nl_send_auto_complete(sk, msg);
//block for message to return
nl_recvmsgs_default(sk);
}
#endif
#include <malloc.h>
int main(int argc, char **argv)
{
int i, j, ret = 0;
DBusConnection* pBus = NULL;
uv_timer_t uvSndLess, uvSndMore;
uv_loop_t* pLoop = GetDBusDefaultLoop();
int modIdx = -1;
char buf[256];
struct tm tm;
memset(&tm, 0, sizeof(struct tm));
strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
puts(buf);
#if 0
i = GetServerModeFromCC(PUBLISH_MODE, &ret);
fprintf(stdout, "Read ServerMode = %d, errno = %d\n", i, ret);
#endif
#if 0
FILE* pFile = fopen("/mnt/UDISK/time.txt", "w+");
fprintf(stdout, "WAKE_CACHE_DATA_SIZE1(%u) --> %u\n", WAKE_CACHE_DATA_SIZE1, round_up_pow_of_two(WAKE_CACHE_DATA_SIZE1));
fprintf(stdout, "127 --> %u\n", roundup_pow_of_two(127));
fprintf(stdout, "3 --> %u\n", roundup_pow_of_two(3));
fprintf(stdout, "256 --> %u\n", roundup_pow_of_two(256));
fprintf(stdout, "1024 * 2 - 1 --> %u\n", roundup_pow_of_two(1024 * 2 - 1));
#endif
#if 0
fprintf(stdout, "Wait system reboot for 10s");
ret = system("sync && ubus call system watchdog \'{\"stop\" : true}\'");
sleep(20);
fprintf(stdout, "Wait WDT 20s End\n");
#endif
#if 0
int fd = open("/dev/watchdog", O_WRONLY);
if(fd == -1)
{
perror("Open WDT");
}
sleep(20);
fprintf(stdout, "Wait WDT 20s\n");
#endif
#ifdef PLATFORM_R16
#endif
//fprintf(stdout, "uv_default_loop = %p\n", pLoop);
if(argc <= 1)
{
fprintf(stderr, "usage: ./dbus-r16.exe <0-%d>\n", MODULE_MAX - 1);
return 0;
}
modIdx = strtol(argv[1], NULL, 10);
if(modIdx >= MODULE_MAX || modIdx < 0)
{
fprintf(stderr, "Bad params of %s, max value is %d\n", argv[1], MODULE_MAX - 1);
return 0;
}
memcpy(&g_ModInfo, &g_pModInfoTable[modIdx], sizeof(MOD_INFO_TABLE));
pBus = DBusWithLibuvInit(pLoop, g_ModInfo.modAliase,
DBusOnMessage,
NULL,
NULL,
&ret);
if(pBus == NULL)
{
fprintf(stderr, "DBusWithLibuvInit Error: %d\n", ret);
exit(1);
return 0;
}
SetHBLAutoExit(TRUE);
//SysPointMarkInit(NULL, -1, -1);
//test_task_new(__uvThreadSysPointUpload, NULL);
//test_netlink();
#ifndef PLATFORM_CPU
//BL_Init(NULL);
//L_SendMessage((unsigned char*)&blMsg, sizeof(BL_IOT_MSG));
//test_netlink();
//__uvThreadTimerV2(pLoop);
//test_task_new(__uvThreadNetlinkSend, NULL);
#endif
//DumpCurServerAddr("Default");
#if 0
for(int i = 0; i < 1; i++)
{
char buf[256];
memset(buf, 0, 256);
sprintf(buf, "dl_%d.bin", i);
InetHttpDlFileAsync("http://10.240.84.163/tina_r16_ota_21.tar.gz",
//"https://vbox-resource.nos-hz.163yun.com/20180628092806976tina_r16_ota_32.tar.gz",
buf,
__onDlCb,
NULL,//__onPrgCb,
NULL);
}
#endif
//SetCurrentServerMode(DEV_MODE);
//DumpCurServerAddr("DEV_MODE");
#if 0
SetCurrentServerMode(TEST_MODE);
DumpCurServerAddr("TEST_MODE");
SetCurrentServerMode(PUBLISH_MODE);
DumpCurServerAddr("PUBLISH_MODE");
#endif
//test_task_new(__uvThreadTimerV2, pLoop);
//HttpPostLogFile("{}");
//SysPointMarkInit("123456", -1, -1);
//SysPointMarkUpload();
#if 0
for(int i = 0; i < 1000; i++)
{
void* pMalloc = malloc(1024 * 1024);
if(pMalloc == NULL)
{
LOG_EX(LOG_Error, "%d: Malloc Error\n", i);
}
else
{
LOG_EX(LOG_Debug, "%d: Malloc %p\n", i, pMalloc);
memset(pMalloc, 0, 1024 * 1024);
}
usleep(100000);
}
#endif
#if 0
g_pOnKevEvt = (uv_fs_event_t*)malloc(sizeof(uv_fs_event_t));
uv_fs_event_init(pLoop, g_pOnKevEvt);
uv_fs_event_start(g_pOnKevEvt, run_command, "./1.txt", UV_FS_EVENT_RECURSIVE);
#endif
//test_task_new(__dlTestThread, NULL);
#if 0
if(modIdx == 20)
{
IHW_EnableLogLevel(LOG_All, 1);
test_task_new(__uvLogCtrlProc, NULL);
}
else if(modIdx == 19)
{
test_task_new(__uvLogTestProc, NULL);
}
else if(modIdx == 21)
{
test_task_new(__uvMsgSendTestProc, NULL);
}
else if(modIdx == 15)
{
test_task_new(__uvThreadTestProc, NULL);
}
else if(modIdx == 16)
{
test_task_new(__uvThreadTestFifo, NULL);
}
#endif
//LOG_EX(LOG_Debug, "Chip Serial: [%s]\n", GetCpuSerial());
//LOG_EX(LOG_Debug, "Chip ID: [%s]\n", GetCpuChipId());
//LOG_BUF(LOG_Error, g_pModInfoTable, 64);
// DBusWithLibuvCfgInit(OnCfgMsgCb);
#if 0
uv_timer_init(pLoop, &uvSndLess);
uvSndLess.data = pBus;
uv_timer_start(&uvSndLess, uvSndLessCb, 1000, 3000);
#endif
//uv_timer_init(pLoop, &uvSndMore);
//uv_timer_start(&uvSndMore, uvTimeoutCb, 3000, 10000);
//EvpEncrypto();
//LOG_EX(LOG_Info, "Struct --> Json: [%s]\n", Struct2Json(NULL, 0));
//Json2Struct(NULL, 0);
//free((void*)EvpBase64Encode(pSrc));
//LOG_EX(LOG_Debug, "Base")
//free((void*)EvpMD5HashFile("/root/time.txt"));
//test_evp_aes();
//test_aes_async();
//test_base64_async();
//test_md5file_async();
//test_task_new(__uvThreadTestConfigure);
//test_task_new(__uvThreadTestOTA, NULL);
//test_task_new(__uvThreadTimer, NULL);
//uv_timer_init(GetDBusDefaultLoop(), &g_tmTest);
//LOG_EX(LOG_Info, "Start Timer............\n");
//uv_timer_start(&g_tmTest, uvSndLessCb, g_Delay, 0);
//test_task_new(__uvThreadTimer, NULL);
//test_s2j_task();
//test_base64_async();
//test_move_data();
//AlarmTimerInit(pLoop);
#if 0
for(i = REPEAT_MODE_NONE; i <= REPEAT_MODE_HOLIDAY; i++)
{
{
AlarmTimerAdd2(2017 - 1900, 11 - 1, 28,
13, 50, 30,
0,
i,
NULL, 0, 0, NULL, NULL);
AlarmTimerAdd2(2017-1900, 11-1, 28,
23, 50, 30,
0,
i,
NULL, 0, 1, NULL, NULL);
}
}
#endif
#if 0
struct tm localTime;
time_t timeStamp = time((time_t*)NULL) + 30;
localtime_r(&timeStamp, &localTime);
AlarmTimerAdd(2018-1900, 7-1, 19,
localTime.tm_hour, localTime.tm_min, localTime.tm_sec,
0,
3,
__onAlarmCb, 0, NULL, NULL);
#endif
#if 0
for(i = REPEAT_MODE_NONE; i <= REPEAT_MODE_HOLIDAY; i++)
{
struct tm localTime;
localtime_r(&timeStamp, &localTime);
AlarmTimerAdd(2017-1900, 11-1, 29,
localTime.tm_hour, localTime.tm_min, localTime.tm_sec,
0,
1,
NULL, 0, i % 2, NULL, NULL);
}
#endif
//InetSmtpSendEmail();
#if 1
#if 1
#endif
#if 1
if(modIdx == 18)
{
SkinInit();
SkinIsVerifyRes(TRUE);
#if 0
char* path = "/mnt/UDISK/skinupgrade.txt";
char* pUpgCmd = "[{\"createTime\":1517832224000,\"enable\":1,\"id\":170,"
"\"md5\":\"0c8d2d487e485cf3553d7e2818ac42d9\",\"osType\":0,"
"\"remark\":\"101\",\"resourceName\":\"v101\",\"resourceType\":1,"
"\"resourceVersion\":\"0.3.2\",\"size\":33734,\"updateTime\":1517832224000,"
"\"url\":\"http://vbox-resource.nos.netease.com/2536ded2-71a5-40ab-98dc-fe824fbbfb64.mp3\","
"\"versionId\":68,\"versionName\":\"0.3.2\",\"versionOsType\":\"0\"}]";
FILE* pFp = fopen(path, "rw");
int fileSize = 0;
GET_FILE_SIZE(path, fileSize);
fprintf(stdout, "%s size = %d\n", path, fileSize);
if(pFp && fileSize > 0)
{
char* pData = (char*)malloc(fileSize);
ret = fread(pData, fileSize, 1, pFp);
fprintf(stdout, "Read: %s\n", pData);
fclose(pFp);
SkinUpgrade(pData);
free(pData);
}
#else
//const char* GetSkinsResource(const char [in] *pKeyName, int [out] *pResType, int [out] *pVersion, const char [out] **pComeFrom)
//fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
#if 0
fprintf(stdout, "[v109] = {%s}\n", GetSkinsResource("v109", NULL, NULL, NULL));
fprintf(stdout, "[v311] = {%s}\n", GetSkinsResource("v311", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
test_task_new(__uvTestSkin, NULL);
#endif
#endif
}
#endif
#endif
#if 0
#define MAIL_SENDER ("pv1_es2@163.com")
#define SENDER_PASSWORD ("pv1Dev163")
#define MAIL_RECEIVER ("pv1_es2@163.com")
#define MAIL_SERVER ("smtps://smtp.163.com")
//#else
#define MAIL_SENDER ("pv1_es2@hotmail.com")
#define SENDER_PASSWORD ("netEase163")
#define MAIL_RECEIVER ("pv1_es2@163.com")
#define MAIL_SERVER ("smtp://smtp-mail.outlook.com")
#endif
#if 0
SMTP_MAIL_CONFIG smtpCfg;
memset(&smtpCfg, 0, sizeof(SMTP_MAIL_CONFIG));
smtpCfg.pUserName = MAIL_SENDER;
smtpCfg.pPassword = SENDER_PASSWORD;
smtpCfg.pSmtpServer = MAIL_SERVER;
const char *pFrom = MAIL_SENDER;
const char *pTo[] = {"pv1_es2@163.com", "pv1_es2@126.com", NULL};
const char *pCc[] = {"xajhuang@qq.com", "xajhuang@163.com", NULL};
const char *pTitle = "Log Message";
const char *pMessage = "Hi All: This is log backup mail.";
const char *pAttact[] = {"mail.txt", "time.txt", NULL};
InetSmtpSendEmail(pFrom, pTo, pCc, pTitle, pMessage, pAttact, &smtpCfg);
#endif
// InetHttpUploadFileSync(UPL_HTTP_URL, "./time.txt");
#if 0
if((i = GZipFileCompress("./input.txt", "./input.gz")) != 0)
{
LOG_EX(LOG_Error, "Create Gzip File Error: %d\n", i);
}
//#else
while(TRUE)
{
for(i = 0; i < 3010; i++)
{
LOG_EX(LOG_Debug, "This is log %d\n", j++);
}
sleep(1);
}
#endif
RunUVLoop(pLoop);
while(TRUE)
{
usleep(1000);
}
return (0);
}