//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// 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()
/** * @brief Receives a message from the device * * @param d Device handle * @param errBufSize The size of the buffer for error string * @param errBuf The buffer for error string * @param extraTimeout Additional timeout to wait for the message * @param expectedPayloadSize Expected size of the message * * @return Pointer to a message structure if expected message was received or 0 otherwise */ const CDevIMI::TMsg *CDevIMI::Receive(PDeviceDescriptor_t d, unsigned errBufSize, TCHAR errBuf[], unsigned extraTimeout, unsigned expectedPayloadSize) { if(expectedPayloadSize > COMM_MAX_PAYLOAD_SIZE) expectedPayloadSize = COMM_MAX_PAYLOAD_SIZE; // set timeout unsigned baudRate = d->Com->GetBaudrate(); if(baudRate == 0U) { baudRate = 4800U; } unsigned timeout = extraTimeout + 10000 * (expectedPayloadSize + sizeof(IMICOMM_MSG_HEADER_SIZE) + 10) / baudRate; int orgTimeout; if(!SetRxTimeout(d, timeout, orgTimeout, errBufSize, errBuf)) return 0; // wait for the message const TMsg *msg = 0; timeout += GetTickCount(); while(GetTickCount() < timeout) { // read message IMIBYTE buffer[64]; IMIDWORD bytesRead = d->Com->Read(buffer, sizeof(buffer)); if(bytesRead == 0) continue; // parse message const TMsg *lastMsg = _parser.Parse(buffer, bytesRead); if(lastMsg) { // message received if(lastMsg->msgID == MSG_ACK_NOTCONFIG) { Disconnect(d, errBufSize, errBuf); } else if(lastMsg->msgID != MSG_CFG_KEEPCONFIG) { msg = lastMsg; } break; } } // restore timeout if(!SetRxTimeout(d, orgTimeout, orgTimeout, errBufSize, errBuf)) return 0; return msg; }
void AndroidIOIOUartPort::Run() { SetRxTimeout(500); while (!CheckStopped()) { int ch = helper->read(Java::GetEnv(), UartID); if (ch >= 0) { char ch2 = ch; handler.DataReceived(&ch2, sizeof(ch2)); } } }
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; }
void AndroidBluetoothPort::Run() { assert(helper != NULL); SetRxTimeout(500); JNIEnv *const env = Java::GetEnv(); while (!CheckStopped()) { int ch = helper->read(env); if (ch >= 0) ProcessChar(ch); } }
void AndroidBluetoothPort::Run() { assert(helper != NULL); SetRxTimeout(500); JNIEnv *const env = Java::GetEnv(); while (!CheckStopped()) { int ch = helper->read(env); if (ch >= 0) { char ch2 = ch; handler.DataReceived(&ch2, sizeof(ch2)); } } }
// 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; }
void SerialPort::Run() { assert(Thread::IsInside()); DWORD dwBytesTransferred; BYTE inbuf[1024]; // JMW added purging of port on open to prevent overflow Flush(); #ifndef _WIN32_WCE OverlappedEvent osStatus, osReader; if (!osStatus.Defined() || !osReader.Defined()) // error creating event; abort return; #endif // Specify a set of events to be monitored for the port. if (is_widcomm) SetRxTimeout(180); else { ::SetCommMask(hPort, EV_RXCHAR); SetRxTimeout(0); } while (!CheckStopped()) { #ifndef _WIN32_WCE WaitResult result = WaitDataPending(osStatus, INFINITE); switch (result) { case WaitResult::READY: break; case WaitResult::TIMEOUT: continue; case WaitResult::FAILED: case WaitResult::CANCELLED: ::Sleep(100); continue; } int nbytes = GetDataPending(); if (nbytes <= 0) { ::Sleep(100); continue; } // Start reading data if ((size_t)nbytes > sizeof(inbuf)) nbytes = sizeof(inbuf); if (!::ReadFile(hPort, inbuf, nbytes, &dwBytesTransferred, osReader.GetPointer())) { if (::GetLastError() != ERROR_IO_PENDING) { // Error in ReadFile() occured ::Sleep(100); continue; } if (osReader.Wait() != OverlappedEvent::FINISHED) { ::CancelIo(hPort); ::SetCommMask(hPort, 0); osReader.Wait(); continue; } if (!::GetOverlappedResult(hPort, osReader.GetPointer(), &dwBytesTransferred, FALSE)) continue; } #else if (is_widcomm) { /* WaitCommEvent() doesn't work with the Widcomm Bluetooth driver, it blocks for 11 seconds, regardless whether data is received. This workaround polls for input manually. Observed on an iPaq hx4700 with WM6. */ } else { // Wait for an event to occur for the port. DWORD dwCommModemStatus; if (!::WaitCommEvent(hPort, &dwCommModemStatus, 0)) { // error reading from port Sleep(100); continue; } if ((dwCommModemStatus & EV_RXCHAR) == 0) /* no data available */ continue; } // Read the data from the serial port. if (!ReadFile(hPort, inbuf, 1024, &dwBytesTransferred, NULL) || dwBytesTransferred == 0) { Sleep(100); continue; } #endif DataReceived(inbuf, dwBytesTransferred); } Flush(); }
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; }
bool SerialPort::Initialize() { TCHAR sysPortName[20]; DCB PortDCB; #if (WINDOWSPC>0) // Do not use COMn , use \\.\COMnn on PC version _stprintf(sysPortName, _T("\\\\.\\%s"), GetPortName()); #else // Do not use COMn , use COMn: on WinCE version _stprintf(sysPortName, _T("%s:"), GetPortName()); #endif StartupStore(_T(". ComPort %u Initialize <%s> speed=%u bit=%u %s"),GetPortIndex()+1,GetPortName(),_dwPortSpeed,8-_dwPortBit,NEWLINE); hPort = CreateFile(sysPortName, // 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) { DWORD dwError = GetLastError(); StartupStore(_T("... ComPort %u Init failed, error=%u%s"), GetPortIndex() + 1, dwError, NEWLINE); // 091117 StatusMessage(MB_OK, NULL, TEXT("%s %s"), gettext(TEXT("_@M762_")), GetPortName()); goto failed; } StartupStore(_T(". ComPort %u <%s> is now open%s"), GetPortIndex() + 1, GetPortName(), NEWLINE); PortDCB.DCBlength = sizeof (DCB); // Get the default port setting information. if (GetCommState(hPort, &PortDCB)==0) { StartupStore(_T("... ComPort %u GetCommState failed, error=%u%s"),GetPortIndex()+1,GetLastError(),NEWLINE); // @M759 = Unable to Change Settings on Port StatusMessage(MB_OK|MB_ICONINFORMATION, NULL, TEXT("%s %s"), gettext(TEXT("_@M759_")), GetPortName()); goto failed; } // 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; 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 = FALSE; 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)) { DWORD dwError = GetLastError(); StartupStore(_T("... ComPort %u Init <%s> change setting FAILED, error=%u%s"), GetPortIndex() + 1, GetPortName(), dwError, NEWLINE); // 091117 // @M759 = Unable to Change Settings on Port StatusMessage(MB_OK, TEXT("Error"), TEXT("%s %s"), gettext(TEXT("_@M759_")), GetPortName()); goto failed; } if (SetRxTimeout(RXTIMEOUT) == -1) { DWORD dwError = GetLastError(); StartupStore(_T("... ComPort %u Init <%s> change TimeOut FAILED, error=%u%s"), GetPortIndex() + 1, GetPortName(), dwError, NEWLINE); // 091117 // LKTOKEN _@M760_ = "Unable to Set Serial Port Timers" StatusMessage(MB_OK, TEXT("Error"), TEXT("%s %s"), gettext(TEXT("_@M760_")), GetPortName()); goto failed; } 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); if(!ComPort::Initialize()) { // no need to log failed of StartRxThread it's already made in ComPort::Initialize(); goto failed; } StartupStore(_T(". ComPort %u Init <%s> end OK%s"), GetPortIndex() + 1, GetPortName(), NEWLINE); return true; failed: if(hPort != INVALID_HANDLE_VALUE) { if (!CloseHandle(hPort)) { StartupStore(_T("... ComPort %u Init <%s> close failed, error=%u%s"),GetPortIndex() + 1, GetPortName(),NEWLINE); } else { StartupStore(_T("... ComPort %u Init <%s> closed%s"),GetPortIndex() + 1, GetPortName(),NEWLINE); } 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; }
bool JackNetMasterInterface::Init() { jack_log ( "JackNetMasterInterface::Init, ID %u.", fParams.fID ); session_params_t host_params; uint attempt = 0; int rx_bytes = 0; //socket if ( fSocket.NewSocket() == SOCKET_ERROR ) { jack_error ( "Can't create socket : %s", StrError ( NET_ERROR_CODE ) ); return false; } //timeout on receive (for init) if ( fSocket.SetTimeOut ( MASTER_INIT_TIMEOUT ) < 0 ) jack_error ( "Can't set timeout : %s", StrError ( NET_ERROR_CODE ) ); //connect if ( fSocket.Connect() == SOCKET_ERROR ) { jack_error ( "Can't connect : %s", StrError ( NET_ERROR_CODE ) ); return false; } //set the number of complete audio frames we can put in a packet SetFramesPerPacket(); //send 'SLAVE_SETUP' until 'START_MASTER' received jack_info ( "Sending parameters to %s ...", fParams.fSlaveNetName ); do { session_params_t net_params; memset(&net_params, 0, sizeof ( session_params_t )); SetPacketType ( &fParams, SLAVE_SETUP ); SessionParamsHToN(&fParams, &net_params); if ( fSocket.Send ( &net_params, sizeof ( session_params_t ), 0 ) == SOCKET_ERROR ) jack_error ( "Error in send : ", StrError ( NET_ERROR_CODE ) ); memset(&net_params, 0, sizeof ( session_params_t )); if ( ( ( rx_bytes = fSocket.Recv ( &net_params, sizeof ( session_params_t ), 0 ) ) == SOCKET_ERROR ) && ( fSocket.GetError() != NET_NO_DATA ) ) { jack_error ( "Problem with network." ); return false; } SessionParamsNToH(&net_params, &host_params); } while ( ( GetPacketType ( &host_params ) != START_MASTER ) && ( ++attempt < SLAVE_SETUP_RETRY ) ); if ( attempt == SLAVE_SETUP_RETRY ) { jack_error ( "Slave doesn't respond, exiting." ); return false; } //set the new timeout for the socket if ( SetRxTimeout() == SOCKET_ERROR ) { jack_error ( "Can't set rx timeout : %s", StrError ( NET_ERROR_CODE ) ); return false; } //set the new rx buffer size if ( SetNetBufferSize() == SOCKET_ERROR ) { jack_error ( "Can't set net buffer sizes : %s", StrError ( NET_ERROR_CODE ) ); return false; } return true; }
void SerialPort::Run() { assert(Thread::IsInside()); DWORD dwBytesTransferred; BYTE inbuf[1024]; // JMW added purging of port on open to prevent overflow Flush(); OverlappedEvent osStatus, osReader; if (!osStatus.Defined() || !osReader.Defined()) // error creating event; abort return; // Specify a set of events to be monitored for the port. ::SetCommMask(hPort, EV_RXCHAR); SetRxTimeout(0); while (!CheckStopped()) { WaitResult result = WaitDataPending(osStatus, INFINITE); switch (result) { case WaitResult::READY: break; case WaitResult::TIMEOUT: continue; case WaitResult::FAILED: case WaitResult::CANCELLED: ::Sleep(100); continue; } int nbytes = GetDataPending(); if (nbytes <= 0) { ::Sleep(100); continue; } // Start reading data if ((size_t)nbytes > sizeof(inbuf)) nbytes = sizeof(inbuf); if (!::ReadFile(hPort, inbuf, nbytes, &dwBytesTransferred, osReader.GetPointer())) { if (::GetLastError() != ERROR_IO_PENDING) { // Error in ReadFile() occured ::Sleep(100); continue; } if (osReader.Wait() != OverlappedEvent::FINISHED) { ::CancelIo(hPort); ::SetCommMask(hPort, 0); osReader.Wait(); continue; } if (!::GetOverlappedResult(hPort, osReader.GetPointer(), &dwBytesTransferred, FALSE)) continue; } DataReceived(inbuf, dwBytesTransferred); } Flush(); }
//////////////////////////////// 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); }