void execute_sensor_measurement()
{
#ifdef PLATFORM_EFM32GG_STK3700
  float internal_temp = hw_get_internal_temperature();
  lcd_write_temperature(internal_temp*10, 1);

  uint32_t vdd = hw_get_battery();


  fs_write_file(SENSOR_FILE_ID, 0, (uint8_t*)&internal_temp, sizeof(internal_temp)); // File 0x40 is configured to use D7AActP trigger an ALP action which broadcasts this file data on Access Class 0
#endif

#if (defined PLATFORM_EFM32HG_STK3400  || defined PLATFORM_EZR32LG_WSTK6200A)
  char str[30];

  float internal_temp = hw_get_internal_temperature();
  sprintf(str, "Int T: %2d.%d C", (int)internal_temp, (int)(internal_temp*10)%10);
  lcd_write_line(2,str);
  log_print_string(str);

  uint32_t rhData;
  uint32_t tData;
  getHumidityAndTemperature(&rhData, &tData);

  sprintf(str, "Ext T: %d.%d C", (tData/1000), (tData%1000)/100);
  lcd_write_line(3,str);
  log_print_string(str);

  sprintf(str, "Ext H: %d.%d", (rhData/1000), (rhData%1000)/100);
  lcd_write_line(4,str);
  log_print_string(str);

  uint32_t vdd = hw_get_battery();

  sprintf(str, "Batt %d mV", vdd);
  lcd_write_line(5,str);
  log_print_string(str);

  //TODO: put sensor values in array

  uint8_t sensor_values[8];
  uint16_t *pointer =  (uint16_t*) sensor_values;
  *pointer++ = (uint16_t) (internal_temp * 10);
  *pointer++ = (uint16_t) (tData /100);
  *pointer++ = (uint16_t) (rhData /100);
  *pointer++ = (uint16_t) (vdd /10);

  fs_write_file(SENSOR_FILE_ID, 0, (uint8_t*)&sensor_values,8);
#endif

  timer_post_task_delay(&execute_sensor_measurement, SENSOR_UPDATE);
}
static void rx_callback(hw_radio_packet_t* tx_packet)
{
	if(tx_packet->length < sizeof(packet_struct_t) - sizeof(hw_radio_packet_t))
		log_print_string("Got an invalid packet at time %d: packet was too short: %d < %d", timer_get_counter_value(), tx_packet->length, sizeof(packet_struct_t));
	else
	{
		packet_struct_t* packet = (packet_struct_t*)tx_packet;
		if(packet->radio_packet.length != sizeof(packet_struct_t) - sizeof(hw_radio_packet_t))
			log_print_string("Got an invalid packet at time %d: packet length didn't match", timer_get_counter_value());
		log_print_string("Got packet from %u to %u, seq: %u at time %u", packet->src_node, packet->dst_node, packet->counter, timer_get_counter_value());
	}
	p_free(tx_packet);
}
示例#3
0
文件: main.c 项目: iotbot/oss7
void rx_callback(Trans_Rx_Query_Result* rx_res)
{
	system_watchdog_timer_reset();

	blink_led();

	dll_foreground_frame_t* frame = (dll_foreground_frame_t*) (rx_res->nwl_rx_res->dll_rx_res->frame);
	log_print_string("Received Query from :%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x;",
					frame->address_ctl->source_id[0] >> 4, frame->address_ctl->source_id[0] & 0x0F,
					frame->address_ctl->source_id[1] >> 4, frame->address_ctl->source_id[1] & 0x0F,
					frame->address_ctl->source_id[2] >> 4, frame->address_ctl->source_id[2] & 0x0F,
					frame->address_ctl->source_id[3] >> 4, frame->address_ctl->source_id[3] & 0x0F,
					frame->address_ctl->source_id[4] >> 4, frame->address_ctl->source_id[4] & 0x0F,
					frame->address_ctl->source_id[5] >> 4, frame->address_ctl->source_id[5] & 0x0F,
					frame->address_ctl->source_id[6] >> 4, frame->address_ctl->source_id[6] & 0x0F,
					frame->address_ctl->source_id[7] >> 4, frame->address_ctl->source_id[7] & 0x0F);
	log_print_string("RSS: %d dBm", rx_res->nwl_rx_res->dll_rx_res->rssi);
	log_print_string("Netto Link: %d dBm", rx_res->nwl_rx_res->dll_rx_res->rssi  - frame->frame_header.tx_eirp);

	switch (rx_res->d7aqp_command.command_code & 0x0F)
	{
		case D7AQP_OPCODE_ANNOUNCEMENT_FILE:
		{
			D7AQP_Single_File_Return_Template* sfr_tmpl = (D7AQP_Single_File_Return_Template*) rx_res->d7aqp_command.command_data;
			log_print_string("D7AQP File Announcement received");
			log_print_string(" - file 0x%x starting from byte %d", sfr_tmpl->return_file_id, sfr_tmpl->file_offset);
			log_print_data(sfr_tmpl->file_data, sfr_tmpl->isfb_total_length - sfr_tmpl->file_offset);

			log_print_string(" isfb_total_length %d", sfr_tmpl->isfb_total_length);
		}
	}

	if (rx_res->d7aqp_command.command_extension & D7AQP_COMMAND_EXTENSION_NORESPONSE)
	{
		// Restart channel scanning
		start_channel_scan = true;
	} else {
		// send ack
		// todo: put outside interrupt
		// todo: use dialog template

		command.command_code = D7AQP_COMMAND_CODE_EXTENSION | D7AQP_COMMAND_TYPE_RESPONSE | D7AQP_OPCODE_ANNOUNCEMENT_FILE;
		command.command_extension = D7AQP_COMMAND_EXTENSION_NORESPONSE;
		command.dialog_template = NULL;
		command.command_data = NULL;

		led_on(3);
		trans_tx_query(&command, 0xFF, RECEIVE_CHANNEL, TX_EIRP);
	}

}
void bootstrap()
{
    log_print_string("Device booted at time: %d\n", timer_get_counter_value());

    hw_radio_init(p_alloc, p_free);
    hw_radio_set_rx(&rx_cfg, rx_callback, rssi_valid);


    NG(tx_buffer).radio_packet.length = sizeof(packet_struct_t) - sizeof(hw_radio_packet_t);
    NG(tx_buffer).radio_packet.tx_meta.tx_cfg.channel_id = rx_cfg.channel_id;
    NG(tx_buffer).radio_packet.tx_meta.tx_cfg.syncword_class = rx_cfg.syncword_class;
    NG(tx_buffer).radio_packet.tx_meta.tx_cfg.eirp = 0;

	NG(tx_buffer).src_node = hw_get_unique_id();
    NG(tx_buffer).dst_node = 0xFFFF;
    NG(tx_buffer).counter = 0;


    sched_register_task(&send_packet);
    timer_post_task_delay(&send_packet, TIMER_TICKS_PER_SEC + (get_rnd() %TIMER_TICKS_PER_SEC));

//    NG(status).is_rx = false;
//    NG(status).is_sleep = true;
//    NG(status).tx_busy = false;
//    NG(status).rx_busy = false;
//    sched_register_task(&poll_status);
//    sched_post_task(poll_status);

}
void send_packet()
{
	hw_radio_send_packet((hw_radio_packet_t*)(&NG(tx_buffer)), tx_callback);
	log_print_string("Sending packet with counter %u", NG(tx_buffer).counter);
	NG(tx_buffer).counter++;
	timer_post_task_delay(send_packet, TIMER_TICKS_PER_SEC + (get_rnd() %TIMER_TICKS_PER_SEC));
}
void timer1_callback()
{
	led_toggle(1);
	timer_post_task_delay(&timer1_callback, 0x0000FFFF + (uint32_t)100);
	log_print_string("Toggled led %d", 1);
	console_print("Toggle led 1\r\n");
}
示例#7
0
int main(void) {

	// Initialize the OSS-7 Stack
	system_init();

	// Currently we address the Transport Layer, this should go to an upper layer once it is working.
	trans_init();
	trans_set_tx_callback(&tx_callback);
	// The initial Tca for the CSMA-CA in
	trans_set_initial_t_ca(200);

	event.next_event = SEND_INTERVAL_MS;
	event.f = &start_tx;

	log_print_string("endpoint started");

	timer_add_event(&event);

	// Log the device id
	log_print_data(device_id, 8);

	system_watchdog_init(WDTSSEL0, 0x03);
	system_watchdog_timer_start();

	while(1)
	{
		if (add_tx_event)
		{
			add_tx_event = false;
			timer_add_event(&event);
		}

		system_lowpower_mode(3,1);
	}
}
void bootstrap()
{
	led_on(0);
	led_on(1);

	log_print_string("Device booted at time: %d\n", timer_get_counter_value());
	console_print("Device Booted\r\n");

    sched_register_task(&led_on_callback);
    sched_register_task(&led_off_callback);
    sched_register_task(&timer1_callback);

    timer_post_task_delay(&led_on_callback, TIMER_TICKS_PER_SEC);
    //timer_post_task_delay(&timer1_callback, 0x0000FFFF + (uint32_t)100);

#if PLATFORM_NUM_BUTTONS > 0
    int i= 0;
    for (i=0;i<PLATFORM_NUM_BUTTONS;i++)
	{
    	ubutton_register_callback(i, &userbutton_callback);
	}
#endif

    led_off(0);
    led_off(1);
}
void led_on_callback()
{
	led_on(0);
	timer_post_task_delay(&led_on_callback, TIMER_TICKS_PER_SEC);
	timer_post_task_delay(&led_off_callback, TIMER_TICKS_PER_SEC*0.050);
	log_print_string("Toggled on %d", 0);

	hw_watchdog_feed();

}
void led_on_callback()
{
  led_toggle(0);
  timer_post_task_delay(&led_on_callback, TIMER_TICKS_PER_SEC * 70);
  //timer_post_task_delay(&led_off_callback, TIMER_TICKS_PER_SEC*0.050);
	log_print_string("Toggled on %d", 0);
	console_print("Toggle led 0\r\n");

	hw_watchdog_feed();

}
void start_rx()
{
    log_print_string("start RX");

#ifdef HAS_LCD
    char channel_str[10] = "";
    channel_id_to_string(&rx_cfg.channel_id, channel_str, sizeof(channel_str));
    lcd_write_string(channel_str);
#endif
	hw_radio_set_rx(&rx_cfg, NULL, &rssi_valid);
}
示例#12
0
void tx_callback(Trans_Tx_Result result)
{
	if(result == TransPacketSent)
	{
		#ifdef USE_LEDS
		led_off(3);
		#endif
		log_print_string("ACK SEND");
	}
	else
	{
		#ifdef USE_LEDS
		led_toggle(2);
		#endif
		log_print_string("TX ACK CCA FAIL");
	}

	// Restart channel scanning
	start_channel_scan = true;
}
示例#13
0
void tx_callback(Trans_Tx_Result result)
{
	counter++;

	if(result == TransPacketSent)
	{
		#ifdef USE_LEDS
		led_off(3);
		#endif
		log_print_string("TX OK");
	}
	else
	{
		#ifdef USE_LEDS
		led_toggle(1);
		#endif
		log_print_string("TX CCA FAIL");
	}

	tx = 0;
}
void read_rssi()
{
    timestamped_rssi_t rssi_measurement;
    rssi_measurement.tick = timer_get_counter_value();
    rssi_measurement.rssi = hw_radio_get_rssi();
    rssi_measurements[rssi_measurements_index] = rssi_measurement;
    rssi_measurements_index++;
    if(rssi_measurements_index < 1000)
        timer_post_task_delay(&read_rssi, 1); // TODO delay
    else
        log_print_string("done");
}
示例#15
0
void start_tx()
{
	if (!tx)
	{
		// Kicks the watchdog timer
		system_watchdog_timer_reset();

		tx = 1;

		#ifdef USE_LEDS
		led_on(3);
		#endif

		log_print_string("TX...");

		trans_tx_foreground_frame((uint8_t*)&counter, sizeof(counter), 0xFF, SEND_CHANNEL, TX_EIRP);
	}
	add_tx_event = true;
}
void start_tx()
{
	if (!tx)
	{
		// Kicks the watchdog timer
		system_watchdog_timer_reset();

		tx = 1;

		#ifdef USE_LEDS
		led_on(3);
		#endif

		log_print_string("TX...");

		data[0] = counter >> 8;
		data[1] = counter & 0xFF;

		trans_tx_query(&command, 0xFF, SEND_CHANNEL, TX_EIRP);
	}
示例#17
0
int main(void) {
	// Initialize the OSS-7 Stack
	system_init();

	// Currently we address the Transport Layer for RX, this should go to an upper layer once it is working.
	trans_init();
	trans_set_query_rx_callback(&rx_callback);
	trans_set_tx_callback(&tx_callback);
	// The initial Tca for the CSMA-CA in
	trans_set_initial_t_ca(200);

	start_channel_scan = true;

	log_print_string("gateway started");

	// Log the device id
	log_print_data(device_id, 8);

	// configure blinking led event
	dim_led_event.next_event = 50;
	dim_led_event.f = &dim_led;

	system_watchdog_init(WDTSSEL0, 0x03);
	system_watchdog_timer_start();

	blink_led();

	while(1)
	{
		if (start_channel_scan)
		{
			start_rx();
		}

		// Don't know why but system reboots when LPM > 1 since ACLK is uses for UART
		system_lowpower_mode(0,1);
	}
}
void bootstrap()
{
	led_on(0);
	led_on(1);

	log_print_string("Device booted at time: %d\n", timer_get_counter_value());

    sched_register_task(&led_on_callback);
    sched_register_task(&led_off_callback);
    sched_register_task(&timer1_callback);

    timer_post_task_delay(&led_on_callback, TIMER_TICKS_PER_SEC);
    timer_post_task_delay(&timer1_callback, 0x0000FFFF + (uint32_t)100);

#if NUM_USERBUTTONS > 0
    ubutton_register_callback(0, &userbutton_callback);
    ubutton_register_callback(1, &userbutton_callback);
#endif

    led_off(0);
    led_off(1);


}
void start_rx()
{
    log_print_string("start RX");
    hw_radio_set_rx(&rx_cfg, NULL, &rssi_valid);
}
static void tx_callback(hw_radio_packet_t* tx_packet)
{
	log_print_string("Sent packet with counter %u", NG(tx_buffer).counter);
	timer_post_task_delay(send_packet, TIMER_TICKS_PER_SEC + (get_rnd() %TIMER_TICKS_PER_SEC));
}
void led_off_callback()
{
	led_off(0);
	log_print_string("Toggled off %d", 0);

}
void userbutton_callback(button_id_t button_id)
{
	log_print_string("Button PB%u pressed.", button_id);
	console_print("Button Pressed\r\n");
	led_toggle(0);
}
static void rssi_valid(int16_t rssi)
{
	log_print_string("Rssi valid at time %u", timer_get_counter_value());
}
void userbutton_callback(button_id_t button_id)
{
	log_print_string("Button PB%u pressed.", button_id);
}
示例#25
0
void rx_callback(Trans_Rx_Query_Result* rx_res)
{
	system_watchdog_timer_reset();

	blink_led();

	dll_foreground_frame_t* frame = (dll_foreground_frame_t*) (rx_res->nwl_rx_res->dll_rx_res->frame);
	log_print_string("Received Query from :%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x;",
				frame->address_ctl->source_id[0] >> 4, frame->address_ctl->source_id[0] & 0x0F,
				frame->address_ctl->source_id[1] >> 4, frame->address_ctl->source_id[1] & 0x0F,
				frame->address_ctl->source_id[2] >> 4, frame->address_ctl->source_id[2] & 0x0F,
				frame->address_ctl->source_id[3] >> 4, frame->address_ctl->source_id[3] & 0x0F,
				frame->address_ctl->source_id[4] >> 4, frame->address_ctl->source_id[4] & 0x0F,
				frame->address_ctl->source_id[5] >> 4, frame->address_ctl->source_id[5] & 0x0F,
				frame->address_ctl->source_id[6] >> 4, frame->address_ctl->source_id[6] & 0x0F,
				frame->address_ctl->source_id[7] >> 4, frame->address_ctl->source_id[7] & 0x0F);
	log_print_string("RSS: %d dBm", rx_res->nwl_rx_res->dll_rx_res->rssi);
	log_print_string("Netto Link: %d dBm", rx_res->nwl_rx_res->dll_rx_res->rssi  - frame->frame_header.tx_eirp);

	switch (rx_res->d7aqp_command.command_code & 0x0F)
	{
		case D7AQP_OPCODE_COLLECTION_FILE_FILE:
		{
			D7AQP_Single_File_Call_Template* sfr_tmpl = (D7AQP_Single_File_Call_Template*) rx_res->d7aqp_command.command_data;
			log_print_string("D7AQP File Call received");
			log_print_string(" - file 0x%x starting from byte %d", sfr_tmpl->return_file_id, sfr_tmpl->return_file_entry_offset);
			log_print_string(" - max return %d bytes", sfr_tmpl->max_returned_bytes);

			if (sfr_tmpl->return_file_id < 3) // for example fixed file system containing 3 files
			{
				if (sfr_tmpl->return_file_entry_offset < 8) // for example fixed file sizes of 8 byte
				{
					command.command_code = D7AQP_COMMAND_CODE_EXTENSION | D7AQP_COMMAND_TYPE_RESPONSE | D7AQP_OPCODE_COLLECTION_FILE_FILE;
					command.command_extension = D7AQP_COMMAND_EXTENSION_NORESPONSE;
					command.dialog_template = NULL;

					D7AQP_Single_File_Return_Template file_template;
					file_template.return_file_id = sfr_tmpl->return_file_id;
					file_template.file_offset = sfr_tmpl->return_file_entry_offset;
					file_template.isfb_total_length = sfr_tmpl->max_returned_bytes < 8 ? sfr_tmpl->max_returned_bytes : 8;
					file_template.file_data = &filesystem[sfr_tmpl->return_file_id][sfr_tmpl->return_file_entry_offset];

					command.command_data = &file_template;
				} else {
					// send error template
				}

			} else {
				// send error template
			}

			led_on(3);
					trans_tx_query(&command, 0xFF, RECEIVE_CHANNEL, TX_EIRP);
			break;
		}

		default:
			// Restart channel scanning
			start_channel_scan = true;
	}

	if (rx_res->d7aqp_command.command_extension & D7AQP_COMMAND_EXTENSION_NORESPONSE)
	{
		// Restart channel scanning
		start_channel_scan = true;
	} else {
		// send ack
		// todo: put outside interrupt
		// todo: use dialog template

		command.command_code = D7AQP_COMMAND_CODE_EXTENSION | D7AQP_COMMAND_TYPE_RESPONSE | D7AQP_OPCODE_ANNOUNCEMENT_FILE;
		command.command_extension = D7AQP_COMMAND_EXTENSION_NORESPONSE;
		command.dialog_template = NULL;
		command.command_data = NULL;

		led_on(3);
		trans_tx_query(&command, 0xFF, RECEIVE_CHANNEL, TX_EIRP);
	}

}
示例#26
0
void log_state()
{
	int s = ReadSingleReg(MARCSTATE);
	log_print_string("MARCSTATE 0x%x", s);
}
示例#27
0
void main()
{
	system_init(buffer, sizeof(buffer), buffer, sizeof(buffer));
#if RF == CC1101 || RF == CC1120
	spi_init();
#endif

	ResetRadioCore();
	int p = ReadSingleReg(PARTNUM);
	log_print_string("PARTNUM 0x%x", p);
	p = ReadSingleReg(VERSION);
	log_print_string("VERSION 0x%x", p);
	log_print_string("started");

	WriteRfSettings(&rfSettings);
//	WriteSingleReg(IOCFG2,0x0B);    //GDO2 Output Pin Configuration
//	WriteSingleReg(IOCFG0,0x0C);    //GDO0 Output Pin Configuration
//	WriteSingleReg(FIFOTHR,0x47);   //RX FIFO and TX FIFO Thresholds
//	WriteSingleReg(PKTCTRL0,0x22);  //Packet Automation Control
//	WriteSingleReg(FSCTRL1,0x08);   //Frequency Synthesizer Control
//	WriteSingleReg(FREQ2,0x10);     //Frequency Control Word, High Byte
//	WriteSingleReg(FREQ1,0xB1);     //Frequency Control Word, Middle Byte
//	WriteSingleReg(FREQ0,0x3A);     //Frequency Control Word, Low Byte
//	WriteSingleReg(MDMCFG4,0xCA);   //Modem Configuration
//	WriteSingleReg(MDMCFG3,0x83);   //Modem Configuration
//	WriteSingleReg(MDMCFG2,0xB0);   //Modem Configuration
//	WriteSingleReg(DEVIATN,0x35);   //Modem Deviation Setting
//	WriteSingleReg(MCSM0,0x18);     //Main Radio Control State Machine Configuration
//	WriteSingleReg(FOCCFG,0x16);    //Frequency Offset Compensation Configuration
//	WriteSingleReg(AGCCTRL2,0x43);  //AGC Control
//	WriteSingleReg(WORCTRL,0xFB);   //Wake On Radio Control
//	WriteSingleReg(FREND0,0x11);    //Front End TX Configuration
//	WriteSingleReg(FSCAL3,0xE9);    //Frequency Synthesizer Calibration
//	WriteSingleReg(FSCAL2,0x2A);    //Frequency Synthesizer Calibration
//	WriteSingleReg(FSCAL1,0x00);    //Frequency Synthesizer Calibration
//	WriteSingleReg(FSCAL0,0x1F);    //Frequency Synthesizer Calibration
//	WriteSingleReg(TEST2,0x81);     //Various Test Settings
//	WriteSingleReg(TEST1,0x35);     //Various Test Settings
//	WriteSingleReg(TEST0,0x09);     //Various Test Settings
//	WriteSingleReg(RSSI,0x80);      //Received Signal Strength Indication
//	WriteSingleReg(MARCSTATE,0x01); //Main Radio Control State Machine State
//	WriteSingleReg(VCO_VC_DAC,0x94);//Current Setting from PLL Calibration Module

	//phy_keep_radio_on(true);

	Strobe(RF_SIDLE);
	Strobe(RF_SFTX);

	//uint8_t spectrum_id[2] = { 4, 0 };
	//phy_translate_and_set_settings(spectrum_id, 0);

	//set_length_infinite(false);
	//WriteSingleReg(PKTLEN, 7);

	Strobe(RF_STX);

	//WriteSingleReg(PKTCTRL0, 0x22);

	//WriteSingleReg(FIFOTHR, RADIO_FIFOTHR_FIFO_THR_17_48);

	//WriteBurstReg(RF_TXFIFOWR, packet, 7);




	/*
	ResetRadioCore();
	log_state();
	Strobe(RF_SIDLE);
	WriteRfSettings(&rfSettings);
	log_print_string("wrote settings");
	log_state();
	Strobe(RF_STX);
	log_print_string("strobed TX");
	*/

	int i;
	for(i = 0; i < 50;i++)
	{
		log_state();
	}



	while(1);
}