コード例 #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;
}
コード例 #2
0
void init_nwk()
{
	NWK_SetAddr(0x0000);
	NWK_SetPanId(0x1973);
	PHY_SetChannel(0x16);
	PHY_SetTxPower(0);
	PHY_SetRxState(true);
	NWK_OpenEndpoint(1, appDataInd);
}
コード例 #3
0
ファイル: LwMesh.cpp プロジェクト: nandojve/embedded
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);
}
コード例 #4
0
ファイル: main.c プロジェクト: keeepcool/Backup
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;
}
コード例 #5
0
ファイル: Peer2Peer.c プロジェクト: justinjonas/micro_project
/*************************************************************************//**
*****************************************************************************/
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;
}
コード例 #6
0
ファイル: radio.c プロジェクト: briantate/C21_ASF_RC_Car
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);
}
コード例 #7
0
ファイル: WSNDemo.c プロジェクト: amedhiou/pinoccio-ide
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;
}
コード例 #8
0
ファイル: main.c プロジェクト: BennettRand/Dr-Wattson
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);
	}
}
コード例 #9
0
ファイル: commands.c プロジェクト: AndreyMostovov/asf
/*************************************************************************//**
*****************************************************************************/
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;
}