Permalink
Browse files

Provide LXNAVV7Device::EnableNMEA()

Remember baud rate when enabling PassThrough mode.
Do not declare V7 as a logger.
  • Loading branch information...
1 parent db1aa33 commit 399546c4f1e58f5d4d55b90900e70ce760055691 @davidswelt committed Mar 20, 2012
@@ -32,6 +32,9 @@ Copyright_License {
class LXDevice: public AbstractDevice
{
+
+protected:
+
enum class Mode : uint8_t {
UNKNOWN,
NMEA,
@@ -40,7 +43,6 @@ class LXDevice: public AbstractDevice
};
-protected:
Port &port;
unsigned bulk_baud_rate;
@@ -34,6 +34,8 @@ Copyright_License {
class LXNAVV7Device: public LXDevice
{
+ bool SetBaudRate(gcc_unused OperationEnvironment &env);
+
public:
LXNAVV7Device(Port &_port, unsigned _bulk_baud_rate)
: LXDevice::LXDevice(_port, _bulk_baud_rate)
@@ -48,6 +50,8 @@ class LXNAVV7Device: public LXDevice
OperationEnvironment &env);
virtual bool EnablePassThrough(OperationEnvironment &env);
+ virtual bool EnableNMEA(gcc_unused OperationEnvironment &env);
+
};
#endif
@@ -33,8 +33,70 @@ Copyright_License {
bool
LXNAVV7Device::EnablePassThrough(OperationEnvironment &env)
{
- return PortWriteNMEA(port, "PLXV0,CONNECTION,W,DIRECT*CS");
+ /* remember baud rate */
+ old_baud_rate = port.GetBaudrate();
+
+ return PortWriteNMEA(port, "PLXV0,CONNECTION,W,DIRECT");
}
// EnableNMEA from base class.
+
+bool
+LXNAVV7Device::SetBaudRate(gcc_unused OperationEnvironment &env)
+{
+ /* Set baud rate of device to current baud rate of port.
+
+ Currently, this seems non-sensical: if the V7 is reading at the
+ wrong baud rate, it won't read the instructions. If it is,
+ it doesn't need them. It may have a role when auto-bauding is enabled.
+ */
+
+ unsigned old_baud_rate = port.GetBaudrate();
+
+ /* translate baud rate into index for V7 */
+ int brc = 0;
+ unsigned int br[] = {4800,9600,19200,38400,57600,115200,230400,256000,460800,512000,1024000,0};
+ for (int i=0; br[i] > 0; i++)
+ if (br[i] == old_baud_rate)
+ {brc = i; break;}
+
+ char tmp[32];
+ sprintf(tmp, "PLXV0,BRPDA,W,%1d",brc);
+ PortWriteNMEA(port, tmp);
+ return true;
+}
+
+bool
+LXNAVV7Device::EnableNMEA(gcc_unused OperationEnvironment &env)
+{
+ {
+ ScopeLock protect(mutex);
+ if (mode == Mode::NMEA)
+ return true;
+
+ mode = Mode::NMEA;
+ busy = false;
+ }
+
+ if (old_baud_rate)
+ port.SetBaudrate(old_baud_rate);
+
+ /* in case the V7 is still in pass-through mode: */
+ PortWriteNMEA(port, "PLXV0,CONNECTION,W,VSEVEN");
+
+ SetBaudRate(env); /* inform V7 of the current baud rate (just in case) */
+
+ /* set NMEAs rate
+ PLXVF rate in Hz (20/10/5/2/1)
+ PLXVS rate
+ LXWP0 - 1/sec (often)
+ LXWP5 - 0 (what is this?)
+ */
+
+ PortWriteNMEA(port, "PLXV0,NMEARATE,W,5,10,1,2,10,0");
+
+ port.Flush();
+
+ return true;
+}
@@ -34,7 +34,6 @@ LXNAVV7CreateOnPort(const DeviceConfig &config, Port &com_port)
const struct DeviceRegister lxNavV7Device = {
_T("LXNAV"),
_T("LXNAV V7"),
- DeviceRegister::DECLARE | DeviceRegister::LOGGER |
DeviceRegister::PASS_THROUGH |
DeviceRegister::BULK_BAUD_RATE |
DeviceRegister::RECEIVE_SETTINGS | DeviceRegister::SEND_SETTINGS,

0 comments on commit 399546c

Please sign in to comment.