void CConnectedPeersDlg::ConnectedPeers(const set<Peer> *pConnectedPeers) { if( pConnectedPeers != NULL ) { int nIndex; IPPort ip; m_peerList.DeleteAllItems(); for( set<Peer>::const_iterator iter = pConnectedPeers->begin(); iter != pConnectedPeers->end(); iter++ ) { ip.SetIP( iter->GetIP() ); ip.SetPort( iter->GetPort() ); nIndex = m_peerList.InsertItem( 0, ip.ToString().c_str() ); if( nIndex == -1 ) { continue; } m_peerList.SetItemText( nIndex, 1, ( iter->IsComplete() ? "true" : "false" ) ); m_peerList.SetItemText( nIndex, 2, ( iter->IsMD() ? "true" : "false" ) ); static char aListBuf[32]; CTimeSpan timeSpan( iter->SecondsSinceLastSeen() ); m_peerList.SetItemText( nIndex, 3, timeSpan.Format( "%D days, %H:%M:%S ago" ) ); } delete pConnectedPeers; } }
CTimeSpan timeSpan (const CTimeDate &StartTime, const CTimeDate &EndTime) // timeSpan // // Returns the difference between the two times { int iDays = EndTime.DaysSince1AD() - StartTime.DaysSince1AD(); if (iDays < 0) return timeSpan(EndTime, StartTime); int iStartTime = StartTime.MillisecondsSinceMidnight(); int iEndTime = EndTime.MillisecondsSinceMidnight(); int iMilliseconds = 0; if (iEndTime > iStartTime) { iMilliseconds = iEndTime - iStartTime; } else { if (iDays > 0) { iDays--; iMilliseconds = (iEndTime + SECONDS_PER_DAY * 1000) - iStartTime; } else iMilliseconds = iStartTime - iEndTime; } return CTimeSpan(iDays, iMilliseconds); }
wxTimeSpan CReminderDialog::GetTimeSpan(int weeks, int days, int hours, int minutes) { if(weeks > 0 && days > 0) hours += (days*24) + (weeks*24*7); else if(weeks > 0) hours += (weeks*24*7); else if(days > 0) hours += (days*24); wxTimeSpan timeSpan(hours, minutes); return timeSpan; }
ALERROR CUniverse::InitImages (SDesignLoadCtx &Ctx, CXMLElement *pImages, CResourceDb &Resources) // InitImages // // Loads all images { ALERROR error; // Nothing to do if we don't want to load resources if (Ctx.bNoResources) return NOERROR; // Figure out if we've got a special folder for the images CString sRoot = pImages->GetAttribute(FOLDER_ATTRIB); Ctx.sFolder = sRoot; #ifdef DEBUG_TIME_IMAGE_LOAD CTimeDate StartTime(CTimeDate::Now); #endif // Load all images for (int i = 0; i < pImages->GetContentElementCount(); i++) { CXMLElement *pItem = pImages->GetContentElement(i); if (error = LoadImage(Ctx, pItem)) return error; } // Restore folder Ctx.sFolder = NULL_STR; #ifdef DEBUG_TIME_IMAGE_LOAD { CTimeDate StopTime(CTimeDate::Now); CTimeSpan Timing = timeSpan(StartTime, StopTime); CString sTime = Timing.Format(CString()); kernelSetDebugLog("Time to load images: "); kernelSetDebugLog(sTime.GetASCIIZPointer()); kernelSetDebugLog("\n"); } #endif return NOERROR; }
void wxNetworkRestartDialog::OnTimer() { switch(mpImpl->mMode) { case ModeFinalCountdown: { // See how much time has passed. unsigned long milliseconds = mpImpl->mStopWatch.Time(); wxTimeSpan timeSpan(0, 0, 0, ((FINAL_SECONDS + 1) * 1000) - milliseconds); wxString str = wxString::Format(mpImpl->mRestart ? stTheGameWillRestartIn.c_str() : stTheGameWillStartIn.c_str(), timeSpan.GetSeconds().GetValue()); spText->SetLabel(str); // Only the host can make the final call. if( (true == NET.Players().IsHost() && (FINAL_SECONDS * 1000) < milliseconds) ) { RULE.Execute(shNetworkRuleAllSeatsFull, DataObject()); } } break; case ModePlayerCountdown: { // Only countdown if we're not starting a new online game. if(true == mpImpl->mRestart) { // Tick off one second from the time span for the player. RULE.AsynchExecute(shNetworkRuleTickCountdown, DataObject()); } } break; default: { wxString str = mpImpl->mRestart ? stWaitingForPlayersToRejoin : stWaitingForPlayersToJoin ; spText->SetLabel(str); } break; } }
BOOL CDevByFileDlg::OnInitDialog() { CDialog::OnInitDialog(); g_SetWndStaticText(this); // TODO: Add extra initialization here m_ctlRecordInfo.SetExtendedStyle(m_ctlRecordInfo.GetExtendedStyle() | LVS_EX_HEADERDRAGDROP | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); m_ctlRecordInfo.InsertColumn(0, ConvertString("ID"), LVCFMT_LEFT, 50, -1); m_ctlRecordInfo.InsertColumn(1, ConvertString("size"), LVCFMT_LEFT, 60, 0); m_ctlRecordInfo.InsertColumn(2, ConvertString("Start time"), LVCFMT_LEFT, 150, 1); m_ctlRecordInfo.InsertColumn(3, ConvertString("End time"), LVCFMT_LEFT, 150, 2); CString strText = ""; int nIndex = 0; for (int i = 0; i < m_nChannelNum; i++) { strText.Format("%d", i); nIndex = m_ctlChannel.AddString(strText); m_ctlChannel.SetItemData(nIndex, i); } m_ctlChannel.SetCurSel(0); nIndex = m_ctlType.AddString(ConvertString("All record")); m_ctlType.SetItemData(nIndex, 0); nIndex = m_ctlType.AddString(ConvertString("Alarm record")); m_ctlType.SetItemData(nIndex, 3); m_ctlType.SetCurSel(0); CTimeSpan timeSpan(1,0,0,0); CTime curTime = CTime::GetCurrentTime(); CTime dateFrom = curTime - timeSpan; m_dateFrom.SetDateTime(dateFrom.GetYear(), dateFrom.GetMonth(), dateFrom.GetDay(), dateFrom.GetHour(), dateFrom.GetMinute(), dateFrom.GetSecond()); m_timeFrom = curTime; m_dateTo.SetDateTime(curTime.GetYear(), curTime.GetMonth(), curTime.GetDay(), curTime.GetHour(), curTime.GetMinute(), curTime.GetSecond()); m_timeTo = curTime; UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
BOOL CPlaybackByTime::OnInitDialog() { CDialog::OnInitDialog(); g_SetWndStaticText(this); // TODO: Add extra initialization here //Set current time CTimeSpan timeSpan(1,0,0,0); CTime curTime = CTime::GetCurrentTime(); CTime dateFrom = curTime - timeSpan; m_dateFrom.SetDateTime(dateFrom.GetYear(), dateFrom.GetMonth(), dateFrom.GetDay(), dateFrom.GetHour(), dateFrom.GetMinute(), dateFrom.GetSecond()); m_timeFrom = curTime; m_dateTo.SetDateTime(curTime.GetYear(), curTime.GetMonth(), curTime.GetDay(), curTime.GetHour(), curTime.GetMinute(), curTime.GetSecond()); m_timeTo = curTime; CTime dateLoadFrom = curTime - timeSpan; m_dateLoadFrom.SetDateTime(dateLoadFrom.GetYear(), dateLoadFrom.GetMonth(), dateLoadFrom.GetDay(), dateLoadFrom.GetHour(), dateLoadFrom.GetMinute(), dateLoadFrom.GetSecond()); m_timeLoadFrom = curTime; m_dateLoadTo.SetDateTime(curTime.GetYear(), curTime.GetMonth(), curTime.GetDay(), curTime.GetHour(), curTime.GetMinute(), curTime.GetSecond()); m_timeLoadTo = curTime; m_ctlPlayMode.ResetContent(); int nIndex = m_ctlPlayMode.AddString( ConvertString("direct")); m_ctlPlayMode.SetItemData(nIndex,EM_DIRECTMODE); nIndex = m_ctlPlayMode.AddString(ConvertString("callback")); m_ctlPlayMode.SetItemData(nIndex,EM_SERVERMODE); m_ctlPlayMode.SetCurSel(0); m_ctlLoadPro.SetRange32(0,(int)(m_dwTotalSize/100)); m_ctlLoadPro.SetPos(0); m_nTimer = SetTimer(1, 500, NULL); UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
bool CUserInfoSession::OnProcessMessage (const SArchonMessage &Msg) // OnProcessMessage // // We received a reply from Aeon { int i; // If this is an error, then we return the error back to the client if (IsError(Msg)) { SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, Msg.dPayload); return false; } // If we're waiting for the user record, then see if we can process it now. if (m_iState == stateWaitingForUserRecord) { // Cryptosaur.getUser if (strEquals(GetOriginalMsg().sMsg, MSG_CRYPTOSAUR_GET_USER)) { CDatum dUserData = Msg.dPayload; // If the user does not exist, then we return Nil if (dUserData.IsNil()) { SendMessageReply(MSG_REPLY_DATA, CDatum()); return false; } // Generate a sanitized user record CComplexStruct *pReply = new CComplexStruct; pReply->SetElement(FIELD_USERNAME, dUserData.GetElement(FIELD_USERNAME)); // Sanitize rights CDatum dRights = dUserData.GetElement(FIELD_RIGHTS); if (!m_sScope.IsEmpty()) { CComplexArray *pRights = new CComplexArray; for (i = 0; i < dRights.GetCount(); i++) if (strStartsWith(dRights.GetElement(i), m_sScope)) pRights->Insert(dRights.GetElement(i)); pReply->SetElement(FIELD_RIGHTS, CDatum(pRights)); } else pReply->SetElement(FIELD_RIGHTS, dRights); // Done SendMessageReply(MSG_REPLY_DATA, CDatum(pReply)); return false; } // If we get back nil then the user does not exist. else if (Msg.dPayload.IsNil()) { SendMessageReplyError(MSG_ERROR_DOES_NOT_EXIST, strPattern(ERR_UNKNOWN_USERNAME, m_sUsername)); return false; } // Otherwise, we handle the result based on the original message else if (strEquals(GetOriginalMsg().sMsg, MSG_CRYPTOSAUR_CHECK_PASSWORD_SHA1)) { // Get the parameters from the original message CDatum dChallenge = GetOriginalMsg().dPayload.GetElement(1); CDatum dResponse = GetOriginalMsg().dPayload.GetElement(2); // Get the password has from the response CDatum dAuthDesc = Msg.dPayload.GetElement(FIELD_AUTH_DESC); CDatum dPasswordHash = dAuthDesc.GetElement(FIELD_CREDENTIALS); // Create a response to the challenge based on the password hash that // we have stored. CDatum dCorrect = CAI1Protocol::CreateSHAPasswordChallengeResponse(dPasswordHash, dChallenge); // Compare the correct response to the actual if ((const CIPInteger &)dResponse == (const CIPInteger &)dCorrect) return UpdateLoginSuccess(stateWaitingForSuccessUpdate); else return UpdateLoginFailure(); } // Cryptosaur.hasRights else if (strEquals(GetOriginalMsg().sMsg, MSG_CRYPTOSAUR_HAS_RIGHTS)) { CDatum dRights = Msg.dPayload.GetElement(FIELD_RIGHTS); CDatum dRightsRequired = m_dPayload.GetElement(1); // Get the rights from the user CAttributeList Rights; dRights.AsAttributeList(&Rights); // Check for (i = 0; i < dRightsRequired.GetCount(); i++) { if (!Rights.HasAttribute(dRightsRequired.GetElement(i))) { SendMessageReply(MSG_REPLY_DATA, CDatum()); return false; } } // We have all rights SendMessageReply(MSG_REPLY_DATA, CDatum(CDatum::constTrue)); return false; } // Cryptosaur.loginUser else if (strEquals(GetOriginalMsg().sMsg, MSG_CRYPTOSAUR_LOGIN_USER)) { // Get the parameters from the original message CDatum dRequestAuthDesc = GetOriginalMsg().dPayload.GetElement(1); CDatum dCredentials = dRequestAuthDesc.GetElement(FIELD_CREDENTIALS); CDatum dChallengeCredentials = dRequestAuthDesc.GetElement(FIELD_CHALLENGE_CREDENTIALS); CDatum dPassword = dRequestAuthDesc.GetElement(FIELD_PASSWORD); m_bActual = !dRequestAuthDesc.GetElement(FIELD_ACTUAL).IsNil(); if (!dRequestAuthDesc.GetElement(FIELD_AUTH_TOKEN_INFINITE).IsNil()) m_dwAuthTokenLifetime = 0; else { m_dwAuthTokenLifetime = (DWORD)(int)dRequestAuthDesc.GetElement(FIELD_AUTH_TOKEN_LIFETIME); if (m_dwAuthTokenLifetime == 0) m_dwAuthTokenLifetime = DEFAULT_AUTH_TOKEN_TIMEOUT; } // If we're not actual and have no scope, then we can't continue if (!m_bActual && m_sScope.IsEmpty()) { SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, ERR_SCOPE_REQUIRED); return false; } // User data CDatum dUserData = Msg.dPayload; CDatum dAuthDesc; if (m_bActual) dAuthDesc = dUserData.GetElement(FIELD_AUTH_DESC); else dAuthDesc = dUserData.GetElement(strPattern("%s%s", m_sScope, FIELD_AUTH_DESC)); // If we have no authdesc, then we can't continue. This is likely // because the client is in a sandbox that the user has not registered // with. We treat it the same as a username/password failure. if (dAuthDesc.IsNil()) { SendMessageReplyError(MSG_ERROR_DOES_NOT_EXIST, ERR_INVALID_USERNAME_OR_PASSWORD); return false; } // If we've failed more than 5 consecutive times, we may need to delay // the next login attempt. if ((int)dUserData.GetElement(FIELD_LOGIN_FAILURE_COUNT) > MAX_LOGIN_ATTEMPTS) { CDateTime LastLoginFailure = dUserData.GetElement(FIELD_LAST_LOGIN_FAILURE_ON); CTimeSpan TimeSinceLastFailure = timeSpan(LastLoginFailure, CDateTime(CDateTime::Now)); // If it has not been at least 1 hour, we return an error. if (TimeSinceLastFailure.Days() == 0 && TimeSinceLastFailure.Seconds() < LOGIN_TIMEOUT) { // Timeout SendMessageReplyError(MSG_ERROR_DOES_NOT_EXIST, ERR_FAILURE_TIMEOUT); return false; } } // If we have straight credentials, then just compare bool bSuccess; if (!dCredentials.IsNil()) bSuccess = ((const CIPInteger &)dCredentials == (const CIPInteger &)dAuthDesc.GetElement(FIELD_CREDENTIALS)); // Otherwise, we compare against the challenge else if (!dChallengeCredentials.IsNil()) { // Get the challenge. If not provided then we get it from the user // record. CDatum dChallenge = GetOriginalMsg().dPayload.GetElement(2); if (dChallenge.IsNil()) { // Get the expiration time of the challenge const CDateTime &Expires = dAuthDesc.GetElement(FIELD_CHALLENGE_EXPIRATION); if (Expires < CDateTime(CDateTime::Now)) { SendMessageReplyError(MSG_ERROR_DOES_NOT_EXIST, ERR_INVALID_USERNAME_OR_PASSWORD); return false; } dChallenge = dAuthDesc.GetElement(FIELD_CHALLENGE); } // Create a response to the challenge based on the password hash that // we have stored. CDatum dCorrectChallenge = CAI1Protocol::CreateSHAPasswordChallengeResponse( dAuthDesc.GetElement(FIELD_CREDENTIALS), dChallenge ); bSuccess = ((const CIPInteger &)dChallengeCredentials == (const CIPInteger &)dCorrectChallenge); } // Otherwise we expect a clear text password else if (!dPassword.IsNil()) { // We have to hash the password to compare with credentials. CIPInteger Credentials; CCryptosaurInterface::CreateCredentials(dUserData.GetElement(FIELD_USERNAME), dPassword, &Credentials); // Compare bSuccess = (Credentials == (const CIPInteger &)dAuthDesc.GetElement(FIELD_CREDENTIALS)); } else bSuccess = false; // Success or failure if (bSuccess) return UpdateLoginSuccess(stateWaitingForCredentials); else return UpdateLoginFailure(); } // Can never get here. else { ASSERT(false); return false; } } // Otherwise, if we're waiting for the user record update, then continue else if (m_iState == stateWaitingForSuccessUpdate) { // Since we succeeded, we send the user sanitized user record back. SendMessageReply(MSG_REPLY_DATA, CreateSanitizedUserRecord(Msg.dPayload)); return false; } // If we're waiting for credentials, compose them else if (m_iState == stateWaitingForCredentials) { // The mutation returns the full record CDatum dUserData = Msg.dPayload; // Compute the result CComplexStruct *pAuthToken = new CComplexStruct; pAuthToken->SetElement(FIELD_USERNAME, dUserData.GetElement(FIELD_USERNAME)); pAuthToken->SetElement(FIELD_RIGHTS, dUserData.GetElement(FIELD_RIGHTS)); if (!m_bActual) pAuthToken->SetElement(FIELD_SCOPE, m_sScope); CDatum dAuthToken = m_pEngine->GenerateAuthToken(CDatum(pAuthToken), m_dwAuthTokenLifetime); // Compose a basic user record CComplexStruct *pReply = new CComplexStruct; pReply->SetElement(FIELD_AUTH_TOKEN, dAuthToken); pReply->SetElement(FIELD_RIGHTS, dUserData.GetElement(FIELD_RIGHTS)); pReply->SetElement(FIELD_USERNAME, dUserData.GetElement(FIELD_USERNAME)); // Send the reply SendMessageReply(MSG_REPLY_DATA, CDatum(pReply)); // Done return false; } // Otherwise, failure else if (m_iState == stateWaitingForFailureUpdate) { CDatum dUserData = Msg.dPayload; // If we've exceeded our limit, log it int iAttempts = (int)dUserData.GetElement(FIELD_LOGIN_FAILURE_COUNT); if (iAttempts > MAX_LOGIN_ATTEMPTS) GetProcessCtx()->Log(MSG_LOG_INFO, strPattern(ERR_USERNAME_TIMEOUT, m_sUsername, iAttempts)); // Send a failure SendMessageReplyError(MSG_ERROR_DOES_NOT_EXIST, ERR_INVALID_USERNAME_OR_PASSWORD); return false; } // Can never get here else { ASSERT(false); return false; } }
void VoxMain::run() { int modesw = 3; uint64_t cnt = 0; timeval tvchk = {0, 0}; timeval tvcur = {0, 0}; std::string datastr = ""; INFORMATION("(MAIN) start of loop"); pinMode(modesw, INPUT); pullUpDnControl(modesw, PUD_UP); gettimeofday(&tvchk, NULL); while(!m_exit) { int onoff = digitalRead(modesw); gettimeofday(&tvcur, NULL); if(onoff == LOW) { std::string retstr = ""; if(m_mode > MD5) --m_mode; else m_mode = MD1; NOTICE("mode changed: mode=%d", m_mode); if(m_mode == MD1) // control { } else if(m_mode == MD2) // vision { //if(!createProcess("/home/pi/mjpg-streamer/stop_mjpg.sh", retstr)) // ERROR("(MAIN) failed to stop mjpg-streamer"); } else if(m_mode == MD3) // voice { } Servo* servo = VoxControl::getInstance().getServo(); servo->setNeutral(); VoxPlayer::getInstance().play("", false); delay(300); } if(timeSpan(tvchk, tvcur) >= 1.0f) { cpuUsage(); tvchk.tv_sec = tvcur.tv_sec; tvchk.tv_usec = tvcur.tv_usec; } if((cnt % 100) == 0) { std::vector<std::string> addrs; getLocalIPString(addrs); m_myip = ""; for(size_t i = 0; i < addrs.size(); i++) { std::string acls = ""; extractSubString(acls, addrs[i].c_str(), 0, '.'); if(isPositiveNumber(acls)) { if(acls != "127") m_myip += addrs[i] + ", "; } } m_myip = strTrim(m_myip, " ,"); std::string retstr = ""; if(createProcess("/usr/bin/vcgencmd measure_temp", retstr)) { strRemove(retstr, "temp="); strRemove(retstr, "'C"); m_cputemp = atof(retstr.c_str()); } m_appmem = getRss(); } if((cnt % 2) == 0) { bool voice = VoxVoice::getInstance().isRunning(); datastr = strFormat("%s|%d|%d|%d|%.1f|%.1f|%.1f|%.1f|%.1f|%.1f|%.1f|%.1f|%.1f|%d|%d|%d|%.1f|%d|%d|%s|%s", m_myip.c_str(), abs(MD1 - m_mode) + 1, m_stat, VoxSensor::getInstance().isFreeze(), VoxSensor::getInstance().getTemperature(), VoxSensor::getInstance().getHumidity(), VoxSensor::getInstance().getDistF(), VoxSensor::getInstance().getDistB(), VoxSensor::getInstance().getDistL(), VoxSensor::getInstance().getDistR(), m_cpuusage, m_cputemp, (float)(m_appmem / 1024.0 / 1024.0), VoxVision::getInstance().isFollowing(), VoxVision::getInstance().getPosX(), VoxVision::getInstance().getPosY(), VoxVision::getInstance().getRadius(), VoxVision::getInstance().getBallCount(), (voice) ? VoxVoice::getInstance().readyToGo() : 0, (voice) ? VoxVoice::getInstance().getReq().c_str() : "", (voice) ? VoxVoice::getInstance().getRsp().c_str() : "" ); writeDataFile(datastr); } delay(150); ++cnt; } pinMode(modesw, OUTPUT); digitalWrite(modesw, LOW); INFORMATION("(MAIN) end of loop"); }
void VDVSubscriptionService::_setFromParametersMap(const ParametersMap& map) { string content(map.getDefault<string>(PARAMETER_POST_DATA)); XMLResults results; XMLNode allNode = XMLNode::parseString(content.c_str(), "AboAnfrage", &results); if( results.error != eXMLErrorNone || allNode.isEmpty() ){ _errorNumber = "100"; _errorText = "Malformed XML"; return; } try { string sender(allNode.getAttribute("Sender")); _client = &DataExchangeModule::GetVDVClient(sender); // Trace _client->trace("AboAnfrage", content); // Check if the client is declared as active if(!_client->get<Active>()) { _errorNumber = "300"; _errorText = "Sender is forbidden right now"; return; } // Subscriptions cleaning XMLNode cleanNode(allNode.getChildNode("AboLoeschenAlle")); if(!cleanNode.isEmpty()) { string cleanNodeStr(cleanNode.getText()); if( cleanNodeStr == "true" || cleanNodeStr == "1" ){ _client->cleanSubscriptions(); } } // New subscriptions size_t nbNodes(allNode.nChildNode("AboAZB")); for(size_t i(0); i<nbNodes; ++i) { XMLNode aboAZBNode(allNode.getChildNode("AboAZB", static_cast<int>(i))); string id(aboAZBNode.getAttribute("AboID")); if(id.empty()) { continue; } boost::shared_ptr<VDVClientSubscription> subscription(new VDVClientSubscription(id, *_client)); if(aboAZBNode.nChildNode("AZBID")) { XMLNode azbidNode(aboAZBNode.getChildNode("AZBID")); StopArea* stopArea( _client->get<DataSource>()->getObjectByCode<StopArea>(azbidNode.getText()) ); if(!stopArea) { continue; } subscription->setStopArea(stopArea); } if(aboAZBNode.nChildNode("LinienID")) { XMLNode linienNode(aboAZBNode.getChildNode("LinienID")); CommercialLine* line( _client->get<DataSource>()->getObjectByCode<CommercialLine>(linienNode.getText()) ); if(!line) { continue; } subscription->setLine(line); } // Direction filter if(aboAZBNode.nChildNode("RichtungsID")) { XMLNode linienNode(aboAZBNode.getChildNode("RichtungsID")); subscription->setDirectionFilter(linienNode.getText()); } XMLNode durationNode(aboAZBNode.getChildNode("Vorschauzeit")); if(!durationNode.isEmpty()) { try { time_duration timeSpan( minutes( lexical_cast<long>(durationNode.getText()) ) ); subscription->setTimeSpan(timeSpan); } catch(bad_lexical_cast&) { } } XMLNode hysteresisNode(aboAZBNode.getChildNode("Hysterese")); if(!hysteresisNode.isEmpty()) { try { time_duration hysteresis( seconds( lexical_cast<long>(hysteresisNode.getText()) ) ); subscription->setHysteresis(hysteresis); } catch(bad_lexical_cast&) { } } _client->addSubscription(subscription); } } catch (Exception&) { _errorNumber = "200"; _errorText = "Invalid sender"; return; } // Error if the VDV server is inactive if(!DataExchangeModule::GetVDVServerActive()) { _errorNumber = "400"; _errorText = "Service temporary unavailable"; return; } }
bool TimePermRingBuffer::insert(DataSample &data, long current_time) { long last_time, delta, steps; m_lastTimeStamp.readData((void*)&last_time); delta = current_time - last_time; #ifdef SERIAL_DEBUG Serial.print("==== TimePermRingBuffer["); Serial.print(m_bufferStart, DEC); Serial.print("]::insert -> current="); Serial.print(current_time, DEC); Serial.print(" - last_time="); Serial.print(last_time, DEC); Serial.print(" : delta="); Serial.println(delta, DEC); #endif if ( delta < 0 ) { // something happened: we are going back in the past // just let clear everything and start orer #ifdef SERIAL_DEBUG Serial.println("------ back to the past -> clear"); #endif clear(); m_lastTimeStamp.writeData((void*)¤t_time); push(data.data()); return true; } if ( delta > timeSpan() ) { // elapsed time greater than buffer time span #ifdef SERIAL_DEBUG Serial.println("------ elapsed time greater than buffer time span -> clear"); #endif clear(); m_lastTimeStamp.writeData((void*)¤t_time); push(data.data()); } else { if ( 0 == delta % m_period ) { steps = delta / m_period; if ( steps > 0 ) { // this is time to insert the new sample if ( steps > 1 ) { // elapsed time more than one single period #ifdef SERIAL_DEBUG Serial.print("------ elapsed time more than a single period -> rotate steps = "); Serial.println(steps-1, DEC); #endif rotate(steps-1); } m_lastTimeStamp.writeData((void*)¤t_time); push(data.data()); } } else { #ifdef SERIAL_DEBUG Serial.println("------ period not elapsed -> no insertion"); #endif return false; } } return true; }