Ejemplo n.º 1
0
	void Stopwatch::stop() {	
		stop_time = getTimeMs64();
	}
Ejemplo n.º 2
0
	void Stopwatch::start() {
		start_time = getTimeMs64();
	}
Ejemplo n.º 3
0
void PerfCalc::start()
{
    startTs_ = getTimeMs64();
    numTimes_++;
}
Ejemplo n.º 4
0
void PerfCalc::end()
{
    uint64_t elapsedTime = getTimeMs64() - startTs_;
    totalElapsedTime_ += elapsedTime;
    OUTPUT("---%s elapsedTimeInMs=%llu, avgElapsedTimeInMs=%llu", prefix_.c_str(), elapsedTime, (totalElapsedTime_/numTimes_));
}
Ejemplo n.º 5
0
static void routingReceive(Socket_t *s, uint8_t *data, uint16_t len)
{
    // PRINTF("routingReceive %d bytes from %#04x\n", len,
    //         s->recvMacInfo->originalSrc.shortAddr);

//    PRINTF("routing rx\n");

    if (len == 0) {
        PRINTF("routingReceive: no data!\n");
        return;
    }

#if PRECONFIGURED_NH_TO_ROOT
    if (s->recvMacInfo->originalSrc.shortAddr != PRECONFIGURED_NH_TO_ROOT) {
        PRINTF("Dropping routing info: not from the nexthop, but from %#04x\n",
                s->recvMacInfo->originalSrc.shortAddr);
        return;
    }
    PRINTF("Got routing info from the nexthop\n");
#endif

    uint8_t type = data[0];
    if (type == ROUTING_REQUEST) {
        uint8_t senderType = data[1];
        if (senderType != SENDER_MOTE) return;
        uint8_t idx = markAsSeen(s->recvMacInfo->originalSrc.shortAddr, true);
        if (gotRreq == 0xff) {
            gotRreq = idx;
            alarmSchedule(&roOutOfOrderForwardTimer, randomNumberBounded(400));
        }
        return;
    }

    if (type != ROUTING_INFORMATION) {
        PRINTF("routingReceive: unknown type!\n");
        return;
    }

    if (len < sizeof(RoutingInfoPacket_t)) {
        PRINTF("routingReceive: too short for info packet!\n");
        return;
    }

    RoutingInfoPacket_t ri;
    memcpy(&ri, data, sizeof(RoutingInfoPacket_t));

    bool update = false;
    if (!isRoutingInfoValid() || timeAfter16(ri.seqnum, lastSeenSeqnum)) {
        // XXX: theoretically should add some time to avoid switching to
        // worse path only because packets from it travel faster
        update = true;
        TPRINTF("RI updated: > seqnum\n");
    }
    else if (ri.seqnum == lastSeenSeqnum) {
        if (ri.hopCount < hopCountToRoot) {
            update = true;
            TPRINTF("RI updated: < metric\n");
        }
        else if (ri.hopCount == hopCountToRoot && !seenRoutingInThisFrame) {
            update = true;
            TPRINTF("RI updated: == metric\n");
        }
    }
    if (ri.hopCount > MAX_HOP_COUNT) update = false;

    if (update) {
        if (timeSinceFrameStart() < 2000 || timeSinceFrameStart() > 4000) {
            PRINTF("*** forwarder (?) sends out of time!\n");
        }

        seenRoutingInThisFrame = true;
        rootAddress = ri.rootAddress;
        nexthopToRoot = s->recvMacInfo->originalSrc.shortAddr;
        lastSeenSeqnum = ri.seqnum;
        hopCountToRoot = ri.hopCount;
        lastRootMessageTime = (uint32_t) getJiffies();
        int64_t oldRootClockDeltaMs = rootClockDeltaMs;
        rootClockDeltaMs = ri.rootClockMs - getTimeMs64();
        if (abs((int32_t)oldRootClockDeltaMs - (int32_t)rootClockDeltaMs) > 500) {
            PRINTF("large delta change=%ld, time sync off?!\n", (int32_t)rootClockDeltaMs - (int32_t)oldRootClockDeltaMs);
            PRINTF("delta: old=%ld, new=%ld\n", (int32_t)oldRootClockDeltaMs, (int32_t)rootClockDeltaMs);
        }
        // TPRINTF("OK!%s\n", isListening ? "" : " (not listening)");

        // reschedule next listen start after this timesync
        alarmSchedule(&roStartListeningTimer, timeToNextFrame() + 2000);
    }
    else {
        TPRINTF("RI not updated!\n");
    }
}