Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions software/acoustic-release/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-docstring-first
- id: check-merge-conflict
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-ast
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint --disable=too-many-instance-attributes,too-many-arguments,missing-module-docstring
language: python
types: [ python ]
- repo: local
hooks:
- id: unittest
name: Full release sequence
entry: pytest python/unit_test.py
language: system
'types': [ python ]
pass_filenames: false
stages: [ commit ]
34 changes: 34 additions & 0 deletions software/acoustic-release/arduino_rx/arduino_rx.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "src/flag_tones_to_symbol.h"
#include "src/update_flag_wake_up.h"

void setup() {
Serial.begin(9600);

// put your setup code here, to run once:
float tab[] = {1.0, -1.0};

int symbol = flag_tones_to_symbol(tab);
Serial.print("test flag_tones_to_symbol : ");
Serial.println(symbol);

bool flag[] = {true, false, false};
int index[] = {4, -1, -1};
int threshold = 4;
int index_flag_update = 1;

int event = update_flag_wake_up(flag, index, index_flag_update, threshold);
for (int i_tone = 0; i_tone < 3; i_tone++) {
Serial.println("==========================");
Serial.print("test flag[i_tone] : ");
Serial.println(flag[i_tone]);
Serial.print("test index[i_tone] ");
Serial.println(index[i_tone]);
}

Serial.print("test flag_tones_to_symbol EVENT: ");
Serial.println(event);
}

void loop() {

}
Empty file.
14 changes: 14 additions & 0 deletions software/acoustic-release/arduino_rx/src/flag_tones_to_symbol.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "flag_tones_to_symbol.h"

