Exemple #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;
}
/*************************************************************************//**
*****************************************************************************/
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;
}
Exemple #3
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);
}
Exemple #4
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);

#if APP_COORDINATOR
  // Enable RCB_BB RS232 level converter
  #if defined(PLATFORM_RCB128RFA1) || defined(PLATFORM_RCB256RFR2)
    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

#if defined(PLATFORM_XPLAINED_PRO) && defined(HAL_ATMEGA256RFR2)
  // Enable chip antenna
  DDRG = (1 << 1);
  PORTG = (0 << 1);

  DDRF = (1 << 2);
  PORTF = (1 << 2);
#endif

  HAL_LedInit();

  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);

#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
  HAL_LedOn(LED_NETWORK);
#endif

#ifdef PHY_ENABLE_RANDOM_NUMBER_GENERATOR
  PHY_RandomReq();
#endif

  appState = APP_STATE_SEND;
}
Exemple #5
0
/*************************************************************************//**
*****************************************************************************/
AppStatus_t appCommandReceived(uint8_t *buf, uint16_t size)
{
	AppReceiveCommand_t *cmd = (AppReceiveCommand_t *)buf;

	switch (cmd->header.id) {
	case APP_COMMAND_DUMMY:
	{
	}
	break;

	case APP_COMMAND_RESET:
	{
		/* TODO: reset */
	}
	break;

	case APP_COMMAND_RANDOMIZE:
	{
		srand(cmd->randomize.rnd);
	}
	break;

#ifdef APP_ENABLE_EVENTS_BUFFER
	case APP_COMMAND_GET_EVENTS:
	{
		appCommandsSendEvents();
	}
	break;
#endif

	case APP_COMMAND_DATA_REQ:
	{
		return appProcessDataReq(&cmd->dataReq);
	}
	break;

	case APP_COMMAND_OPEN_ENDPOINT:
	{
		appOpenEndpoint(cmd->openEndpoint.index,
				cmd->openEndpoint.state);
	}
	break;

	case APP_COMMAND_SET_ACK_STATE:
	{
		appEndpointAckState[cmd->setAckState.index]
			= cmd->setAckState.state;
	}
	break;

	case APP_COMMAND_SET_ADDR:
	{
		NWK_SetAddr(cmd->setAddr.addr);
	}
	break;

	case APP_COMMAND_SET_PANID:
	{
		NWK_SetPanId(cmd->setPanId.panId);
	}
	break;

	case APP_COMMAND_SET_CHANNEL:
	{
		PHY_SetChannel(cmd->setChannel.channel);
    #ifdef PHY_AT86RF212
		PHY_SetBand(cmd->setChannel.band);
		PHY_SetModulation(cmd->setChannel.modulation);
    #endif
	}
	break;

	case APP_COMMAND_SET_RX_STATE:
	{
		PHY_SetRxState(cmd->setRxState.rxState);
	}
	break;

#ifdef NWK_ENABLE_SECURITY
	case APP_COMMAND_SET_SECURITY_KEY:
	{
		NWK_SetSecurityKey(cmd->setSecurityKey.securityKey);
	}
	break;
#endif

	case APP_COMMAND_SET_TX_POWER:
	{
		PHY_SetTxPower(cmd->setTxPower.txPower);
	}
	break;

#ifdef NWK_ENABLE_MULTICAST
	case APP_COMMAND_GROUP_ADD:
	{
		NWK_GroupAdd(cmd->groupAdd.group);
	}
	break;

	case APP_COMMAND_GROUP_REMOVE:
	{
		NWK_GroupRemove(cmd->groupRemove.group);
	}
	break;
#endif

#ifdef NWK_ENABLE_ROUTING
	case APP_COMMAND_ROUTE_ADD:
	{
		NWK_RouteTableEntry_t *entry;

		entry = NWK_RouteNewEntry();
		entry->fixed       = cmd->routeAdd.fixed;
		entry->multicast   = cmd->routeAdd.multicast;
		entry->dstAddr     = cmd->routeAdd.dstAddr;
		entry->nextHopAddr = cmd->routeAdd.nextHopAddr;
		entry->lqi         = cmd->routeAdd.lqi;
	}
	break;

	case APP_COMMAND_ROUTE_REMOVE:
	{
		NWK_RouteTableEntry_t *entry;

		entry = NWK_RouteFindEntry(cmd->routeRemove.dstAddr,
				cmd->routeRemove.multicast);

		if (entry) {
			if (cmd->routeRemove.removeFixed) {
				entry->fixed = 0;
			}

			NWK_RouteFreeEntry(entry);
		}
	}
	break;

	case APP_COMMAND_ROUTE_FLUSH:
	{
		NWK_RouteTableEntry_t *entry = NWK_RouteTable();

		for (uint16_t i = 0; i < NWK_ROUTE_TABLE_SIZE; i++, entry++) {
			if (NWK_ROUTE_UNKNOWN == entry->dstAddr) {
				continue;
			}

			if (cmd->routeFlush.removeFixed) {
				entry->fixed = 0;
			}

			NWK_RouteFreeEntry(entry);
		}
	}
	break;

	case APP_COMMAND_ROUTE_TABLE:
	{
		NWK_RouteTableEntry_t *entry = NWK_RouteTable();

		for (uint16_t i = 0; i < NWK_ROUTE_TABLE_SIZE; i++, entry++) {
			if (NWK_ROUTE_UNKNOWN != entry->dstAddr) {
				appCommandsSendRouteEntry(i, entry);
			}
		}
	}
	break;
#endif

#ifdef NWK_ENABLE_ADDRESS_FILTER
	case APP_COMMAND_FILTER_ADD:
	{
		if (!appFilterAdd(cmd->filterAdd.addr, cmd->filterAdd.allow,
				cmd->filterAdd.setLqi,
				cmd->filterAdd.lqi)) {
			return APP_STATUS_TABLE_IS_FULL;
		}
	}
	break;

	case APP_COMMAND_FILTER_REMOVE:
	{
		if (!appFilterRemove(cmd->filterRemove.addr)) {
			return APP_STATUS_ENTRY_NOT_FOUND;
		}
	}
	break;
#endif

	default:
		return APP_STATUS_UNKNOWN_COMMAND;
	}

	(void)size;
	return APP_STATUS_SUCESS;
}