Download Goby v2 - gobysoft
Transcript
6.3
Writing a new driver
–
35
goby::acomms::ABCDriver::ABCDriver()
{
// other initialization you can do before you have your
goby::acomms::DriverConfig configuration object
}
– At startup() you get your configuration from the application (e.g. pAcommsHandler)
void goby::acomms::ABCDriver::startup(const
protobuf::DriverConfig& cfg)
{
driver_cfg_ = cfg;
// check ‘driver_cfg_‘ to your satisfaction and then start the modem
physical interface
if(!driver_cfg_.has_serial_baud())
driver_cfg_.set_serial_baud(DEFAULT_BAUD);
glog.is(DEBUG1) && glog << group("modem_out") << "ABCDriver
configuration good. Starting modem..." << std::endl;
ModemDriverBase::modem_start(driver_cfg_);
// set your local modem id (MAC address)
{
std::stringstream raw;
raw << "CONF,MAC:" << driver_cfg_.modem_id() << "\r\n";
signal_and_write(raw.str());
}
// now set our special configuration values
{
std::stringstream raw;
raw << "CONF,FOO:" << driver_cfg_.GetExtension(
ABCDriverConfig::enable_foo) << "\r\n";
signal_and_write(raw.str());
}
{
std::stringstream raw;
raw << "CONF,BAR:" << driver_cfg_.GetExtension(
ABCDriverConfig::enable_bar) << "\r\n";
signal_and_write(raw.str());
}
} // startup
– At shutdown() you should make yourself ready to startup() again if necessary and stop the modem:
void goby::acomms::ABCDriver::shutdown()
{
// put the modem in a low power state?
// ...
ModemDriverBase::modem_close();
} // shutdown
– handle_initiate_transmission() is called when you are expected to initiate a transmission. It may contain
data (in the ModemTransmission::frame field). If not, you are required to request data using the goby::acomms::ModemDriverBase::signal_data_request signal. Once you have data, you are responsible
for sending it. I think a bit of code will make this clearer:
void goby::acomms::ABCDriver::handle_initiate_transmission
(const protobuf::ModemTransmission& orig_msg)
{
// copy so we can modify
protobuf::ModemTransmission msg = orig_msg;
// rate() can be 0 (lowest), 1, 2, 3, 4, or 5 (lowest). Map these
integers onto real bit-rates
// in a meaningful way (on the WHOI Micro-Modem 0 ~= 80 bps, 5 ~= 5000
bps).
glog.is(DEBUG1) && glog << group("modem_out") << "We were asked to
transmit from "
<< msg.src() << " to " << msg.dest()
<< " at bitrate code " << msg.rate() << std::endl;
// let’s say ABC modem uses 500 byte packet
msg.set_max_frame_bytes(500);
// no data given to us, let’s ask for some
if(msg.frame_size() == 0)
ModemDriverBase::signal_data_request(&msg);
glog.is(DEBUG1) && glog << group("modem_out") << "Sending these
data now: " << msg.frame(0) << std::endl;
Generated on Wed Mar 26 2014 01:41:49 for Goby v2 by Doxygen