Skip to content
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

Detect/pay sounds via mplayer or aplay #18

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ccd316c
Detect/pay sounds via mplayer or aplay
TheBiggerGuy Feb 11, 2017
f56c4a0
Merge remote-tracking branch 'upstream/master'
TheBiggerGuy Feb 11, 2017
ca9bca2
Merge branch 'master' of https://github.com/muccc/iridium-toolkit
TheBiggerGuy Mar 29, 2017
63921be
Update stats-voc.py to more modern python
TheBiggerGuy May 10, 2018
066c25c
Make play-iridium-ambe streamable
TheBiggerGuy May 10, 2018
c6e6093
Only parse each line once in stats-voc.py
TheBiggerGuy May 10, 2018
3e48bdf
Add clustering to stats-voc.py
TheBiggerGuy May 10, 2018
e252732
Detect and fail on raw data in stats-voc.py
TheBiggerGuy May 10, 2018
fd1b736
Add tests for bits_to_dfs.py
TheBiggerGuy May 10, 2018
a1c56ec
Auto calculate good cluster threshold
TheBiggerGuy May 10, 2018
d372ea2
More bits_to_dfs.py tests
TheBiggerGuy May 11, 2018
bb9c8e4
Allow filtering stats-voc.py by start time
TheBiggerGuy May 11, 2018
72cc33a
Allow filtering stats-voc.py by end time
TheBiggerGuy May 11, 2018
82d47e9
First setup.py work
TheBiggerGuy May 11, 2018
af0d007
Limit coverage metrics to this package
TheBiggerGuy May 11, 2018
4650072
Add pypy testing
TheBiggerGuy May 11, 2018
b2c18ae
Try and get travis working
TheBiggerGuy May 11, 2018
88c9c35
Update Readme
TheBiggerGuy May 11, 2018
b5b08d6
Alow pypy builds to fail
TheBiggerGuy May 11, 2018
0d8f869
Alow numpy 1.11.1 the default for pypy
TheBiggerGuy May 11, 2018
b895435
Disable pypy buid due to scipy
TheBiggerGuy May 11, 2018
7d607ec
Reorg VOC line parsing
TheBiggerGuy May 11, 2018
fe750f2
Add more stats_voc tests
TheBiggerGuy May 12, 2018
970022e
Remove scipy dependency
TheBiggerGuy May 12, 2018
bcd7d5a
Update stats.py and rename graphing tools
TheBiggerGuy May 12, 2018
dd46e51
Small clean up and missing renames
TheBiggerGuy May 12, 2018
0a4342e
Fix play-iridium-ambe script
TheBiggerGuy May 12, 2018
1fe78fa
Remove multiple file writes when playing audio
TheBiggerGuy May 12, 2018
072396b
Clean up audio playing in graph_voc.py
TheBiggerGuy May 13, 2018
2f3c205
Add the first linter, flake8
TheBiggerGuy May 13, 2018
d56a4a1
Add pylint to linters
TheBiggerGuy May 13, 2018
4d421e2
Enable more linter options
TheBiggerGuy May 13, 2018
607afe9
Clean up rx-stats-X-hist.py ready for merging
TheBiggerGuy May 13, 2018
4bf6277
Add template for iridiumtk/test_graph_by_type.py
TheBiggerGuy May 13, 2018
8faaee5
Fix lint rule
TheBiggerGuy May 13, 2018
4949aee
Merge common rx_stats tools into rx_stats_hist.py
TheBiggerGuy May 13, 2018
b2f59fb
Enable linters in travis
TheBiggerGuy May 13, 2018
8bbd587
First support for Python3.6 in graph-voc
TheBiggerGuy May 14, 2018
e5baf64
Test Python3.6 in travis
TheBiggerGuy May 14, 2018
bdef505
Clean up and add py3 support
TheBiggerGuy May 15, 2018
8a8957a
Move reassembler and add to setup
TheBiggerGuy May 15, 2018
c55f2ef
Clean up and add py3 support
TheBiggerGuy May 15, 2018
871d9aa
Enable travis for reassembler branch
TheBiggerGuy May 15, 2018
d1409c1
Add IraLine parser
TheBiggerGuy May 15, 2018
b6b9cd5
Add MSG parser and impprove base_parser
TheBiggerGuy May 15, 2018
d2f222c
Open output file as binary
TheBiggerGuy May 29, 2018
aafb11d
Add extra type filter to graph_by_type
TheBiggerGuy May 29, 2018
41a2bd7
Work to clean up reassembler.py
TheBiggerGuy May 29, 2018
99fac54
Merge branch 'reassembler'
TheBiggerGuy May 29, 2018
fc8b0c1
Enable travis on all branches
TheBiggerGuy May 29, 2018
4d214d7
Move to just Python3.6+ support
TheBiggerGuy May 30, 2018
4aee04c
Fix timezone and py2->3 conversion issues.
TheBiggerGuy May 30, 2018
6dddc27
Fix lint issues
TheBiggerGuy May 30, 2018
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
Prev Previous commit
Next Next commit
Allow filtering stats-voc.py by start time
TheBiggerGuy committed May 11, 2018
commit bb9c8e4a714aa99bacd5371104e6f6664c7de95c
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
numpy>=1.14.0
scipy>=1.1.0
six>=1.11.0
dateparser>=0.7.0
71 changes: 51 additions & 20 deletions stats-voc.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
#!/usr/bin/python
# vim: set ts=4 sw=4 tw=0 et fenc=utf8 pm=:
#VOC: i-1430527570.4954-t1 421036605 1625859953 66% 0.008 219 L:no LCW(0,001111,100000000000000000000 E1) 101110110101010100101101111000111111111001011111001011010001000010010001101110011010011001111111011101111100011001001001000111001101001011001011000101111111101110110011111000000001110010001110101101001010011001101001010111101100011100110011110010110110101010110001010000100100101011010010100100100011010110101001

