MinDelaySensor.cc 863 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
// MinDelaySensor.cc

#include "lib.h"
#include "MinDelaySensor.h"
#include "DelaySensor.h"
#include "CommandOutput.h"

using namespace std;

MinDelaySensor::MinDelaySensor(DelaySensor * newDelay)
11
  : minimum(1000000, -0.01), minDelay(1000000)
12 13 14 15 16 17 18 19 20 21 22 23 24
{
  delay = newDelay;
}

void MinDelaySensor::localSend(PacketInfo *)
{
}

void MinDelaySensor::localAck(PacketInfo * packet)
{
  int current = delay->getLastDelay();
  if (current < minimum && current != 0)
  {
25
    minDelay = current;
26
    ostringstream buffer;
27
    buffer << "delay=" << minDelay/2;
28 29 30 31 32 33 34 35 36 37 38
    minimum.reset(current);
    global::output->eventMessage(buffer.str(), packet->elab,
                                 CommandOutput::FORWARD_PATH);
    global::output->eventMessage(buffer.str(), packet->elab,
                                 CommandOutput::BACKWARD_PATH);
  }
  else
  {
    minimum.decay();
  }
}