Merge pull request #65 from ea/master

Added command to export random integers as per suggestion in #63
This commit is contained in:
Travis Goodspeed 2018-01-29 14:39:11 -05:00 committed by GitHub
commit b7d6800ede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -259,6 +259,11 @@ class GoodWatch:
def dmesg(self):
"""Returns the DMESG buffer."""
return self.transact("\x04");
def randint(self,n):
"""Returns n random 16bit integer. """
import struct
r = struct.unpack("<"+"H"*n,self.transact("\x05\x00"+chr16(n)));
return "%04x "*n%r
def radioonoff(self,on=1):
"""Turns the radio on or off."""
return self.transact("\x10"+chr(on));
@ -301,7 +306,8 @@ if __name__=='__main__':
help='Write a string the LCD.');
parser.add_argument('-D','--dmesg',
help='Prints the dmesg.',action='count');
parser.add_argument('-R','--randint',
help='Get RANDINT random 16bit integers.');
parser.add_argument('-b','--beacon',
help='Transmits a beacon.');
parser.add_argument('-B','--beaconsniff',
@ -330,6 +336,8 @@ if __name__=='__main__':
if args.dmesg>0:
print goodwatch.dmesg();
if args.randint != None:
print goodwatch.randint(int(args.randint));
if args.beacon!=None:
print "Turning radio on.";

View File

@ -12,6 +12,7 @@
#include<string.h>
#include "api.h"
#include "rng.h"
enum {
SETTURBOMODE = 0x00,
@ -19,6 +20,7 @@ enum {
POKE = 0x02,
LCDSTRING = 0x03,
DMESG = 0x04,
RANDINT = 0x05,
RADIOONOFF = 0x10,
RADIOCONFIG = 0x11,
@ -48,6 +50,30 @@ static void send_dmesg(){
uart_tx(0x00);
}
//! Local command to generate and send n random integers.
static void send_randint(uint16_t n){
uint16_t i;
uint16_t len = n*2;
uint16_t rints[n]; // are var len arrays ok here?
for(i = 0; i < n; i++){ //pre-generate enough ints
rints[i] = true_rand();
}
//Start the frame
uart_tx(0x00);
uart_tx(0x80);
//Length
uart_tx(len&0xFF);
uart_tx(len>>8);
//Send integers byte by byte
for(i=0;i<len;i++){
uart_tx(((char*)rints)[i]);
}
// no checksum ?
uart_tx(0x00);
uart_tx(0x00);
}
//! Local pointer to packet.c's buffer.
static uint8_t *packetbuf=0;
@ -142,6 +168,10 @@ int monitor_handle(uint8_t *buffer, int len){
len=0;
break;
case RANDINT:
send_randint((uint16_t)buffer16[1]);
len=0;
break;
case RADIOONOFF: //One byte parameter, on or off.
if(buffer[1]){