Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
Merge branch 'rpi' of localhost:/home/git/sensorgnome into rpi
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrzusto committed Apr 1, 2017
2 parents 43139a6 + 1368f30 commit 618e91d
Show file tree
Hide file tree
Showing 49 changed files with 12,472 additions and 136 deletions.
3 changes: 3 additions & 0 deletions master/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
get_clocks: get_clocks.c
gcc -O3 -o get_clocks get_clocks.c -lrt
strip get_clocks
108 changes: 108 additions & 0 deletions master/defaultDeployment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"info": "default deployment",
"who": "who is responsible for this deployment",
"contact": "contact information for responsible party",
"shortLabel": "SG1",
"acquire": {
"gps": {
"secondsBetweenFixes": 300
},
"USB": {
"portInfo": [
"info for USB hub port 1",
"info for USB hub port 2",
"info for USB hub port 3",
"info for USB hub port 4",
"info for USB hub port 5",
"info for USB hub port 6",
"info for USB hub port 7",
"info for USB hub port 8",
"info for USB hub port 9",
"info for USB hub port 10"
],
"portLabel": [
"p1",
"p2",
"p3",
"p4",
"p5",
"p6",
"p7",
"p8",
"p9",
"p10"
]
},
"plans": [
{
"key": {
"port": ".*",
"devType": "funcube.*"
},
"rate": 48000,
"channels": 2,
"schedule": {
"type": "AlwaysOn"
},
"devParams": [
{
"name": "frequency",
"schedule": {
"type": "Constant",
"value": 166.376
}
}
],
"raw": {
"enabled": false,
"chunkMinutes": 1
},
"plugins": [
{
"library": "lotek-plugins.so",
"name": "findpulsefdbatch",
"outputID": "pulses",
"params": [
{
"name": "plen",
"value": 2.5
},
{
"name": "minfreq",
"value": 2
},
{
"name": "maxfreq",
"value": 24
}
]
}
]
},
{
"key": {
"port": ".*",
"devType": "usbAudio"
},
"rate": 48000,
"channels": 1,
"schedule": {
"type": "AlwaysOn"
},
"raw": {
"enabled": true,
"chunkMinutes": 60
}
}
]
},
"module_options": {
"find_tags": {
"params": [
"--default-freq", 166.380,
"--pulse-slop", 1.5
],
"enabled": true
}
}
}
106 changes: 106 additions & 0 deletions master/events.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
SensorGnome policies on event callbacks and timer chains
(notes by a javascript newbie)

* SensorGnome's Matron object (singleton instance is "TheMatron").
TheMatron is the central event emitter, which is handy for debugging.

* Policy for event handlers requiring 'this': Use prototype methods,
bind to this in constructor to make a closure, then pass the closure;
this simplifies debugging, and avoids duplicating method code for
every object (as private methods do).

Example.
To handle event "eventName" from object "EmitObj"
// handler:
MyClass.prototype.eventName = function(...) {
stuff using "this"
}

// closure:
in Myclass constructor,
this.this_eventName = this.eventName.bind(this);

// registration:
EmitObj.on("eventName", this.this_eventName);

* Bind: only use "this.XXX.bind(this)" in the constructor of
an object, as shown above.

* Policy for setTimeout loops:
i.e. where a callback from setTimeout eventually calls setTimeout with
the same callback. Use an extra "self" parameter to setTimout; don't use
bind or anonymous functions as this will leak memory (fast!).

Suppose method "onTimer" is called by a timeout, and that eventually
leads to another timeout being set on "onTimer" (perhaps in another
method).

