23 #include "abc_driver.h" 24 #include "driver_exception.h" 26 #include "goby/common/logger.h" 27 #include "goby/util/binary.h" 30 using goby::util::hex_decode;
31 using goby::util::hex_encode;
34 goby::acomms::ABCDriver::ABCDriver()
43 if (!driver_cfg_.has_serial_baud())
44 driver_cfg_.set_serial_baud(DEFAULT_BAUD);
46 glog.is(DEBUG1) &&
glog << group(glog_out_group())
47 <<
"ABCDriver configuration good. Starting modem..." << std::endl;
48 ModemDriverBase::modem_start(driver_cfg_);
52 std::stringstream raw;
53 raw <<
"CONF,MAC:" << driver_cfg_.modem_id() <<
"\r\n";
54 signal_and_write(raw.str());
59 std::stringstream raw;
60 raw <<
"CONF,FOO:" << driver_cfg_.GetExtension(ABCDriverConfig::enable_foo) <<
"\r\n";
61 signal_and_write(raw.str());
64 std::stringstream raw;
65 raw <<
"CONF,BAR:" << driver_cfg_.GetExtension(ABCDriverConfig::enable_bar) <<
"\r\n";
66 signal_and_write(raw.str());
74 ModemDriverBase::modem_close();
85 glog.is(DEBUG1) &&
glog << group(glog_out_group()) <<
"We were asked to transmit from " 86 << msg.src() <<
" to " << msg.dest() <<
" at bitrate code " 87 << msg.rate() << std::endl;
90 msg.set_max_frame_bytes(500);
93 if (msg.frame_size() == 0)
94 ModemDriverBase::signal_data_request(&msg);
96 glog.is(DEBUG1) &&
glog << group(glog_out_group()) <<
"Sending these data now: " << msg.frame(0)
100 const unsigned BITRATE[] = {100, 1000, 10000, 10000, 10000, 10000};
103 std::stringstream raw;
104 raw <<
"SEND,TO:" << msg.dest() <<
",FROM:" << msg.src() <<
",HEX:" << hex_encode(msg.frame(0))
105 <<
",BITRATE:" << BITRATE[msg.rate()] <<
",ACK:TRUE" 109 signal_and_write(raw.str());
115 while (modem_read(&in))
117 std::map<std::string, std::string> parsed;
124 parse_in(in, &parsed);
129 ModemDriverBase::signal_raw_incoming(raw);
132 msg.set_src(goby::util::as<int32>(parsed[
"FROM"]));
133 msg.set_dest(goby::util::as<int32>(parsed[
"TO"]));
136 glog.is(DEBUG1) &&
glog << group(glog_in_group()) << in << std::endl;
138 if (parsed[
"KEY"] ==
"RECV")
140 msg.set_type(protobuf::ModemTransmission::DATA);
141 msg.add_frame(hex_decode(parsed[
"HEX"]));
142 glog.is(DEBUG1) &&
glog << group(glog_in_group()) <<
"received: " << msg
145 else if (parsed[
"KEY"] ==
"ACKN")
147 msg.set_type(protobuf::ModemTransmission::ACK);
150 ModemDriverBase::signal_receive(msg);
152 catch (std::exception& e)
154 glog.is(WARN) &&
glog <<
"Bad line: " << in << std::endl;
155 glog.is(WARN) &&
glog <<
"Exception: " << e.what() << std::endl;
160 void goby::acomms::ABCDriver::signal_and_write(
const std::string& raw)
163 raw_msg.set_raw(raw);
164 ModemDriverBase::signal_raw_outgoing(raw_msg);
166 glog.is(DEBUG1) &&
glog << group(glog_out_group()) << boost::trim_copy(raw) << std::endl;
167 ModemDriverBase::modem_write(raw);
170 void goby::acomms::ABCDriver::parse_in(
const std::string& in,
171 std::map<std::string, std::string>* out)
173 std::vector<std::string> comma_split;
174 boost::split(comma_split, in, boost::is_any_of(
","));
175 out->insert(std::make_pair(
"KEY", comma_split.at(0)));
176 for (
int i = 1, n = comma_split.size(); i < n; ++i)
178 std::vector<std::string> colon_split;
179 boost::split(colon_split, comma_split[i], boost::is_any_of(
":"));
180 out->insert(std::make_pair(colon_split.at(0), colon_split.at(1)));
uint64 goby_time< uint64 >()
Returns current UTC time as integer microseconds since 1970-01-01 00:00:00.
void do_work()
Allows the modem driver to do its work.
common::FlexOstream glog
Access the Goby logger through this object.
void handle_initiate_transmission(const protobuf::ModemTransmission &m)
Virtual initiate_transmission method. Typically connected to MACManager::signal_initiate_transmission...
void startup(const protobuf::DriverConfig &cfg)
Starts the modem driver. Must be called before poll().
void shutdown()
Shuts down the modem driver.