Пример #1
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Starts LX NMEA mode.
///
/// @param d           device descriptor
/// @param errBufSize  error message buffer size
/// @param errBuf[]    [out] error message
///
/// @retval true  mode successfully set
/// @retval false error (description in @p errBuf)
///
//static
bool DevLXNano::StartNMEAMode(PDeviceDescriptor_t d, unsigned errBufSize, TCHAR errBuf[])
{
  ComWrite(d, PKT_SYN, errBufSize, errBuf);
  ComExpect(d, PKT_ACK, 10, NULL, errBufSize, errBuf);

  ComWrite(d, PKT_SYN, errBufSize, errBuf);
  ComExpect(d, PKT_ACK, 10, NULL, errBufSize, errBuf);

  ComWrite(d, PKT_SYN, errBufSize, errBuf);
  ComExpect(d, PKT_ACK, 10, NULL, errBufSize, errBuf);

  // XCSoar:
  //if (!ComExpect(d, "$$$", 32, NULL, errBufSize, errBuf))
  //  return(false);

  return(true);
} // StartNMEAMode()
Пример #2
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Starts LX command mode.
///
/// @param d           device descriptor
/// @param errBufSize  error message buffer size
/// @param errBuf[]    [out] error message
///
/// @retval true  mode successfully set
/// @retval false error (description in @p errBuf)
///
//static
bool DevLXNano::StartCMDMode(PDeviceDescriptor_t d, unsigned errBufSize, TCHAR errBuf[])
{
  // we have to wait longer while enabling declaration phase because we have
  // to parse all NMEA sequences that are incomming before declaration mode
  // is enabled.
  ComWrite(d, PKT_SYN, errBufSize, errBuf);
  ComExpect(d, PKT_ACK, 512, NULL, errBufSize, errBuf);

  ComWrite(d, PKT_SYN, errBufSize, errBuf);
  ComExpect(d, PKT_ACK, 512, NULL, errBufSize, errBuf);

  ComWrite(d, PKT_SYN, errBufSize, errBuf);
  if (!ComExpect(d, PKT_ACK, 512, NULL, errBufSize, errBuf))
    return(false);

  return(true);
} // StartCMDMode()
Пример #3
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Writes competition class declaration into the device.
/// The CRC will be calculated before.
///
/// @param d           device descriptor
/// @param lxClass     competition class for device
/// @param errBufSize  error message buffer size
/// @param errBuf[]    [out] error message
///
/// @retval true  declaration successfully written
/// @retval false error (description in @p errBuf)
///
//static
bool DevLXNano::WriteClass(PDeviceDescriptor_t d, Class& lxClass, unsigned errBufSize, TCHAR errBuf[])
{
  byte buf[sizeof(Class)];

  int size = lxClass.ToStream(buf);

  bool status =      ComWrite(d, PKT_STX, errBufSize, errBuf);
  status = status && ComWrite(d, PKT_CCWRITE, errBufSize, errBuf);
  status = status && ComWrite(d, buf, size, errBufSize, errBuf);
  status = status && ComExpect(d, PKT_ACK, 10, NULL, errBufSize, errBuf);

  return(status);
} // WriteClass()
Пример #4
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Writes declaration into the device.
/// The CRC will be calculated before.
///
/// @param d           device descriptor
/// @param decl        task declaration data for device
/// @param errBufSize  error message buffer size
/// @param errBuf[]    [out] error message
///
/// @retval true  declaration successfully written
/// @retval false error (description in @p errBuf)
///
//static
bool DevLXNano::WriteDecl(PDeviceDescriptor_t d, Decl& decl, unsigned errBufSize, TCHAR errBuf[])
{
  byte buf[sizeof(Decl)];

  int size = decl.ToStream(buf);

  bool status =      ComWrite(d, PKT_STX, errBufSize, errBuf);
  status = status && ComWrite(d, PKT_PCWRITE, errBufSize, errBuf);
  status = status && ComWrite(d, buf, size, errBufSize, errBuf);
  status = status && ComExpect(d, PKT_ACK, 10, NULL, errBufSize, errBuf);

  return(status);
} // WriteDecl()
Пример #5
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Reads data from COM port and checks if they contain expected string.
/// Up to @p checkChars characters is read, then @c false is returned if
/// expected string has not been found.
///
/// If @p rxBuf <> @c NULL, all read characters are stored in the buffer.
/// It must be large enough to store up to @p checkChars.
///
/// @param d            device descriptor
/// @param expected     expected string
/// @param checkChars   maximum characters to read
/// @param rxBuf        [out] received data (up to checkChars)
/// @param errBufSize   error message buffer size
/// @param errBuf[]     [out] error message
///
/// @retval true  Rx thread started
/// @retval false error (description in @p errBuf)
///
//static
bool DevBase::ComExpect(PDeviceDescriptor_t d, const char* expected,
  int checkChars, void* rxBuf, unsigned errBufSize, TCHAR errBuf[])
{
  return(ComExpect(
    d, expected, strlen(expected), checkChars, rxBuf, errBufSize, errBuf));
} // ComExpect()