/**************************************************************************** * * NAME: clientOtaFinishing * * DESCRIPTION: * OTA download finishing routine, check the crc of total downloaded image * at the external flash * * PARAMETERS: Name RW Usage * None * * RETURNS: * void * ****************************************************************************/ void clientOtaFinishing() { #ifdef OTA_CLIENT DBG_vPrintf(TRACE_EP, "OtaFinishing: get all %d blocks \r\n", g_sDevice.otaCurBlock); g_sDevice.otaDownloading = 0; PDM_vSaveRecord(&g_sDevicePDDesc); //verify the external flash image uint8 au8Values[OTA_MAGIC_NUM_LEN]; uint32 u32TotalImage = 0; bool valid = true; //first, check external flash to detect image header APP_vOtaFlashLockRead(OTA_MAGIC_OFFSET, OTA_MAGIC_NUM_LEN, au8Values); if (memcmp(magicNum, au8Values, OTA_MAGIC_NUM_LEN) == 0) { DBG_vPrintf(TRACE_EP, "OtaFinishing: found image magic num. \r\n"); //read the image length out APP_vOtaFlashLockRead(OTA_IMAGE_LEN_OFFSET, 4, (uint8 *)(&u32TotalImage)); if (u32TotalImage != g_sDevice.otaTotalBytes) { DBG_vPrintf(TRACE_EP, "OtaFinishing: total length not match. \r\n"); valid = false; } } else { DBG_vPrintf(TRACE_EP, "OtaFinishing: not find magic num. \r\n"); valid = false; } //second, check crc uint32 crc = imageCrc(u32TotalImage); DBG_vPrintf(TRACE_EP, "OtaFinishing: verify crc: 0x%x \r\n", crc); if (crc != g_sDevice.otaCrc) { DBG_vPrintf(TRACE_EP, "OtaFinishing: crc not match \r\n"); valid = false; } if (valid) { //send upgrade request to ota server g_sDevice.otaDownloading = 2; PDM_vSaveRecord(&g_sDevicePDDesc); //OS_eActivateTask(APP_taskOTAReq); vResetATimer(APP_OTAReqTimer, APP_TIME_MS(1000)); //APP_vOtaKillInternalReboot(); } else { clientOtaRestartDownload(); } #endif }
/**************************************************************************** * * NAME: MibGroup_vSecond * * DESCRIPTION: * Timing function * ****************************************************************************/ PUBLIC void MibGroup_vSecond(void) { /* Need to save record ? */ if (psMibGroup->bSaveRecord) { /* Clear flag */ psMibGroup->bSaveRecord = FALSE; /* Make sure permament data is saved */ PDM_vSaveRecord(&psMibGroup->sDesc); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_GROUP, "\nMibGroup_vSecond()"); DBG_vPrintf(CONFIG_DBG_MIB_GROUP, "\n\tPDM_vSaveRecord(MibGroup)"); #if CONFIG_DBG_MIB_GROUP { uint8 u8Group; /* Loop through current groups */ for (u8Group = 0; u8Group < MIB_GROUP_MAX; u8Group++) { /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_GROUP, "\n\tasGroupAddr[%d] = %x:%x:%x:%x:%x:%x:%x:%x)", u8Group, psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[0], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[1], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[2], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[3], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[4], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[5], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[6], psMibGroup->sPerm.asGroupAddr[u8Group].s6_addr16[7]); } } #endif } }
/* * UART Init * - uart_device: uart device pointer, IGNORED for Mesh Bee * - uart_num: for some MCU, there's more than one uart, this is the number of uart * for Arduino-UNO(or others use 328, 32u4, 168), these is a hardware uart and software uart. * for Mesh Bee (JN5168), IGNORED as only UART1 is for user * - baud? baudrate */ void suli_uart_init(void * uart_device, int16 uart_num, uint32 baud) { //#define E_AHI_UART_RATE_4800 0 //#define E_AHI_UART_RATE_9600 1 //#define E_AHI_UART_RATE_19200 2 //#define E_AHI_UART_RATE_38400 3 //#define E_AHI_UART_RATE_76800 //76800's not a well-used baudrate, we take 57600 instead. //#define E_AHI_UART_RATE_115200 5 switch(baud) { case 4800: g_sDevice.config.baudRateUart1 = 0; break; case 9600: g_sDevice.config.baudRateUart1 = 1; break; case 19200: g_sDevice.config.baudRateUart1 = 2; break; case 38400: g_sDevice.config.baudRateUart1 = 3; break; case 57600: g_sDevice.config.baudRateUart1 = 4; break; case 115200: g_sDevice.config.baudRateUart1 = 5; break; default: g_sDevice.config.baudRateUart1 = 5; break; } PDM_vSaveRecord(&g_sDevicePDDesc); AT_setBaudRateUart1(&g_sDevice.config.baudRateUart1); }
/**************************************************************************** * * NAME: MibNodeStatus_vSecond * * DESCRIPTION: * Timing function * ****************************************************************************/ PUBLIC void MibNodeStatus_vSecond(void) { /* Need to save record ? */ if (psMibNodeStatus->bSaveRecord) { /* Clear flag */ psMibNodeStatus->bSaveRecord = FALSE; /* Make sure permament data is saved */ PDM_vSaveRecord(&psMibNodeStatus->sDesc); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NODE_STATUS, "\nMibNodeStatus_vSecond()"); DBG_vPrintf(CONFIG_DBG_MIB_NODE_STATUS, "\n\tPDM_vSaveRecord(MibNodeStatus)"); } }
/**************************************************************************** * * NAME: MibNwkSecurity_vSecond * * DESCRIPTION: * Timer function * ****************************************************************************/ PUBLIC void MibNwkSecurity_vSecond(void) { /* Need to save record ? */ if (psMibNwkSecurity->bSaveRecord) { /* Clear flag */ psMibNwkSecurity->bSaveRecord = FALSE; /* Make sure permanent data is saved */ PDM_vSaveRecord(&psMibNwkSecurity->sDesc); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_SECURITY, "\nMibNwkSecurity_vSecond()"); DBG_vPrintf(CONFIG_DBG_MIB_NWK_SECURITY, "\n\tPDM_vSaveRecord(MibNwkSecurity)"); } }
/**************************************************************************** * * NAME: MibNwkProfile_vSecond * * DESCRIPTION: * Timing function * ****************************************************************************/ PUBLIC void MibNwkProfile_vSecond(void) { /* Need to save record ? */ if (psMibNwkProfile->bSaveRecord) { /* Clear flag */ psMibNwkProfile->bSaveRecord = FALSE; /* Make sure permament data is saved */ PDM_vSaveRecord(&psMibNwkProfile->sDesc); /* Debug */ DBG_vPrintf(CONFIG_DBG_MIB_NWK_PROFILE, "\nMibNwkProfile_vSecond()"); DBG_vPrintf(CONFIG_DBG_MIB_NWK_PROFILE, "\n\tPDM_vSaveRecord(MibNwkProfile)"); /* Apply potential changes */ MibNwkProfile_vApply(); } }
/**************************************************************************** * * NAME: clientOtaRestartDownload * * DESCRIPTION: * restart OTA download when crc check failed * * PARAMETERS: Name RW Usage * None * * RETURNS: * void * ****************************************************************************/ void clientOtaRestartDownload() { if (g_sDevice.otaTotalBytes == 0) { DBG_vPrintf(TRACE_EP, "otaTotalBytes info lost, cant restart download. \r\n"); return; } // restart the downloading g_sDevice.otaCurBlock = 0; g_sDevice.otaDownloading = 1; DBG_vPrintf(TRACE_EP, "restart downloading... \r\n"); PDM_vSaveRecord(&g_sDevicePDDesc); //erase covered sectors APP_vOtaFlashLockEraseAll(); //start the ota task OS_eActivateTask(APP_taskOTAReq); }
/**************************************************************************** * * NAME: vHandleNetworkFormationEvent * * DESCRIPTION: * Handles stack events when the Controller is in its network formation state * * PARAMETERS: Name RW Usage * sStackEvent R Contains details of the stack event * * RETURNS: * Sequence number * ****************************************************************************/ PRIVATE void vHandleNetworkFormationEvent(ZPS_tsAfEvent sStackEvent, APP_tsEvent sAppEvent) { /*wait for network stack to start up as a coordinator */ if (ZPS_EVENT_NONE != sStackEvent.eType) { if (ZPS_EVENT_NWK_STARTED == sStackEvent.eType) { DBG_vPrintf(TRACE_APP, "APP: Network Started\r\n"); /* Turn off LEDs to indicate network formation complete */ APP_vLedSet(0, FALSE); APP_vLedSet(1, FALSE); APP_vLedSet(2, FALSE); APP_vLedSet(3, FALSE); /* turn on joining */ s_sDevice.bPermitJoining = TRUE; ZPS_eAplZdoPermitJoining(0xff); /* start logging now the network is up */ APP_vLogStart(); APP_vDisplaySetState(APP_E_DISPLAY_STATE_NETWORK); APP_vDisplayUpdate(); s_sDevice.eState = E_NETWORK_SCREEN; PDM_vSaveRecord(&s_sDevicePDDesc); } } else { if (APP_E_EVENT_NONE == sAppEvent.eType) { DBG_vPrintf(TRACE_APP, "APP: Unexpected event in E_NETWORK_FORMATION"); } } }
/**************************************************************************** * * NAME: setNodeState * * DESCRIPTION: * set the state of node * * PARAMETERS: Name RW Usage * state W state of node * 0:DATA_MODE * 1:AT_MODE * 2:MCU_MODE * RETURNS: * void * ****************************************************************************/ void setNodeState(uint32 state) { g_sDevice.eMode = state; PDM_vSaveRecord(&g_sDevicePDDesc); }