Ejemplo n.º 1
0
/*************************************************************************//**
*****************************************************************************/
static void appInit(void)
{
  appMsg.messageType          = 1;
  appMsg.nodeType             = APP_NODE_TYPE;
  appMsg.extAddr              = APP_ADDR;
  appMsg.shortAddr            = APP_ADDR;
  appMsg.softVersion          = 0x01010100;
  appMsg.channelMask          = (1L << APP_CHANNEL);
  appMsg.panId                = APP_PANID;
  appMsg.workingChannel       = APP_CHANNEL;
  appMsg.parentShortAddr      = 0;
  appMsg.lqi                  = 0;
  appMsg.rssi                 = 0;

  appMsg.sensors.type        = 1;
  appMsg.sensors.size        = sizeof(int32_t) * 3;
  appMsg.sensors.battery     = 0;
  appMsg.sensors.temperature = 0;
  appMsg.sensors.light       = 0;

  appMsg.caption.type         = 32;
  appMsg.caption.size         = APP_CAPTION_SIZE;
  memcpy(appMsg.caption.text, APP_CAPTION, APP_CAPTION_SIZE);

  NWK_SetAddr(APP_ADDR);
  NWK_SetPanId(APP_PANID);
  PHY_SetChannel(APP_CHANNEL);
#if (defined(PHY_AT86RF212B) || defined(PHY_AT86RF212))
  PHY_SetBand(APP_BAND);
  PHY_SetModulation(APP_MODULATION);
#endif
  PHY_SetRxState(true);

#ifdef NWK_ENABLE_SECURITY
  NWK_SetSecurityKey((uint8_t *)APP_SECURITY_KEY);
#endif

  NWK_OpenEndpoint(APP_ENDPOINT, appDataInd);

  appDataSendingTimer.interval = APP_SENDING_INTERVAL;
  appDataSendingTimer.mode = SYS_TIMER_INTERVAL_MODE;
  appDataSendingTimer.handler = appDataSendingTimerHandler;

#if APP_ROUTER || APP_ENDDEVICE
  appNetworkStatus = false;
  appNetworkStatusTimer.interval = 500;
  appNetworkStatusTimer.mode = SYS_TIMER_PERIODIC_MODE;
  appNetworkStatusTimer.handler = appNetworkStatusTimerHandler;
  SYS_TimerStart(&appNetworkStatusTimer);
#else
  LED_On(LED_NETWORK);
#endif

#ifdef PHY_ENABLE_RANDOM_NUMBER_GENERATOR
  srand(PHY_RandomReq());
#endif

  appState = APP_STATE_SEND;
}
Ejemplo n.º 2
0
void init_nwk()
{
	NWK_SetAddr(0x0000);
	NWK_SetPanId(0x1973);
	PHY_SetChannel(0x16);
	PHY_SetTxPower(0);
	PHY_SetRxState(true);
	NWK_OpenEndpoint(1, appDataInd);
}
Ejemplo n.º 3
0
/*************************************************************************//**
  @brief Initializes the Rx module
*****************************************************************************/
void nwkRxInit(void)
{
  for (uint8_t i = 0; i < NWK_DUPLICATE_REJECTION_TABLE_SIZE; i++)
    nwkRxDuplicateRejectionTable[i].ttl = 0;

  nwkRxDuplicateRejectionTimer.interval = NWK_RX_DUPLICATE_REJECTION_TIMER_INTERVAL;
  nwkRxDuplicateRejectionTimer.mode = SYS_TIMER_INTERVAL_MODE;
  nwkRxDuplicateRejectionTimer.handler = nwkRxDuplicateRejectionTimerHandler;

  NWK_OpenEndpoint(NWK_SERVICE_ENDPOINT_ID, nwkRxSeriveDataInd);
}
Ejemplo n.º 4
0
void LwMesh::begin(bool (*handler)(NWK_DataInd_t *ind), uint16_t netaddr, uint16_t panid, uint8_t channel)
{
	SYS_Init();

	NWK_SetAddr(netaddr);
	NWK_SetPanId(panid);
	PHY_SetChannel(channel);
	PHY_SetTxPower(0x00);		// Max Power
	PHY_SetRxState(true);

	NWK_OpenEndpoint(LwMeshDefaultEndPoint, handler);
}
Ejemplo n.º 5
0
static void appInit(void){
	
	NWK_SetAddr(APP_ADDR);
	NWK_SetPanId(APP_PANID);
	PHY_SetChannel(APP_CHANNEL);
	PHY_SetRxState(true);

	NWK_OpenEndpoint(APP_ENDPOINT, appDataInd);

	appTimer.interval = APP_FLUSH_TIMER_INTERVAL;
	appTimer.mode = SYS_TIMER_INTERVAL_MODE;
	appTimer.handler = appTimerHandler;
}
Ejemplo n.º 6
0
/*************************************************************************//**
*****************************************************************************/
void appCommandsInit(void)
{
	for (uint8_t i = 0; i < APP_NUMBER_OF_ENDPOINTS; i++) {
		appEndpointAckState[i] = true;
	}

	for (uint8_t i = 0; i < APP_NUMBER_OF_REQUEST_BUFFERS; i++) {
		appRequestBuffer[i].busy = false;
		appRequestBuffer[i].req.data = appRequestBuffer[i].buf;
	}

	appOpenEndpoint(1, true);
	NWK_OpenEndpoint(APP_RESPONDER_ENDPOINT, appResponderDataInd);
}
Ejemplo n.º 7
0
/*************************************************************************//**
*****************************************************************************/
static void appInit(void)
{
	NWK_SetAddr(APP_ADDR);
	NWK_SetPanId(APP_PANID);
	PHY_SetChannel(APP_CHANNEL);
	#ifdef PHY_AT86RF212
	PHY_SetBand(APP_BAND);
	PHY_SetModulation(APP_MODULATION);
	#endif
	PHY_SetRxState(true);
	PHY_SetTxPower(0x23);
	NWK_SetSecurityKey((uint8_t *)APP_SECURITY_KEY);
	NWK_OpenEndpoint(APP_ENDPOINT, appDataInd);

	appTimer.interval = APP_FLUSH_TIMER_INTERVAL;
	appTimer.mode = SYS_TIMER_INTERVAL_MODE;
	appTimer.handler = appTimerHandler;
}
Ejemplo n.º 8
0
/*************************************************************************//**
*****************************************************************************/
void OTA_ServerInit(void)
{
  otaServer.state = OTA_SERVER_STATE_IDLE;

  otaDataReq.srcEndpoint = APP_OTA_ENDPOINT;
  otaDataReq.dstEndpoint = APP_OTA_ENDPOINT;
  otaDataReq.data = (uint8_t *)&otaCommand;
  otaDataReq.confirm = otaDataConf;

  otaResponseTimer.interval = OTA_RESPONSE_TIMEOUT;
  otaResponseTimer.mode = SYS_TIMER_INTERVAL_MODE;
  otaResponseTimer.handler = otaResponseTimerHandler;

  otaFrameSpacingTimer.interval = OTA_FRAME_SPACING;
  otaFrameSpacingTimer.mode = SYS_TIMER_INTERVAL_MODE;
  otaFrameSpacingTimer.handler = otaFrameSpacingTimerHandler;

  NWK_OpenEndpoint(APP_OTA_ENDPOINT, otaServerDataInd);
}
Ejemplo n.º 9
0
void radioInit(void)
{
	NWK_SetAddr(APP_ADDR);
	NWK_SetPanId(APP_PANID);
	PHY_SetChannel(APP_CHANNEL);
	#ifdef PHY_AT86RF212
	PHY_SetBand(APP_BAND);
	PHY_SetModulation(APP_MODULATION);
	#endif
	PHY_SetRxState(true);

	NWK_OpenEndpoint(APP_ENDPOINT, radioDataInd);

	radioTimer.interval = APP_FLUSH_TIMER_INTERVAL;
	radioTimer.mode = SYS_TIMER_INTERVAL_MODE;
	radioTimer.handler = radioTimerHandler;

//	uint8_t value = trx_reg_read(0x1d);//VERSION_NUM_REG (0x1D) = 0x03  -- PART_NUM_REG(0x1C) = 0x07
//	printf("VERSION_NUM_REG = %u", value);
}
Ejemplo n.º 10
0
/*************************************************************************//**
*****************************************************************************/
void APP_CommandsInit(void)
{
	appCmdIdentifyDurationTimer.mode = SYS_TIMER_INTERVAL_MODE;
	appCmdIdentifyDurationTimer.handler
		= appCmdIdentifyDurationTimerHandler;

	appCmdIdentifyPeriodTimer.mode = SYS_TIMER_PERIODIC_MODE;
	appCmdIdentifyPeriodTimer.handler = appCmdIdentifyPeriodTimerHandler;

	appCmdInProgress = NULL;
	appCmdDataReq.dstAddr = 0;
	appCmdDataReq.dstEndpoint = APP_CMD_ENDPOINT;
	appCmdDataReq.srcEndpoint = APP_CMD_ENDPOINT;
	appCmdDataReq.options = NWK_OPT_ENABLE_SECURITY;
	appCmdDataReq.confirm = appCmdDataConf;

	for (uint8_t i = 0; i < APP_CMD_PENDING_TABLE_SIZE; i++) {
		appCmdPendingTable[i].addr = APP_CMD_INVALID_ADDR;
		appCmdPendingTable[i].ready = false;
	}

	NWK_OpenEndpoint(APP_CMD_ENDPOINT, appCmdDataInd);
}
Ejemplo n.º 11
0
static void appInit(void)
{
  msg.messageType          = 1;
  msg.nodeType             = APP_NODE_TYPE;
  msg.extAddr              = APP_ADDR;
  msg.shortAddr            = APP_ADDR;
  msg.softVersion          = 0x01010100;
  msg.channelMask          = (1L << APP_CHANNEL);
  msg.panId                = APP_PANID;
  msg.workingChannel       = APP_CHANNEL;
  msg.parentShortAddr      = 0;
  msg.lqi                  = 0;
  msg.rssi                 = 0;

  msg.sensors.type        = 1;
  msg.sensors.size        = sizeof(int32_t) * 3;
  msg.sensors.battery     = 0;
  msg.sensors.temperature = 0;
  msg.sensors.light       = 0;

  msg.caption.type         = 32;
  msg.caption.size         = APP_CAPTION_SIZE;
  memcpy(msg.caption.text, APP_CAPTION, APP_CAPTION_SIZE);

#if APP_COORDINATOR
  // Enable RCB_BB RS232 level converter
  #if defined(PLATFORM_RCB128RFA1)
    DDRD = (1 << 4) | (1 << 6) | (1 << 7);
    PORTD = (0 << 4) | (1 << 6) | (1 << 7);
  #endif

  #if defined(PLATFORM_RCB231)
    DDRC = (1 << 4) | (1 << 6) | (1 << 7);
    PORTC = (0 << 4) | (1 << 6) | (1 << 7);
  #endif
#endif

  ledsInit();

  NWK_SetAddr(APP_ADDR);
  NWK_SetPanId(APP_PANID);
  PHY_SetChannel(APP_CHANNEL);
  PHY_SetRxState(true);

#ifdef NWK_ENABLE_SECURITY
  NWK_SetSecurityKey((uint8_t *)APP_SECURITY_KEY);
#endif

  NWK_OpenEndpoint(APP_ENDPOINT, appDataInd);

  appDataSendingTimer.interval = APP_SENDING_INTERVAL;
  appDataSendingTimer.mode = SYS_TIMER_INTERVAL_MODE;
  appDataSendingTimer.handler = appDataSendingTimerHandler;

#if APP_ROUTER || APP_ENDDEVICE
  appNetworkStatus = false;
  appNetworkStatusTimer.interval = 500;
  appNetworkStatusTimer.mode = SYS_TIMER_PERIODIC_MODE;
  appNetworkStatusTimer.handler = appNetworkStatusTimerHandler;
  SYS_TimerStart(&appNetworkStatusTimer);
#else
  ledOn(LED_NETWORK);
#endif

#ifdef PHY_ENABLE_RANDOM_NUMBER_GENERATOR
  PHY_RandomReq();
#endif

  appState = APP_STATE_SEND;
}
Ejemplo n.º 12
0
int main(void) {
	SYS_Init(); // Init Atmel Lightweight Mesh stack

	SYS_TaskHandler(); // Call the system task handler once before we configure the radio
	NWK_SetAddr(eeprom_read_word((uint16_t*)0));
	NWK_SetPanId(0); // Default PAN ID will be 0, can be changed using the set PAN command
	PHY_SetChannel(APP_CHANNEL);
	//NWK_SetSecurityKey(APP_SECURITY_KEY);
	PHY_SetRxState(true);
	NWK_OpenEndpoint(APP_ENDPOINT, rfReceivePacket);
	PHY_SetTxPower(0);

	// Seed the pseudorandom number generator
	srand(eeprom_read_word((uint16_t*)0));

	// Read eeprom data
	eeprom_read_block(&deviceCalibration, (void*)8, sizeof(deviceCalibration));
	if (eeprom_read_byte((uint8_t*)26)) { // There is valid data in the network information struct
		eeprom_read_block(baseStationList, (void*)27, sizeof(struct baseStation));
		uint8_t ch = 17;
		while ((baseStationList[0].name[ch] == ' ') || (baseStationList[0].name[ch] == '\0') || (baseStationList[0].name[ch] == 0xFF)) {
			baseStationList[0].name[ch] = ' ';
			ch -= 1;
		}
		baseStationList[0].nameLen = ch+1;
		baseStationListLength += 1;

		for (int cnt = 0; cnt < BASESTATION_LIST_SIZE; cnt++) {
			baseStationList[cnt].name[16] = ' ';
			baseStationList[cnt].name[17] = ' ';
		}
		sendConnectionRequest(0, &deviceCalibration);
	}	

	initDataAck();
	initLCD(display_cmd_buffer, 64);
	initUI();

	TCCR0B |= (1<<CS01);
	TCCR3B |= (1<<CS32) | (1<<CS30);

	sei();
	startDataAck();

	while (1) {
		SYS_TaskHandler();

		if (receivedDataRequest) {
			handleDataRequest();
			receivedDataRequest = false;
		}

		if (receivedColdStart) {
			if (connectedBaseStation == -1)
				sendConnectionRequest(0, &deviceCalibration);
			else
				sendConnectionRequest(connectedBaseStation, &deviceCalibration);
			ui_baseStationDisconnected();
			receivedColdStart = false;
		}

		updateUI();

		if (sampleCount > 40000) {
			if (dataPacket.sampleCount != 0)
				removeSamples(&dataPacket); // If the last transmitted data has not been acked then first remove the old data.
			getData(&dataPacket); // Sample new data
			ui_updatePowerValues(&dataPacket); // Update display
			removeSamples(&dataPacket); // Get rid of these samples now
		}
		
		if (TCNT0 > 80) {
			serviceLCD();
			TCNT0 = 0;
		}

		TCCR3B &= ~((1<<CS32) | (1<<CS30));
		if (TCNT3 != 0) {
			for (uint8_t cnt = 0; cnt < DATA_REQ_BUFFER_CNT; cnt++) {
				if (dataReqBusy[cnt] && (retransmit_time[cnt] != 0)) {
					if (retransmit_time[cnt] <= TCNT3) {
						NWK_DataReq(&(nwkPacket[cnt]));
						retransmit_time[cnt] = 0;
					}
					else
						retransmit_time[cnt] -= TCNT3;
				}
			}
		}
		TCNT3 = 0;
		TCCR3B |= (1<<CS32) | (1<<CS30);
	}
}
Ejemplo n.º 13
0
/*************************************************************************//**
*****************************************************************************/
static void appOpenEndpoint(uint8_t index, bool state)
{
	NWK_OpenEndpoint(index, state ? appDataInd : NULL);
}