Skip to content

Commit

Permalink
v1.0.1 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielguerrer authored Nov 4, 2023
1 parent 9c0a969 commit e4efe7a
Show file tree
Hide file tree
Showing 17 changed files with 840 additions and 936 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## 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)
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ pip install rng_rava
```

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

## Usage

Expand All @@ -50,11 +49,11 @@ rng = rava.RAVA_RNG()
rng.connect(serial_number=rava_sns[0])
'''
The default PWM and RNG configuration parameters are stored in the EEPROM memory
and can be accessed with rng.get_eeprom_pwm() and rng.get_eeprom_rng(). If
desired, users can modify the default values using the respective snd_ functions.
Additionally, it is possible to make non-permanent configuration changes using
the following commands:
The default PWM and RNG configuration parameters are stored in the EEPROM memory
and can be accessed with rng.get_eeprom_pwm() and rng.get_eeprom_rng(). If
desired, users can modify the default values using the respective snd_
functions. Additionally, it is possible to make non-permanent configuration
changes using the following commands:
'''
# Configure PWM
Expand All @@ -71,25 +70,22 @@ Next, the generation of various random data types is demonstrated.
pc_a, pc_b = rng.get_rng_pulse_counts(n_counts=100)
# Generate a random bit XORing both channels
bit = rng.get_rng_bits(bit_type_id=rava.D_RNG_BIT_SRC['AB_XOR'])
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
bytes_a, bytes_b = rng.get_rng_bytes(n_bytes=100,
postproc_id=rava.D_RNG_POSTPROC['NONE'],
out_type=rava.D_RNG_BYTE_OUT['NUMPY_ARRAY'])
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_max=100)
ints8 = rng.get_rng_int8s(n_ints=100, int_delta=100)
# Generate 100 16-bit integers between 0 and 999
ints16 = rng.get_rng_int16s(n_ints=100, int_max=999)
# Generate 100 16-bit integers between 0 and 9999
ints16 = rng.get_rng_int16s(n_ints=100, int_delta=10000)
# Generate 100 32-bit floats ranging between 0 and 1
floats = rng.get_rng_floats(n_floats=100)
# Generate 100 64-bit doubles ranging between 0 and 1
doubles = rng.get_rng_doubles(n_doubles=100)
```

## Associated projects
Expand Down
28 changes: 10 additions & 18 deletions examples/lamp_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,37 +52,29 @@ def measure_lamp_statistics():

