X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=blobdiff_plain;f=apps%2Ftests%2FTestNetwork%2FTestNetworkC.nc;h=05e44d2fbf2ca1b41a5fc246a7d4864d233e1e0c;hp=28e248f0d3e42589b593df059c1a1ee2a278b88c;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hpb=adf1de6c009d13b7b52e68535c63b28f59c97400 diff --git a/apps/tests/TestNetwork/TestNetworkC.nc b/apps/tests/TestNetwork/TestNetworkC.nc index 28e248f0..05e44d2f 100644 --- a/apps/tests/TestNetwork/TestNetworkC.nc +++ b/apps/tests/TestNetwork/TestNetworkC.nc @@ -20,7 +20,7 @@ module TestNetworkC { uses interface SplitControl as SerialControl; uses interface StdControl as RoutingControl; uses interface StdControl as DisseminationControl; - uses interface DisseminationValue as DisseminationPeriod; + uses interface DisseminationValue as DisseminationPeriod; uses interface Send; uses interface Leds; uses interface Read as ReadSensor; @@ -87,7 +87,7 @@ implementation { void sendMessage() { TestNetworkMsg* msg = (TestNetworkMsg*)call Send.getPayload(&packet, sizeof(TestNetworkMsg)); uint16_t metric; - am_addr_t parent; + am_addr_t parent = 0; call CtpInfo.getParent(&parent); call CtpInfo.getEtx(&metric); @@ -113,10 +113,9 @@ implementation { event void Timer.fired() { - uint16_t nextInt; - call Leds.led0Toggle(); + uint32_t nextInt; dbg("TestNetworkC", "TestNetworkC: Timer fired.\n"); - nextInt = call Random.rand16() % SEND_INTERVAL; + nextInt = call Random.rand32() % SEND_INTERVAL; nextInt += SEND_INTERVAL >> 1; call Timer.startOneShot(nextInt); if (!sendBusy) @@ -125,25 +124,38 @@ implementation { event void Send.sendDone(message_t* m, error_t err) { if (err != SUCCESS) { - // call Leds.led0On(); + call Leds.led0On(); } sendBusy = FALSE; dbg("TestNetworkC", "Send completed.\n"); } event void DisseminationPeriod.changed() { - const uint16_t* newVal = call DisseminationPeriod.get(); + const uint32_t* newVal = call DisseminationPeriod.get(); call Timer.stop(); call Timer.startPeriodic(*newVal); } + + uint8_t prevSeq = 0; + uint8_t firstMsg = 0; + event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) { dbg("TestNetworkC", "Received packet at %s from node %hhu.\n", sim_time_string(), call CollectionPacket.getOrigin(msg)); - call Leds.led1Toggle(); - if (!call Pool.size() <= (TEST_NETWORK_QUEUE_SIZE < 4)? 1:3) { - // call CtpCongestion.setClientCongested(TRUE); + call Leds.led1Toggle(); + + if (call CollectionPacket.getOrigin(msg) == 1) { + if (firstMsg == 1) { + if (call CollectionPacket.getSequenceNumber(msg) - prevSeq > 1) { + call Leds.led2On(); + } + } else { + firstMsg = 1; + } + prevSeq = call CollectionPacket.getSequenceNumber(msg); } + if (!call Pool.empty() && call Queue.size() < call Queue.maxSize()) { message_t* tmp = call Pool.get(); call Queue.enqueue(msg);