Skip to content

Commit

Permalink
Added python script that generates random UID header file for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jumptuck-dev committed Dec 31, 2013
1 parent 4513052 commit c84a514
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
8 changes: 7 additions & 1 deletion uid_voting/uid_voting.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@

#include <EEPROM.h>

#include "/home/mike/compile/nfc-voting/uid_voting/uniqueSet.h"

PN532_SPI pn532spi(SPI, 10);
PN532 nfc(pn532spi);



/* //Testing:
unsigned int uniqueSetLen = 3;
uint8_t uniqueSet[21] PROGMEM= {
Expand All @@ -25,6 +30,7 @@ uint8_t uniqueSet[21] PROGMEM= {
0x04, 0x81, 0x78, 0xD2, 0x85, 0x32, 0x80,
};
*/

//Need no more than 500 booleans so just use 64 bytes
uint8_t hasVoted[64];
Expand Down Expand Up @@ -183,7 +189,7 @@ void loop(void) {
Serial.println("Found a card!");
//NTAG203 has 7-byte UID, ignore all others
if (uidLength == 7) {
Serial.print(uid[0], HEX);Serial.print(uid[1], HEX);Serial.print(uid[1], HEX);Serial.print(uid[2], HEX);Serial.print(uid[3], HEX);Serial.print(uid[4], HEX);Serial.print(uid[5], HEX);Serial.println(uid[6], HEX);
Serial.print(uid[0], HEX);Serial.print(uid[1], HEX);Serial.print(uid[2], HEX);Serial.print(uid[3], HEX);Serial.print(uid[4], HEX);Serial.print(uid[5], HEX);Serial.println(uid[6], HEX);

castBallot(uid);

Expand Down
43 changes: 43 additions & 0 deletions unique-string-gen/generate-uid-test-header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
###########
# Generate UID Test in C Header File
#
###########

import string
import random
import pickle

setSize = 500
uniqueLen = 7

uniqueSet = []

print "Generating Set"
while (len(uniqueSet) < setSize):
if len(uniqueSet)%50 == 49:
print str(len(uniqueSet)+1) + " values have been generated"
thisUID = []
for i in range(7):
thisUID.append(random.choice(range(0xFF)))
if thisUID not in uniqueSet:
print thisUID
uniqueSet.append(thisUID)

print "Generating PROGMEM array as uniqueSet.h"
with open('uniqueSet.h', 'w') as f:
f.write("//THIS IS FOR TESTING ONLY!!!!!!\n\n")
f.write("unsigned int uniqueSetLen = " + str(setSize) + ";\n\n")
f.write("unsigned char uniqueSet[" + str(setSize)*uniqueLen + "] PROGMEM = {\n")
for i in range(len(uniqueSet)):
outStr = " "
for d in range(6):
outStr += "0x{:02x}".format(uniqueSet[i][d]).upper().replace("X","x") + ", "

outStr += "0x{:02x}".format(uniqueSet[i][6]).upper().replace("X","x")
if (i == (len(uniqueSet)-1)):
outStr += "\n"
else:
outStr += ",\n"
f.write(outStr)
f.write("};\n")

0 comments on commit c84a514

Please sign in to comment.