# Print results
print('\nLamp Statistics'
'\nLasted {:.0f}h {:.0f}m {:.0f}s, yielding {} experiments'
.format(delta_t_h, delta_t_min, delta_t_s, exp_n),
'\nLasted {:.0f}h {:.0f}m {:.0f}s, yielding {} experiments'.format(delta_t_h, delta_t_min, delta_t_s, exp_n),

'\n where {} ({:.2f}%) reached statistical significance'
.format(stats['exp_n_zsig'],
stats['exp_n_zsig']/exp_n*100),
'\n where {} ({:.2f}%) reached statistical significance'.format(stats['exp_n_zsig'],
stats['exp_n_zsig']/exp_n*100),

'\nMeaning one should expect to find:',

'\n {:.2f} significant events per 1 min'
.format(stats['exp_n_zsig']/delta_t*60),
'\n {:.2f} significant events per 1 min'.format(stats['exp_n_zsig']/delta_t*60),

'\n {:.2f} significant events per 5 min'
.format(stats['exp_n_zsig']/delta_t*300),
'\n {:.2f} significant events per 5 min'.format(stats['exp_n_zsig']/delta_t*300),

'\n {:.2f} significant events per 10 min'
.format(stats['exp_n_zsig']/delta_t*600),
'\n {:.2f} significant events per 10 min'.format(stats['exp_n_zsig']/delta_t*600),

'\n {:.2f} significant events per 30 min'
.format(stats['exp_n_zsig']/delta_t*1800),
'\n {:.2f} significant events per 30 min'.format(stats['exp_n_zsig']/delta_t*1800),

'\n {:.2f} significant events per 1 h'
.format(stats['exp_n_zsig']/delta_t*3600),
'\n {:.2f} significant events per 1 h'.format(stats['exp_n_zsig']/delta_t*3600),

'\nColor distribution (%):',

'\n R={:.2f} O={:.2f} Y={:.2f} G={:.2f}'
'\n C={:.2f} B={:.2f} PU={:.2f} PI={:.2f}'
.format(stats['red']/exp_n*100, stats['orange']/exp_n*100,
stats['yellow']/exp_n*100, stats['green']/exp_n*100,
stats['cyan']/exp_n*100, stats['blue']/exp_n*100,
.format(stats['red']/exp_n*100, stats['orange']/exp_n*100, stats['yellow']/exp_n*100,
stats['green']/exp_n*100, stats['cyan']/exp_n*100, stats['blue']/exp_n*100,
stats['purple']/exp_n*100, stats['pink']/exp_n*100))

measure_lamp_statistics()
6 changes: 3 additions & 3 deletions examples/led_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
rngled = rava.RAVA_RNG_LED()
dev_sns = rava.find_rava_sns()
if len(dev_sns):
rngled.connect(serial_number=dev_sns[0])
rngled.connect(serial_number=dev_sns[0])
else:
rava.lg.error('No device found')
exit()
Expand All @@ -21,8 +21,8 @@
rngled.snd_led_color(color_hue=rava.D_LED_COLOR['BLUE'], intensity=0)

# Fade to full intensity
rngled.snd_led_intensity_fade(intensity_tgt=255, duration_ms=1000)
time.sleep(2)
rngled.snd_led_intensity_fade(intensity_tgt=255, duration_ms=2000)
time.sleep(3)

# Oscilate colors
rngled.snd_led_color_oscillate(n_cycles=3, duration_ms=4000)
Expand Down
88 changes: 39 additions & 49 deletions examples/rava_interactive.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'''
This file should be opened in an interactive Python environment. In VSCode, the
users can utilize the F6 shortcut to execute the initial code, establishing a
connection with the device. Next, users can navigate the code and execute each
line by positioning the cursor and pressing Shift + Enter. This approach
This file should be opened in an interactive Python environment. In VSCode, the
users can utilize the F6 shortcut to execute the initial code, establishing a
connection with the device. Next, users can navigate the code and execute each
line by positioning the cursor and pressing Shift + Enter. This approach
facilitates comprehensive testing of the RAVA's functionality.
This example code is in the public domain.
Expand All @@ -27,27 +27,23 @@
def DEVICE():

rng.connect(serial_number=rava_sns[0])

rng.connected()

rng.close()

rng.get_device_serial_number()

rng.get_device_temperature()

rng.get_device_free_ram()

rng.snd_device_reboot()


def EEPROM():

rng.snd_eeprom_reset_to_default()

rng.get_eeprom_device()
rng.snd_eeprom_device(temp_calib_slope=397, temp_calib_intercept=-280)
rng.snd_eeprom_device(temp_calib_slope=300, temp_calib_intercept=-200)
rng.snd_eeprom_device(temp_calib_slope=1, temp_calib_intercept=0)

rng.get_eeprom_firmware()

Expand All @@ -64,8 +60,8 @@ def EEPROM():
rng.snd_eeprom_rng(sampling_interval_us=15)

rng.get_eeprom_led()
rng.snd_eeprom_led(led_attached=0)
rng.snd_eeprom_led(led_attached=1)
rng.snd_eeprom_led(led_attached=False)
rng.snd_eeprom_led(led_attached=True)

rng.get_eeprom_lamp()
rng.snd_eeprom_lamp(exp_dur_max_ms=5*60*1000, exp_z_significant=3.925, exp_mag_smooth_n_trials=20)
Expand Down Expand Up @@ -93,44 +89,37 @@ 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=100)

rng.get_rng_bits(bit_type_id=rava.D_RNG_BIT_SRC['AB'])
rng.get_rng_bits(bit_type_id=rava.D_RNG_BIT_SRC['A'])
rng.get_rng_bits(bit_type_id=rava.D_RNG_BIT_SRC['B'])
rng.get_rng_bits(bit_type_id=rava.D_RNG_BIT_SRC['AB_XOR'])
rng.get_rng_bits(bit_type_id=rava.D_RNG_BIT_SRC['AB_RND'])

rng.get_rng_bytes(n_bytes=100, postproc_id=rava.D_RNG_POSTPROC['NONE'], out_type=rava.D_RNG_BYTE_OUT['NUMPY_ARRAY'])
rng.get_rng_bytes(n_bytes=100, postproc_id=rava.D_RNG_POSTPROC['XOR'], out_type=rava.D_RNG_BYTE_OUT['PY_LIST'])
rng.get_rng_bytes(n_bytes=100, postproc_id=rava.D_RNG_POSTPROC['XOR_DICHTL'], out_type=rava.D_RNG_BYTE_OUT['PY_BYTES'])
rng.get_rng_bytes(n_bytes=100, postproc_id=rava.D_RNG_POSTPROC['VON_NEUMANN'], out_type=rava.D_RNG_BYTE_OUT['NUMPY_ARRAY'])

rng.get_rng_int8s(n_ints=100, int_max=99)
rng.get_rng_int16s(n_ints=100, int_max=999)
rng.get_rng_floats(n_floats=100)
rng.get_rng_doubles(n_doubles=100)

rng.get_rng_byte_stream_status()
rng.get_rng_pulse_counts(n_counts=15)

rng.snd_rng_byte_stream_start(n_bytes=1, stream_delay_ms=50, postproc_id=rava.D_RNG_POSTPROC['NONE'])
rng.snd_rng_byte_stream_start(n_bytes=10000, stream_delay_ms=0, postproc_id=rava.D_RNG_POSTPROC['NONE'])
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'])
rng.get_rng_bits(bit_source_id=rava.D_RNG_BIT_SRC['B'])
rng.get_rng_bits(bit_source_id=rava.D_RNG_BIT_SRC['AB_XOR'])
rng.get_rng_bits(bit_source_id=rava.D_RNG_BIT_SRC['AB_RND'])

rng.get_rng_byte_stream_data(out_type=rava.D_RNG_BYTE_OUT['PY_BYTES'])
rng.get_rng_byte_stream_data(out_type=rava.D_RNG_BYTE_OUT['NUMPY_ARRAY'])
rng.get_rng_bytes(n_bytes=15, postproc_id=rava.D_RNG_POSTPROC['NONE'], list_output=True)
rng.get_rng_bytes(n_bytes=15, postproc_id=rava.D_RNG_POSTPROC['XOR'], list_output=True)
rng.get_rng_bytes(n_bytes=15, postproc_id=rava.D_RNG_POSTPROC['XOR_DICHTL'], list_output=True)
rng.get_rng_bytes(n_bytes=15, postproc_id=rava.D_RNG_POSTPROC['VON_NEUMANN'], list_output=True)

rng.get_rng_int8s(n_ints=15, int_delta=10)
rng.get_rng_int8s(n_ints=15, int_delta=100)
rng.get_rng_int16s(n_ints=15, int_delta=1000)
rng.get_rng_floats(n_floats=15)

rng.get_rng_byte_stream_status()
rng.snd_rng_byte_stream_start(n_bytes=10, stream_interval_ms=200, postproc_id=rava.D_RNG_POSTPROC['NONE'])
rng.get_rng_byte_stream_data(list_output=True)
rng.snd_rng_byte_stream_stop()


def HEALTH():

rng.snd_health_startup_run()

rng.get_health_startup_results()

rava.print_health_startup_results(*rng.get_health_startup_results())

rng.get_health_continuous_errors()


Expand Down Expand Up @@ -177,8 +166,8 @@ def PERIPHERALS():
rng.snd_periph_d1_trigger_input(on=True)
rng.snd_periph_d1_trigger_input(on=False)

rng.snd_periph_d1_comparator(neg_to_adc12=False)
rng.snd_periph_d1_comparator(neg_to_adc12=True)
rng.snd_periph_d1_comparator(neg_to_d5=False)
rng.snd_periph_d1_comparator(neg_to_d5=True)
rng.snd_periph_d1_comparator(on=False)

rng.snd_periph_digi_mode(periph_id=1, mode_id=rava.D_PERIPH_MODES['OUTPUT'])
Expand All @@ -187,13 +176,13 @@ def PERIPHERALS():
rng.snd_periph_d1_delay_us_test(delay_us=10)

# Running with an unconnected D2 may flood the driver with random signaling
rng.snd_periph_d2_input_capture(on=True)
rng.snd_periph_d2_input_capture(on=True)
rng.snd_periph_d2_input_capture(on=False)
rng.get_periph_d2_input_capture()
rng.get_periph_d2_input_capture()

rng.snd_periph_d3_timer3_trigger_output(delay_ms=1)
rng.snd_periph_d3_timer3_trigger_output(delay_ms=10)
rng.snd_periph_d3_timer3_trigger_output(delay_ms=100)
rng.snd_periph_d3_timer3_trigger_output(interval_ms=1)
rng.snd_periph_d3_timer3_trigger_output(interval_ms=10)
rng.snd_periph_d3_timer3_trigger_output(interval_ms=100)
rng.snd_periph_d3_timer3_trigger_output(on=False)

rng.snd_periph_d3_timer3_pwm(freq_prescaler=1, top=2**16-1, duty=1000)
Expand All @@ -202,15 +191,15 @@ def PERIPHERALS():
rng.snd_periph_d3_timer3_pwm(on=False)

rng.snd_periph_d4_pin_change(on=True)
rng.snd_periph_d4_pin_change(on=False)
rng.snd_periph_d4_pin_change(on=False)

rng.get_periph_d5_adc_read(ref_5v=0, clk_prescaler=1, oversampling_n_bits=0)
rng.get_periph_d5_adc_read(ref_5v=0, clk_prescaler=6, oversampling_n_bits=0)
rng.get_periph_d5_adc_read(ref_5v=1, clk_prescaler=6, oversampling_n_bits=0)
rng.get_periph_d5_adc_read(ref_5v=0, clk_prescaler=6, oversampling_n_bits=6)
rng.get_periph_d5_adc_read(on=False)
rng.get_periph_d5_adc_read(ref_5v=1, clk_prescaler=6, oversampling_n_bits=6)


def INTERFACES():
def INTERFACES():

rng.get_interface_ds18bs0()

Expand Down Expand Up @@ -255,6 +244,7 @@ def LAMP():
rng.snd_lamp_mode(on=False)

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

rng.get_lamp_statistics()
19 changes: 9 additions & 10 deletions examples/rng_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
This example showcases asynchronous RNG functionality.
This example showcases asynchronous RNG functionality.
This example code is in the public domain.
Author: Gabriel Guerrer
Expand All @@ -15,7 +15,7 @@ async def main():
rng = rava.RAVA_RNG_AIO()
dev_sns = rava.find_rava_sns()
if len(dev_sns):
await rng.connect(dev_sns[0])
await rng.connect(dev_sns[0])
else:
rava.lg.error('No device found')
exit()
Expand All @@ -25,15 +25,14 @@ async def main():
print('\nRNG setup: {}\n'.format(await rng.get_rng_setup()))

# Generate random data
N_DATA = 30
results = await asyncio.gather(
rng.get_rng_pulse_counts(n_counts=10),
rng.get_rng_bits(bit_type_id=rava.D_RNG_BIT_SRC['AB']),
rng.get_rng_bytes(n_bytes=10, postproc_id=rava.D_RNG_POSTPROC['NONE'],
out_type=rava.D_RNG_BYTE_OUT['NUMPY_ARRAY']),
rng.get_rng_int8s(n_ints=10, int_max=99),
rng.get_rng_int16s(n_ints=10, int_max=999),
rng.get_rng_floats(n_floats=10),
rng.get_rng_doubles(n_doubles=10)
rng.get_rng_pulse_counts(n_counts=N_DATA),
rng.get_rng_bits(bit_source_id=rava.D_RNG_BIT_SRC['AB']),
rng.get_rng_bytes(n_bytes=N_DATA, postproc_id=rava.D_RNG_POSTPROC['NONE'], list_output=True),
rng.get_rng_int8s(n_ints=N_DATA, int_delta=100),
rng.get_rng_int16s(n_ints=N_DATA, int_delta=1000),
rng.get_rng_floats(n_floats=N_DATA)
)
print('\nRNG data: {}\n'.format(results))

Expand Down
7 changes: 3 additions & 4 deletions examples/rng_byte_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@
rng = rava.RAVA_RNG()
dev_sns = rava.find_rava_sns()
if len(dev_sns):
rng.connect(serial_number=dev_sns[0])
rng.connect(serial_number=dev_sns[0])
else:
rava.lg.error('No device found')
exit()

# Generate 3 bytes every 0.5s
rng.snd_rng_byte_stream_start(n_bytes=3, stream_delay_ms=500)
rng.snd_rng_byte_stream_start(n_bytes=5, stream_interval_ms=500)

# Print 10 first values
print()
for i in range(10):
rnd_a, rnd_b = rng.get_rng_byte_stream_data(
out_type=rava.D_RNG_BYTE_OUT['NUMPY_ARRAY'])
rnd_a, rnd_b = rng.get_rng_byte_stream_data(list_output=True)
print('RNG A, B = {}, {}'.format(rnd_a, rnd_b))

# Stop stream
Expand Down
Loading

0 comments on commit e4efe7a

Please sign in to comment.