Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 12d998444476c95316e3ee9c38e3e5e0a6f43039 1 parent 2e19f1b
David Grayson DavidEGrayson authored
6 apps/io_repeater/io_repeater.c
@@ -18,8 +18,6 @@ For complete documentation and a precompiled version of this app, see the
18 18 #include <gpio.h>
19 19 #include <radio_queue.h>
20 20
21   -#define MAX_TX_INTERVAL 10 // maximum time between transmissions (ms)
22   -
23 21 #define PIN_COUNT 15
24 22 static uint8 CODE pins[PIN_COUNT] = {0, 1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 21};
25 23
@@ -165,6 +163,7 @@ void main(void)
165 163 uint8 XDATA * rxBuf;
166 164
167 165 uint8 lastTx = 0;
  166 + uint8 txInterval = 0;
168 167
169 168 systemInit();
170 169 usbInit();
@@ -187,13 +186,14 @@ void main(void)
187 186 }
188 187
189 188 // read our input pins and transmit pin states to other Wixel(s) every MAX_TX_INTERVAL milliseconds
190   - if (txEnabled && (uint8)(getMs() - lastTx) > MAX_TX_INTERVAL && (txBuf = radioQueueTxCurrentPacket()))
  189 + if (txEnabled && (uint8)(getMs() - lastTx) > txInterval && (txBuf = radioQueueTxCurrentPacket()))
191 190 {
192 191 readPins(txBuf + 1);
193 192 *txBuf = inPinCount; // set packet length byte
194 193 radioQueueTxSendPacket();
195 194
196 195 lastTx = getMs();
  196 + txInterval = 7 + (adcRead(14 | ADC_BITS_7) & 3);
197 197 }
198 198 }
199 199 }
18 apps/test_random/test_random.c
@@ -108,6 +108,24 @@ void receiveCommands()
108 108 response[responseLength++] = '\r';
109 109 response[responseLength++] = '\n';
110 110 break;
  111 +
  112 + case 't':
  113 + // Perform a low-resolution reading of the temperature sensor.
  114 + // The lowest few bits should be random.
  115 + rand = adcRead(14 | ADC_BITS_7);
  116 + response[responseLength++] = ',';
  117 + response[responseLength++] = (rand & 0x80) ? '1' : '0';
  118 + response[responseLength++] = (rand & 0x40) ? '1' : '0';
  119 + response[responseLength++] = (rand & 0x20) ? '1' : '0';
  120 + response[responseLength++] = (rand & 0x10) ? '1' : '0';
  121 + response[responseLength++] = (rand & 0x08) ? '1' : '0';
  122 + response[responseLength++] = (rand & 0x04) ? '1' : '0';
  123 + response[responseLength++] = (rand & 0x02) ? '1' : '0';
  124 + response[responseLength++] = (rand & 0x01) ? '1' : '0';
  125 + response[responseLength++] = '\r';
  126 + response[responseLength++] = '\n';
  127 + break;
  128 +
111 129 default: response[0] = '?'; break;
112 130 }
113 131 usbComTxSend(response, responseLength);

0 comments on commit 12d9984

Please sign in to comment.
Something went wrong with that request. Please try again.