int main() { Init(); Config(); Start(); // Run this loop waiting for either motion detected, e.g., something triggering the robot to wake up, // or the PC has sent operational state configuration information, i.e., the robot is ready to do something // Note: Run this loop every 1 second so as to not overwhelm the serial port with junk. while (!MotionDetected() && !OpStateReceived()) { ProcessIncomingMessages(); CheckEnvironment(); SendStatusMessages(); pause(INIT_LOOP_WAIT_TIME); }; // We're ready to do something, enable odometry and sensors ENABLE_ODOM(); ENABLE_SENSORS(); // Run the main loop while (1) { ProcessIncomingMessages(); CheckEnvironment(); UpdateMotorSpeed(); SendStatusMessages(); } }
void ezPipeChannel_win::OnIOCompleted(IOContext* pContext, DWORD uiBytesTransfered, DWORD uiError) { EZ_ASSERT_DEBUG(m_ThreadId == ezThreadUtils::GetCurrentThreadID(), "Function must be called from worker thread!"); bool bRes = true; if (pContext == &m_InputState.Context) { if (!m_Connected) { if (!ProcessConnection()) return; bool bHasOutput = false; { EZ_LOCK(m_OutputQueueMutex); bHasOutput = !m_OutputQueue.IsEmpty(); } if (bHasOutput && m_OutputState.IsPending == 0) ProcessOutgoingMessages(0); if (m_InputState.IsPending) return; } bRes = ProcessIncomingMessages(uiBytesTransfered); } else { EZ_ASSERT_DEBUG(pContext == &m_OutputState.Context, ""); bRes = ProcessOutgoingMessages(uiBytesTransfered); } if (!bRes && m_PipeHandle != INVALID_HANDLE_VALUE) { InternalDisconnect(); } }
void Channel::OnIOCompleted( Thread::IOContext* context, DWORD bytes_transfered, DWORD error) { bool ok = true; //assert(thread_check_->CalledOnValidThread()); if (context == &input_state_.context) { if (waiting_connect_) { if (!ProcessConnection()) return; // We may have some messages queued up to send... if (!output_queue_.empty() && !output_state_.is_pending) ProcessOutgoingMessages(NULL, 0); if (input_state_.is_pending) return; // else, fall-through and look for incoming messages... } // We don't support recursion through OnMessageReceived yet! assert(!processing_incoming_); processing_incoming_ = true; // Process the new data. if (input_state_.is_pending) { // This is the normal case for everything except the initialization step. input_state_.is_pending = false; if (!bytes_transfered) ok = false; else if (pipe_ != INVALID_HANDLE_VALUE) ok = AsyncReadComplete(bytes_transfered); } else { assert(!bytes_transfered); } // Request more data. if (ok) ok = ProcessIncomingMessages(); processing_incoming_ = false; } else { assert(context == &output_state_.context); ok = ProcessOutgoingMessages(context, bytes_transfered); } if (!ok && INVALID_HANDLE_VALUE != pipe_) { // We don't want to re-enter Close(). Close(); listener()->OnChannelError(); } }