-
Notifications
You must be signed in to change notification settings - Fork 881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flipper raw #1000
Flipper raw #1000
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import math | ||
import os | ||
import re | ||
import tarfile | ||
import wave | ||
|
||
|
@@ -57,6 +58,7 @@ def __init__(self, filename: str, name="Signal", modulation: str = None, sample_ | |
self.iq_array = IQArray(None, np.int8, 1) | ||
|
||
self.wav_mode = filename.endswith(".wav") | ||
self.flipper_raw_mode = filename.endswith(".sub") | ||
self.__changed = False | ||
if modulation is None: | ||
modulation = "FSK" | ||
|
@@ -71,6 +73,8 @@ def __init__(self, filename: str, name="Signal", modulation: str = None, sample_ | |
if len(filename) > 0: | ||
if self.wav_mode: | ||
self.__load_wav_file(filename) | ||
elif self.flipper_raw_mode: | ||
self.__load_sub_file(filename) | ||
elif filename.endswith(".coco"): | ||
self.__load_compressed_complex(filename) | ||
else: | ||
|
@@ -131,6 +135,27 @@ def __load_wav_file(self, filename: str): | |
|
||
self.sample_rate = sample_rate | ||
|
||
def __load_sub_file(self, filename: str): | ||
# Flipper RAW file format (OOK): space separated values, number of samples above (positive value -> 1) | ||
# or below (negative value -> 0) center | ||
params = {"min": 0, "max": 255, "fmt": np.uint8} | ||
params["center"] = (params["min"] + params["max"]) / 2 | ||
arr = [] | ||
with open(filename, 'r') as subfile: | ||
for line in subfile: | ||
dataline = re.match(r'RAW_Data:\s*([-0-9 ]+)\s*$', line) | ||
if dataline: | ||
values = dataline[1].split(r' ') | ||
for value in values: | ||
intval = int(value) | ||
if intval > 0: | ||
arr.extend(np.full(intval, params["max"], dtype=params["fmt"])) | ||
else: | ||
arr.extend(np.zeros(-intval, dtype=params["fmt"])) | ||
Comment on lines
+151
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious about the performance of this: As There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually .sub files are rather small, so that wouldn't be a problem in practice. Due to the file format concept, you unfortunately do not know the number of samples beforehand. I would rather like to stick to the 1-pass solution and risk a slower performance for unusual large files. |
||
self.iq_array = IQArray(None, np.float32, n=len(arr)) | ||
self.iq_array.real = np.multiply(1 / params["max"], np.subtract(arr, params["center"])) | ||
self.__already_demodulated = True | ||
|
||
def __load_compressed_complex(self, filename: str): | ||
obj = tarfile.open(filename, "r") | ||
members = obj.getmembers() | ||
|
@@ -418,6 +443,7 @@ def create_new(self, start=0, end=0, new_data=None): | |
new_signal.__bits_per_symbol = self.bits_per_symbol | ||
new_signal.__center = self.center | ||
new_signal.wav_mode = self.wav_mode | ||
new_signal.flipper_raw_mode = self.flipper_raw_mode | ||
new_signal.__already_demodulated = self.__already_demodulated | ||
new_signal.changed = True | ||
new_signal.sample_rate = self.sample_rate | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we rather check
as we refer to
dataline[1]
in the next line?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When re fails, dataline does not have a len. This code follows the concept from: https://gist.github.com/jinschoi/40a470e432c6ac244be8159145454b5c