int flag_tones_to_symbol(float* flag){
/*
The flag_tones_to_symbol function takes a flag as input and
returns the symbol that it represents.

:param flag: Store the flag tones
:return: The number of tones in the flag

*/

return static_cast<int>(flag[1] - flag[0]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef FLAG_TONES_TO_SYMBOL_H_INCLUDED
#define FLAG_TONES_TO_SYMBOL_H_INCLUDED

int flag_tones_to_symbol(float* flag);

#endif /*FLAG_TONES_TO_SYMBOL_H_INCLUDED*/
52 changes: 52 additions & 0 deletions software/acoustic-release/arduino_rx/src/update_flag_wake_up.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "update_flag_wake_up.h"
#include <string.h> // for using memcpy (library function)

int update_flag_wake_up(bool* flag_tab, int* index_tab, int current_flag, int threshold){
/*
The update_flag_wake_up function is used to update the flag and
index values for each channel. The function takes in a flag, current_flag,
and threshold value as inputs. The function then updates the flag_value array
by setting all the values that are equal to True in current_flag to 0. It then
sets all the values that are equal to True in flag_value (which will be any
peaks detected) to 1 more than their previous value. If this new value is greater
than a threshold, it sets both its index and flag_value
back down to - 1 (so it can start over).

:param flag: Keep track of the previous state of the flag
:param current_flag: Indicate the index of the current flag
:param threshold: Determine how many samples must pass before the flag is reset
:return: The flag and the index of the changed flags
*/

bool new_flag_tab[3];
memcpy(new_flag_tab, flag_tab, 3 * sizeof(bool)); // int is a POD

// if a peak is detected
index_tab[current_flag] = 0;
flag_tab[current_flag] = true;

for (int i_tone = 0; i_tone < 3; i_tone++) {

// update counter for each detected tone
if (flag_tab[i_tone] == true){
index_tab[i_tone]++;
}

// if the last peak was threshold samples ago
if (index_tab[i_tone] > threshold){
flag_tab[i_tone] = false;
index_tab[i_tone] = -1;
}
}

// check if one flag has changed: the loop could be avoided
int event = -1;
for (int i_tone = 0; i_tone < 3; i_tone++) {
if (new_flag_tab[i_tone] != flag_tab[i_tone]){
event = i_tone;
break;
}
}

return event;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef UPDATE_FLAG_WAKE_UP_H_INCLUDED
#define UPDATE_FLAG_WAKE_UP_H_INCLUDED

int update_flag_wake_up(bool* flag_tab, int* index_tab, int current_flag, int threshold);

#endif /*UPDATE_FLAG_WAKE_UP_H_INCLUDED*/
31 changes: 31 additions & 0 deletions software/acoustic-release/arduino_rx/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CC=g++

CFLAGS=-O0 -g3 -march=native -mtune=native -std=c++14

LDFLAGS=

EXEC=main

SRC=./utils/flag_tones_to_symbol.cpp \
./utils/update_flag_wake_up.cpp \
main.cpp


OBJ= $(SRC:.cpp=.o)

all: $(EXEC)

main: $(OBJ)
$(CC) $(CFLAGS) -o ./$@ $^ $(LDFLAGS)

%.o: %.cpp
$(CC) $(CFLAGS) -o $@ -c $<

.PHONY: clean mrproper

clean:
find ./bin -name main -exec rm {} \;
find ./src -name *.o -exec rm {} \;

mrproper: clean
rm $(EXEC)
Binary file added software/acoustic-release/arduino_rx/tests/main
Binary file not shown.
26 changes: 26 additions & 0 deletions software/acoustic-release/arduino_rx/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include "./utils/flag_tones_to_symbol.h"
#include "./utils/update_flag_wake_up.h"
using namespace std;

int main(int argc, char** argv){
float tab[] = {1.0, -1.0};

int symbol = flag_tones_to_symbol(tab);
cout << "test flag_tones_to_symbol : " << symbol << endl;

bool flag[] = {true, false, false};
int index[] = {4, -1, -1};
int threshold = 4;
int index_flag_update = 1;

int event = update_flag_wake_up(flag, index, index_flag_update, threshold);
for (int i_tone = 0; i_tone < 3; i_tone++) {
cout << " ========== " << endl;
cout << "test flag[i_tone] : " << flag[i_tone] << endl;
cout << "test index[i_tone] : " << index[i_tone] << endl;
}
cout << "test flag_tones_to_symbol EVENT: " << event << endl;

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "tones_detection.h"

int tones_detection(float* signal, int* index_tones, float threshold){



}
29 changes: 29 additions & 0 deletions software/acoustic-release/arduino_rx/tests/tones_detection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* CPixel.h
* P_Bitmap
*
* Created by Le Gal on 24/10/06.
* Copyright 2006 __MyCompanyName__. All rights reserved.
*
*/
/*
* CPixel.h
* P_Bitmap
*
* Created by Le Gal on 24/10/06.
* Copyright 2006 __MyCompanyName__. All rights reserved.
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;

#ifndef TONES_DETECTION_H_
#define TONES_DETECTION_H_

int tones_detection(float* signal, int* index_tones, float threshold);

#endif /*TONES_DETECTION_H_*/
9 changes: 9 additions & 0 deletions software/acoustic-release/arduino_tx/arduino_tx.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}
15 changes: 15 additions & 0 deletions software/acoustic-release/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"waveform": {
"pulse_width": 0.8,
"pulse_repetition_interval": 1,
"carrier_frequency": 10000,
"frequency_shift": 400
},
"processing": {
"threshold_wake_up": 4,
"threshold_release": 4,
"n_sample_buffer": 500,
"n_sample_step": 128,
"sample_rate": 48000
}
}
27 changes: 27 additions & 0 deletions software/acoustic-release/config/generator/generate_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# %% Packages
import json
import jsbeautifier

# %% Data to be written
dictionary = {
"waveform": {"pulse_width": 0.8,
"pulse_repetition_interval": 1,
"carrier_frequency": 10_000,
"frequency_shift": 400
},
"processing": {"threshold_wake_up": 4,
"threshold_release": 4,
"n_sample_buffer": 500,
"n_sample_step": 128,
"sample_rate": 48_000
},
}

# %% Serializing json
options = jsbeautifier.default_options()
options.indent_size = 4
payload = jsbeautifier.beautify(json.dumps(dictionary), options)

# %% Writing to sample.json
with open("../config.json", "w", encoding="utf-8") as outfile:
outfile.write(payload)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# %% Packages
import json
import jsbeautifier
import numpy as np
from numpy.random import randint

# %% Parameters
n_sequences = 2048
length_sequence = 13

# %% Generate sequence
sequences = randint(low=0, high=2, size=(n_sequences, length_sequence))
# the first sequence is a 13-Barker Code
sequences[0, :] = np.array([1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1])

# Take only unique sequences
_, index_unique = np.unique(np.array([str(e) for e in sequences]), return_index=True)
sequences = sequences[index_unique.sort(), :].reshape(-1, length_sequence)

# convert to list
sequences = sequences.tolist()
n_sequences = len(sequences)

# %% Generate associate index
ids = [str(current_id) for current_id in np.arange(1, n_sequences + 1).tolist()]
release_sequence = [{'release_sequence': current_sequence} for current_sequence in sequences]

# %% Data to be written
nested_dictionary = dict(zip(ids, release_sequence))

# %% Serializing json
options = jsbeautifier.default_options()
options.indent_size = 4
payload = jsbeautifier.beautify(json.dumps(nested_dictionary), options)

# %% Writing to sample.json
with open("../release_sequences.json", "w", encoding="utf-8") as outfile:
outfile.write(payload)
Loading