void MQTT::Do_Work() { bool bFirstTime=true; int msec_counter = 0; int sec_counter = 0; while (!m_stoprequested) { sleep_milliseconds(100); if (!bFirstTime) { int rc = loop(); if (rc) { if (rc != MOSQ_ERR_NO_CONN) { if (!m_stoprequested) { if (!m_bDoReconnect) { reconnect(); } } } } } msec_counter++; if (msec_counter == 10) { msec_counter = 0; sec_counter++; if (sec_counter % 12 == 0) { m_LastHeartbeat=mytime(NULL); } if (bFirstTime) { bFirstTime = false; ConnectInt(); } else { if (sec_counter % 30 == 0) { if (m_bDoReconnect) ConnectIntEx(); } } } } _log.Log(LOG_STATUS,"MQTT: Worker stopped..."); }
int main(int argc, char **argv) { double estimado, inicio, fim; int amostras; if (argc<2){ printf("Estimando pi com uma amostra de 1000000 de pontos\n"); amostras = 1000000; } else { amostras = atoi(argv[1]); printf("Estimando pi com uma amostra de %d pontos\n", amostras); } mytime(&inicio); //temporização da execução do método principal estimado = pi(amostras); mytime(&fim); printf("Estimativa do valor de pi = %lf\n",estimado); printf("Tempo de execucao = %lf s\n",fim-inicio); return 0; }
void CEcoDevices::Do_Work() { int LastMinute=-1; _log.Log(LOG_STATUS,"EcoDevices: Worker started..."); while (!m_stoprequested) { sleep_seconds(1); time_t atime=mytime(NULL); if (atime%ECODEVICES_POLL_INTERVAL == 0) { GetMeterDetails(); } if (atime % 12 == 0) { mytime(&m_LastHeartbeat); } } _log.Log(LOG_STATUS,"EcoDevices: Worker stopped..."); }
bool CNotificationHelper::CheckAndHandleValueNotification( const uint64_t Idx, const std::string &DeviceName, const int value) { std::vector<_tNotification> notifications = GetNotifications(Idx); if (notifications.size() == 0) return false; char szTmp[600]; std::string szExtraData = "|Name=" + DeviceName + "|"; time_t atime = mytime(NULL); //check if not sent 12 hours ago, and if applicable atime -= m_NotificationSensorInterval; std::string msg = ""; std::string notValue; std::string signvalue = Notification_Type_Desc(NTYPE_VALUE, 1); std::vector<_tNotification>::const_iterator itt; for (itt = notifications.begin(); itt != notifications.end(); ++itt) { if (itt->LastUpdate) TouchLastUpdate(itt->ID); if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true { std::vector<std::string> splitresults; StringSplit(itt->Params, ";", splitresults); if (splitresults.size() < 2) continue; //impossible std::string ntype = splitresults[0]; int svalue = static_cast<int>(atoi(splitresults[1].c_str())); if (ntype == signvalue) { if (value > svalue) { sprintf(szTmp, "%s is %d", DeviceName.c_str(), value); msg = szTmp; sprintf(szTmp, "%d", value); notValue = szTmp; if (!itt->CustomMessage.empty()) msg = ParseCustomMessage(itt->CustomMessage, DeviceName, notValue); SendMessageEx(Idx, DeviceName, itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true); TouchNotification(itt->ID); } } } } return true; }
CDomoticzHardwareBase::CDomoticzHardwareBase() { m_HwdID=0; //should be uniquely assigned m_bEnableReceive=false; m_rxbufferpos=0; m_SeqNr=0; m_pUserData=NULL; m_bIsStarted=false; m_stopHeartbeatrequested = false; mytime(&m_LastHeartbeat); mytime(&m_LastHeartbeatReceive); m_DataTimeout = 0; m_bSkipReceiveCheck = false; m_bOutputLog = true; m_iHBCounter = 0; m_baro_minuteCount = 0; m_last_forecast = wsbaroforcast_unknown; mytime(&m_BaroCalcLastTime); };
void CNestThermostat::Do_Work() { _log.Log(LOG_STATUS,"NestThermostat: Worker started..."); while (!m_stoprequested) { sleep_seconds(1); time_t atime=mytime(NULL); struct tm ltime; localtime_r(&atime,<ime); if (ltime.tm_min/NEST_POLL_INTERVAL!=m_LastMinute) { m_LastMinute=ltime.tm_min/NEST_POLL_INTERVAL; GetMeterDetails(); } if (ltime.tm_sec % 12 == 0) { mytime(&m_LastHeartbeat); } } _log.Log(LOG_STATUS,"NestThermostat: Worker stopped..."); }
void P1MeterSerial::Do_Work() { int secCounter = 0; while (!m_stoprequested) { sleep_milliseconds(200); if (m_stoprequested) break; secCounter++; if (secCounter == 5) { secCounter = 0; time_t atime = mytime(NULL); struct tm ltime; localtime_r(&atime, <ime); if (ltime.tm_sec % 12 == 0) { mytime(&m_LastHeartbeat); } } } }
void CPhilipsHue::Do_Work() { int LastSecond=-1; _log.Log(LOG_STATUS,"Philips Hue: Worker started..."); while (!m_stoprequested) { sleep_milliseconds(500); time_t atime=mytime(NULL); int tsec = atime%HUE_POLL_INTERVAL; if (((tsec == 0) && ((atime%60) != LastSecond)) || (LastSecond == -1)) { LastSecond = (atime % 60); GetLightStates(); mytime(&m_LastHeartbeat); } } _log.Log(LOG_STATUS,"Philips Hue: Worker stopped..."); }
void C1Wire::Do_Work() { time_t lastPollTime=mytime(NULL); GetDeviceDetails(); while (!m_stoprequested) { sleep_seconds(1); time_t atime = mytime(NULL); struct tm ltime; localtime_r(&atime, <ime); if (mytime(NULL)-lastPollTime>=Wire1_POLL_INTERVAL) { GetDeviceDetails(); lastPollTime=mytime(NULL); } if (ltime.tm_sec % 12 == 0) { mytime(&m_LastHeartbeat); } } }
void potion_garbagecollect(Potion *P, int sz, int full) { struct PNMemory *M = P->mem; if (M->collecting) return; #ifdef DEBUG double time = mytime(); #endif M->pass++; M->collecting = 1; if (M->old_lo == NULL) { int gensz = POTION_MIN_BIRTH_SIZE * 4; if (gensz < sz * 4) gensz = min(POTION_MAX_BIRTH_SIZE, PN_ALIGN(sz * 4, POTION_PAGESIZE)); void *page = pngc_page_new(&gensz, 0); if (page == NULL) { fprintf(stderr, "** Out of memory\n"); return; } SET_GEN(old, page, gensz); full = 0; } else if ((char *) M->old_cur + sz + potion_birth_suggest(sz, M->old_lo, M->old_cur) + ((char *) M->birth_hi - (char *) M->birth_lo) > (char *) M->old_hi) full = 1; #if POTION_GC_PERIOD>0 else if (M->pass % POTION_GC_PERIOD == POTION_GC_PERIOD) full = 1; #endif if (full) potion_gc_major(P, sz); else potion_gc_minor(P, sz); #ifdef DEBUG M->time += mytime() - time; #endif M->dirty = 0; M->collecting = 0; }
void CPVOutputInput::Do_Work() { int LastMinute=-1; _log.Log(LOG_STATUS,"PVOutput (Input): Worker started..."); while (!m_stoprequested) { sleep_seconds(1); time_t atime=mytime(NULL); struct tm ltime; localtime_r(&atime,<ime); if (((ltime.tm_min/PVOUTPUT_POLL_INTERVAL!=LastMinute))&&(ltime.tm_sec>20)) { LastMinute=ltime.tm_min/PVOUTPUT_POLL_INTERVAL; GetMeterDetails(); } if (ltime.tm_sec % 12 == 0) { mytime(&m_LastHeartbeat); } } _log.Log(LOG_STATUS,"PVOutput (Input): Worker stopped..."); }
void CLimitLess::Do_Work() { int sec_counter = 0; while (!m_stoprequested) { sleep_seconds(1); sec_counter++; if (sec_counter % 12 == 0) { m_LastHeartbeat=mytime(NULL); } } _log.Log(LOG_STATUS,"AppLamp: Worker stopped..."); }
void _tWindCalculationStruct::Init() { //clear buffer memset(&m_minute_counter,0,sizeof(m_minute_counter)); m_FirstMeasureTime=mytime(NULL); m_history_fifo.clear(); m_bHaveLastDirection=false; m_last_direction = 0; m_MaxSpeed = -1; m_MaxGust = -1; m_MinSpeed = -1; m_MinGust = -1; }
int main(){ FILE *fp; fp = fopen("numbers","r"); int i; uint64_t x; uint64_t position; uint64_t counter = 0; double time = mytime(); for (i = 0; i < pow(2,23); i++){ fscanf(fp, "%llu\n", (unsigned long long *) (&x)); int j; for (j = 0; j < 64; j++){ position = pow(2,j); if (position & x){ counter++; } } } time = mytime() -time; printf("Time for log2: %f counter: %llu\n", time/1000000, (unsigned long long) counter); fclose(fp); return 0; }
/// Ask the server to stop using asynchronous command void server_base::stop() { if (is_running) { // Post a call to the stop function so that server_base::stop() is safe to call from any thread. io_service_.post(boost::bind(&server_base::handle_stop, this)); } else { // if io_service is not running then the post call will not be performed handle_stop(); } // Wait for acceptor and connections to stop int timeout = 15; // force stop after 15 seconds time_t start = mytime(NULL); while(true) { if (!is_running && is_stop_complete) { break; } if ((mytime(NULL) - start) > timeout) { // timeout occurred break; } sleep_milliseconds(500); } }
CFitbit::CFitbit(const int ID, const std::string& username, const std::string& password) : m_username(CURLEncode::URLEncode(username)), m_password(CURLEncode::URLEncode(password)), m_clientId("12345"), m_clientSecret("123456789abcdef") { m_nextRefreshTs = mytime(NULL); m_isLogged = false; m_HwdID=ID; m_stoprequested=false; Init(); }
void MochadTCP::Do_Work() { bool bFirstTime = true; while (!m_stoprequested) { time_t atime = mytime(NULL); struct tm ltime; localtime_r(&atime, <ime); if (ltime.tm_sec % 12 == 0) { mytime(&m_LastHeartbeat); } if (bFirstTime) { bFirstTime = false; if (!mIsConnected) { m_rxbufferpos = 0; connect(m_szIPAddress, m_usIPPort); } } else { if ((m_bDoRestart) && (ltime.tm_sec % 30 == 0)) { _log.Log(LOG_STATUS, "Mochad: trying to connect to %s:%d", m_szIPAddress.c_str(), m_usIPPort); connect(m_szIPAddress, m_usIPPort); } sleep_milliseconds(40); update(); } } _log.Log(LOG_STATUS,"Mochad: TCP/IP Worker stopped..."); }
void CTE923::Do_Work() { time_t atime; while (!m_stoprequested) { sleep_seconds(1); atime = mytime(NULL); struct tm ltime; localtime_r(&atime, <ime); if (ltime.tm_sec % 12 == 0) { mytime(&m_LastHeartbeat); } if (atime-m_LastPollTime>=TE923_POLL_INTERVAL) { GetSensorDetails(); m_LastPollTime=mytime(NULL); } } _log.Log(LOG_STATUS,"TE923: Worker stopped..."); }
int main(int argc, char *argv[]) { int nc=1000000000; double t1, t2, dt, sum; t1 = mytime(0); sum = integrate(f1,0.0,1.0,nc); t1 = mytime(1); t2 = mytime(0); sum = integrate(f2,0.0,1.0,nc); t2 = mytime(1); dt = 1.0/dabs(t2-t1); printf("Time: %lf %lf sec Div. perf.: %le GFlops\n",t1,t2,dt); t1 = mytime(0); sum = integrate(f3,0.0,1.0,nc); t1 = mytime(1); t2 = mytime(0); sum = integrate(f4,0.0,1.0,nc); t2 = mytime(1); dt = 8.0/dabs(t2-t1); printf("Time: %lf %lf sec Mult. perf.: %le GFlops\n",t1,t2,dt); return 0; }
void CYouLess::Do_Work() { while (!m_stoprequested) { sleep_seconds(1); time_t atime = mytime(NULL); struct tm ltime; localtime_r(&atime, <ime); if (ltime.tm_sec % 12 == 0) { mytime(&m_LastHeartbeat); } m_PollCounter++; if (m_PollCounter>=YOULESS_POLL_INTERVAL) { GetMeterDetails(); m_PollCounter=0; } } _log.Log(LOG_STATUS,"YouLess: Worker stopped..."); }
void OTGWTCP::Do_Work() { bool bFirstTime=true; int sec_counter = 25; while (!m_stoprequested) { sleep_seconds(1); sec_counter++; if (sec_counter % 12 == 0) { m_LastHeartbeat=mytime(NULL); } if (bFirstTime) { bFirstTime=false; connect(m_szIPAddress,m_usIPPort); if (mIsConnected) { GetGatewayDetails(); } } else { if ((m_bDoRestart) && (sec_counter % 30 == 0)) { connect(m_szIPAddress,m_usIPPort); } update(); if (mIsConnected) { if ((sec_counter % 28 == 0) && (m_bRequestVersion)) { m_bRequestVersion = false; GetVersion(); } else if (sec_counter % 30 == 0)//updates every 30 seconds { bFirstTime=false; SendOutsideTemperature(); SendTime(); GetGatewayDetails(); } } } } _log.Log(LOG_STATUS,"OTGW: TCP/IP Worker stopped..."); }
bool CNotificationHelper::CheckAndHandleNotification( const uint64_t Idx, const std::string &devicename, const _eNotificationTypes ntype, const std::string &message) { std::vector<_tNotification> notifications = GetNotifications(Idx); if (notifications.size() == 0) return false; std::vector<std::vector<std::string> > result; result = m_sql.safe_query("SELECT SwitchType, CustomImage FROM DeviceStatus WHERE (ID=%" PRIu64 ")", Idx); if (result.size() == 0) return false; std::string szExtraData = "|Name=" + devicename + "|SwitchType=" + result[0][0] + "|CustomImage=" + result[0][1] + "|"; std::string notValue; time_t atime = mytime(NULL); //check if not sent 12 hours ago, and if applicable atime -= m_NotificationSensorInterval; std::string ltype = Notification_Type_Desc(ntype, 1); std::vector<_tNotification>::const_iterator itt; for (itt = notifications.begin(); itt != notifications.end(); ++itt) { if (itt->LastUpdate) TouchLastUpdate(itt->ID); std::vector<std::string> splitresults; StringSplit(itt->Params, ";", splitresults); if (splitresults.size() < 1) continue; //impossible std::string atype = splitresults[0]; if (atype == ltype) { if ((atime >= itt->LastSend) || (itt->SendAlways)) //emergency always goes true { std::string msg = message; if (!itt->CustomMessage.empty()) msg = ParseCustomMessage(itt->CustomMessage, devicename, notValue); SendMessageEx(Idx, devicename, itt->ActiveSystems, msg, msg, szExtraData, itt->Priority, std::string(""), true); TouchNotification(itt->ID); } } } return true; }
void OTGWSerial::Do_PollWork() { bool bFirstTime=true; int sec_counter = 25; while (!m_stoprequestedpoller) { sleep_seconds(1); sec_counter++; if (sec_counter % 12 == 0) { m_LastHeartbeat=mytime(NULL); } if (!isOpen()) { if (m_retrycntr==0) { _log.Log(LOG_STATUS,"OTGW: serial setup retry in %d seconds...", RETRY_DELAY); } m_retrycntr++; if (m_retrycntr>=RETRY_DELAY) { m_retrycntr=0; if (OpenSerialDevice()) { bFirstTime = true; } } } else { if ((sec_counter % 28 == 0) && (m_bRequestVersion)) { m_bRequestVersion = false; GetVersion(); } else if ((sec_counter % 30 == 0) || (bFirstTime)) //updates every 30 seconds { bFirstTime = false; SendOutsideTemperature(); SendTime(); GetGatewayDetails(); } } } _log.Log(LOG_STATUS,"OTGW: Worker stopped..."); }
void CWunderground::Do_Work() { while (!m_stoprequested) { sleep_seconds(1); time_t atime=mytime(NULL); struct tm ltime; localtime_r(&atime,<ime); if ((ltime.tm_min/10!=m_LastMinute)) { GetMeterDetails(); m_LastMinute=ltime.tm_min/10; } } _log.Log(LOG_NORM,"Wunderground Worker stopped..."); }
void OTGWBase::SendTime() { time_t atime = mytime(NULL); struct tm ltime; localtime_r(&atime, <ime); int lday = 0; if (ltime.tm_wday == 0) lday = 7; else lday = ltime.tm_wday; char szCmd[20]; sprintf(szCmd, "SC=%d:%02d/%d\r\n", ltime.tm_hour, ltime.tm_min, lday); WriteInt((const unsigned char*)&szCmd, strlen(szCmd)); }
void CJabloDongle::Do_Work() { int sec_counter=30-5; _log.Log(LOG_STATUS,"JabloDongle: Worker started..."); while (!m_stoprequested) { sleep_seconds(1); sec_counter++; if (sec_counter%12==0) { m_LastHeartbeat=mytime(NULL); } if (sec_counter%30==0) { //poll status } if(!isOpen()) { OpenSerialDevice(); if(ProbeDongle()) { m_stoprequested = true; } ReadSlots(); SendSwitchIfNotExists(0x1000000, SUBSWITCH_PGX, 0, false, 0, "PGX"); SendSwitchIfNotExists(0x1000000, SUBSWITCH_PGY, 0, false, 0, "PGY"); if(!SendSwitchIfNotExists(0x1000001, 0, 0, false, 0, "SIREN_LOUD")) { SetSwitchIcon(0x1000001, 0, 13); //Set wonderful red light icon in web gui } if(!SendSwitchIfNotExists(0x1000002, 0, 0, false, 0, "SIREN_BEEP")) { SetSwitchType(0x1000002, 0, STYPE_Dimmer); } if(!SendSwitchIfNotExists(0x1000003, 0, 0, false, 0, "ENROLL")) { SetSwitchIcon(0x1000003, 0, 9); } //add smoke detectors at startup (they are difficult to activate :-) ) for(std::vector<Ja_device*>::iterator i = slots.begin(); i != slots.end(); i++) { if((*i)->model == JDEV_JA85ST) { std::stringstream dev_desc; dev_desc << (*i)->ModelAsString() << "_" << std::setfill('0') << (*i)->id << "_SENSOR"; SendSwitchIfNotExists((*i)->id, SUBSWITCH_SENSOR, 0, false, 0, dev_desc.str()); } } } } _log.Log(LOG_STATUS,"JabloDongle: Worker stopped..."); }
void GSA::buildLCPs( const char *lcp_file, const char *mcp_file ) { double t0 = mytime(); SFA::buildLCP(); if ( verbose ) std::cout << "LCP created:" << mytime()-t0 << " sec\n"; t0 = mytime(); SFA::writeLCP( lcp_file ); if ( verbose ) std::cout << "LCP written & purged:" << mytime()-t0 << " sec\n"; t0 = mytime(); SFA::purgeDoc(); SFA::purgeSA(); if ( verbose ) std::cout << "Concatenated string & Suffix array written/purged:" << mytime()-t0 << " sec\n"; t0 = mytime(); SFA::buildMLCP(); if ( verbose ) std::cout << "lLCP/rLCP created:" << mytime()-t0 << " sec\n"; t0 = mytime(); SFA::writeMLCP( mcp_file ); SFA::purgeMLCP(); if ( verbose ) std::cout << "lLCP/rLCP written & purged:" << mytime()-t0 << " sec\n"; }
void CWunderground::Do_Work() { int sec_counter = 590; while (!m_stoprequested) { sleep_seconds(1); sec_counter++; if (sec_counter % 10 == 0) { m_LastHeartbeat=mytime(NULL); } if (sec_counter % 600 == 0) { GetMeterDetails(); } } _log.Log(LOG_STATUS,"Wunderground: Worker stopped..."); }
void CEcoDevices::Do_Work() { int sec_counter = 0; _log.Log(LOG_STATUS,"EcoDevices: Worker started..."); while (!m_stoprequested) { sleep_seconds(1); sec_counter++; if (sec_counter % 12 == 0) { mytime(&m_LastHeartbeat); } if (sec_counter%ECODEVICES_POLL_INTERVAL == 0) { GetMeterDetails(); } } _log.Log(LOG_STATUS,"EcoDevices: Worker stopped..."); }
void CThermosmart::Do_Work() { _log.Log(LOG_STATUS,"Thermosmart: Worker started..."); int sec_counter = THERMOSMART_POLL_INTERVAL-5; while (!m_stoprequested) { sleep_seconds(1); sec_counter++; if (sec_counter % 12 == 0) { m_LastHeartbeat=mytime(NULL); } if (sec_counter % THERMOSMART_POLL_INTERVAL == 0) { GetMeterDetails(); } } _log.Log(LOG_STATUS,"Thermosmart: Worker stopped..."); }