Пример #1
0
bool GpsIdPort::Initialize() {
    _hLoc = ::CreateEvent(NULL, FALSE, FALSE, NULL);
    _hState = ::CreateEvent(NULL, FALSE, FALSE, NULL);
    _hGPS = ::GPSOpenDevice(_hLoc, _hState, NULL, 0);
    if (0 == _hGPS) {
        StartupStore(_T("Unable to Open GPS Intermediate driver %s"), NEWLINE);    
        return false;
    }
    SetPortStatus(CPS_OPENOK);

    GPS_DEVICE dev = {0};
    GPSResetData(dev);
    GPSGetDeviceState(&dev);
    StartupStore(_T("GPSID : DeviceState: %lX, ServiceState: %lX%s"), dev.dwDeviceState, dev.dwServiceState, NEWLINE);
//    StartupStore(_T("GPSID : LastDataTime: %s%s"), dev.ftLastDataReceived, NEWLINE);
    StartupStore(_T("GPSID : DrvPrefix; %s%s"), dev.szGPSDriverPrefix, NEWLINE);
    StartupStore(_T("GPSID : MxPrefix %s%s"), dev.szGPSMultiplexPrefix, NEWLINE);
    StartupStore(_T("GPSID : Name:%s%s"), dev.szGPSFriendlyName, NEWLINE);

    if (!StartRxThread()) {
        StartupStore(_T(". ComPort %u <%s> Failed to start Rx Thread%s"), GetPortIndex() + 1, GetPortName(), NEWLINE);
        return false;
    }
    return true;
}
Пример #2
0
bool ComPort::Initialize() {
    if(!StartRxThread()) {
        StartupStore(_T(". ComPort %u <%s> Failed to start Rx Thread%s"), (unsigned)(GetPortIndex() + 1), GetPortName(), NEWLINE);
        return false;
    }
    return true;
}
Пример #3
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Writes declaration into the logger.
///
/// @param d           device descriptor to be installed
/// @param lkDecl      LK task declaration data
/// @param errBufSize  error message buffer size
/// @param errBuf[]    [out] error message
///
/// @retval true  declaration has been written successfully
/// @retval false error during declaration (description in @p errBuf)
///
//static
BOOL DevLXNano::DeclareTask(PDeviceDescriptor_t d,
  Declaration_t* lkDecl, unsigned errBufSize, TCHAR errBuf[])
{
  Decl  decl;
  Class lxClass;

  if (!FillFlight(*lkDecl, decl, errBufSize, errBuf))
    return(false);

  if (!FillTask(*lkDecl, decl, errBufSize, errBuf))
    return(false);

  // we will use text-defined class
  decl.flight.cmp_cls = Decl::cls_textdef;
  lxClass.SetName(lkDecl->CompetitionClass);

  // stop RX thread
  if (!StopRxThread(d, errBufSize, errBuf))
    return(false);

  // set new Rx timeout
  int  orgRxTimeout;
  bool status = SetRxTimeout(d, 2000, orgRxTimeout, errBufSize, errBuf);

  if (status)
  {
    ShowProgress(decl_enable);
    status = StartCMDMode(d, errBufSize, errBuf);

    if (status)
    {
      ShowProgress(decl_send);
      status = status && WriteDecl(d, decl, errBufSize, errBuf);
      status = status && WriteClass(d, lxClass, errBufSize, errBuf);
    }

    ShowProgress(decl_disable);
    // always do the following step otherwise NMEA will not be sent
    // (don't overwrite error descr)
    status = StartNMEAMode(d, status ? errBufSize : 0, errBuf) && status;

    // restore Rx timeout (we must try that always; don't overwrite error descr)
    status = SetRxTimeout(d, orgRxTimeout,
      orgRxTimeout, status ? errBufSize : 0, errBuf) && status;
  }

  // restart RX thread (we must try that always; don't overwrite error descr)
  status = StartRxThread(d, status ? errBufSize : 0, errBuf) && status;

  return(status);
} // DeclareTask()
Пример #4
0
BOOL CDevIMI::DeclareTask(PDeviceDescriptor_t d, Declaration_t *decl, unsigned errBufSize, TCHAR errBuf[])
{
  // verify WP number
  if(!CheckWPCount(*decl, 2, 13, errBufSize, errBuf))
    return false;
  
  // stop Rx thread
  if(!StopRxThread(d, errBufSize, errBuf))
    return false;
  
  // set new Rx timeout
  int orgRxTimeout;
  bool status = SetRxTimeout(d, 2000, orgRxTimeout, errBufSize, errBuf);
  if(status) {
    // connect to the device
    ShowProgress(decl_enable);
    status = Connect(d, errBufSize, errBuf);
    if(status) {
      // task declaration
      ShowProgress(decl_send);
      status = status && DeclarationWrite(d, *decl, errBufSize, errBuf);
    }
    
    // disconnect
    ShowProgress(decl_disable);
    status = Disconnect(d, status ? errBufSize : 0, errBuf) && status;
    
    // restore Rx timeout (we must try that always; don't overwrite error descr)
    status = SetRxTimeout(d, orgRxTimeout, orgRxTimeout, status ? errBufSize : 0, errBuf) && status;
  }
  
  // restart Rx thread
  status = StartRxThread(d, status ? errBufSize : 0, errBuf) && status;
  
  return status;
}
Пример #5
0
// Initialize is called from device  devInit, and dwPortNumber is passed along new threads
BOOL ComPort::Initialize(LPCTSTR lpszPortName, DWORD dwPortSpeed, DWORD dwPortBit, DWORD dwPortNumber)
{
  DWORD dwError;
  DCB PortDCB;
  TCHAR lkbuf[100];
  TCHAR lkPortName[10]; // 9 should be enough
  if (SIMMODE) return FALSE;

#if (WINDOWSPC>0)
  // Do not use anymore COMn: , use \\.\COMnn  on PC version
  if (lpszPortName) {
	_tcscpy(sPortName,_T("\\\\.\\")); // 091117
	_tcscat(sPortName, lpszPortName);
	_tcscpy(lkPortName, lpszPortName);
  }
#else
  if (lpszPortName) {
	_tcscpy(sPortName, lpszPortName);
	_tcscpy(lkPortName, lpszPortName);
  }
#endif

  StartupStore(_T(". ComPort %u Initialize <%s> speed=%u bit=%u %s"),dwPortNumber+1,lkPortName,dwPortSpeed,8-dwPortBit,NEWLINE);

  hPort = CreateFile(sPortName, // Pointer to the name of the port
                      GENERIC_READ | GENERIC_WRITE,
                                    // Access (read-write) mode
                      0,            // Share mode
                      NULL,         // Pointer to the security attribute
                      OPEN_EXISTING,// How to open the serial port
                      FILE_ATTRIBUTE_NORMAL,            // Port attributes
                      NULL);        // Handle to port with attribute
                                    // to copy

  if (hPort == INVALID_HANDLE_VALUE) {
	dwError = GetLastError();
	_stprintf(lkbuf,_T("... ComPort %u Init failed, error=%u%s"),dwPortNumber+1,dwError,NEWLINE); // 091117
	StartupStore(lkbuf);
	// LKTOKEN  _@M762_ = "Unable to open port" 
	ComPort_StatusMessage(MB_OK|MB_ICONINFORMATION, NULL, TEXT("%s %s"), gettext(TEXT("_@M762_")), lkPortName);
	return FALSE;
  }
  StartupStore(_T(". ComPort %u  <%s> is now open%s"),dwPortNumber+1,lkPortName,NEWLINE);

  PortDCB.DCBlength = sizeof(DCB);     

  // Get the default port setting information.
  if (GetCommState(hPort, &PortDCB)==0) {
	dwError = GetLastError();
	_stprintf(lkbuf,_T("... ComPort %u GetCommState failed, error=%u%s"),dwPortNumber+1,dwError,NEWLINE);
	StartupStore(lkbuf);
	// cannot set serial port timers. good anyway
	ComPort_StatusMessage(MB_OK|MB_ICONINFORMATION, NULL, TEXT("%s %s"), gettext(TEXT("_@M760_")), lkPortName);
	return FALSE;
  }

  // Change the DCB structure settings.
  PortDCB.BaudRate = dwPortSpeed;       // Current baud 
  PortDCB.fBinary = TRUE;               // Binary mode; no EOF check 
  PortDCB.fParity = TRUE;               // Enable parity checking  
  PortDCB.fOutxCtsFlow = FALSE;         // CTS output flow control: when TRUE, and CTS off, output suspended
  PortDCB.fOutxDsrFlow = FALSE;         // DSR output flow control 
  PortDCB.fDtrControl = DTR_CONTROL_ENABLE; 
                                        // DTR flow control type 
  PortDCB.fDsrSensitivity = FALSE;      // DSR sensitivity 
  PortDCB.fTXContinueOnXoff = TRUE;     // XOFF continues Tx 
  PortDCB.fOutX = FALSE;                // No XON/XOFF out flow control 
  PortDCB.fInX = FALSE;                 // No XON/XOFF in flow control 
  PortDCB.fErrorChar = FALSE;           // Disable error replacement 
  PortDCB.fNull = FALSE;                // Disable null removal
  PortDCB.fRtsControl = RTS_CONTROL_ENABLE; 
                                        // RTS flow control 

  PortDCB.fAbortOnError = TRUE;         // FALSE need something else to work
  switch(dwPortBit) {
	case bit7E1:
			PortDCB.ByteSize = 7;
			PortDCB.Parity = EVENPARITY; 
			break;
	case bit8N1:
	default:
			PortDCB.ByteSize = 8;
			PortDCB.Parity = NOPARITY; 
			break;
  }

  PortDCB.StopBits = ONESTOPBIT;

  PortDCB.EvtChar = '\n'; // wait for end of line, RXFLAG should detect it

  if (!SetCommState(hPort, &PortDCB)) {
	// Could not create the read thread.
	CloseHandle(hPort);
	hPort = INVALID_HANDLE_VALUE;
#if (WINDOWSPC>0) || NEWCOMM // 091206
	Sleep(2000); // needed for windows bug 101116 not verified
#endif
#if !(WINDOWSPC>0)
	if (PollingMode) Sleep(2000);
#endif
	// LKTOKEN  _@M759_ = "Unable to Change Settings on Port" 
	ComPort_StatusMessage(MB_OK, TEXT("Error"), TEXT("%s %s"), gettext(TEXT("_@M759_")), lkPortName);
	dwError = GetLastError();
	_stprintf(lkbuf,_T("... ComPort %u Init <%s> change setting FAILED, error=%u%s"),dwPortNumber+1,lkPortName,dwError,NEWLINE); // 091117
	StartupStore(lkbuf);
	return FALSE;
  }

  SetRxTimeout(RXTIMEOUT); 

  SetupComm(hPort, 1024, 1024);

  // Direct the port to perform extended functions SETDTR and SETRTS
  // SETDTR: Sends the DTR (data-terminal-ready) signal.
  // SETRTS: Sends the RTS (request-to-send) signal. 
  EscapeCommFunction(hPort, SETDTR);
  EscapeCommFunction(hPort, SETRTS);
  sportnumber=dwPortNumber; // 100210
  if (!StartRxThread()){
	_stprintf(lkbuf,_T("... ComPort %u Init <%s> StartRxThread failed%s"),dwPortNumber+1,lkPortName,NEWLINE);
	StartupStore(lkbuf);
	if (!CloseHandle(hPort)) {
		dwError = GetLastError();
		_stprintf(lkbuf,_T("... ComPort %u Init <%s> close failed, error=%u%s"),dwPortNumber+1,lkPortName,dwError,NEWLINE);
		StartupStore(lkbuf);
	} else {
		_stprintf(lkbuf,_T("... ComPort %u Init <%s> closed%s"),dwPortNumber+1,lkPortName,NEWLINE);
		StartupStore(lkbuf);
	}
	hPort = INVALID_HANDLE_VALUE;
#if (WINDOWSPC>0) || NEWCOMM // 091206
	Sleep(2000); // needed for windows bug
#endif
#if !(WINDOWSPC>0)
	if (PollingMode) Sleep(2000);
#endif

	return FALSE;
  }

  _stprintf(lkbuf,_T(". ComPort %u Init <%s> end OK%s"),dwPortNumber+1,lkPortName,NEWLINE);
  StartupStore(lkbuf);
  return TRUE;
}
Пример #6
0
BOOL CDevCAIGpsNav::DeclareTask(PDeviceDescriptor_t d, Declaration_t *decl, unsigned errBufSize, TCHAR errBuf[])
{
  // check requirements
  if(!CheckWPCount(*decl, 1, 9, errBufSize, errBuf))  /// @todo: check min number
    return false;

  // create a unique set of task waypoints
  CTaskWPSet wps;
  for(int i=0; i<decl->num_waypoints; i++)
    wps.insert(decl->waypoint[i]);

  // create a list of waypoint indexes in a task
  CTaskWPIdxArray task;
  for(int i=0; i<decl->num_waypoints; i++) {
    int j=0;
    for(CTaskWPSet::const_iterator it=wps.begin(), end=wps.end(); it!=end; ++it, j++)
      if(decl->waypoint[i] == *it)
        task.push_back(j);
  }

  const unsigned BUFF_LEN = 128;
  TCHAR buffer[BUFF_LEN];
  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1404_ = "Opening connection"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1404));
  CreateProgressDialog(buffer);

  // prepare communication
  if(!StopRxThread(d, errBufSize, errBuf))
    return false;
  int timeout;
  bool status = SetRxTimeout(d, 500, timeout, errBufSize, errBuf);

  if(status) {
    EmptyRXBuffer(d);
    status = CAICommandMode(d, errBufSize, errBuf);
  }

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1403_ = "Sending declaration"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1403));
  CreateProgressDialog(buffer);

  if(status) {
    int temptimeout;
    status = SetRxTimeout(d, 5000, temptimeout, errBufSize, errBuf);
  }

  if(status)
    status = WaypointsClear(d, errBufSize, errBuf);

  if(status)
    // enter CAI download mode
    status = CAIDownloadMode(d, errBufSize, errBuf);

  if(status)
    // upload waypoints
    status = WaypointsUpload(d, wps, errBufSize, errBuf);

  if(status)
    // upload task
    status = TaskUpload(d, task, errBufSize, errBuf);

  if(status)
    // upload pilot and glider data
    status = PilotAndGliderUpload(d, *decl, errBufSize, errBuf);

  // LKTOKEN  _@M1400_ = "Task declaration"
  // LKTOKEN  _@M1406_ = "Closing connection"
  _sntprintf(buffer, BUFF_LEN, _T("%s: %s..."), MsgToken(1400), MsgToken(1406));
  CreateProgressDialog(buffer);

  // restore NMEA mode
  status &= CAINMEAMode(d, errBufSize, errBuf);

  // restore regular communication
  status &= SetRxTimeout(d, timeout, timeout, errBufSize, errBuf);
  status &= StartRxThread(d, errBufSize, errBuf);

  return status;
}
Пример #7
0
////////////////////////////////   TASK    /////////////////////////////////////
BOOL DevLXMiniMap::DeclareTaskMinimap(PDeviceDescriptor_t d,
  Declaration_t* lkDecl, unsigned errBufSize, TCHAR errBuf[])
{
  Decl  decl;
  Class lxClass;



  if (!FillFlight(*lkDecl, decl, errBufSize, errBuf))
    return(false);

  if (!FillTask(*lkDecl, decl, errBufSize, errBuf))
    return(false);

  // we will use text-defined class
  decl.flight.cmp_cls = Decl::cls_textdef;
  lxClass.SetName(lkDecl->CompetitionClass);

  // stop RX thread
  if (!StopRxThread(d, errBufSize, errBuf))
    return(false);

  // set new Rx timeout
  int  orgRxTimeout;
  bool status = SetRxTimeout(d, 2000, orgRxTimeout, errBufSize, errBuf);

  if (status)
  {
	  devWriteNMEAString(d,TEXT("PFLX0,COLIBRI") );

	 Sleep(100);


	 d->Com->SetBaudrate(4800);
	 d->Com->SetRxTimeout(2000);

    ShowProgress(decl_enable);
    status = StartCMDMode(d, errBufSize, errBuf);

    if(status == false)
    {
   	  d->Com->SetBaudrate(9600);
   	  d->Com->SetRxTimeout(2000);
      status = StartCMDMode(d, errBufSize, errBuf);
    }
    if(status == false)
    {
   	  d->Com->SetBaudrate(19200);
   	  d->Com->SetRxTimeout(2000);
      status = StartCMDMode(d, errBufSize, errBuf);
    }
    if(status == false)
    {
   	  d->Com->SetBaudrate(38400);
   	  d->Com->SetRxTimeout(2000);
      status = StartCMDMode(d, errBufSize, errBuf);
    }



    if (status)
    {
      ShowProgress(decl_send);
      status = status && WriteDecl(d, decl, errBufSize, errBuf);
      status = status && WriteClass(d, lxClass, errBufSize, errBuf);
    }

    ShowProgress(decl_disable);
    // always do the following step otherwise NMEA will not be sent
    // (don't overwrite error descr)
    status = StartNMEAMode(d, status ? errBufSize : 0, errBuf) && status;


	 d->Com->SetBaudrate(4800);
	 devWriteNMEAString(d,TEXT("PFLX0,LX160") );

	 d->Com->SetBaudrate(38400);


    // restore Rx timeout (we must try that always; don't overwrite error descr)
    status = SetRxTimeout(d, orgRxTimeout,
      orgRxTimeout, status ? errBufSize : 0, errBuf) && status;
  }

  // restart RX thread (we must try that always; don't overwrite error descr)
  status = StartRxThread(d, status ? errBufSize : 0, errBuf) && status;

  return(status);
}