int Volkslogger::SendCommandReadBulk(Port &port, unsigned baud_rate, OperationEnvironment &env, Command cmd, uint8_t param1, void *buffer, size_t max_length, const unsigned timeout_firstchar_ms) { unsigned old_baud_rate = port.GetBaudrate(); if (old_baud_rate != 0) { if (!SendCommandSwitchBaudRate(port, env, cmd, param1, baud_rate)) return -1; /* after switching baud rates, this sleep time is necessary; it has been verified experimentally */ env.Sleep(300); } else { /* port does not support baud rate switching, use plain SendCommand() without new baud rate */ if (!SendCommand(port, env, cmd, param1)) return -1; } int nbytes = ReadBulk(port, env, buffer, max_length, timeout_firstchar_ms); if (old_baud_rate != 0) port.SetBaudrate(old_baud_rate); return nbytes; }
/** * Cancel pass-through mode on the LX1600. This command was provided * by Crtomir Rojnik (LX Navigation) in an email. It must always be * sent at 4800 baud. After this command has been sent, we switch * back to the "real" baud rate. */ static bool ModeLX1600(Port &port, OperationEnvironment &env) { unsigned old_baud_rate = port.GetBaudrate(); if (old_baud_rate == 4800) old_baud_rate = 0; else if (!port.SetBaudrate(4800)) return false; const bool success = PortWriteNMEA(port, "PFLX0,LX1600", env); if (old_baud_rate != 0) port.SetBaudrate(old_baud_rate); return success; }
bool IMI::Connect(Port &port, OperationEnvironment &env) { if (_connected) return true; memset(&_info, 0, sizeof(_info)); _serialNumber = 0; MessageParser::Reset(); // check connectivity if (!Send(port, env, MSG_CFG_HELLO) || env.IsCancelled()) return false; const TMsg *msg = Receive(port, env, 100, 0); if (!msg || msg->msgID != MSG_CFG_HELLO || env.IsCancelled()) return false; _serialNumber = msg->sn; // configure baudrate unsigned baudRate = port.GetBaudrate(); if (baudRate == 0) return false; if (!Send(port, env, MSG_CFG_STARTCONFIG, 0, 0, IMICOMM_BIGPARAM1(baudRate), IMICOMM_BIGPARAM2(baudRate)) || env.IsCancelled()) return false; // get device info for (unsigned i = 0; i < 4; i++) { if (!Send(port, env, MSG_CFG_DEVICEINFO)) continue; if (env.IsCancelled()) return false; const TMsg *msg = Receive(port, env, 300, sizeof(TDeviceInfo)); if (!msg || env.IsCancelled()) return false; if (msg->msgID != MSG_CFG_DEVICEINFO) continue; if (msg->payloadSize == sizeof(TDeviceInfo)) { memcpy(&_info, msg->payload, sizeof(TDeviceInfo)); } else if (msg->payloadSize == 16) { // old version of the structure memset(&_info, 0, sizeof(TDeviceInfo)); memcpy(&_info, msg->payload, 16); } else { return false; } _connected = true; return true; } return false; }