diff --git a/ModuleRadio/Firmware/src/ZiGate/Source/Common/app_common.h b/ModuleRadio/Firmware/src/ZiGate/Source/Common/app_common.h index d9449dd5..f7a4d251 100644 --- a/ModuleRadio/Firmware/src/ZiGate/Source/Common/app_common.h +++ b/ModuleRadio/Firmware/src/ZiGate/Source/Common/app_common.h @@ -155,7 +155,8 @@ typedef enum typedef struct { enum { FACTORY_NEW = 0, - NOT_FACTORY_NEW = 0xff + NOT_FACTORY_NEW = 0xff, + PDM_UPDATE = 0x80 }eState; teNODE_STATES eNodeState; uint8 u8DeviceType; diff --git a/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/SerialLink.h b/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/SerialLink.h index 335abf4f..782ba8dc 100644 --- a/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/SerialLink.h +++ b/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/SerialLink.h @@ -359,6 +359,12 @@ typedef enum E_SL_MSG_AHI_SET_TX_POWER_RSP = 0x8806, E_SL_MSG_AHI_GET_TX_POWER = 0x0807, E_SL_MSG_AHI_GET_TX_POWER_RSP = 0x8807, + + E_SL_MSG_DUMP_PDM_RECORD = 0x0B00, + E_SL_MSG_DUMP_PDM_RECORD_RESPONSE = 0x8B00, + E_SL_MSG_RESTORE_PDM_RECORD_REQUEST = 0x0B01, + E_SL_MSG_RESTORE_PDM_RECORD_RESPONSE = 0x8B01, + E_SL_MSG_RESTORE_PDM_MODE = 0x0B02, } teSL_MsgType; typedef enum { diff --git a/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/app_Znc_cmds.c b/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/app_Znc_cmds.c index 1e985977..e71c2fae 100644 --- a/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/app_Znc_cmds.c +++ b/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/app_Znc_cmds.c @@ -260,6 +260,9 @@ PRIVATE void APP_vUpdateReportableChange( tuZCL_AttributeReportable *puAttribute #ifdef PDM_DEBUG PRIVATE void APP_CustomPDMDebug( void ); #endif +PRIVATE void dump_PDM(uint8 *pu8LinkRxBuffer, uint16 u16PacketLength); +PRIVATE void restore_PDM(uint8 *pu8LinkRxBuffer, uint16 u16PacketLength); + /****************************************************************************/ /*** Exported Variables ***/ /****************************************************************************/ @@ -439,7 +442,10 @@ PUBLIC void APP_vProcessIncomingSerialCommands ( uint8 u8RxByte ) vSL_WriteMessage ( E_SL_MSG_VERSION_LIST, sizeof ( uint32 ), ( uint8* ) &u32Version, - 0); + 0 ); + vLog_Printf ( TRACE_APP, LOG_DEBUG, "\nRaw: %d\n", sZllState.u8RawMode ); + vLog_Printf ( TRACE_APP, LOG_DEBUG, "\nChannel: %d\n", sZllState.u8MyChannel ); + vLog_Printf ( TRACE_APP, LOG_DEBUG, "\nMyAddr: %04x\n", sZllState.u16MyAddr ); return; } break; @@ -2614,9 +2620,29 @@ PUBLIC void APP_vProcessIncomingSerialCommands ( uint8 u8RxByte ) #endif - default: + case E_SL_MSG_DUMP_PDM_RECORD: + { + dump_PDM(au8LinkRxBuffer, u16PacketLength); + } + break; + + case E_SL_MSG_RESTORE_PDM_RECORD_REQUEST: + { + restore_PDM(au8LinkRxBuffer, u16PacketLength); + } + break; + + case E_SL_MSG_RESTORE_PDM_MODE: + { + sZllState.eState = PDM_UPDATE; + PDM_eSaveRecordData(PDM_ID_APP_ZLL_CMSSION, &sZllState, sizeof(sZllState)); + bResetIssued = TRUE; + ZTIMER_eStart( u8IdTimer, ZTIMER_TIME_MSEC ( 1 ) ); + } + break; + default: u8Status = E_SL_MSG_STATUS_UNHANDLED_COMMAND; - break; + break; } } //PDM Messages @@ -2648,6 +2674,110 @@ PUBLIC void APP_vProcessIncomingSerialCommands ( uint8 u8RxByte ) } +PRIVATE void dump_PDM( uint8 *pu8LinkRxBuffer, + uint16 u16PacketLength ) +{ + uint16 i; + uint16 offset=0; + uint16 found; + uint16 dataLength; + uint16 u16DataBytesRead; + uint16 hits=0; + uint16 fullsize=2; + uint16 pdm_addresses[17] = { 0x0010, 0xf000, 0xf001, 0xf002, 0xf003, 0xf004, 0xf005, 0xf006, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104, 0xf105, 0xf106, 0x0001, 0x0002, 0x0003 }; + uint8 tmp[0x800]; + uint16 addr = ZNC_RTN_U16(pu8LinkRxBuffer, 0); + + if(u16PacketLength>0 || addr == 0xffff) + { + if( PDM_bDoesDataExist(addr, &dataLength)!=0) { + PDM_eReadDataFromRecord ( addr, &tmp[8], dataLength, &u16DataBytesRead ); + //PDM address + tmp[0] = addr >> 8; + tmp[1] = addr & 0xff; + //Data size + tmp[2] = dataLength >> 8; + tmp[3] = dataLength & 0xff; + //PDM data size + tmp[4] = dataLength >> 8; + tmp[5] = dataLength & 0xff; + //PDM data offset + tmp[6]=0; + tmp[7]=0; + vLog_Printf ( TRACE_APP, LOG_INFO, "\n**Dump %04x [%04x] %04x** ", addr, dataLength, u16DataBytesRead ); + vSL_WriteMessage ( E_SL_MSG_DUMP_PDM_RECORD_RESPONSE, dataLength+8, tmp, 0 ); + } + else + { + vLog_Printf ( TRACE_APP, LOG_INFO, "\n**Not found %04x [%04x]** ", addr, dataLength ); + vSL_WriteMessage ( E_SL_MSG_DUMP_PDM_RECORD_RESPONSE, 0, pu8LinkRxBuffer, 0 ); + } + } + else + { + for (i=0; i<17; i++) + { + if( PDM_bDoesDataExist( pdm_addresses[i], &dataLength ) != 0 ) + { + PDM_eReadDataFromRecord ( pdm_addresses[i], &tmp[8], dataLength, &u16DataBytesRead ); + //PDM address + tmp[0] = pdm_addresses[i] >> 8; + tmp[1] = pdm_addresses[i] & 0xff; + //Data size + tmp[2] = dataLength >> 8; + tmp[3] = dataLength & 0xff; + //PDM data size + tmp[4] = dataLength >> 8; + tmp[5] = dataLength & 0xff; + //PDM data offset + tmp[6]=0; + tmp[7]=0; + vLog_Printf ( TRACE_APP, LOG_INFO, "\n**Dump %04x [%04x] %04x** ", pdm_addresses[i], dataLength, u16DataBytesRead ); + vSL_WriteMessage ( E_SL_MSG_DUMP_PDM_RECORD_RESPONSE, dataLength+8, tmp, 0 ); + } + } + } +} + +PRIVATE void restore_PDM(uint8 *pu8LinkRxBuffer, uint16 u16PacketLength) +{ + uint16 i; + uint16 dataLength; + uint16 u16DataBytesRead; + uint16 blockstart = 0; + uint8 tmp[0x800]; + uint16 addr = ZNC_RTN_U16 ( pu8LinkRxBuffer, blockstart + 0 );//PDM address + uint16 size = ZNC_RTN_U16 ( pu8LinkRxBuffer, blockstart + 2 );//data size + uint16 fullsize = ZNC_RTN_U16 ( pu8LinkRxBuffer, blockstart + 4 );//PDM size + uint16 offset = ZNC_RTN_U16 ( pu8LinkRxBuffer, blockstart + 6 );//data offset + + vLog_Printf ( TRUE, LOG_INFO, "\n**Restore data addr: %04x size: %04x [%04x] %04x**\n", addr, size, fullsize, offset); + + if( PDM_bDoesDataExist( addr, &dataLength ) ) + { + PDM_eReadDataFromRecord ( addr, &tmp, dataLength, &u16DataBytesRead ); + for( i=0; idataLength ) + { + dataLength=size+offset; + } + + PDM_eSaveRecordData( addr, &tmp, dataLength ); + } + else + { + PDM_eSaveRecordData( addr, &pu8LinkRxBuffer[blockstart + 8], size ); + } + + vLog_Printf ( TRUE, LOG_INFO, "\n**Restored %04x [%04x] pkt[%04x]**\n", addr, size, u16PacketLength ); + + tmp[0]=size; + + vSL_WriteMessage ( E_SL_MSG_RESTORE_PDM_RECORD_RESPONSE, 2, tmp, 0 ); +} /**************************************************************************** * * NAME: APP_eZclBasicResetToFactoryDefaults diff --git a/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/app_start.c b/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/app_start.c index f1a0f6c6..81f6feaf 100644 --- a/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/app_start.c +++ b/ModuleRadio/Firmware/src/ZiGate/Source/ZigbeeNodeControlBridge/app_start.c @@ -376,9 +376,9 @@ PUBLIC void vAppMain(void) } //bAHI_FlashInit(141, NULL); vInitialiseApp (); - //app_vFormatAndSendUpdateLists ( ); + if(sZllState.eState != PDM_UPDATE) { + app_vFormatAndSendUpdateLists ( ); - if (sZllState.eNodeState == E_RUNNING) { /* Declared within if statement. If it is declared at the top @@ -408,9 +408,17 @@ PUBLIC void vAppMain(void) ( uint8* ) &sZllState.eNodeState, 0); } + ZTIMER_eStart ( u8TickTimer, ZCL_TICK_TIME ); + DBG_vPrintf( TRACE_APPSTART, "APP: Entering APP_vMainLoop()\n"); + }else{ + vSL_WriteMessage( E_SL_MSG_NODE_FACTORY_NEW_RESTART, + 1, + ( uint8* ) &sZllState.eNodeState, + 0 ); + } APP_vMainLoop(); } @@ -558,6 +566,9 @@ PRIVATE void vInitialiseApp ( void ) vLog_Printf ( TRACE_EXC,LOG_DEBUG, "PDM: test %d\n", sEndpointTable.u8NumRecords ); #endif + if(sZllState.eState != PDM_UPDATE) { + ZPS_u32MacSetTxBuffers ( 5 ); + if ( sZllState.eNodeState == E_RUNNING ) { u8DeviceType = ( sZllState.u8DeviceType >= 2 ) ? 1 : sZllState.u8DeviceType; @@ -603,6 +614,7 @@ PRIVATE void vInitialiseApp ( void ) vAppInitOTA(); #endif } + } } @@ -623,9 +635,12 @@ PUBLIC void APP_vMainLoop(void) while (TRUE) { + if(sZllState.eState != PDM_UPDATE) { zps_taskZPS ( ); bdb_taskBDB ( ); + APP_vHandleAppEvents ( ); + } APP_vProcessRxData ( ); ZTIMER_vTask ( );