Skip to content

Commit

Permalink
First crack at using capnp for serialization instead of protobuf.
Browse files Browse the repository at this point in the history
* Implementing on DriverPacket initial message between radar_control and usrp_driver.
* Currently compiles, but usrp_driver errors out at runtime.
  • Loading branch information
RemingtonRohel committed Oct 18, 2024
1 parent 68fb7fa commit bb91769
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 19 deletions.
2 changes: 1 addition & 1 deletion site_scons/site_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def hidden_dir_skipper(dirpath):
"_common": dict(
# Common flags for all C++ builds
CCFLAGS=["-Wall"],
CXXFLAGS=["-std=c++11"],
CXXFLAGS=["-std=c++14"],
CFLAGS=["-std=c99"],
# Modules should be able to include relative to build root dir
CPPPATH=["#$BUILDROOT"],
Expand Down
17 changes: 9 additions & 8 deletions src/radar_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
sys.path.append(os.environ["BOREALISPATH"])
if __debug__:
from build.debug.src.utils.protobuf.driverpacket_pb2 import DriverPacket
from build.debug.src.utils.capnp.driverpacket_capnp import DriverPacketPnp as DPnp
else:
from build.release.src.utils.protobuf.driverpacket_pb2 import DriverPacket
from build.release.src.utils.capnp.driverpacket_capnp import DriverPacketPnp as DPnp

TIME_PROFILE = False

Expand Down Expand Up @@ -211,14 +213,13 @@ def create_driver_message(radctrl_params, pulse_transmit_data):

# If this is the first time the driver is being set-up, only send tx and rx rates and center frequencies
if radctrl_params.startup_flag:
message.txcenterfreq = (
radctrl_params.slice_dict[0].txctrfreq * 1000
) # convert to Hz
message.rxcenterfreq = (
radctrl_params.slice_dict[0].rxctrfreq * 1000
) # convert to Hz
message.txrate = radctrl_params.experiment.txrate
message.rxrate = radctrl_params.experiment.rxrate
message = DPnp.new_message(
txCtrFreq=radctrl_params.slice_dict[0].txctrfreq * 1000, # convert to Hz
rxCtrFreq=radctrl_params.slice_dict[0].rxctrfreq * 1000, # convert to Hz
txRate=radctrl_params.experiment.txrate,
rxRate=radctrl_params.experiment.rxrate,
)
return message.to_bytes()
else:
timing = pulse_transmit_data["timing"]
SOB = pulse_transmit_data["startofburst"]
Expand Down
2 changes: 1 addition & 1 deletion src/usrp_drivers/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ import os
Import('*')

Prog('usrp_driver', Glob("./*.c*"), with_libs=['utils', 'messages'],
LIBS=['protobuf', 'pthread','boost_system','uhd','zmq','rt'])
LIBS=['protobuf', 'pthread', 'boost_system', 'uhd', 'zmq', 'rt', 'capnp'])
24 changes: 15 additions & 9 deletions src/usrp_drivers/usrp_driver.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*Copyright 2016 SuperDARN*/
#include <capnp/message.h>
#include <capnp/serialize.h>
#include <stdint.h>
#include <sys/mman.h>
#include <unistd.h>
Expand Down Expand Up @@ -27,6 +29,7 @@
#include <vector>
#include <zmq.hpp>

#include "src/utils/capnp/driverpacket.capnp.h"
#include "src/utils/protobuf/driverpacket.pb.h"
#include "src/utils/protobuf/rxsamplesmetadata.pb.h"
#include "usrp.hpp"
Expand Down Expand Up @@ -710,19 +713,22 @@ int32_t UHD_SAFE_MAIN(int32_t argc, char *argv[]) {
// that it can begin processing experiments without low averages in the first
// integration period.

auto setup_data = recv_string(
driver_to_radar_control, driver_options.get_radctrl_to_driver_identity());
auto setup_data = recv_string(driver_to_radar_control,
driver_options.get_radctrl_to_driver_identity())
.c_str();

driverpacket::DriverPacket driver_packet;
if (driver_packet.ParseFromString(setup_data) == false) {
// TODO(keith): handle error
}
auto wordArray = kj::ArrayPtr<capnp::word const>(
reinterpret_cast<capnp::word const *>(&setup_data), sizeof(setup_data));
::capnp::FlatArrayMessageReader msgReader =
::capnp::FlatArrayMessageReader(wordArray);
DriverPacketPnp::Reader driver_packet = msgReader.getRoot<DriverPacketPnp>();

USRP usrp_d(driver_options, driver_packet.txrate(), driver_packet.rxrate());
USRP usrp_d(driver_options, driver_packet.getTxRate(),
driver_packet.getRxRate());
auto tune_delay = uhd::time_spec_t(TUNING_DELAY);
usrp_d.set_tx_center_freq(driver_packet.txcenterfreq(),
usrp_d.set_tx_center_freq(driver_packet.getTxCtrFreq(),
driver_options.get_transmit_channels(), tune_delay);
usrp_d.set_rx_center_freq(driver_packet.rxcenterfreq(),
usrp_d.set_rx_center_freq(driver_packet.getRxCtrFreq(),
driver_options.get_receive_channels(), tune_delay);

driver_to_radar_control.close();
Expand Down
33 changes: 33 additions & 0 deletions src/utils/capnp/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2015 The Ostrich / by Itamar O
# Copyright 2016 SuperDARN

# The MIT License (MIT)

# Copyright (c) 2014 The Ostrich
# Modified 2016 SuperDARN

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

#
# Import('*')
# import os
#
# RadarProtos = ['driverpacket','rxsamplesmetadata']
# Proto(RadarProtos)
# Lib('messages', protos=RadarProtos)
21 changes: 21 additions & 0 deletions src/utils/capnp/driverpacket.capnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@0xd8bfb47e358210a0;

struct DriverPacketPnp {
channelSamples @0 :List(SamplesBuffer);
sqnNum @1 :UInt32;
rxRate @2 :Float64;
txRate @3 :Float64;
rxCtrFreq @4 :Float64;
txCtrFreq @5 :Float64;
numRxSamples @6 :UInt32;
sqnTime @7 :Float64;
timeToSendSamples @8 :Float64;
startBurst @9 :Bool; # start of burst flag
endBurst @10 :Bool; # end of burst flag
alignSqns @11 :Bool;

struct SamplesBuffer {
real @0 :List(Float32);
imag @1 :List(Float32);
}
}
17 changes: 17 additions & 0 deletions src/utils/capnp/rxsamplesmetadata.capnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@0x8156beb63a2eaed2;

struct RxSamplesMetadata {
sqnNum @0 :UInt32;
numRxSamples @1 :UInt32;
rxRate @2 :Float64;
sqnTime @3 :Float64;
initTime @4 :Float64;
sqnStartTime @5 :Float64;
ringbufferSize @6 :UInt64;
agcStatusH @7 :UInt32;
lpStatusH @8 :UInt32;
agcStatusL @9 :UInt32;
lpStatusL @10 :UInt32;
gpsLocked @11 :Bool;
gpsToSystemTimeDiff @12 :Float64;
}

0 comments on commit bb91769

Please sign in to comment.