import sys
import matplotlib.pyplot as plt
import os
import subprocess
import fileinput
import logging
import tempfile
from datetime import datetime
import argparse

import numpy as np
import scipy.cluster.hierarchy as hcluster
import six
import dateparser

from bits_to_dfs import bits_to_dfs

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Example lines
# VOC: i-1430527570.4954-t1 421036605 1625859953 66% 0.008 219 L:no LCW(0,001111,100000000000000000000 E1) 101110110101010100101101111000111111111001011111001011010001000010010001101110011010011001111111011101111100011001001001000111001101001011001011000101111111101110110011111000000001110010001110101101001010011001101001010111101100011100110011110010110110101010110001010000100100101011010010100100100011010110101001
# VOC: i-1526039037-t1 000065686 1620359296 100% 0.003 179 DL LCW(0,T:maint,C:maint[2][lqi:3,power:0,f_dtoa:0,f_dfoa:127](3),786686 E0) [df.ff.f3.fc.10.33.c3.1f.0c.83.c3.cc.cc.30.ff.f3.ef.00.bc.0c.b4.0f.dc.d0.1a.cc.9c.c5.0c.fc.28.01.cc.38.c2.33.e0.ff.4f]

class VocLine(object):
def __init__(self, line):
self.line = line
line_split = line.split()
self.lcw = line[8]
#ts_base = int(line[1].split('-')[1].split('.')[0])
ts_base = 0
self.ts = ts_base + int(line_split[2])/1000.
self.f = int(line_split[3])/1000.
try:
line_split = line.split()

raw_time_base = line_split[1]
ts_base_ms = int(raw_time_base.split('-')[1].split('.')[0])

time_offset_ns = int(line_split[2])
self.ts = ts_base_ms + (time_offset_ns / 1000)

self.f = int(line_split[3])/1000.
self.lcw = line[8]
except Exception as e:
six.raise_from(Exception('Failed to parse line "{}"'.format(line), e), e)

def datetime(self):
return datetime.utcfromtimestamp(self.ts)



class OnClickHandler(object):
@@ -99,40 +116,54 @@ def cut_convert_play(self, t_start, t_stop, f_min, f_max):
logger.info('Finished Playing')


def read_lines():
def read_lines(input_files, start_time_filter):
lines = []
for line in fileinput.input():
for line in fileinput.input(files=input_files):
line = line.strip()
if 'A:OK' in line and "Message: Couldn't parse:" not in line:
raise RuntimeError('Expected "iridium-parser.py" parsed data. Found raw "iridium-extractor" data.')
if 'VOC: ' in line and not "LCW(0,001111,100000000000000000000" in line:
lines.append(VocLine(line))
voc_line = VocLine(line)
if start_time_filter and start_time_filter > voc_line.datetime():
continue
lines.append(voc_line)
return lines

def main():
lines = read_lines()
parser = argparse.ArgumentParser(description='Convert iridium-parser.py VOC output to DFS')
parser.add_argument('--start', metavar='DATETIME', default=None, help='Filter events before this time')
parser.add_argument('input', metavar='FILE', nargs='*', help='Files to read, if empty or -, stdin is used')
args = parser.parse_args()

input_files = args.input if len(args.input) > 0 else ['-']
start_time_filter = dateparser.parse(args.start) if args.start else None

lines = read_lines(input_files, start_time_filter)
number_of_lines = len(lines)
logger.info('Read %d VOC lines from input', number_of_lines)

tsl = np.empty(number_of_lines)
fl = np.empty(number_of_lines)
if number_of_lines == 0:
print('No usable data found')
sys.exit(1)

plot_data = np.empty((number_of_lines, 2))
for i, voc_line in enumerate(lines):
tsl[i] = voc_line.ts
fl[i] = voc_line.f
plot_data[i][0] = voc_line.ts
plot_data[i][1] = voc_line.f
plot_data[i][1] = np.float64(voc_line.f)

distances = hcluster.distance.pdist(plot_data)
thresh = 2 * distances.min()
clusters = hcluster.fclusterdata(plot_data, thresh, criterion="distance")

fig = plt.figure()
#fig.autofmt_xdate()
on_click_handler = OnClickHandler(lines)
fig.canvas.mpl_connect('button_press_event', on_click_handler.onclick)

ax = fig.add_subplot(1, 1, 1)
ax.scatter(*np.transpose(plot_data), c=clusters)

on_click_handler = OnClickHandler(lines)
cid = fig.canvas.mpl_connect('button_press_event', on_click_handler.onclick)
#ax.xaxis_date()
ax.grid(True)

plt.title('Click once left and once right to define an area.\nThe script will try to play iridium using ir77_ambe_decode and aplay.')
plt.xlabel('time')