Fota demo

``` #include "amaziot.h" #define USER_TASK_STACK_SIZE (2048*2) #define USER_TASK_PRIORITY (COS_USER_TASKS_PRIORITY_BASE) #define USER_TASK_STACK_SIZE2 (2048*2) #define USER_TASK_PRIORITY2 (COS_USER_TASKS_PRIORITY_BASE+1) static uint8_t Send_UpdateData_Flag=0; void UserTask(void *p_arg); void Send_UpdateData_Timer(void); lwm2monenet_conf fota_conf; void EventTask(void *p_arg2); extern UINT8 g_DemoMbx; /* add user task here */ VOID UserCreateTask(void) { COS_CreateTask(UserTask, NULL, NULL, USER_TASK_STACK_SIZE, USER_TASK_PRIORITY, COS_CREATE_DEFAULT, 0, "UserTask"); g_DemoMbx = sxr_NewMailBox(); COS_CreateTask(EventTask, NULL, NULL, USER_TASK_STACK_SIZE2, USER_TASK_PRIORITY2, COS_CREATE_DEFAULT, 0, "EventTask"); } void Send_UpdateData_Timer(void) { AT_TC(10,"DMH_UPDATE_TEST"); Send_UpdateData_Flag = 1; sxr_StartFunctionTimer(30 SECOND,Send_UpdateData_Timer,(VOID*)NULL,0x10); } void UserTask(void *p_arg) { fota_conf.refIndex = 0; fota_conf.objectid = 3303; fota_conf.instancecount = 2; sprintf(fota_conf.instancebitmap,"11"); fota_conf.attributecount = 6; fota_conf.actioncount = 1; AT_WriteUart("OneNet FotaTask Runing\r\n", strlen("OneNet FotaTask Runing\r\n")); /*wait_dev_reg_net*/ wait_dev_reg_net(); /*wait_dev_active_net*/ wait_dev_active_net(); PRO_START: wait_at_miplcreate(); wait_at_mipladdobj(fota_conf.refIndex,fota_conf.objectid,fota_conf.instancecount,fota_conf.instancebitmap,fota_conf.attributecount,fota_conf.actioncount); fota_conf.lifetime = 3600; fota_conf.timeout = 30; wait_at_miplopen(fota_conf.refIndex,fota_conf.lifetime,fota_conf.timeout); //fota_conf.lifetime = 0; //fota_conf.withObjectFlag = 0; //wait_at_miplupdate(fota_conf.refIndex,fota_conf.lifetime,fota_conf.withObjectFlag); //wait_at_miplobserversp(fota_conf.refIndex,fota_conf.msgid,fota_conf.result); //wait_at_mipldiscoverrsp(fota_conf.refIndex,fota_conf.msgid,fota_conf.result,fota_conf.length,fota_conf.valuestring ); sxr_StartFunctionTimer(10 SECOND,Send_UpdateData_Timer,(VOID*)NULL,0x10); while (1) { if(Send_UpdateData_Flag){//send data Send_UpdateData_Flag = 0; fota_conf.lifetime = 0; fota_conf.withObjectFlag = 0; wait_at_miplupdate(fota_conf.refIndex,fota_conf.lifetime,fota_conf.withObjectFlag); } sleep(1); } } void EventTask(void *p_arg2) { UINT32 evt[4]; memset(&evt, 0, sizeof(evt)); while(1) { AT_TC(10,"WinUPDATE EventTask Start\n"); //等待事件发生,任务被挂起 //if(sxr_Wait((UINT32*)&evt, g_DemoMbx)) if(sxr_Wait((UINT32*)&evt, g_DemoMbx)==0) { AT_TC(10,"WinUPDATE-Event:%d,%d\n",evt[0],evt[1]); //接收 demo_send_mailbox 事件,消息内容会存放在 evt 中 //evt[0] ==0; //evt[1] ==1; //evt[2] ==2; //evt[3] ==3; switch (evt[0]) { case 0: if(evt[2] == 40){ Send_UpdateData_Flag = 0; sxr_StopFunctionTimer(Send_UpdateData_Timer); } break; case 4: fota_conf.msgid = evt[1]; fota_conf.result = 1; wait_at_miplobserversp(fota_conf.refIndex,fota_conf.msgid,fota_conf.result); break; case 6: //AT+MIPLDISCOVERRSP=0,26693,1,34,"5700;5601;5602;5603;5604;5701;5605" fota_conf.msgid = evt[1]; fota_conf.result = 1; fota_conf.length = 34; sprintf(fota_conf.valuestring,"5700;5601;5602;5603;5604;5701;5605"); wait_at_mipldiscoverrsp(fota_conf.refIndex,fota_conf.msgid,fota_conf.result,fota_conf.length,fota_conf.valuestring ); break; default: break; } } } }