diff options
-rw-r--r-- | firmware/octoclock/lib/udp_handlers.c | 208 | ||||
-rw-r--r-- | host/examples/tx_samples_c.c | 2 | ||||
-rw-r--r-- | host/lib/convert/convert_impl.cpp | 3 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/common.h | 5 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp | 8 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp | 42 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_impl.cpp | 25 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_uart.cpp | 15 | ||||
-rw-r--r-- | host/lib/usrp_clock/octoclock/octoclock_uart.hpp | 3 | ||||
-rw-r--r-- | host/lib/utils/CMakeLists.txt | 9 | ||||
-rw-r--r-- | host/tests/ranges_c_test.c | 4 | ||||
-rw-r--r-- | host/tests/string_vector_c_test.c | 4 | ||||
-rw-r--r-- | host/tests/subdev_spec_c_test.c | 5 | ||||
-rw-r--r-- | host/utils/query_gpsdo_sensors.cpp | 45 | ||||
-rw-r--r-- | host/utils/uhd_usrp_probe.cpp | 4 |
15 files changed, 227 insertions, 155 deletions
diff --git a/firmware/octoclock/lib/udp_handlers.c b/firmware/octoclock/lib/udp_handlers.c index 49b9b8023..293d5f762 100644 --- a/firmware/octoclock/lib/udp_handlers.c +++ b/firmware/octoclock/lib/udp_handlers.c @@ -1,5 +1,5 @@ /* - * Copyright 2014 Ettus Research LLC + * Copyright 2014,2016 Ettus Research LLC * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,89 +36,86 @@ void handle_udp_ctrl_packet( pkt_out.proto_ver = OCTOCLOCK_FW_COMPAT_NUM; pkt_out.sequence = pkt_in->sequence; - // If the firmware is incompatible, only respond to queries - if(pkt_in->code == OCTOCLOCK_QUERY_CMD){ - pkt_out.code = OCTOCLOCK_QUERY_ACK; - pkt_out.len = 0; - send_udp_pkt(OCTOCLOCK_UDP_CTRL_PORT, src, (void*)&pkt_out, sizeof(octoclock_packet_t)); - } - else if(pkt_in->proto_ver == OCTOCLOCK_FW_COMPAT_NUM){ - switch(pkt_in->code){ - case SEND_EEPROM_CMD: - pkt_out.code = SEND_EEPROM_ACK; - pkt_out.len = sizeof(octoclock_fw_eeprom_t); - - octoclock_fw_eeprom_t *eeprom_info = (octoclock_fw_eeprom_t*)pkt_out.data; - - // Read values from EEPROM into packet - eeprom_busy_wait(); - eeprom_read_block(eeprom_info, 0, sizeof(octoclock_fw_eeprom_t)); - - // If EEPROM network fields are not fully populated, copy defaults - if(using_network_defaults){ - _MAC_ADDR(eeprom_info->mac_addr, 0x00,0x80,0x2F,0x11,0x22,0x33); - eeprom_info->ip_addr = _IP(192,168,10,3); - eeprom_info->dr_addr = _IP(192,168,10,1); - eeprom_info->netmask = _IP(255,255,255,0); - } - - // Check if strings or revision is empty - if(eeprom_info->revision == 0xFF) eeprom_info->revision = 0; - break; - - case BURN_EEPROM_CMD:{ - // Confirm length of data - if(pkt_in->len != sizeof(octoclock_fw_eeprom_t)){ - pkt_out.code = BURN_EEPROM_FAILURE_ACK; - break; - } - - /* - * It is up to the host to make sure that the values that should be - * preserved are present in the octoclock_fw_eeprom_t struct. - */ - const octoclock_fw_eeprom_t *eeprom_pkt = (octoclock_fw_eeprom_t*)pkt_in->data; - pkt_out.len = 0; - - // Write EEPROM data from packet - eeprom_busy_wait(); - eeprom_write_block(eeprom_pkt, 0, sizeof(octoclock_fw_eeprom_t)); - - // Read back and compare to packet to confirm successful write - uint8_t eeprom_contents[sizeof(octoclock_fw_eeprom_t)]; - eeprom_busy_wait(); - eeprom_read_block(eeprom_contents, 0, sizeof(octoclock_fw_eeprom_t)); - uint8_t n = memcmp(eeprom_contents, eeprom_pkt, sizeof(octoclock_fw_eeprom_t)); - pkt_out.code = n ? BURN_EEPROM_FAILURE_ACK - : BURN_EEPROM_SUCCESS_ACK; - break; + switch(pkt_in->code){ + case OCTOCLOCK_QUERY_CMD: + pkt_out.code = OCTOCLOCK_QUERY_ACK; + pkt_out.len = 0; + break; + + case RESET_CMD: + pkt_out.code = RESET_ACK; + send_udp_pkt(OCTOCLOCK_UDP_CTRL_PORT, src, (void*)&pkt_out, sizeof(octoclock_packet_t)); + wdt_enable(WDTO_30MS); + while(1); + break; + + case SEND_EEPROM_CMD: + pkt_out.code = SEND_EEPROM_ACK; + pkt_out.len = sizeof(octoclock_fw_eeprom_t); + + octoclock_fw_eeprom_t *eeprom_info = (octoclock_fw_eeprom_t*)pkt_out.data; + + // Read values from EEPROM into packet + eeprom_busy_wait(); + eeprom_read_block(eeprom_info, 0, sizeof(octoclock_fw_eeprom_t)); + + // If EEPROM network fields are not fully populated, copy defaults + if(using_network_defaults){ + _MAC_ADDR(eeprom_info->mac_addr, 0x00,0x80,0x2F,0x11,0x22,0x33); + eeprom_info->ip_addr = _IP(192,168,10,3); + eeprom_info->dr_addr = _IP(192,168,10,1); + eeprom_info->netmask = _IP(255,255,255,0); } - case SEND_STATE_CMD: - pkt_out.code = SEND_STATE_ACK; - pkt_out.len = sizeof(octoclock_state_t); + // Check if strings or revision is empty + if(eeprom_info->revision == 0xFF) eeprom_info->revision = 0; + break; - // Populate octoclock_state_t fields - octoclock_state_t *state = (octoclock_state_t*)pkt_out.data; - state->external_detected = g_ext_ref_present ? 1 : 0; - state->gps_detected = g_gps_present ? 1 : 0; - state->which_ref = (uint8_t)g_ref; - state->switch_pos = (uint8_t)g_switch_pos; + case BURN_EEPROM_CMD:{ + // Confirm length of data + if(pkt_in->len != sizeof(octoclock_fw_eeprom_t)){ + pkt_out.code = BURN_EEPROM_FAILURE_ACK; break; + } - case RESET_CMD: - pkt_out.code = RESET_ACK; - send_udp_pkt(OCTOCLOCK_UDP_CTRL_PORT, src, (void*)&pkt_out, sizeof(octoclock_packet_t)); - wdt_enable(WDTO_30MS); - while(1); - return; - - default: - return; + /* + * It is up to the host to make sure that the values that should be + * preserved are present in the octoclock_fw_eeprom_t struct. + */ + const octoclock_fw_eeprom_t *eeprom_pkt = (octoclock_fw_eeprom_t*)pkt_in->data; + pkt_out.len = 0; + + // Write EEPROM data from packet + eeprom_busy_wait(); + eeprom_write_block(eeprom_pkt, 0, sizeof(octoclock_fw_eeprom_t)); + + // Read back and compare to packet to confirm successful write + uint8_t eeprom_contents[sizeof(octoclock_fw_eeprom_t)]; + eeprom_busy_wait(); + eeprom_read_block(eeprom_contents, 0, sizeof(octoclock_fw_eeprom_t)); + uint8_t n = memcmp(eeprom_contents, eeprom_pkt, sizeof(octoclock_fw_eeprom_t)); + pkt_out.code = n ? BURN_EEPROM_FAILURE_ACK + : BURN_EEPROM_SUCCESS_ACK; + break; } - send_udp_pkt(OCTOCLOCK_UDP_CTRL_PORT, src, (void*)&pkt_out, sizeof(octoclock_packet_t)); + case SEND_STATE_CMD: + pkt_out.code = SEND_STATE_ACK; + pkt_out.len = sizeof(octoclock_state_t); + + // Populate octoclock_state_t fields + octoclock_state_t *state = (octoclock_state_t*)pkt_out.data; + state->external_detected = g_ext_ref_present ? 1 : 0; + state->gps_detected = g_gps_present ? 1 : 0; + state->which_ref = (uint8_t)g_ref; + state->switch_pos = (uint8_t)g_switch_pos; + break; + + default: + return; } + + send_udp_pkt(OCTOCLOCK_UDP_CTRL_PORT, src, (void*)&pkt_out, sizeof(octoclock_packet_t)); } void handle_udp_gpsdo_packet( @@ -130,35 +127,34 @@ void handle_udp_gpsdo_packet( pkt_out.proto_ver = OCTOCLOCK_FW_COMPAT_NUM; pkt_out.sequence = pkt_in->sequence; - if(pkt_in->proto_ver == OCTOCLOCK_FW_COMPAT_NUM){ - switch(pkt_in->code){ - case HOST_SEND_TO_GPSDO_CMD: - send_gpsdo_cmd((char*)pkt_in->data, pkt_in->len); - pkt_out.code = HOST_SEND_TO_GPSDO_ACK; - pkt_out.len = 0; - break; - - case SEND_POOLSIZE_CMD: - pkt_out.code = SEND_POOLSIZE_ACK; - pkt_out.len = 0; - pkt_out.poolsize = POOLSIZE; - break; - - case SEND_CACHE_STATE_CMD: - pkt_out.code = SEND_CACHE_STATE_ACK; - pkt_out.state = gpsdo_state; - break; - - case SEND_GPSDO_CACHE_CMD: - pkt_out.code = SEND_GPSDO_CACHE_ACK; - pkt_out.state = gpsdo_state; - memcpy(pkt_out.data, gpsdo_buf, POOLSIZE); - break; - - default: - return; - } - - send_udp_pkt(OCTOCLOCK_UDP_GPSDO_PORT, src, (void*)&pkt_out, sizeof(octoclock_packet_t)); + switch(pkt_in->code){ + case HOST_SEND_TO_GPSDO_CMD: + send_gpsdo_cmd((char*)pkt_in->data, pkt_in->len); + pkt_out.code = HOST_SEND_TO_GPSDO_ACK; + pkt_out.len = 0; + break; + + case SEND_POOLSIZE_CMD: + pkt_out.code = SEND_POOLSIZE_ACK; + pkt_out.len = 0; + pkt_out.poolsize = POOLSIZE; + break; + + case SEND_CACHE_STATE_CMD: + pkt_out.code = SEND_CACHE_STATE_ACK; + pkt_out.state = gpsdo_state; + break; + + case SEND_GPSDO_CACHE_CMD: + pkt_out.code = SEND_GPSDO_CACHE_ACK; + pkt_out.state = gpsdo_state; + pkt_out.len = POOLSIZE; + memcpy(pkt_out.data, gpsdo_buf, POOLSIZE); + break; + + default: + return; } + + send_udp_pkt(OCTOCLOCK_UDP_GPSDO_PORT, src, (void*)&pkt_out, sizeof(octoclock_packet_t)); } diff --git a/host/examples/tx_samples_c.c b/host/examples/tx_samples_c.c index e10d585ce..3c3fcc8fe 100644 --- a/host/examples/tx_samples_c.c +++ b/host/examples/tx_samples_c.c @@ -196,7 +196,7 @@ int main(int argc, char* argv[]){ buffs_ptr = (const void**)&buff; size_t i = 0; for(i = 0; i < (samps_per_buff*2); i+=2){ - buff[i] = 0.1; + buff[i] = 0.1f; buff[i+1] = 0; } diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp index d90bb9c94..7dfbb33fd 100644 --- a/host/lib/convert/convert_impl.cpp +++ b/host/lib/convert/convert_impl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2011 Ettus Research LLC +// Copyright 2011,2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -162,7 +162,6 @@ UHD_STATIC_BLOCK(convert_register_item_sizes){ convert::register_bytes_per_item("sc64", sizeof(std::complex<boost::int64_t>)); convert::register_bytes_per_item("sc32", sizeof(std::complex<boost::int32_t>)); convert::register_bytes_per_item("sc16", sizeof(std::complex<boost::int16_t>)); - convert::register_bytes_per_item("sc12", 3 * sizeof(std::complex<boost::int8_t>)); convert::register_bytes_per_item("sc8", sizeof(std::complex<boost::int8_t>)); //register standard real types diff --git a/host/lib/usrp_clock/octoclock/common.h b/host/lib/usrp_clock/octoclock/common.h index 89fec9ce5..191b93d36 100644 --- a/host/lib/usrp_clock/octoclock/common.h +++ b/host/lib/usrp_clock/octoclock/common.h @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 Ettus Research LLC + * Copyright 2014-2016 Ettus Research LLC * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,7 +46,8 @@ extern "C" { // These values are placed in the octoclock_packet_t.proto_ver field #define OCTOCLOCK_BOOTLOADER_PROTO_VER 1234 -#define OCTOCLOCK_FW_COMPAT_NUM 3 +#define OCTOCLOCK_FW_MIN_COMPAT_NUM 2 +#define OCTOCLOCK_FW_COMPAT_NUM 4 // UDP ports assigned for different tasks #define OCTOCLOCK_UDP_CTRL_PORT 50000 diff --git a/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp b/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp index 49d1a0442..8ac38011d 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_eeprom.cpp @@ -1,5 +1,5 @@ // -// Copyright 2014-2015 Ettus Research LLC +// Copyright 2014-2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -46,7 +46,8 @@ void octoclock_eeprom_t::_load(){ const octoclock_fw_eeprom_t *eeprom_in = reinterpret_cast<const octoclock_fw_eeprom_t*>(pkt_in->data); octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<boost::uint32_t>(std::rand()); + // To avoid replicating sequence numbers between sessions + pkt_out.sequence = boost::uint32_t(std::rand()); size_t len = 0; UHD_OCTOCLOCK_SEND_AND_RECV(xport, SEND_EEPROM_CMD, pkt_out, len, octoclock_data); @@ -94,7 +95,8 @@ void octoclock_eeprom_t::_store() const { const octoclock_packet_t *pkt_in = reinterpret_cast<const octoclock_packet_t *>(octoclock_data); octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<boost::uint32_t>(std::rand()); + // To avoid replicating sequence numbers between sessions + pkt_out.sequence = boost::uint32_t(std::rand()); pkt_out.len = sizeof(octoclock_fw_eeprom_t); size_t len = 0; diff --git a/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp b/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp index fdb254024..e12256c15 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_image_loader.cpp @@ -1,5 +1,5 @@ // -// Copyright 2015 Ettus Research LLC +// Copyright 2015-2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -59,9 +59,11 @@ typedef struct { std::string image_filepath; boost::uint16_t crc; boost::uint16_t num_blocks; + boost::uint32_t sequence; udp_simple::sptr ctrl_xport; udp_simple::sptr fw_xport; boost::uint8_t data_in[udp_simple::mtu]; + boost::uint32_t starting_firmware_version; std::vector<boost::uint8_t> image; } octoclock_session_t; @@ -169,6 +171,19 @@ static void octoclock_setup_session(octoclock_session_t &session, BOOST_STRINGIZE(OCTOCLOCK_UDP_CTRL_PORT)); session.fw_xport = udp_simple::make_connected(session.dev_addr["addr"], BOOST_STRINGIZE(OCTOCLOCK_UDP_FW_PORT)); + // To avoid replicating sequence numbers between sessions + session.sequence = boost::uint32_t(std::rand()); + + // Query OctoClock again to get compat number + octoclock_packet_t pkt_out; + const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); + size_t len = 0; + UHD_OCTOCLOCK_SEND_AND_RECV(session.ctrl_xport, OCTOCLOCK_QUERY_CMD, pkt_out, len, session.data_in); + if(UHD_OCTOCLOCK_PACKET_MATCHES(OCTOCLOCK_QUERY_ACK, pkt_out, pkt_in, len)){ + session.starting_firmware_version = uhd::htonx<boost::uint32_t>(pkt_in->proto_ver); + } else { + throw uhd::runtime_error("Failed to communicate with OctoClock."); + } } static void octoclock_reset_into_bootloader(octoclock_session_t &session){ @@ -177,15 +192,18 @@ static void octoclock_reset_into_bootloader(octoclock_session_t &session){ if(session.dev_addr["type"] == "octoclock-bootloader") return; + // Force compat num to device's current, works around old firmware bug octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<boost::uint32_t>(std::rand()); - const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); - size_t len; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); + pkt_out.proto_ver = uhd::htonx<boost::uint32_t>(session.starting_firmware_version); + pkt_out.code = RESET_CMD; std::cout << " -- Resetting into bootloader..." << std::flush; - UHD_OCTOCLOCK_SEND_AND_RECV(session.ctrl_xport, RESET_CMD, pkt_out, len, session.data_in); - if(UHD_OCTOCLOCK_PACKET_MATCHES(RESET_ACK, pkt_out, pkt_in, len)){ + session.ctrl_xport->send(boost::asio::buffer(&pkt_out, sizeof(octoclock_packet_t))); \ + size_t len = session.ctrl_xport->recv(boost::asio::buffer(session.data_in), 2);\ + const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); + if(UHD_OCTOCLOCK_PACKET_MATCHES(RESET_ACK, pkt_out, pkt_in, len)){ // Make sure this device is now in its bootloader boost::this_thread::sleep(boost::posix_time::milliseconds(500)); uhd::device_addrs_t octoclocks = uhd::device::find( @@ -217,7 +235,7 @@ static void octoclock_burn(octoclock_session_t &session){ octoclock_reset_into_bootloader(session); octoclock_packet_t pkt_out; - pkt_out.sequence = htonx<boost::uint32_t>(std::rand()); + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); // Tell OctoClock to prepare for burn @@ -237,7 +255,7 @@ static void octoclock_burn(octoclock_session_t &session){ // Start burning for(size_t i = 0; i < session.num_blocks; i++){ - pkt_out.sequence++; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); pkt_out.addr = i * OCTOCLOCK_BLOCK_SIZE; std::cout << str(boost::format("\r -- Loading firmware: %d%% (%d/%d blocks)") @@ -260,16 +278,16 @@ static void octoclock_burn(octoclock_session_t &session){ } static void octoclock_verify(octoclock_session_t &session){ - + octoclock_packet_t pkt_out; - pkt_out.sequence = htonx<boost::uint32_t>(std::rand()); + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); size_t len = 0; boost::uint8_t image_part[OCTOCLOCK_BLOCK_SIZE]; boost::uint16_t cmp_len = 0; for(size_t i = 0; i < session.num_blocks; i++){ - pkt_out.sequence++; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); pkt_out.addr = i * OCTOCLOCK_BLOCK_SIZE; std::cout << str(boost::format("\r -- Verifying firmware load: %d%% (%d/%d blocks)") @@ -302,7 +320,7 @@ static void octoclock_verify(octoclock_session_t &session){ static void octoclock_finalize(octoclock_session_t &session){ octoclock_packet_t pkt_out; - pkt_out.sequence = htonx<boost::uint32_t>(std::rand()); + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++session.sequence); const octoclock_packet_t* pkt_in = reinterpret_cast<const octoclock_packet_t*>(session.data_in); size_t len = 0; diff --git a/host/lib/usrp_clock/octoclock/octoclock_impl.cpp b/host/lib/usrp_clock/octoclock/octoclock_impl.cpp index 94e8b05d8..7ca83ddb1 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_impl.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_impl.cpp @@ -110,7 +110,8 @@ device_addrs_t octoclock_find(const device_addr_t &hint){ //Send a query packet octoclock_packet_t pkt_out; pkt_out.proto_ver = OCTOCLOCK_FW_COMPAT_NUM; - pkt_out.sequence = uhd::htonx<boost::uint32_t>(std::rand()); + // To avoid replicating sequence numbers between sessions + pkt_out.sequence = boost::uint32_t(std::rand()); pkt_out.len = 0; pkt_out.code = OCTOCLOCK_QUERY_CMD; try{ @@ -144,12 +145,17 @@ device_addrs_t octoclock_find(const device_addr_t &hint){ new_addr["type"] = "octoclock-bootloader"; octoclock_addrs.push_back(new_addr); } - else{ + else { new_addr["type"] = "octoclock"; - octoclock_eeprom_t oc_eeprom(ctrl_xport); - new_addr["name"] = oc_eeprom["name"]; - new_addr["serial"] = oc_eeprom["serial"]; + if(pkt_in->proto_ver >= OCTOCLOCK_FW_MIN_COMPAT_NUM and pkt_in->proto_ver <= OCTOCLOCK_FW_COMPAT_NUM) { + octoclock_eeprom_t oc_eeprom(ctrl_xport); + new_addr["name"] = oc_eeprom["name"]; + new_addr["serial"] = oc_eeprom["serial"]; + } else { + new_addr["name"] = ""; + new_addr["serial"] = ""; + } //Filter based on optional keys (if any) if( @@ -184,7 +190,8 @@ octoclock_impl::octoclock_impl(const device_addr_t &_device_addr){ UHD_MSG(status) << "Opening an OctoClock device..." << std::endl; _type = device::CLOCK; device_addrs_t device_args = separate_device_addr(_device_addr); - _sequence = std::rand(); + // To avoid replicating sequence numbers between sessions + _sequence = boost::uint32_t(std::rand()); //////////////////////////////////////////////////////////////////// // Initialize the property tree @@ -220,7 +227,7 @@ octoclock_impl::octoclock_impl(const device_addr_t &_device_addr){ // Check the firmware compatibility number //////////////////////////////////////////////////////////////////// boost::uint32_t fw_version = _get_fw_version(oc); - if(fw_version != OCTOCLOCK_FW_COMPAT_NUM){ + if(fw_version < OCTOCLOCK_FW_MIN_COMPAT_NUM or fw_version > OCTOCLOCK_FW_COMPAT_NUM){ throw uhd::runtime_error(str(boost::format( "\n\nPlease update your OctoClock's firmware.\n" "Expected firmware compatibility number %d, but got %d:\n" @@ -325,7 +332,7 @@ void octoclock_impl::_set_eeprom(const std::string &oc, const octoclock_eeprom_t boost::uint32_t octoclock_impl::_get_fw_version(const std::string &oc){ octoclock_packet_t pkt_out; - pkt_out.sequence = _sequence++; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++_sequence); pkt_out.len = 0; size_t len; @@ -341,7 +348,7 @@ boost::uint32_t octoclock_impl::_get_fw_version(const std::string &oc){ void octoclock_impl::_get_state(const std::string &oc){ octoclock_packet_t pkt_out; - pkt_out.sequence = _sequence++; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++_sequence); pkt_out.len = 0; size_t len = 0; diff --git a/host/lib/usrp_clock/octoclock/octoclock_uart.cpp b/host/lib/usrp_clock/octoclock/octoclock_uart.cpp index f366bac30..e0a9f08cf 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_uart.cpp +++ b/host/lib/usrp_clock/octoclock/octoclock_uart.cpp @@ -1,5 +1,5 @@ // -// Copyright 2014-2015 Ettus Research LLC +// Copyright 2014-2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -47,11 +47,13 @@ namespace uhd{ _state.pos = 0; _device_state.num_wraps = 0; _device_state.pos = 0; + // To avoid replicating sequence numbers between sessions + _sequence = boost::uint32_t(std::rand()); size_t len = 0; //Get pool size from device octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<boost::uint16_t>(std::rand()); + pkt_out.sequence = uhd::htonx<boost::uint32_t>(_sequence); pkt_out.len = 0; boost::uint8_t octoclock_data[udp_simple::mtu]; @@ -70,7 +72,7 @@ namespace uhd{ size_t len = 0; octoclock_packet_t pkt_out; - pkt_out.sequence = uhd::htonx<boost::uint32_t>(std::rand()); + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++_sequence); pkt_out.len = to_send.size(); memcpy(pkt_out.data, to_send.c_str(), to_send.size()); @@ -111,14 +113,13 @@ namespace uhd{ void octoclock_uart_iface::_update_cache(){ octoclock_packet_t pkt_out; pkt_out.len = 0; - pkt_out.sequence = 0; size_t len = 0; boost::uint8_t octoclock_data[udp_simple::mtu]; const octoclock_packet_t *pkt_in = reinterpret_cast<octoclock_packet_t*>(octoclock_data); if(STATES_EQUAL or LOCAL_STATE_AHEAD){ - pkt_out.sequence++; + pkt_out.sequence = uhd::htonx<boost::uint32_t>(++_sequence); UHD_OCTOCLOCK_SEND_AND_RECV(_udp, SEND_GPSDO_CACHE_CMD, pkt_out, len, octoclock_data); if(UHD_OCTOCLOCK_PACKET_MATCHES(SEND_GPSDO_CACHE_ACK, pkt_out, pkt_in, len)){ memcpy(&_cache[0], pkt_in->data, _poolsize); @@ -137,7 +138,7 @@ namespace uhd{ //We may have wrapped around locally if(_state.pos == 0) _state.num_wraps++; } - _state.pos = (_state.pos+1) % _poolsize; + if (_cache[_state.pos] == '\n') _state.pos = (_state.pos+1) % _poolsize; //We may have wrapped around locally if(_state.pos == 0) _state.num_wraps++; } @@ -145,7 +146,7 @@ namespace uhd{ } char octoclock_uart_iface::_getchar(){ - if(LOCAL_STATE_AHEAD){ + if(STATES_EQUAL or LOCAL_STATE_AHEAD){ return 0; } diff --git a/host/lib/usrp_clock/octoclock/octoclock_uart.hpp b/host/lib/usrp_clock/octoclock/octoclock_uart.hpp index 05d1bb121..d7a77288f 100644 --- a/host/lib/usrp_clock/octoclock/octoclock_uart.hpp +++ b/host/lib/usrp_clock/octoclock/octoclock_uart.hpp @@ -1,5 +1,5 @@ // -// Copyright 2014 Ettus Research LLC +// Copyright 2014,2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -45,6 +45,7 @@ private: gpsdo_cache_state_t _device_state; std::vector<boost::uint8_t> _cache; std::string _rxbuff; + boost::uint32_t _sequence; void _update_cache(); char _getchar(); diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index 72e2f3f50..790ef72ad 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -119,11 +119,18 @@ SET_SOURCE_FILES_PROPERTIES( FILE(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX} UHD_PKG_PATH) STRING(REPLACE "\\" "\\\\" UHD_PKG_PATH ${UHD_PKG_PATH}) +STRING(REGEX MATCH ".*/.*" SLASH "${LIB_SUFFIX}") +IF(SLASH STREQUAL "") + SET(UHD_LIB_DIR "lib${LIB_SUFFIX}") +ELSE() + SET(UHD_LIB_DIR "lib") +ENDIF(SLASH STREQUAL "") + SET_SOURCE_FILES_PROPERTIES( ${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp ${CMAKE_CURRENT_SOURCE_DIR}/images.cpp PROPERTIES COMPILE_DEFINITIONS - "UHD_PKG_PATH=\"${UHD_PKG_PATH}\";UHD_LIB_DIR=\"lib${LIB_SUFFIX}\"" + "UHD_PKG_PATH=\"${UHD_PKG_PATH}\";UHD_LIB_DIR=\"${UHD_LIB_DIR}\"" ) ######################################################################## diff --git a/host/tests/ranges_c_test.c b/host/tests/ranges_c_test.c index da9c86a48..2398588a6 100644 --- a/host/tests/ranges_c_test.c +++ b/host/tests/ranges_c_test.c @@ -1,5 +1,5 @@ // -// Copyright 2015 Ettus Research LLC +// Copyright 2015-2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -155,7 +155,7 @@ int main(){ if(size != 2){ fprintf(stderr, "%s:%d: Invalid size: %lu vs. 2", __FILE__, __LINE__, - size); + (unsigned long)size); goto free_meta_range1; } diff --git a/host/tests/string_vector_c_test.c b/host/tests/string_vector_c_test.c index fe055fd91..f7f2f7b69 100644 --- a/host/tests/string_vector_c_test.c +++ b/host/tests/string_vector_c_test.c @@ -1,5 +1,5 @@ // -// Copyright 2015 Ettus Research LLC +// Copyright 2015-2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -60,7 +60,7 @@ int main(){ if(size != 2){ return_code = EXIT_FAILURE; fprintf(stderr, "%s:%d: Invalid size: %lu vs. 2", - __FILE__, __LINE__,size); + __FILE__, __LINE__, (unsigned long)size); goto free_string_vector; } diff --git a/host/tests/subdev_spec_c_test.c b/host/tests/subdev_spec_c_test.c index 7663ba357..f69b825a8 100644 --- a/host/tests/subdev_spec_c_test.c +++ b/host/tests/subdev_spec_c_test.c @@ -1,5 +1,5 @@ // -// Copyright 2015 Ettus Research LLC +// Copyright 2015-2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -71,7 +71,8 @@ int main(){ uhd_subdev_spec_size(subdev_spec2, &size2) ) if(size1 != size2){ - printf("%s:%d: Sizes do not match. %lu vs. %lu\n", __FILE__, __LINE__, size1, size2); + printf("%s:%d: Sizes do not match. %lu vs. %lu\n", __FILE__, __LINE__, + (unsigned long)size1, (unsigned long)size2); return_code = EXIT_FAILURE; goto free_subdev_spec2; } diff --git a/host/utils/query_gpsdo_sensors.cpp b/host/utils/query_gpsdo_sensors.cpp index 21d26e81e..7c5728e39 100644 --- a/host/utils/query_gpsdo_sensors.cpp +++ b/host/utils/query_gpsdo_sensors.cpp @@ -19,6 +19,7 @@ #include <uhd/utils/thread_priority.hpp> #include <uhd/utils/safe_main.hpp> #include <uhd/usrp/multi_usrp.hpp> +#include <uhd/usrp_clock/multi_usrp_clock.hpp> #include <boost/filesystem.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> @@ -41,6 +42,38 @@ void print_notes(void) { std::cout << boost::format("****************************************************************************************************************\n"); } +int query_clock_sensors(const std::string &args) { + std::cout << boost::format("\nCreating the clock device with: %s...\n") % args; + uhd::usrp_clock::multi_usrp_clock::sptr clock = uhd::usrp_clock::multi_usrp_clock::make(args); + + //Verify GPS sensors are present + std::vector<std::string> sensor_names = clock->get_sensor_names(0); + if(std::find(sensor_names.begin(), sensor_names.end(), "gps_locked") == sensor_names.end()) { + std::cout << boost::format("\ngps_locked sensor not found. This could mean that this unit does not have a GPSDO.\n\n"); + return EXIT_FAILURE; + } + + // Print NMEA strings + try { + uhd::sensor_value_t gga_string = clock->get_sensor("gps_gpgga"); + uhd::sensor_value_t rmc_string = clock->get_sensor("gps_gprmc"); + uhd::sensor_value_t servo_string = clock->get_sensor("gps_servo"); + std::cout << boost::format("\nPrinting available NMEA strings:\n"); + std::cout << boost::format("%s\n%s\n") % gga_string.to_pp_string() % rmc_string.to_pp_string(); + std::cout << boost::format("\nPrinting GPS servo status:\n"); + std::cout << boost::format("%s\n\n") % servo_string.to_pp_string(); + } catch (uhd::lookup_error &e) { + std::cout << "NMEA strings not implemented for this device." << std::endl; + } + std::cout << boost::format("GPS Epoch time: %.5f seconds\n") % clock->get_sensor("gps_time").to_real(); + std::cout << boost::format("PC Clock time: %.5f seconds\n") % time(NULL); + + //finished + std::cout << boost::format("\nDone!\n\n"); + + return EXIT_SUCCESS; +} + int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::set_thread_priority_safe(); @@ -51,6 +84,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ desc.add_options() ("help", "help message") ("args", po::value<std::string>(&args)->default_value(""), "Device address arguments specifying a single USRP") + ("clock", "query a clock device's sensors") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -65,6 +99,11 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ return EXIT_FAILURE; } + //If specified, query a clock device instead + if(vm.count("clock")) { + return query_clock_sensors(args); + } + //Create a USRP device std::cout << boost::format("\nCreating the USRP device with: %s...\n") % args; uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); @@ -91,7 +130,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << "trying \"external\"..." <<std::endl; try { usrp->set_time_source("external"); - } catch (uhd::value_error &e) { + } catch (uhd::value_error&) { std::cout << "\"external\" failed, too." << std::endl; } } @@ -115,7 +154,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << "trying \"external\"..." <<std::endl; try{ usrp->set_clock_source("external"); - } catch (uhd::value_error &e) { + } catch (uhd::value_error&) { std::cout << "\"external\" failed, too." << std::endl; } } @@ -179,7 +218,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::sensor_value_t rmc_string = usrp->get_mboard_sensor("gps_gprmc"); std::cout << boost::format("Printing available NMEA strings:\n"); std::cout << boost::format("%s\n%s\n") % gga_string.to_pp_string() % rmc_string.to_pp_string(); - } catch (uhd::lookup_error &e) { + } catch (uhd::lookup_error&) { std::cout << "NMEA strings not implemented for this device." << std::endl; } std::cout << boost::format("GPS Epoch time at last PPS: %.5f seconds\n") % usrp->get_mboard_sensor("gps_time").to_real(); diff --git a/host/utils/uhd_usrp_probe.cpp b/host/utils/uhd_usrp_probe.cpp index 4a84fef55..ae86b0dba 100644 --- a/host/utils/uhd_usrp_probe.cpp +++ b/host/utils/uhd_usrp_probe.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010-2011,2015 Ettus Research LLC +// Copyright 2010-2011,2015-2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -172,7 +172,7 @@ static std::string get_mboard_pp_string(property_tree::sptr tree, const fs_path ss << make_border(get_dboard_pp_string("TX", tree, path / "dboards" / name)); } } - catch (const uhd::lookup_error &e) { + catch (const uhd::lookup_error&) { /* nop */ } return ss.str(); |