📄 sensor.c
字号:
// *******************************************************************
// Sensor.c
//
// 采集器的应用程序
//
// Copyright 2006 by Holley Corporation. All rights reserved.
// *******************************************************************
#include "app/sensor/common.h"
#include "Holley_ext.h"
// *******************************************************************
// Ember endpoint and interface configuration
int8u emberEndpointCount = 1;
EmberEndpointDescription PGM endpointDescription = { PROFILE_ID, 0, };
EmberEndpoint emberEndpoints[] = {
{ ENDPOINT, &endpointDescription },
};
// End Ember endpoint and interface configuration
// *******************************************************************
BOOL buttonZeroPress = FALSE; // for button push - see halButtonIsr
//int main(void);
//void emberIncomingMessageHandler( EmberIncomingMessageType, EmberApsFrame *, EmberMessageBuffer );
//void emberStackStatusHandler( EmberStatus status );
static void applicationTick(void);
void checkButtonEvents(void);
//void halButtonIsr(int8u button, int8u state);
//void emberMessageSent( int8u bindingTableIndex, int8u, EmberMessageBuffer, EmberStatus );
//void emberUnicastSent ( EmberNodeId, EmberApsFrame *, EmberMessageBuffer, EmberStatus );
//EmberStatus emberRemoteSetBindingHandler( EmberBindingTableEntry *entry );
//EmberStatus emberRemoteDeleteBindingHandler( int8u index );
//void bootloadUtilQueryResponseHandler( BOOL, int16u, int8u *, EmberEUI64, int8u, int8u, int8u, int8u );
//BOOL bootloadUtilLaunchRequestHandler( int16u, int8u *, EmberEUI64 );
// *******************************************************************
// *******************************************************************
int main(void)
{
EmberStatus status;
EmberResetType reset;
int8u ucBaud;
EmberNodeType nodeType;
halInit(); //Initialize the hal
INTERRUPTS_ON(); // allow interrupts
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialInit( APP_SERIAL, BAUD_19200, PARITY_EVEN, 1 );
#endif
#ifdef DEBUG
emberDebugInit(DEBUG_SERIAL);
#endif
reset = halGetResetInfo();
status = emberInit(reset); // emberInit must be called before other EmberNet stack functions
if ( status != EMBER_SUCCESS )
{
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialGuaranteedPrintf ( APP_SERIAL,
"\r\nERROR: emberInit 0x%x\r\n", status );
#endif
assert(FALSE);
}
else
{
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf( APP_SERIAL, "\r\nEVENT: emberInit passed\r\n" );
#endif
}
GPIO_SETL = BIT(13); //turn off Led1 tx data
GPIO_SETL = BIT(14); //turn off Led2 rx data
GPIO_SETL = BIT(15); //turn off Led3
emberClearBindingTable();
Sensor_Para_Init();
// Set the security key - specific to this application, all variants
// of this application (sink, sensor, sleepy-sensor, mobile-sensor)
// need to use the same key. This function is in app/sensor/common.c
setSecurityKey();
#ifdef USE_BOOTLOADER_LIB
// Using the same port for application serial print and passthru
// bootloading. User must be careful not to print anything to the port
// while doing passthru bootload since that can interfere with the data
// stream. Also the port's baud rate will be set to 115200 kbps in order
// to maximize bootload performance.
//bootloadUtilInit(APP_SERIAL, APP_SERIAL);
bootloadUtilInit(APP_SERIAL, DEBUG_SERIAL);
#endif // USE_BOOTLOADER_LIB
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialWriteString( APP_SERIAL, "\r\nINIT: sensor app " );
printEUI64( APP_SERIAL, (EmberEUI64*) emberGetEui64() );
emberSerialPrintf( APP_SERIAL, "\r\n" );
emberSerialWaitSend( APP_SERIAL );
#endif
// if ( ( emberGetNodeType(&nodeType) == EMBER_SUCCESS ) &&
// ( nodeType == EMBER_ROUTER ) &&
// ( emberNetworkInit() == EMBER_SUCCESS ) )
// {
// // were able to join the old network
// #ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
// emberSerialPrintf( APP_SERIAL, "SENSOR APP: joined to network\r\n" );
// emberSerialWaitSend( APP_SERIAL );
// #endif
// }
// else
{
// were not able to join the old network
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf( APP_SERIAL, "\r\nSENSOR APP: trying to join a network\r\n" );
emberSerialWaitSend(APP_SERIAL);
#endif
buttonZeroPress = TRUE; // if not joined with a network, join
checkButtonEvents();
}
Read_OD( HL_AMR_PARA_CONFIG_INDEX, 1, &ucBaud );
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf( APP_SERIAL, "\r\nSet Baud Rate %x\r\n", ucBaud );
#endif
if ( emberSerialInit( HOLLEY_SERIAL, ucBaud, PARITY_EVEN, 1 ) != EMBER_SUCCESS )
{
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf( APP_SERIAL, "\r\nSet Baud Rate %x failed.\r\n", ucBaud );
emberSerialPrintf( APP_SERIAL, "\r\nReSet Baud Rate to default value: %x\r\n", sHL_AMR_Para_Config.ucBaud_Rate );
emberSerialWaitSend(APP_SERIAL);
#endif
status = emberSerialInit( HOLLEY_SERIAL, sHL_AMR_Para_Config.ucBaud_Rate, PARITY_EVEN, 1 );
if ( status == EMBER_SUCCESS )
{
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf( APP_SERIAL, "\r\nReSet Baud Rate %x success.\r\n", sHL_AMR_Para_Config.ucBaud_Rate );
emberSerialPrintf( APP_SERIAL, "\r\nReSet HL_AMR_Para_Config parameter to default value.\r\n", sHL_AMR_Para_Config.ucBaud_Rate );
emberSerialWaitSend(APP_SERIAL);
#endif
halCommonSetToken( TOKEN_HL_AMR_PARA_CONFIG, ( int8u *)&sHL_AMR_Para_Config );
}
else
assert(FALSE);
}
while(TRUE) // event loop
{
halResetWatchdog();
emberTick();
Sensor_Store_UART_Data();
Sensor_Process_Buffered_UART_Data();
Sensor_Process_Buffered_RF_Data();
if ( emberNetworkState() == EMBER_JOINED_NETWORK )
applicationTick();
else
{
buttonZeroPress = TRUE;
checkButtonEvents();
}
#ifdef DEBUG
emberSerialBufferTick(); // Needed for debug which uses buffered serial
#endif
}
}
void emberIncomingMessageHandler ( EmberIncomingMessageType type,
EmberApsFrame *apsFrame,
EmberMessageBuffer message )
{
#ifdef USE_BOOTLOADER_LIB
// If we are in the middle of bootloading, then we want to limit the
// radio activity to minimum to avoid causing any interruptions to the
// bootloading process.
if ( IS_BOOTLOADING )
return;
#endif
// if ( type == EMBER_INCOMING_DATAGRAM || type == EMBER_INCOMING_MULTICAST )
if ( type != EMBER_INCOMING_MULTICAST_LOOPBACK )
{
if ( Store_RF_Data( message ) == FALSE )
{
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf( APP_SERIAL, "\r\nOut of aucRF_MSG_Index slot. Oldest RF frame is deleted\r\n" );
emberSerialWaitSend( APP_SERIAL );
#endif
}
}
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
switch ( apsFrame->clusterId )
{
case HL_CMD_READ_OD:
emberSerialPrintf( APP_SERIAL, "\r\nReceive Read_OD Command.\r\n" );
emberSerialWaitSend( APP_SERIAL );
break;
case HL_CMD_WRITE_OD:
emberSerialPrintf( APP_SERIAL, "\r\nReceive Write_OD Command.\r\n" );
emberSerialWaitSend( APP_SERIAL );
break;
case HL_CMD_STATEMENT:
emberSerialPrintf( APP_SERIAL, "Receive Advertise.\r\n" );
emberSerialWaitSend( APP_SERIAL );
break;
case HL_CMD_COLLECT_DATA:
emberSerialPrintf( APP_SERIAL, "\r\nReceive Collect Data Command.\r\n" );
emberSerialWaitSend( APP_SERIAL );
break;
case HL_CMD_TRANSFER_MTR:
emberSerialPrintf( APP_SERIAL, "\r\nReceive Transfer Data Command.\r\n" );
emberSerialWaitSend( APP_SERIAL );
break;
case HL_CMD_FORCE_RESET:
emberSerialPrintf( APP_SERIAL, "\r\nReceive Reset Command.\r\n" );
emberSerialPrintf( APP_SERIAL, "Node will be Reseted in 60 seconds.\r\n" );
emberSerialWaitSend( APP_SERIAL );
break;
case HL_CMD_RESET_TOKEN:
emberSerialPrintf( APP_SERIAL, "\r\nReceive Reset Token Command.\r\n" );
emberSerialWaitSend( APP_SERIAL );
break;
}
#endif // HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
}
// this is called when the stack status changes
void emberStackStatusHandler( EmberStatus status )
{
switch ( status )
{
case EMBER_NETWORK_UP:
Set_Multicast_Binding();
emberPermitJoining(0xff);
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf ( APP_SERIAL,
"\r\nEVENT: stackStatus now EMBER_NETWORK_UP\r\n" );
#endif
break;
case EMBER_NETWORK_DOWN:
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf ( APP_SERIAL,
"\r\nEVENT: stackStatus now EMBER_NETWORK_DOWN\r\n");
#endif
break;
case EMBER_JOIN_FAILED:
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf ( APP_SERIAL,
"\r\nEVENT: stackStatus now EMBER_JOIN_FAILED\r\n");
#endif
buttonZeroPress = TRUE;
checkButtonEvents();
break;
default:
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialPrintf ( APP_SERIAL, "\r\nEVENT: stackStatus now 0x%x\r\n", status);
#endif
break;
}
#ifdef HL_OUTPUT_DEBUG_INFO_VIA_SERIAL
emberSerialWaitSend(APP_SERIAL);
#endif
}
static void applicationTick(void)
{
static int16u lastBlinkTime = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -