__LINK_C void log_print_raw_phy_packet(hw_radio_packet_t* packet, bool is_tx)
{
#ifdef FRAMEWORK_LOG_BINARY
    uart_transmit_data(0xDD);
    if(is_tx) {
        uart_transmit_data(LOG_TYPE_PHY_PACKET_TX);
        uart_transmit_message(&(packet->tx_meta.timestamp), sizeof(timer_tick_t));
        uart_transmit_data(packet->tx_meta.tx_cfg.channel_id.channel_header_raw);
        uart_transmit_data(packet->tx_meta.tx_cfg.channel_id.center_freq_index);
        uart_transmit_data(packet->tx_meta.tx_cfg.syncword_class);
        uart_transmit_data(packet->tx_meta.tx_cfg.eirp);
        uart_transmit_message(packet->data, packet->length+1);
    } else {
        uart_transmit_data(LOG_TYPE_PHY_PACKET_RX);
        uart_transmit_message(&(packet->rx_meta.timestamp), sizeof(timer_tick_t));
        uart_transmit_data(packet->rx_meta.rx_cfg.channel_id.channel_header_raw);
        uart_transmit_data(packet->rx_meta.rx_cfg.channel_id.center_freq_index);
        uart_transmit_data(packet->rx_meta.rx_cfg.syncword_class);
        uart_transmit_data(packet->rx_meta.lqi);
        uart_transmit_message(&(packet->rx_meta.rssi), sizeof(int16_t));
        // TODO CRC?
        uart_transmit_message(packet->data, packet->length+1);
    }
#endif // FRAMEWORK_LOG_BINARY
}
Exemplo n.º 2
0
void log_printf(char* format, ...)
{
    va_list args;
    va_start(args, format);
    uint8_t len = vsnprintf(buffer, BUFFER_SIZE, format, args);
    va_end(args);
#ifndef USE_SIMPLE_TERMINAL
    uart_transmit_data(0xDD);
    uart_transmit_data(LOG_TYPE_STRING);
    uart_transmit_data(len);
    uart_transmit_message((unsigned char*) buffer, len);
#else
    char buf[BUFFER_SIZE];
    sprintf(buf, "\n\r[%03d] %s", counter, buffer);
    uart_transmit_message((unsigned char*) buf, len+8);
    counter++;
#endif
}
Exemplo n.º 3
0
void log_print_data(uint8_t* message, uint8_t length)
{
#ifndef USE_SIMPLE_TERMINAL
    uart_transmit_data(0xDD);
    uart_transmit_data(LOG_TYPE_DATA);
    uart_transmit_data(length);
    uart_transmit_message((unsigned char*) message, length);
#else
    char buf[BUFFER_SIZE], i;
    sprintf(buf, "\n\r[%03d]", counter);
    uart_transmit_message((unsigned char*) buf, 7);
    for( i=0 ; i<length ; i++ )
    {
        sprintf(buf, " %02X", message[i]);
        uart_transmit_message((unsigned char*) buf, 3);
    }
    counter++;
#endif
}
Exemplo n.º 4
0
void log_print_stack_string(char type, char* format, ...)
{
    va_list args;
    va_start(args, format);
    uint8_t len = vsnprintf(buffer, BUFFER_SIZE, format, args);
    va_end(args);

#ifndef USE_SIMPLE_OUTPUT
    uart_transmit_data(0xDD);
    uart_transmit_data(LOG_TYPE_STACK);
    uart_transmit_data(type);
    uart_transmit_data(len);
    uart_transmit_message((unsigned char*) buffer, len);
#else
    char buf[BUFFER_SIZE];
    sprintf(buf, "[%03d] %s\n\r", counter, buffer);
    uart_transmit_message((unsigned char*) buf, len+8);
    counter++;
#endif
}
Exemplo n.º 5
0
static void packet_received(hw_radio_packet_t* packet)
{
    uint16_t crc = __builtin_bswap16(crc_calculate(packet->data, packet->length - 2));
    if(memcmp(&crc, packet->data + packet->length + 1 - 2, 2) != 0)
    {
        DPRINT("CRC error");
        missed_packets_counter++;
    }
    else
    {
		#if HW_NUM_LEDS > 0
			led_toggle(0);
		#endif
		uint16_t msg_counter = 0;
        uint64_t msg_id;
        memcpy(&msg_id, packet->data + 1, sizeof(msg_id));
        memcpy(&msg_counter, packet->data + 1 + sizeof(msg_id), sizeof(msg_counter));
        char chan[8];
        channel_id_to_string(&(packet->rx_meta.rx_cfg.channel_id), chan, sizeof(chan));
        sprintf(record, "%7s,%i,%i,%lu,%lu,%i\n", chan, msg_counter, packet->rx_meta.rssi, (unsigned long)msg_id, (unsigned long)id, packet->rx_meta.timestamp);
		uart_transmit_message(record, strlen(record));

		if(counter == 0)
		{
			// just start, assume received all previous counters to reset PER to 0%
			received_packets_counter = msg_counter - 1;
			counter = msg_counter - 1;
		}

		uint16_t expected_counter = counter + 1;
		if(msg_counter == expected_counter)
		{
			received_packets_counter++;
			counter++;
		}
		else if(msg_counter > expected_counter)
		{
			missed_packets_counter += msg_counter - expected_counter;
			counter = msg_counter;
		}
		else
		{
            sched_post_task(&start);
		}

	    double per = 0;
	    if(msg_counter > 0)
	        per = 100.0 - ((double)received_packets_counter / (double)msg_counter) * 100.0;

	    sprintf(lcd_msg, "%i %i", (int)per, packet->rx_meta.rssi);
	    lcd_write_string(lcd_msg);
    }
}
Exemplo n.º 6
0
void log_phy_rx_res(phy_rx_data_t* res)
{
	// transmit the log header
	uart_transmit_data(0xDD);
	uart_transmit_data(LOG_TYPE_PHY_RX_RES);
	uart_transmit_data(LOG_TYPE_PHY_RX_RES_SIZE + res->length);

	// transmit struct member per member, so we are not dependent on packing
	uart_transmit_data(res->rssi);
	uart_transmit_data(res->lqi);
	uart_transmit_data(res->length);

	// transmit the packet
	uart_transmit_message(res->data, res->length);
}
__LINK_C void log_print_data(uint8_t* message, uint32_t length)
{
#ifdef FRAMEWORK_LOG_BINARY
    uart_transmit_data(0xDD);
    uart_transmit_data(LOG_TYPE_DATA);
    uart_transmit_data(length);
    uart_transmit_message(message, length);
#else
    printf("\n\r[%03d]", NG(counter)++);
    for( uint32_t i=0 ; i<length ; i++ )
    {
        printf(" %02X", message[i]);
    }
#endif //FRAMEWORK_LOG_BINARY
}
__LINK_C void log_print_string(char* format, ...)
{
    va_list args;
    va_start(args, format);
#ifdef FRAMEWORK_LOG_BINARY
    uint8_t len = vsnprintf(NG(buffer), BUFFER_SIZE, format, args);
    uart_transmit_data(0xDD);
    uart_transmit_data(LOG_TYPE_STRING);
    uart_transmit_data(len);
    uart_transmit_message(NG(buffer),len);
#else
    printf("\n\r[%03d] ", NG(counter)++);
    vprintf(format, args);
#endif //FRAMEWORK_LOG_BINARY
    va_end(args);
}
Exemplo n.º 9
0
static void start()
{
    counter = 0;
    missed_packets_counter = 0;
    received_packets_counter = 0;

    switch(current_state)
    {
        case STATE_CONFIG_DIRECTION:
            is_mode_rx? sprintf(lcd_msg, "PER RX") : sprintf(lcd_msg, "PER TX");
            break;
        case STATE_CONFIG_DATARATE:
            switch(current_channel_id.channel_header.ch_class)
            {
                case PHY_CLASS_LO_RATE:
                    sprintf(lcd_msg, "LO-RATE");
                    break;
                case PHY_CLASS_NORMAL_RATE:
                    sprintf(lcd_msg, "NOR-RATE");
                    break;
                case PHY_CLASS_HI_RATE:
                    sprintf(lcd_msg, "HI-RATE");
                    break;
            }
            break;
        case STATE_RUNNING:
            if(is_mode_rx)
            {
                sprintf(lcd_msg, "RUN RX");
                lcd_write_string(lcd_msg);
                sprintf(record, "%s,%s,%s,%s,%s,%s\n", "channel_id", "counter", "rssi", "tx_id", "rx_id", "timestamp");
                uart_transmit_message(record, strlen(record));
                rx_cfg.channel_id = current_channel_id;
                timer_post_task(&start_rx, TIMER_TICKS_PER_SEC * 5);
            }
            else
            {
                hw_radio_set_idle();
                sprintf(lcd_msg, "RUN TX");
                lcd_write_string(lcd_msg);
                timer_post_task(&transmit_packet, TIMER_TICKS_PER_SEC * 5);
            }
            break;
    }

    lcd_write_string(lcd_msg);
}
Exemplo n.º 10
0
void log_phy_rx_res(phy_rx_data_t* res)
{
	// TODO: add channel id and frame_type
	// transmit the log header
	uart_transmit_data(0xDD);
	uart_transmit_data(LOG_TYPE_PHY_RX_RES);
	uart_transmit_data(LOG_TYPE_PHY_RX_RES_SIZE + res->length);

	// transmit struct member per member, so we are not dependent on packing
	uart_transmit_data(res->rssi);
	uart_transmit_data(res->lqi);
	uart_transmit_data(res->spectrum_id[1]);
	uart_transmit_data(res->spectrum_id[0]);
	uart_transmit_data(res->sync_word_class);
	uart_transmit_data(res->length);

	// transmit the packet
	uart_transmit_message(res->data, res->length);
}
//Overwrite _write so 'printf''s get pushed over the uart
int _write(int fd, char *ptr, int len)
{
    uart_transmit_message(ptr, len);
    return len;
}