Permalink
Browse files

io_repeater app: Changed it to randomize the time between transmittin…

…g packets. The randomness comes from an ADC reading of the temperature sensor.
  • Loading branch information...
1 parent 2e19f1b commit 12d998444476c95316e3ee9c38e3e5e0a6f43039 @DavidEGrayson DavidEGrayson committed Jun 21, 2012
Showing with 21 additions and 3 deletions.
  1. +3 −3 apps/io_repeater/io_repeater.c
  2. +18 −0 apps/test_random/test_random.c
@@ -18,8 +18,6 @@ For complete documentation and a precompiled version of this app, see the
#include <gpio.h>
#include <radio_queue.h>
-#define MAX_TX_INTERVAL 10 // maximum time between transmissions (ms)
-
#define PIN_COUNT 15
static uint8 CODE pins[PIN_COUNT] = {0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 21};
@@ -165,6 +163,7 @@ void main(void)
uint8 XDATA * rxBuf;
uint8 lastTx = 0;
+ uint8 txInterval = 0;
systemInit();
usbInit();
@@ -187,13 +186,14 @@ void main(void)
}
// read our input pins and transmit pin states to other Wixel(s) every MAX_TX_INTERVAL milliseconds
- if (txEnabled && (uint8)(getMs() - lastTx) > MAX_TX_INTERVAL && (txBuf = radioQueueTxCurrentPacket()))
+ if (txEnabled && (uint8)(getMs() - lastTx) > txInterval && (txBuf = radioQueueTxCurrentPacket()))
{
readPins(txBuf + 1);
*txBuf = inPinCount; // set packet length byte
radioQueueTxSendPacket();
lastTx = getMs();
+ txInterval = 7 + (adcRead(14 | ADC_BITS_7) & 3);
}
}
}
@@ -108,6 +108,24 @@ void receiveCommands()
response[responseLength++] = '\r';
response[responseLength++] = '\n';
break;
+
+ case 't':
+ // Perform a low-resolution reading of the temperature sensor.
+ // The lowest few bits should be random.
+ rand = adcRead(14 | ADC_BITS_7);
+ response[responseLength++] = ',';
+ response[responseLength++] = (rand & 0x80) ? '1' : '0';
+ response[responseLength++] = (rand & 0x40) ? '1' : '0';
+ response[responseLength++] = (rand & 0x20) ? '1' : '0';
+ response[responseLength++] = (rand & 0x10) ? '1' : '0';
+ response[responseLength++] = (rand & 0x08) ? '1' : '0';
+ response[responseLength++] = (rand & 0x04) ? '1' : '0';
+ response[responseLength++] = (rand & 0x02) ? '1' : '0';
+ response[responseLength++] = (rand & 0x01) ? '1' : '0';
+ response[responseLength++] = '\r';
+ response[responseLength++] = '\n';
+ break;
+
default: response[0] = '?'; break;
}
usbComTxSend(response, responseLength);

0 comments on commit 12d9984

Please sign in to comment.