This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from EnAccess/openpaygo-v2-1-1
2020-10-23: v2.1.1 release
- Loading branch information
Showing
9 changed files
with
206 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
siphash | ||
siphash==0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# OpenPAYGO Token - CSV Generator | ||
|
||
## Installation | ||
|
||
Nothing special to do, just make sure you have Python version 3.6 or above installed and setup in your path. | ||
|
||
## Usage | ||
|
||
1. In a command line window, go to the csv_generator folder and run: **python openpaygo_csv_generator.py** | ||
2. At the first run, you will be prompted to setup some parameters (e.g. manufacturer prefix, hardware model, etc.) | ||
If you wish to change them later you can directly edit the openpaygo_csv_generator.conf file. | ||
3. You will be prompted for the last serial number that was generated in order to avoid two devices having the same serial number. | ||
The latest serial number from the last batch will be shown to you if it was generated on the same computer and the config file was kept. | ||
For your first batch you can use 0. | ||
4. You will then be prompted for the number of devices for which you want to generate the CSV for. | ||
5. You will then find the CSV file generated in the same folder with the name "openpaygo_batch_XXX-YYY.csv" | ||
with XXX being the first serial number in the batch and YYY the last serial number in the batch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import sys | ||
import os | ||
import random | ||
import csv | ||
import codecs | ||
import configparser | ||
|
||
CONF_FILE = 'openpaygo_csv_generator.conf' | ||
|
||
|
||
def raw_input(): | ||
return sys.stdin.readline().replace('\n', '') | ||
|
||
|
||
def number_to_serial(manufacturer_prefix, number): | ||
return manufacturer_prefix + str(number).zfill(9) | ||
|
||
|
||
def generate_csv(serial_start, number_of_devices, config): | ||
base_config = config['BASE_CONFIG'] | ||
# We load the config | ||
manufacturer_prefix = base_config['manufacturer_prefix'] | ||
count = 1 | ||
time_divider = base_config['time_divider'] | ||
restricted_digit_set = base_config['restricted_digit_set'] | ||
hardware_model = base_config['hardware_model'] | ||
firmware_version = base_config['firmware_version'] | ||
filename = 'openpaygo_batch_' + number_to_serial(manufacturer_prefix, serial_start+1) + '-' + \ | ||
number_to_serial(manufacturer_prefix, serial_start+number_of_devices) + '.csv' | ||
with open(filename, 'w') as csvfile: | ||
device_list_csv = csv.writer(csvfile, delimiter=',') | ||
headers = ['Serial Number', 'Starting Code', 'Key', 'Count', 'Time Divider', 'Restricted Digit Mode', | ||
'Hardware Model', 'Firmware Version'] | ||
device_list_csv.writerow(headers) | ||
for number in range(1, number_of_devices+1): | ||
device_serial = number_to_serial(manufacturer_prefix, number) | ||
starting_code = random.randint(1, 999999999) | ||
key = codecs.encode(os.urandom(16), 'hex').decode('utf-8') | ||
device_data = [device_serial, starting_code, key, count, time_divider, restricted_digit_set, | ||
hardware_model, firmware_version] | ||
device_list_csv.writerow(device_data) | ||
|
||
|
||
def setup_conf_menu(): | ||
config = configparser.ConfigParser() | ||
config.read(CONF_FILE) | ||
if 'BASE_CONFIG' in config: | ||
return # Already configured | ||
print('--- Setup ---') | ||
config['BASE_CONFIG'] = {} | ||
config['BATCH_CONFIG'] = {'last_generated': 0} | ||
base_config = config['BASE_CONFIG'] | ||
print('Enter your manufacturer serial number prefix: ') | ||
base_config['manufacturer_prefix'] = raw_input() | ||
print('Enter the time divider setup for your devices (Default: 1): ') | ||
base_config['time_divider'] = raw_input() | ||
print('Are your devices using Restricted Digit set (Y/N)? (Default: N)') | ||
base_config['restricted_digit_set'] = str(1 if raw_input() == 'Y' else 0) | ||
print('Enter your device hardware model: ') | ||
base_config['hardware_model'] = raw_input() | ||
print('Enter your device firmware version (optional): ') | ||
base_config['firmware_version'] = raw_input() | ||
with open(CONF_FILE, 'w') as configfile: | ||
config.write(configfile) | ||
|
||
|
||
def generate_csv_menu(): | ||
config = configparser.ConfigParser() | ||
config.read(CONF_FILE) | ||
last_generated = config['BATCH_CONFIG']['last_generated'] | ||
print('--- Batch Generation ---') | ||
print('Enter the last serial number that you generated without prefix (Last Generated: '+str(last_generated)+'): ') | ||
serial_start = int(raw_input()) | ||
print('Enter the number of units you want to generate serial numbers for: ') | ||
number_of_devices = int(raw_input()) | ||
print('Generating CSV...') | ||
generate_csv(serial_start, number_of_devices, config) | ||
config['BATCH_CONFIG']['last_generated'] = str(serial_start+number_of_devices) | ||
with open(CONF_FILE, 'w') as configfile: | ||
config.write(configfile) | ||
print('CSV generated! ') | ||
|
||
|
||
if __name__ == '__main__': | ||
print('--- OpenPAYGO Token - CSV Generator ---') | ||
setup_conf_menu() | ||
generate_csv_menu() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# OpenPAYGO Token - Factory Flashing Tool | ||
|
||
## Installation | ||
|
||
1. Make sure you have Python version 2.7 or above installed and setup in your path. | ||
2. Run **pip install -r requirements.txt** | ||
3. Make sure you have a Serial interface with the correct drivers installed on your system (e.g. FTDI USB to UART adapter) | ||
|
||
## Usage | ||
|
||
1. In a command line window, go to the csv_generator folder and run: **python factory_flashing_tool.py** | ||
2. At the first run, you will be prompted to enter the Serial port you want to use (this depends) | ||
3. You will be prompted for the CSV file you want to use for this batch. Enter the path to the CSV file | ||
(you can drag and drop the file to the terminal window and press enter on most system) | ||
4. You will then repeatedly be prompted for the serial numbers of the device you want to flash. | ||
Make sure that the device is connected to the serial interface before continuing. | ||
You can enter this serial number manually or use an HID barcode scanners if the devices have barcodes with the serial number. | ||
Make sure the barcode scanner is configured to enter a carriage return after reading the barcode to save time. | ||
5. Wait for the device to be flashed and continue to the next one or press Ctrl+C to quit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import sys | ||
import csv | ||
import serial | ||
from serial.tools import list_ports | ||
import time | ||
import configparser | ||
|
||
CONF_FILE = 'factory_flashing_tool.conf' | ||
|
||
|
||
def raw_input(): | ||
return sys.stdin.readline().replace('\n', '') | ||
|
||
|
||
def flash_device(serial_number, starting_code, key, port, baud): | ||
clean_key = " ".join(key[i:i+2] for i in range(0, len(key), 2)) | ||
print('Flashing device with serial number: '+serial_number+', starting_code: '+str(starting_code)+', key: '+str(clean_key)) | ||
flashed = False | ||
with serial.Serial(port, baud, timeout=5) as uart: | ||
uart.write(('#'+str(serial_number)+';'+str(starting_code)+';'+clean_key).encode('ascii')) | ||
time.sleep(0.25) | ||
flashed = True | ||
if flashed: | ||
print('Finished Flashing! Check that the device is correctly setup. \n') | ||
else: | ||
print('ERROR: Could not connect to the device, please try again! \n') | ||
|
||
|
||
def setup_conf(config): | ||
print('--- Setup ---') | ||
config['BASE_CONFIG'] = {} | ||
base_config = config['BASE_CONFIG'] | ||
print('Available UART interfaces: ') | ||
list_ports.main() | ||
time.sleep(1) | ||
print('Enter the name of the UART interface to use (copy paste from list above): ') | ||
port = raw_input() | ||
print('Enter the baud rate to use (e.g. 9600): ') | ||
baud = raw_input() | ||
base_config['port'] = port | ||
base_config['baud'] = baud | ||
with open(CONF_FILE, 'w') as configfile: | ||
config.write(configfile) | ||
|
||
|
||
if __name__ == '__main__': | ||
print('--- OpenPAYGO Token - Factory Flashing Tool ---') | ||
print('This is meant to be used with the OpenPAYGO Arduino example or a device using the same UART protocol.') | ||
config = configparser.ConfigParser() | ||
config.read(CONF_FILE) | ||
if not 'BASE_CONFIG' in config: | ||
setup_conf(config) | ||
base_config = config['BASE_CONFIG'] | ||
port = base_config['port'] | ||
baud = int(base_config['baud']) | ||
print('Enter the path to the csv file you want to load: ') | ||
csv_file = raw_input() | ||
with open(csv_file, newline='') as csvfile: | ||
device_list_csv = csv.reader(csvfile) | ||
device_data_dict = {serial_number: (starting_code, key) for | ||
serial_number, starting_code, key, c, t, r, h, f in list(device_list_csv)} | ||
print('CSV file loaded! ') | ||
while(1): | ||
print('To flash a device, make sure the device is connected and enter the serial number of the device you want to flash: ') | ||
print('You can press Ctrl+C to quit. ') | ||
serial_number = raw_input() | ||
this_device_data = device_data_dict.get(serial_number) | ||
if not this_device_data: | ||
print('ERROR: Device is not in list!') | ||
else: | ||
flash_device(serial_number, this_device_data[0], this_device_data[1], port, baud) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pyserial==3.4 |
This file was deleted.
Oops, something went wrong.