void loop () { if (Serial.available()) handleInput(Serial.read()); if (tempTimer.poll()) { sendTempPacket(); tempTimer.set(TEMP_INTERVAL); } unsigned long now = millis(); cli(); bool needSendPulse = false; if (pulseActivity && (lastPulsePacket + PULSE_INTERVAL < now)) { pulseActivity = false; lastPulsePacket = now; needSendPulse = true; } sei(); if (needSendPulse) { sendPulsePacket(); } if (!rf12_recvDone() || rf12_crc != 0) return; // nothing to do digitalWrite(PIN_LED, HIGH); forwardPacket(); digitalWrite(PIN_LED, LOW); }
// Wait a few milliseconds for proper ACK byte waitForAck(byte myNodeID) { MilliTimer ackTimer; while (!ackTimer.poll(ACK_TIME)) { if (rf12_recvDone() && rf12_crc == 0 && rf12_hdr == (RF12_HDR_DST | RF12_HDR_CTL | myNodeID)) return 1; } return 0; }
int TalkServiceI::getUserOnlineStatV1(const long userId, const Ice::Current& current){ MilliTimer tStart; LOG_DEBUG("TalkServiceI::getUserOnlineStat => userId = " << userId); int stat = MY_INSTANCE(TalkServer).getUserOnlineStat(userId); LOG_TIME("TalkServiceI::getUserOnlineStat|" << tStart.elapsed() ); return stat; }
vector<int> TalkServiceI::getUsersOnlineStatSeq(const vector<long>& users, const Ice::Current& current){ MilliTimer tStart; LOG_DEBUG("TalkServiceI::getUsersOnlineStatSeq => size = " << users.size()); vector<int> intVec = MY_INSTANCE(TalkServer).getLocalUsersOnlineStatSeq(users); LOG_TIME("TalkServiceI::getUsersOnlineStatSeq|" << users.size() << "|" << tStart.elapsed() ); return intVec; }
void forwardPacket() { // make copies, because rf12_* will change in next rf12_recvDone byte hdr = rf12_hdr, len = rf12_len; if (config.multi_node) { // special case: insert original header (src node ID) as first data byte // careful with max-length packets in multi-node mode: drop last byte! // this is necessary because we're inserting an extra byte at the front if (len >= sizeof buf) --len; buf[0]= hdr; } memcpy(buf + config.multi_node, (void*) rf12_data, len); // save these for later as well, same reason as above byte wantsAck = RF12_WANTS_ACK, ackReply = RF12_ACK_REPLY; if (config.acks_enable) { // if we're not supposed to send back ACKs, then don't ask for 'em wantsAck = false; hdr &= ~ RF12_HDR_ACK; } Serial.print("\n[*]"); // switch to outgoing group rf12_initialize(config.out_node, code2type(config.freq), config.out_group); // send our packet, once possible while (!rf12_canSend()) rf12_recvDone(); rf12_sendStart(hdr, buf, len + config.multi_node, 1); if (wantsAck) { ackTimer.set(100); // wait up to 100 ms for a valid ack packet wantsAck = false; while (!wantsAck && !ackTimer.poll()) wantsAck = rf12_recvDone() && rf12_crc == 0; } // switch back to incoming group rf12_initialize(config.in_node, code2type(config.freq), config.in_group); if (wantsAck) { // copy ack packet to our temp buffer, same reason as above len = rf12_len; memcpy(buf, (void*) rf12_data, rf12_len); // send ACK packet back, once possible while (!rf12_canSend()) rf12_recvDone(); rf12_sendStart(ackReply, buf, len, 1); } }
void Router2TalkServiceI::forwardIq(const std::string& xmppString, const Ice::Current& current) { MilliTimer tStart; LOG_DEBUG("Router2TalkServiceI::forwordIq ==> begin."); int flag = router2talkServerPtr_->forwardIq(xmppString); if(flag < 0) { LOG_ERROR("Router2TalkServiceI::forwardIq ==> return error: "<<flag); } LOG_DEBUG("Route2TalkServiceI::forwordIq ==> end. use:"<<tStart.elapsed()); }
map<long, int> TalkServiceI::getUsersOnlineStatMapV1(const vector<long>& users, const Ice::Current& current){ LOG_DEBUG("TalkServiceI::getUsersOnlineStatMap => size = " << users.size()); MilliTimer tStart; vector<int> statVector = MY_INSTANCE(TalkServer).getLocalUsersOnlineStatSeq(users); map<long, int> statMap; for(size_t i = 0; i < statVector.size(); ++i){ statMap[users[i]] = statVector[i]; } LOG_TIME("TalkServiceI::getUsersOnlineStatMap|" << users.size() << "|" << tStart.elapsed() ); return statMap; }
void EndpointServiceProxy::deliverMsg(const long connectionId, const string& msg, long mid, int msgType){ MilliTimer tStart; ReadLock lock(mutex_); EndpointServicePrx proxy = getProxy(connectionId); if(!proxy){ LOG_ERROR("EndpointServiceProxy::deliverMsg => get proxy failure : cid = " << connectionId); return; } try{ proxy->deliverMsg(connectionId, msg); }catch(std::exception& e){ std::cout<<"EndpointServicePrx deliverMsg catch exception ="<<e.what()<<std::endl; }catch(...){ std::cout<<"EndpointServicePrx deliverMsg unknow exception"<<std::endl; } LOG_TIME("EndpointServicePrx::deliverMsg|" << tStart.elapsed() ); return; }
void setup () { Serial.begin(57600); Serial.print("\n[groupRelay]"); loadConfig(); tempTimer.set(TEMP_INTERVAL); pinMode(PIN_LED, OUTPUT); attachInterrupt(1, pulse, CHANGE); // pinMode(PIN_TEMP1, INPUT); // pinMode(PIN_TEMP2, INPUT); // digitalWrite(PIN_TEMP1, LOW); // disable pullup // digitalWrite(PIN_TEMP2, LOW); // disable pullup }
void loop() { for (int i = 0; i < NUM_COUNTERS; i++) { // loop through the counters // read the counter input pin: counterState[i] = digitalRead(counterPin[i]); // compare the counterState to its previous state if (counterState[i] != lastCounterState[i]) { if (counterState[i] == LOW) { digitalWrite(LED1, HIGH); // if the current state is HIGH then the button // wend from off to on: #ifdef DEBUG_ENABLED Serial.print(i); Serial.println(" LOW"); #endif payload.active_counter = i; counterMillis[i] = millis(); payload.counter_millis = counterMillis[i]; if (counterMillis[i] - lastCounterMillis[i] > 90) { // send a packet while (!rf12_canSend()) rf12_recvDone(); // send as broadcast, payload will be encrypted rf12_sendStart(0, &payload, sizeof(payload)); rf12_sendWait(1); } lastCounterMillis[i] = counterMillis[i]; #ifdef DEBUG_ENABLED } else { // transision from LOW to HIGH means the pulse is over // we're not interested in that Serial.print(i); Serial.println(" HIGH"); #endif } Serial.println(); } // save the current state as the last state, //for next time through the loop lastCounterState[i] = counterState[i]; if (led1Timer.poll(90)) { digitalWrite(LED1, LOW); } } wdt_reset(); }