Here's how to do this:
MyClass = function() {
var self = this
...
// handler
MyClass.prototype.onTimer = function(self, args) {
// stuff using self and args
//
// inside the method which sets the timeout
setTimeout (self.onTimer, delay, self);

* Events
The events listed here are mainly emitted via the Matron object's public emit() method, but can be
be listened for by anyone.

** devAdded
*** args = [dev]
dev = {
path: // path_to_device,
attr:{
type: // device type
port: // usb hub port number
usbPath: // libusb-style path to device in form "x:y"
alsaDev: // ALSA device number
stat: // fs.fileStat output for path
}
}
*** emitters:
**** HubMan
when device added to watched dir (e.g. "/dev/sensorgnome")
*** listeners:
**** Matron
- consult Deployment for a plan; if found, create an appropriate device object with
the first found plan
**** GPS
- set baud rate for device,
- if successful, open the device for reading and begin reading and parsing fixes

** devRemoved
*** args = [dev]
dev = same arg as when "devAdded" was emitted for the device
*** emitters:
**** HubMan
when device removed from watched dir
*** listeners:
**** GPS
shut down the reader for the device
**** usbAudio
- tell VAH to close device

** devStalled
*** args = [vahDev]
vahDev: label of VAH device as given by its vahOpen event

*** emitters:
**** VAH when receiving a JSON message on stderr of vamp-alsa-host
** vahOpen
*** args = [devPar, callback, callbackParams]
- devPar = {
port: usb port of device
dev: ALSA device name (e.g. "hw:0")
rate: the hardware sampling rate to request from the device
channels: the number of channels (mono=1 or stereo=2) we want
}
- callback: function which receives the JSON reply object
from vamp-alsa-host
- callbackParams: additional parameter object passed to callback after
the reply object

70 changes: 70 additions & 0 deletions master/get_clocks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Repeatedly get values of realtime and monotonic clocks with microsecond
precision as a JSON string of the form
{"real":XXX.XXXXXX,"mono":YYY.YYYYYY}
Each time a character is read from stdin, the time is read and a JSON
string is written to stdout, which is then flushed.
If an error occurs on reading stdin, get_clocks terminates.
If started with an argument, that is assumed to be the filename of a PPS
signal hardware line, and the realtime and monotonic clocks for that PPS
signal are also output.
Author: John Brzustowski
Licence: public domain
*/
#include <time.h>
#include <stdio.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

main (int argc, char *argv[]) {
struct timespec tmm, tmr, ppsm, ppsr;
double real, mono, ppsreal, ppsmono;
struct pollfd pollFDs[2];
int numFD = 0;
int i;
int rv;
char buf;

pollFDs[numFD].fd = fileno(stdin);
pollFDs[numFD++].events = POLLIN;
if (argc > 1) {
pollFDs[numFD].fd = open(argv[1], O_RDONLY);
pollFDs[numFD++].events = POLLPRI;
}

for (;;) {
rv=poll(pollFDs, numFD, -1);
printf("Poll returned %d\n", rv);
if (pollFDs[0].revents & (POLLERR | POLLHUP))
break;
if (numFD > 1 && pollFDs[1].revents & POLLPRI) {
clock_gettime(CLOCK_MONOTONIC, &ppsm);
clock_gettime(CLOCK_REALTIME, &ppsr);
ppsreal = ppsr.tv_sec + ppsr.tv_nsec / 1.0e9;
ppsmono = ppsm.tv_sec + ppsm.tv_nsec / 1.0e9;
lseek(pollFDs[1].fd, 0, SEEK_SET);
read(pollFDs[1].fd, &buf, 1);
printf("Got PPS and read of %c\n", buf);
};
if (pollFDs[0].revents & POLLIN) {
clock_gettime(CLOCK_MONOTONIC, &tmm);
clock_gettime(CLOCK_REALTIME, &tmr);
real = tmr.tv_sec + tmr.tv_nsec / 1.0e9;
mono = tmm.tv_sec + tmm.tv_nsec / 1.0e9;
}
if (numFD > 1) {
printf("{\"real\":%.6lf, \"mono\":%.6lf, \"ppsreal:\":%.6lf, \"ppsmono\":%.6lf}\n", real, mono, ppsreal, ppsmono);
} else {
printf("{\"real\":%.6lf, \"mono\":%.6lf}\n", real, mono);
}
fflush(stdout);
}
}

2 changes: 1 addition & 1 deletion master/gps.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ GPS.prototype.waitForClockSync = function() {
// Due to an apparent bug in chronyc wherein "chronyc waitsync 0 1" sometimes
// waits forever with a server-connection problem, we do a finite wait then
// respawn.
this.chronyChild = ChildProcess.execFile("/usr/local/bin/chronyc", ["waitsync", "30", Math.pow(10, -(this.clockSyncDigits + 1))], this.this_GPSSetClock);
this.chronyChild = ChildProcess.execFile("/usr/bin/chronyc", ["waitsync", "30", Math.pow(10, -(this.clockSyncDigits + 1))], this.this_GPSSetClock);
};

GPS.prototype.timeStampCode = function() {
Expand Down
2 changes: 0 additions & 2 deletions master/machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/

var machineID = Fs.readFileSync("/etc/beaglebone_id").toString().substring(0, 12);
var macAddr = Fs.readFileSync("/sys/class/net/eth0/address").toString();
var bootCountFile = "/etc/bootcount"
var bootCount = "" + (Fs.existsSync(bootCountFile) ?
Number(Fs.readFileSync(bootCountFile).toString()) % (1000000)
Expand All @@ -30,7 +29,6 @@ else
version = "UNKNOWN";

exports.machineID = machineID;
exports.macAddr = macAddr;
exports.bootCount = bootCount;
exports.version = version;

Expand Down
4 changes: 2 additions & 2 deletions master/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Deployment = new (require("./deployment.js").Deployment) (
[
"/boot/uboot/deployment.txt",
"/media/internal_SD_card/deployment.txt",
"/home/bone/proj/sensorgnome/plans/deployment.txt"
"/home/pi/proj/sensorgnome/plans/deployment.txt"
]);

// replace "-" with "_" in deployment short label, so filenames
Expand All @@ -72,7 +72,7 @@ Deployment = new (require("./deployment.js").Deployment) (
Deployment.shortLabel = Deployment.shortLabel.replace(/-/g,"_");

TagFinder = new (require('./tagfinder.js').TagFinder) (TheMatron,
"/home/bone/proj/sensorgnome/find_tags/find_tags_unifile",
"/home/pi/proj/sensorgnome/find_tags/find_tags_unifile",
TheMatron.tagDBFile,
Deployment.module_options.find_tags.params
);
Expand Down
18 changes: 3 additions & 15 deletions master/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,7 @@ <h3> What I'm doing now:</h3>
<div id="dataFiles">
<b> Files I have recorded:</b>
<br>
<p> The following are available via FTP at <br>
<b><a href="ftp://bone:bone@192.168.7.2">USB Cable: ftp://bonebone@192.168.7.2</a><br>
<b><a href="ftp://bone:bone@192.168.9.2">Ethernet Cable: ftp://bonebone@192.168.9.2</a><br>
(right click on the FTP link and open with FireFTP, if using that Firefox extension)<br><br>
<b> or </b> via a Windows shared drive at <br>
<b>USB Cable: \\192.168.7.2\data</b><br>
<b>Ethernet Cable: \\192.168.9.2\data</b><br>:
<p> The following are available via a Windows shared drive at <b>\\192.168.7.2\data</b> :
<textarea id="lsDataFiles" rows=20 cols=160 readonly></textarea>
<br>
<button id="lsDataFilesRefresh" type="button" onclick="$('#lsDataFilesRefresh').text('..refreshing..');lsDataFilesScrollTop=$('#lsDataFiles')[0].scrollTop;socket.emit('lsdata')">Refresh File Listing</button>
Expand All @@ -142,9 +136,7 @@ <h3> What I'm doing now:</h3>
<div id="plan">
<b> Deployment Plan</b>
<br>
<p> This file shows the current deployment plan, which was read from the file <br> <pre> <span id="planPath">.<blink>.</blink>.</span></pre> <br> You can change this then upload it to the shared drive as:<br>
<b>USB Cable: \\192.168.7.2\data\internal_SD_drive\deployment.txt </b><br>
<b>Ethernet Cable: \\192.168.9.2\data\internal_SD_drive\deployment.txt </b><br>
<p> This file shows the current deployment plan, which was read from the file <br> <pre> <span id="planPath">.<blink>.</blink>.</span></pre> <br> You can change this then upload it to the shared drive as <b> \\192.168.7.2\data\internal_SD_drive\deployment.txt </b>
<textarea id="planText" rows=20 cols=160 readonly></textarea>
<br>
</div>
Expand All @@ -154,11 +146,7 @@ <h3> What I'm doing now:</h3>
<a name="tagDB"></a>
<b> Tag Database</b>
<br>
<p> This file shows the database of tags known to this SensorGnome. <br>
The database is stored as <b><span id="tag-database-name"></span></b> on the shared drive:<br>
<b>USB Cable: \\192.168.7.2\boot\</b><br>
<b>Ethernet Cable: \\192.168.9.2\boot\</b> <br>
which is on the SENSORGNOME disk of the microSD card. <br>
<p> This file shows the database of tags known to this SensorGnome. <br> The database is stored on the shared drive as <br> <b> \\192.168.7.2\boot\<span id="tag-database-name"></span> </b> <br> which is on the SENSORGNOME disk of the microSD card. <br>
These tags are known to this sensorgnome:<br><br>
<span style="font-size:100%;font-family:monospace"><b>&nbsp;&nbsp;&nbsp;ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Freq.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Offset&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Project</b></span><br>
<textarea id="tagDBText" rows=20 cols=50 readonly></textarea>
Expand Down
Loading

0 comments on commit 618e91d

Please sign in to comment.