Skip to content

Commit

Permalink
version 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielguerrer authored Jan 20, 2024
1 parent e4efe7a commit d586e74
Show file tree
Hide file tree
Showing 14 changed files with 519 additions and 264 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
## v1.0.1

* Removed numpy dependency
* Changed maximum line length from 80 to 120. This change does not apply to the code's documentation
* Using "not in" and "is not None"
* Correcting firmware version in eeprom_firmware
* Adding callbacks
* Setting logger name to 'rava'
* Changed health startup results format
* Including hardware float generation (and moved software double to examples)
* Including hardware float generation


## v1.0.2
* Checking for n > 0 in data generation
* Max n of pulse counts, bytes, ints, and floats changed to 2^16 (instead of 2^32)
* Improved the disconnection detection methodology
* Corrected the int_delta in integers generation
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include CHANGELOG.md
include examples/*.py
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ The [RAVA Python Driver](https://github.com/gabrielguerrer/rng_rava_driver_py)
implements the code for communicating with an
[RAVA Device](https://github.com/gabrielguerrer/rng_rava) running the
[RAVA Firmware](https://github.com/gabrielguerrer/rng_rava_firmware).
The computer running the driver assumes the role of the leader device, sending
command requests and reading the data replies.

The firmware establishes a USB CDC communication protocol with the computer
host. Both Linux and Windows are equipped with generic drivers for CDC,
eliminating the need for any specific driver software. This package implements
the serial commands used to control the RAVA device.

The RAVA_RNG class enables the request of pulse counts, random bits, random
bytes, and random numbers (integers and floats). Additionally, it establishes
Expand Down Expand Up @@ -33,8 +36,8 @@ The driver code is available as the
pip install rng_rava
```

Requirements:
* [pyserial](https://github.com/pyserial/pyserial)
Requirements: [pyserial](https://github.com/pyserial/pyserial)


## Usage

Expand Down Expand Up @@ -73,7 +76,7 @@ pc_a, pc_b = rng.get_rng_pulse_counts(n_counts=100)
bit = rng.get_rng_bits(bit_source_id=rava.D_RNG_BIT_SRC['AB_XOR'])
# Generate 100 random bytes en each channel without post-processing
# Output as numpy array
# Output as list, instead of bytestring
bytes_a, bytes_b = rng.get_rng_bytes(n_bytes=100,
postproc_id=rava.D_RNG_POSTPROC['NONE'],
list_output=True)
Expand All @@ -88,11 +91,18 @@ ints16 = rng.get_rng_int16s(n_ints=100, int_delta=10000)
floats = rng.get_rng_floats(n_floats=100)
```

## Firmware Compatibility

Regarding the [RAVA Firmware](https://github.com/gabrielguerrer/rng_rava_firmware):
* Firmware v1.0 is compatible with driver versions from v1.0.0 to latest


## Associated projects

- [RAVA Device](https://github.com/gabrielguerrer/rng_rava)
- [RAVA Firmware](https://github.com/gabrielguerrer/rng_rava_firmware)
- RAVA Python Diagnostics Tool
- [RAVA Python Diagnostics](https://github.com/gabrielguerrer/rng_rava_diagnostics_py)


## Contact

Expand Down
8 changes: 7 additions & 1 deletion examples/led_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@
exit()

# Set color as blue (intensity=0)
print('> Blue color')
rngled.snd_led_color(color_hue=rava.D_LED_COLOR['BLUE'], intensity=0)

# Fade to full intensity
print('> Fade to full intensity')
rngled.snd_led_intensity_fade(intensity_tgt=255, duration_ms=2000)
time.sleep(3)

# Oscilate colors
# Oscillate colors
print('> Oscillate colors')
rngled.snd_led_color_oscillate(n_cycles=3, duration_ms=4000)
time.sleep(5)

# Oscilate intensities
print('> Oscillate intensity')
for i in range(2):
rngled.snd_led_intensity_fade(intensity_tgt=10, duration_ms=2000)
time.sleep(2)
Expand All @@ -37,10 +41,12 @@
time.sleep(1)

# Fade color to red
print('> Fade color to red')
rngled.snd_led_color_fade(color_hue_tgt=rava.D_LED_COLOR['RED'], duration_ms=2000)
time.sleep(3)

# Turn off lights
print('> Lights off')
rngled.snd_led_intensity(intensity=0)

# Close device
Expand Down
8 changes: 4 additions & 4 deletions examples/rava_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import rng_rava as rava

# Set logging level
rava.lg.setLevel(10) # DEBUG
# rava.lg.setLevel(20) # INFO
# rava.lg.setLevel(10) # DEBUG
rava.lg.setLevel(20) # INFO

# Find RAVA device and connect
rava_sns = rava.find_rava_sns()
Expand Down Expand Up @@ -90,7 +90,7 @@ def RNG():
rng.snd_rng_timing_debug_d1(on=True)
rng.snd_rng_timing_debug_d1(on=False)

rng.get_rng_pulse_counts(n_counts=15)
rng.get_rng_pulse_counts(n_counts=15, list_output=True)

rng.get_rng_bits(bit_source_id=rava.D_RNG_BIT_SRC['AB'])
rng.get_rng_bits(bit_source_id=rava.D_RNG_BIT_SRC['A'])
Expand Down Expand Up @@ -244,7 +244,7 @@ def LAMP():
rng.snd_lamp_mode(on=False)

rng.snd_lamp_debug(on=True)
rng.get_lamp_debug()
rng.get_lamp_debug_data()
rng.snd_lamp_debug(on=False)

rng.get_lamp_statistics()
67 changes: 67 additions & 0 deletions examples/rng_bytes_acquisition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'''
This example showcases the generation of a binary file containing random bytes.
This example code is in the public domain.
Author: Gabriel Guerrer
'''

import itertools
import rng_rava as rava

# Variables
FILE_OUTPUT = 'random.bin'
N_BYTES = 1000000 # 1MB
N_CHUNK = 10000

# Find RAVA device and connect
rng = rava.RAVA_RNG()
dev_sns = rava.find_rava_sns()
if len(dev_sns):
rng.connect(serial_number=dev_sns[0])
else:
rava.lg.error('No device found')
exit()

# Calculate n measurements
n_measurements = N_BYTES // N_CHUNK
n_bytes_remmaining = (N_BYTES % N_CHUNK)

# Open file
with open(FILE_OUTPUT, mode='bw') as f:

# Loop over n measurements
for i in range(n_measurements):
print('{:.0f}%'.format(i / n_measurements * 100))

# Generate bytes
bytes_a, bytes_b = rng.get_rng_bytes(n_bytes=N_CHUNK // 2,
postproc_id=rava.D_RNG_POSTPROC['NONE'],
list_output=False,
timeout=None)

# Alternate RNG A and B bytes
bytes_ab = bytes(itertools.chain.from_iterable(zip(bytes_a, bytes_b)))

# Write to file
f.write(bytes_ab)

# Remaining bytes
if n_bytes_remmaining:

# Generate bytes
bytes_a, bytes_b = rng.get_rng_bytes(n_bytes=n_bytes_remmaining // 2,
postproc_id=rava.D_RNG_POSTPROC['NONE'],
list_output=False,
timeout=None)

# Alternate RNG A and B bytes
bytes_ab = bytes(itertools.chain.from_iterable(zip(bytes_a, bytes_b)))

# Write to file
f.write(bytes_ab)

# Finished
print('100%')

# Close device
rng.close()
37 changes: 0 additions & 37 deletions examples/rng_bytes_to_file.py

This file was deleted.

6 changes: 3 additions & 3 deletions examples/rng_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
bit = rng.get_rng_bits(bit_source_id=rava.D_RNG_BIT_SRC['AB_XOR'])

# Generate 100 random bytes en each channel without post-processing
# Output as numpy array
# Output as list, instead of bytestring
bytes_a, bytes_b = rng.get_rng_bytes(n_bytes=100,
postproc_id=rava.D_RNG_POSTPROC['NONE'],
list_output=True)

# Generate 100 8-bit integers between 0 and 99
ints8 = rng.get_rng_int8s(n_ints=100, int_delta=100)
ints8 = rng.get_rng_int8s(n_ints=100, int_delta=99)

# Generate 100 16-bit integers between 0 and 9999
ints16 = rng.get_rng_int16s(n_ints=100, int_delta=10000)
ints16 = rng.get_rng_int16s(n_ints=100, int_delta=9999)

# Generate 100 32-bit floats ranging between 0 and 1
floats = rng.get_rng_floats(n_floats=100)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "rng_rava"
version = "1.0.1"
version = "1.0.2"
authors = [
{ name="Gabriel Guerrer", email="[email protected]" },
]
Expand Down
6 changes: 6 additions & 0 deletions src/rng_rava/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
Copyright (c) 2023 Gabriel Guerrer
Distributed under the MIT license - See LICENSE for details
"""

from .rava_defs import *
from .rava_rng import *
from .rava_rng_aio import *
Expand Down
9 changes: 3 additions & 6 deletions src/rng_rava/rava_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
RAVA_USB_PID = 0x4884

COMM_MSG_START = b'$'

COMM_MSG_LEN = 8

PERIPH_PORTS = 5

GET_TIMEOUT_S = 3.

SERIAL_LISTEN_LOOP_INTERVAL_S = 0.02 # 20 ms, 50 Hz readings

RNG_BYTE_STREAM_MAX_INTERVAL_MS = 4194
GET_TIMEOUT_S = 3.

PERIPH_PORTS = 5

D_DEV_COMM = {
'DEVICE_SERIAL_NUMBER':1,
Expand Down
Loading

0 comments on commit d586e74

Please sign in to comment.