Exemple #1
0
int main(void){
	
	uint16_t byteCount = 0;
	char buffer0[32];
	
	HAL_Init();
	SYS_TimerInit();
	PHY_Init();
	NWK_Init();
	//SYS_INIT()
	timer3Init();
	uartInit();
	sei();

	while (1){
		
		SYS_TaskHandler();
		
		byteCount = uartAvailable();
		
		if(byteCount > 0){
			HAL_UartBytesReceived(byteCount);
			sprintf(buffer0, "Bytes to send: %i\n", byteCount);
			uartPuts(buffer0);
		}
		APP_TaskHandler();
	}
}
int main(void)
{
	SYS_Init();
	HAL_UartInit(38400);
	HAL_LedInit();
	HAL_LedOff(0);

	init_nwk();
	startTimeoutTimer();
	while (1)
	{
		SYS_TaskHandler();
		HAL_UartTaskHandler();
		APP_TaskHandler();
	}
}
Exemple #3
0
static void run_lwmesh_nwk_darareq_test(const struct test_case *test)
{
	unitDataReq();
	while (1) {
		if (result) {
			break;
		}

		if (timeout) {
			test_assert_true(test, 0,
					"AVR2130_LWMesh - NWK Data request failed");
		}

		SYS_TaskHandler();
	}
}
Exemple #4
0
int main(void)
{
	
    SYS_Init();

#if APP_COORDINATOR		
    sio2host_init();
#endif	
    		
    while (1)
    {
		
        SYS_TaskHandler();
	    APP_TaskHandler();
		
    }
}
Exemple #5
0
int main(void)
{
  SYS_Init();
  HAL_UartInit(38400);
#ifdef APP_ENABLE_OTA
  OTA_ClientInit();
#endif

  while (1)
  {
    SYS_TaskHandler();
    HAL_UartTaskHandler();
#ifdef APP_ENABLE_OTA
    OTA_ClientTaskHandler();
#endif
    APP_TaskHandler();
  }
}
int main(void)
{
	irq_initialize_vectors();
	#if SAMD || SAMR21
	system_init();
	delay_init();
	#else
	sysclk_init();
	board_init();
	#endif
	SYS_Init();
	//sio2host_init();
	configure_console();
	printf("we made it");
	cpu_irq_enable();
	LED_On(LED0);
	appInit();
	while (1) {
		SYS_TaskHandler();
		//APP_TaskHandler();
	}
}
Exemple #7
0
void handleDataRequest() {
	if (dataReady()) {
		dataSequence += 1;
		dataPacket.requestSequence = datRequest.requestSequence;
		getData(&dataPacket);
	
		uint8_t ind = 0;
		while (dataReqBusy[ind]) {
			SYS_TaskHandler();
			ind = (ind < (DATA_REQ_BUFFER_CNT - 1)) ? (ind+1) : 0;
		}
		nwkPacket[ind].dstAddr = baseStationList[connectedBaseStation].addr;
		nwkPacket[ind].dstEndpoint = APP_ENDPOINT;
		nwkPacket[ind].srcEndpoint = APP_ENDPOINT;
		nwkPacket[ind].options = NWK_OPT_ACK_REQUEST;
		nwkPacket[ind].data = (uint8_t *)(&dataPacket);
		nwkPacket[ind].size = sizeof(dataPacket_t);
		nwkPacket[ind].confirm = packetTxConf;
		dataReqBusy[ind] = true;
		retransmit_cnt[ind] = 1;
		retransmit_time[ind] = TCNT3 + 5 + (rand()/(RAND_MAX/(128*retransmit_cnt[ind]))); // Retransmit the packet at a random time in the future
		ui_updatePowerValues(&dataPacket);
	}
}
Exemple #8
0
void LwMesh::task(void)
{
	SYS_TaskHandler();
}
Exemple #9
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);
	}
}