void Logging::periodicLog(unsigned long interval_ms) { while (ros::ok()) { sleepMS(interval_ms); log(); } }
QString Win_WindowManager::waitForTopLevelWindowImpl(unsigned /* count */, Q_PID pid, int timeOutMS, QString *errorMessage) { QTime elapsed; elapsed.start(); // First, wait until the application is up if (WaitForInputIdle(pid->hProcess, timeOutMS) != 0) { *errorMessage = QString::fromLatin1("WaitForInputIdle time out after %1ms").arg(timeOutMS); return QString(); } // Try to locate top level app window. App still might be in splash screen or initialization // phase. const int remainingMilliSeconds = qMax(timeOutMS - elapsed.elapsed(), 500); const int attempts = 10; const int intervalMilliSeconds = remainingMilliSeconds / attempts; for (int a = 0; a < attempts; a++) { FindProcessWindowEnumContext context(pid->dwProcessId); EnumWindows(findProcessWindowEnumWindowProc, reinterpret_cast<LPARAM>(&context)); if (context.window) return QLatin1String("0x") + QString::number(reinterpret_cast<quintptr>(context.window), 16); sleepMS(intervalMilliSeconds); } *errorMessage = QString::fromLatin1("Unable to find toplevel of process %1 after %2ms.").arg(pid->dwProcessId).arg(timeOutMS); return QString(); }
int main(int argc, char *argv[]) { // Try to change the value of `OPERATION_DELAY` and see how the behavior of this program changes. #ifndef NDEBUG const int OPERATION_DELAY(200); #else int OPERATION_DELAY; if (argc < 2) { OPERATION_DELAY = 200; } else { try { OPERATION_DELAY = std::stoi(argv[1]); } catch (...) { OPERATION_DELAY = 200; } } #endif std::unique_ptr<serial::Serial> serialPtr = nullptr; try { serialPtr = std::unique_ptr<serial::Serial>(new serial::Serial(GetDevicePort(), 576000)); } catch (const std::exception &e) { RETURN_ON_FAILURE(); } serial::Serial &serialPort = *serialPtr; std::function<void (std::uint8_t b0, std::uint8_t b1)> sendTwoBytesCommand = [&](std::uint8_t b0, std::uint8_t b1) { std::uint8_t command[] = {b0, b1}; if (serialPort.isOpen()) { serialPort.write(command, 2); } }; std::function<void ()> start = std::bind(sendTwoBytesCommand, 0xAA, 0xAA); std::function<void ()> stop = std::bind(sendTwoBytesCommand, 0xBB, 0xBB); std::function<void ()> getVer = std::bind(sendTwoBytesCommand, 0xCC, 0xCC); std::function<void ()> reopen = [&]() { serialPort.close(); serialPort.open(); if (serialPort.isOpen()) { std::uint8_t version[3] = {0}; try { // Send a command to get the version of our device getVer(); // Receive version information std::size_t len = serialPort.read(version, ARRAYSIZE(version)); if (len != ARRAYSIZE(version) || version[0] != 0x50) { serialPort.close(); } } catch (...) { serialPort.close(); } } }; while (true) { try { if (!serialPort.isOpen()) { putchar('.'); reopen(); // *** Important sleepMS(OPERATION_DELAY); } else { getVer(); std::uint8_t version[3]; std::size_t len = serialPort.read(version, ARRAYSIZE(version)); if (len == ARRAYSIZE(version) && version[0] == 0x50) { std::printf("%#02x %#02x %#02x\n", version[0], version[1], version[2]); } // *** Important sleepMS(OPERATION_DELAY); } } catch (...) { serialPort.close(); } } PAUSE(); return 0; }
void Logging::logUcPacketsSummary(unsigned long interval_ms) { #ifndef PERFORMANCE_LOGGING return; #endif #ifndef PERFORMANCE_LOGGING_UC_LINK_SUMMARY return; #endif while (ros::ok()) { sleepMS(interval_ms); string entry = getIntAsString(getMillisecondsTime()) + ","; { boost::unique_lock<boost::mutex> lock(Logging::mtx_logging); uint32_properties["num_total_frames_sent"] = 0; uint32_properties["num_total_frames_received"] = 0; } /* num_unique_data_frames_sent */ entry += getIntAsString(getProperty("num_unique_data_frames_sent")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_unique_data_frames_sent")); /* getProperty("num_unique_data_frames_forwarded*/ entry += getIntAsString(getProperty("num_unique_data_frames_forwarded")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_unique_data_frames_forwarded")); /* num_data_frames_resent*/ entry += getIntAsString(getProperty("num_data_frames_resent")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_data_frames_resent")); /* num_data_frames_reforwarded*/ entry += getIntAsString(getProperty("num_data_frames_reforwarded")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_data_frames_reforwarded")); /* num_data_frames_relayed*/ entry += getIntAsString(getProperty("num_data_frames_relayed")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_data_frames_relayed")); /*num_acknowledgments_sent */ entry += getIntAsString(getProperty("num_acknowledgments_sent")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_acknowledgments_sent")); /* getProperty("num_acknowledgments_relayed*/ entry += getIntAsString(getProperty("num_acknowledgments_relayed")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_acknowledgments_relayed")); /* num_rreq_sent*/ entry += getIntAsString(getProperty("num_rreq_sent")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_rreq_sent")); /* num_rrep_sent*/ entry += getIntAsString(getProperty("num_rrep_sent")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_rrep_sent")); /*num_beacons_sent */ entry += getIntAsString(getProperty("num_beacons_sent")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_beacons_sent")); /*num_relay_selection_sent */ entry += getIntAsString(getProperty("num_relay_selection_sent")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_relay_selection_sent")); /*num_relay_detection_sent */ entry += getIntAsString(getProperty("num_relay_detection_sent")) + ","; increaseProperty("num_total_frames_sent", getProperty("num_relay_detection_sent")); /*num_total_frames_sent */ entry += getIntAsString(getProperty("num_total_frames_sent")) + ","; // num_total_frames_received = 0; /*num_unique_data_frames_received_directly */ entry += getIntAsString(getProperty("num_unique_data_frames_received_directly")) + ","; /*num_unique_data_frames_received_relay */ increaseProperty("num_total_frames_received", getProperty("num_unique_data_frames_received_relay")); entry += getIntAsString(getProperty("num_unique_data_frames_received_relay")) + ","; /*num_data_frames_received_directly */ increaseProperty("num_total_frames_received", getProperty("num_data_frames_received_directly")); entry += getIntAsString(getProperty("num_data_frames_received_directly")) + ","; /*num_data_frames_received_relay */ increaseProperty("num_total_frames_received", getProperty("num_data_frames_received_relay")); entry += getIntAsString(getProperty("num_data_frames_received_relay")) + ","; /*num_acknowledgments_received_directly */ increaseProperty("num_total_frames_received", getProperty("num_acknowledgments_received_directly")); entry += getIntAsString(getProperty("num_acknowledgments_received_directly")) + ","; /*num_acknowledgments_received_relay */ increaseProperty("num_total_frames_received", getProperty("num_acknowledgments_received_relay")); entry += getIntAsString(getProperty("num_acknowledgments_received_relay")) + ","; /*num_rreq_received */ increaseProperty("num_total_frames_received", getProperty("num_rreq_received")); entry += getIntAsString(getProperty("num_rreq_received")) + ","; /*num_rrep_received */ increaseProperty("num_total_frames_received", getProperty("num_rrep_received")); entry += getIntAsString(getProperty("num_rrep_received")) + ","; /*num_relay_selection_received */ increaseProperty("num_total_frames_received", getProperty("num_relay_selection_received")); entry += getIntAsString(getProperty("num_relay_selection_received")) + ","; /*num_relay_detection_received */ increaseProperty("num_total_frames_received", getProperty("num_relay_detection_received")); entry += getIntAsString(getProperty("num_relay_detection_received")) + ","; /*num_duplicate_frames_received */ increaseProperty("num_total_frames_received", getProperty("num_duplicate_frames_received")); entry += getIntAsString(getProperty("num_duplicate_frames_received")) + ","; /*num_beacons_received */ increaseProperty("num_total_frames_received", getProperty("num_beacons_received")); entry += getIntAsString(getProperty("num_beacons_received")) + ","; /*um_total_frames_received */ entry += getIntAsString(getProperty("num_total_frames_received")) + ","; /*num_total_bytes_sent */ entry += getIntAsString(getProperty("num_total_bytes_sent")) + ","; /*num_total_bytes_received */ entry += getIntAsString(getProperty("num_total_bytes_received")) + ","; entries_uc_frames.push_back(entry); } }
void Logging::logMemoryConsumptionPackets(unsigned long interval_ms, boost::mutex* mtx_pack, list<Packet>* packets, boost::mutex* mtx_cached_mc, list<Packet>* cached_mc, boost::mutex* mtx_unack_link_frames, list<stc_frame>* unack_link_frames, boost::mutex* mtx_unack_cr_frames, list<ack_cr_info>* unack_cr_frames) { #ifndef PERFORMANCE_LOGGING return; #endif while (ros::ok()) { sleepMS(interval_ms); string entry = getIntAsString(getMillisecondsTime()) + ","; std::size_t size_uc_pack = 0, size_mc_pack = 0, size_cached_mc_packets = 0, size_unack_l_f = 0, size_unack_cr_f = 0; { /* size_cached_multicast_packets complete */ boost::unique_lock<boost::mutex> lock_g(*mtx_cached_mc); for (list<Packet>::iterator i = cached_mc->begin(); i != cached_mc->end(); i++) { size_cached_mc_packets += (*i).getSize(); } entry += getIntAsString(size_cached_mc_packets) + ","; } { /* size_multicast_packets_incomplete + size_unicast_packets_incomplete */ boost::unique_lock<boost::mutex> lock_g(*mtx_pack); for (list<Packet>::iterator i = packets->begin(); i != packets->end(); i++) { if ((*i).isMcFrame()) size_mc_pack += (*i).getSize(); else size_uc_pack += (*i).getSize(); } entry += getIntAsString(size_mc_pack) + ","; entry += getIntAsString(size_uc_pack) + ","; } { /* size unack link frames */ boost::unique_lock<boost::mutex> lock_g(*mtx_unack_link_frames); for (list<stc_frame>::iterator i = unack_link_frames->begin(); i != unack_link_frames->end(); i++) size_unack_l_f += sizeof (*i); entry += getIntAsString(size_unack_l_f) + ","; } { /* size unack cr frames */ boost::unique_lock<boost::mutex> lock_g(*mtx_unack_cr_frames); for (list<ack_cr_info>::iterator i = unack_cr_frames->begin(); i != unack_cr_frames->end(); i++) size_unack_cr_f += sizeof (*i); entry += getIntAsString(size_unack_cr_f) + ","; } entry += getIntAsString(getProperty("running_unicast_link_threads")) + ","; entry += getIntAsString(getProperty("running_multicast_threads")) + ","; entry += getIntAsString(getProperty("running_unicast_cr_threads")) + ","; entry += getIntAsString(getProperty("running_unicast_transport_threads")) + ","; entries_mem_consumption.push_back(entry); } }
void Logging::logMcPacketsSummary(unsigned long interval_ms) { #ifndef PERFORMANCE_LOGGING return; #endif #ifndef PERFORMANCE_LOGGING_MC_LINK_SUMMARY return; #endif while (ros::ok()) { sleepMS(interval_ms); string entry = getIntAsString(getMillisecondsTime()) + ","; /*num_mc_unique_data_frames_sent */ entry += getIntAsString(getProperty("num_mc_unique_data_frames_sent")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_unique_data_frames_sent")); /* num_mc_unique_data_frames_forwarded*/ entry += getIntAsString(getProperty("num_mc_unique_data_frames_forwarded")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_unique_data_frames_forwarded")); /* num_mc_data_frames_resent*/ entry += getIntAsString(getProperty("num_mc_data_frames_resent")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_data_frames_resent")); /* num_mc_data_frames_reforwarded*/ entry += getIntAsString(getProperty("num_mc_data_frames_reforwarded")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_data_frames_reforwarded")); /* num_mc_data_frames_relayed*/ entry += getIntAsString(getProperty("num_mc_data_frames_relayed")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_data_frames_relayed")); /*num_mc_acknowledgments_sent */ entry += getIntAsString(getProperty("num_mc_acknowledgments_sent")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_acknowledgments_sent")); /* num_mc_acknowledgments_relayed*/ entry += getIntAsString(getProperty("num_mc_acknowledgments_relayed")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_acknowledgments_relayed")); /* num_mc_rreq_sent*/ entry += getIntAsString(getProperty("num_mc_rreq_sent")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_rreq_sent")); /* num_mc_rrep_sent*/ entry += getIntAsString(getProperty("num_mc_rrep_sent")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_rrep_sent")); /*num_mc_ract_sent */ entry += getIntAsString(getProperty("num_mc_ract_sent")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_ract_sent")); /*num_mc_relay_selection_sent */ entry += getIntAsString(getProperty("num_mc_relay_selection_sent")) + ","; increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_relay_selection_sent")); /*num_mc_total_frames_sent */ entry += getIntAsString(getProperty("num_mc_total_frames_sent")) + ","; /*num_mc_unique_data_frames_received_directly */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_unique_data_frames_received_directly")); entry += getIntAsString(getProperty("num_mc_unique_data_frames_received_directly")) + ","; /*num_mc_unique_data_frames_received_relay */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_unique_data_frames_received_relay")); entry += getIntAsString(getProperty("num_mc_unique_data_frames_received_relay")) + ","; /*num_mc_data_frames_received_directly */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_data_frames_received_directly")); entry += getIntAsString(getProperty("num_mc_data_frames_received_directly")) + ","; /*num_mc_data_frames_received_relay */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_data_frames_received_relay")); entry += getIntAsString(getProperty("num_mc_data_frames_received_relay")) + ","; /*num_mc_acknowledgments_received_directly */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_acknowledgments_received_directly")); entry += getIntAsString(getProperty("num_mc_acknowledgments_received_directly")) + ","; /*num_mc_acknowledgments_received_relay */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_acknowledgments_received_relay")); entry += getIntAsString(getProperty("num_mc_acknowledgments_received_relay")) + ","; /*num_mc_rreq_received */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_rreq_received")); entry += getIntAsString(getProperty("num_mc_rreq_received")) + ","; /*num_mc_rrep_received */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_rrep_received")); entry += getIntAsString(getProperty("num_mc_rrep_received")) + ","; /*num_mc_ract_received */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_ract_received")); entry += getIntAsString(getProperty("num_mc_ract_received")) + ","; /*num_mc_relay_selection_received */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_relay_selection_received")); entry += getIntAsString(getProperty("num_mc_relay_selection_received")) + ","; /*num_mc_duplicate_frames_received */ increaseProperty("num_mc_total_frames_received", getProperty("num_mc_duplicate_frames_received")); entry += getIntAsString(getProperty("num_mc_duplicate_frames_received")) + ","; /*num_mc_total_frames_received */ entry += getIntAsString(getProperty("num_mc_total_frames_received")) + ","; /*num_mc_total_frames_received */ entry += getIntAsString(getProperty("num_mc_total_bytes_sent")) + ","; /*num_mc_total_frames_received */ entry += getIntAsString(getProperty("num_mc_total_bytes_received")) + ","; entries_mc_frames.push_back(entry); } }
void *Audio::Play2DProcess(void *data) { App *app = App::GetCurrent(); Play2DStruct *structData = (Play2DStruct *)data; Audio *audio = structData->audio; Thread *thread = structData->thread; delete structData; ALuint source; ALfloat timeS = GetBufferLength(audio->m_buffer); alGenSources(1, &source); if(alGetError() != AL_NO_ERROR) { error("[Error] alGenSources: Unable to generate an audio source.\n"); if(thread) { thread->End(); Thread::Exit(NULL); } return 0; } ALfloat listenerPosition [] = { 0.f, 0.f, 0.f }; ALfloat listenerVelocity [] = { 0.f, 0.f, 0.f }; ALfloat listenerOrientation [] = { 0.f, 0.f, -1.f, 0.f, 1.f, 0.f }; alListenerfv(AL_POSITION, listenerPosition); alListenerfv(AL_VELOCITY, listenerVelocity); alListenerfv(AL_ORIENTATION, listenerOrientation); ALfloat sourcePosition [] = { 0.f, 0.f, 0.f }; ALfloat sourceVelocity [] = { 0.f, 0.f, 0.f }; alSourcei(source, AL_BUFFER, audio->m_buffer); alSourcef(source, AL_PITCH, 1.0f); alSourcef(source, AL_GAIN, 1.0f); alSourcefv(source, AL_POSITION, sourcePosition); alSourcefv(source, AL_VELOCITY, sourceVelocity); alSourcei(source, AL_LOOPING, AL_FALSE); alSourcePlay(source); if(alGetError() != AL_NO_ERROR) { error("[Error] alSourcePlay: Unable to play audio.\n"); Thread::Exit(NULL); return 0; } unsigned long long timeMS = (unsigned long long)(timeS * 1000); unsigned long long targetTime = app->GetRunTimeMS() + timeMS + 50; while(app->IsRunning()) { if(app->GetRunTimeMS() > targetTime) break; sleepMS(100); } alDeleteSources(1, &source); if(thread) { thread->End(); Thread::Exit(NULL); } return 0; }