23 #ifndef BenthosATM900DriverFSM20161221H 24 #define BenthosATM900DriverFSM20161221H 28 #include <boost/circular_buffer.hpp> 29 #include <boost/format.hpp> 30 #include <boost/mpl/list.hpp> 31 #include <boost/statechart/custom_reaction.hpp> 32 #include <boost/statechart/deep_history.hpp> 33 #include <boost/statechart/event.hpp> 34 #include <boost/statechart/in_state_reaction.hpp> 35 #include <boost/statechart/simple_state.hpp> 36 #include <boost/statechart/state.hpp> 37 #include <boost/statechart/state_machine.hpp> 38 #include <boost/statechart/transition.hpp> 40 #include "goby/acomms/acomms_constants.h" 41 #include "goby/common/logger.h" 42 #include "goby/common/time.h" 43 #include "goby/util/binary.h" 45 #include "goby/acomms/protobuf/benthos_atm900.pb.h" 46 #include "goby/acomms/protobuf/modem_message.pb.h" 65 EvAck(
const std::string& response) : response_(response) {}
67 std::string response_;
79 EvDial(
int dest,
int rate) : dest_(dest), rate_(rate) {}
87 EvRange(
int dest) : dest_(dest) {}
115 EvReceive(
const std::string& first) : first_(first) {}
148 : serial_tx_buffer_(SERIAL_BUFFER_CAPACITY), received_(RECEIVED_BUFFER_CAPACITY),
149 driver_cfg_(driver_cfg), data_out_(DATA_BUFFER_CAPACITY)
152 glog_fsm_group_ =
"benthosatm900::fsm::" + goby::util::as<std::string>(count_);
158 boost::circular_buffer<std::string>& serial_tx_buffer() {
return serial_tx_buffer_; }
161 boost::circular_buffer<protobuf::ModemTransmission>& received() {
return received_; }
164 boost::circular_buffer<protobuf::ModemTransmission>& data_out() {
return data_out_; }
168 const std::string& glog_fsm_group()
const {
return glog_fsm_group_; }
173 SERIAL_BUFFER_CAPACITY = 10
177 RECEIVED_BUFFER_CAPACITY = 10
180 boost::circular_buffer<std::string> serial_tx_buffer_;
181 boost::circular_buffer<protobuf::ModemTransmission> received_;
186 DATA_BUFFER_CAPACITY = 5
188 boost::circular_buffer<protobuf::ModemTransmission> data_out_;
190 std::string glog_fsm_group_;
199 glog.is(goby::common::logger::DEBUG1) &&
glog << group(
"benthosatm900::fsm") << name_
204 glog.is(goby::common::logger::DEBUG1) &&
glog << group(
"benthosatm900::fsm") <<
"~" << name_
214 boost::statechart::has_deep_history>,
222 typedef boost::mpl::list<
223 boost::statechart::transition<EvReset, Active>,
224 boost::statechart::in_state_reaction<EvRxSerial, Active, &Active::in_state_react>,
225 boost::statechart::transition<EvReceive, ReceiveData> >
236 typedef boost::mpl::list<
237 boost::statechart::in_state_reaction<EvRxSerial, ReceiveData, &ReceiveData::in_state_react>,
239 boost::statechart::deep_history<Command> > >
243 unsigned reported_size_;
244 std::string encoded_bytes_;
249 boost::statechart::has_deep_history>,
253 void in_state_react(
const EvAck&);
255 boost::statechart::result react(
const EvConnect&)
257 if (at_out_.empty() || at_out_.front().second !=
"+++")
260 return transit<Online>();
265 return discard_event();
272 context<Command>().push_at_command(
"+++");
274 context<Command>().push_clam_command(
"@OpMode=0");
278 typedef boost::mpl::list<
279 boost::statechart::custom_reaction<EvConnect>,
280 boost::statechart::in_state_reaction<EvAck, Command, &Command::in_state_react>,
281 boost::statechart::in_state_reaction<EvTxSerial, Command, &Command::in_state_react> >
287 double last_send_time_;
291 void push_at_command(std::string cmd)
298 void push_clam_command(
const std::string& cmd)
303 boost::circular_buffer<std::pair<ATSentenceMeta, std::string> >& at_out() {
return at_out_; }
308 AT_BUFFER_CAPACITY = 100
310 boost::circular_buffer<std::pair<ATSentenceMeta, std::string> > at_out_;
313 COMMAND_TIMEOUT_SECONDS = 2
318 RETRIES_BEFORE_RESET = 10
324 typedef boost::mpl::list<boost::statechart::transition<EvAtEmpty, SetClock> > reactions;
328 context<Command>().push_at_command(
"");
331 context<Command>().push_clam_command(
"@P1EchoChar=Dis");
333 if (context<BenthosATM900FSM>().driver_cfg().GetExtension(
334 benthos::protobuf::BenthosATM900DriverConfig::factory_reset))
335 context<Command>().push_clam_command(
"factory_reset");
337 if (context<BenthosATM900FSM>().driver_cfg().HasExtension(
338 benthos::protobuf::BenthosATM900DriverConfig::config_load))
340 context<Command>().push_clam_command(
341 "cfg load " + context<BenthosATM900FSM>().driver_cfg().GetExtension(
342 benthos::protobuf::BenthosATM900DriverConfig::config_load));
345 for (
int i = 0, n = context<BenthosATM900FSM>().driver_cfg().ExtensionSize(
346 benthos::protobuf::BenthosATM900DriverConfig::config);
349 context<Command>().push_clam_command(
350 context<BenthosATM900FSM>().driver_cfg().GetExtension(
351 benthos::protobuf::BenthosATM900DriverConfig::config, i));
355 context<Command>().push_clam_command(
"@Prompt=7");
356 context<Command>().push_clam_command(
"@Verbose=3");
359 context<Command>().push_clam_command(
"@DataRetry=0");
362 context<Command>().push_clam_command(
"@FwdDelay=0.05");
363 context<Command>().push_clam_command(
365 goby::util::as<std::string>(context<BenthosATM900FSM>().driver_cfg().modem_id()));
368 context<Command>().push_clam_command(
"@PrintHex=Ena");
371 context<Command>().push_clam_command(
"@WakeTones=Ena");
374 context<Command>().push_clam_command(
"@RcvAll=Ena");
377 context<Command>().push_clam_command(
"@ShowBadData=Ena");
380 context<Command>().push_clam_command(
"@OpMode=0");
391 typedef boost::mpl::list<boost::statechart::transition<EvAtEmpty, Ready> > reactions;
397 std::string date_str = boost::str(boost::format(
"-d%02d/%02d/%04d") %
398 (
int)p.date().month() % p.date().day() % p.date().year());
399 std::string time_str =
400 boost::str(boost::format(
"-t%02d:%02d:%02d") % p.time_of_day().hours() %
401 p.time_of_day().minutes() % p.time_of_day().seconds());
403 context<Command>().push_clam_command(
"date " + time_str +
" " + date_str);
412 void in_state_react(
const EvRequestLowPower&) { context<Command>().push_at_command(
"L"); }
418 typedef boost::mpl::list<
419 boost::statechart::transition<EvDial, Dial>, boost::statechart::transition<EvRange, Range>,
420 boost::statechart::in_state_reaction<EvRequestLowPower, Ready, &Ready::in_state_react>,
421 boost::statechart::transition<EvLowPower, LowPower> >
429 BENTHOS_BROADCAST_ID = 255
439 : my_base(ctx),
StateNotify(
"Dial"), dest_(BENTHOS_BROADCAST_ID), rate_(DEFAULT_RATE)
441 if (
const EvDial* evdial = dynamic_cast<const EvDial*>(triggering_event()))
443 dest_ = evdial->dest_;
445 dest_ = BENTHOS_BROADCAST_ID;
447 if (evdial->rate_ >= RATE_MIN && evdial->rate_ <= RATE_MAX)
448 rate_ = evdial->rate_;
450 context<Command>().push_clam_command(
"@RemoteAddr=" + goby::util::as<std::string>(dest_));
451 context<Command>().push_clam_command(
"@TxRate=" + goby::util::as<std::string>(rate_));
452 context<Command>().push_at_command(
"O");
473 if (
const EvRange* ev = dynamic_cast<const EvRange*>(triggering_event()))
477 context<Command>().push_at_command(
"R" + goby::util::as<std::string>(dest_));
481 typedef boost::mpl::list<
482 boost::statechart::transition<EvRangingComplete, Ready>,
483 boost::statechart::in_state_reaction<EvRxSerial, Range, &Range::in_state_react> >
496 typedef boost::mpl::list<
497 boost::statechart::transition<EvShellPrompt, boost::statechart::deep_history<Command> > >
505 if (!context<BenthosATM900FSM>().data_out().empty())
510 typedef boost::mpl::list<boost::statechart::transition<EvTransmit, TransmitData> > reactions;
519 void in_state_react(
const EvAck&);
521 typedef boost::mpl::list<
522 boost::statechart::transition<EvTransmitBegun, Ready>,
524 &TransmitData::in_state_react>,
525 boost::statechart::in_state_reaction<EvAck, TransmitData, &TransmitData::in_state_react> >
ReturnType goby_time()
Returns current UTC time as a boost::posix_time::ptime.
const int BROADCAST_ID
special modem id for the broadcast destination - no one is assigned this address. Analogous to 192...
common::FlexOstream glog
Access the Goby logger through this object.
The global namespace for the Goby project.