Skip to content

Commit

Permalink
adds fingerprint to api
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrux committed Sep 27, 2018
1 parent d1e5ea7 commit 94bafd9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 64 deletions.
64 changes: 22 additions & 42 deletions app/actions/eon_detail_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,6 @@ export function FAIL_uninstall(err) {
};
}

export function BEGIN_fetchPid() {
return {
type: types.FETCH_PID
};
}

export function SUCCESS_fetchPid(results) {
return {
type: types.FETCH_PID_SUCCESS,
payload: {
pid: results
}
};
}

export function FAIL_fetchPid(error) {
return {
type: types.FETCH_PID_FAIL,
payload: {
error
}
};
}

export function OPEN_REQUEST_EON_STATE() {
return {
type: types.EON_STATE
Expand Down Expand Up @@ -171,27 +147,29 @@ export function CLOSE_REQUEST_EON_STATE() {
// dispatch(CLOSE_REQUEST_EON_STATE());
// }
// }
export function installFork(fork) {
return (dispatch, getState) => {
dispatch(BEGIN_fetchPid());
eonListActions.sendCommand(selectedEon, commands.OPENPILOT_PID).then((result) => {
const pid = result.stdout.split('\n')[0].trim();
// export function installFork(fork) {
// return (dispatch, getState) => {
// dispatch(BEGIN_fetchPid());
// eonListActions.sendCommand(selectedEon, commands.OPENPILOT_PID).then((result) => {
// const pid = result.stdout.split('\n')[0].trim();

if (result.stderr) {
dispatch(FAIL_fetchPid(result.stderr));
} else {
if (pid && pid.length) {
dispatch(SUCCESS_fetchPid(pid));
} else {
dispatch(FAIL_fetchPid("Openpilot is not running, or too many processes were returned."));
}
}
});
}
}
// if (result.stderr) {
// dispatch(FAIL_fetchPid(result.stderr));
// } else {
// if (pid && pid.length) {
// dispatch(SUCCESS_fetchPid(pid));
// } else {
// dispatch(FAIL_fetchPid("Openpilot is not running, or too many processes were returned."));
// }
// }
// });
// }
// }

export function fetchEonState(eon) {
export function fetchEonState() {
return (dispatch, getState) => {
const { selectedEon, scanResults } = getState().eonList;
const eon = scanResults[selectedEon];
const { polling } = getState().eonDetail
setTimeout(() => {
fetch(`http://${eon.ip}:8080/state.json`)
Expand Down Expand Up @@ -240,6 +218,8 @@ export function install() {
export function uninstall() {
return (dispatch, getState) => {
const { selectedEon, scanResults } = getState().eonList;
console.warn("scanResults:",scanResults);
console.warn("selectedEon:",selectedEon);
const eon = scanResults[selectedEon];
console.warn("Starting Api UNINSTALL...");
dispatch(BEGIN_uninstall());
Expand Down
8 changes: 1 addition & 7 deletions app/components/EonDetail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@ import { Row, CardHeader, Col, Card, CardBody, CardText, CardTitle, CardSubtitle
const propTypes = {
install: PropTypes.func,
eon: PropTypes.object,
pid: PropTypes.string,
fetchingPid: PropTypes.bool,
sshConnectionError: PropTypes.object,
sshConnectionStatus: PropTypes.string,
tmuxError: PropTypes.string,
tmuxAttached: PropTypes.bool,
tmuxLog: PropTypes.array,
tmuxStartedAt: PropTypes.any,
vehicleStarted: PropTypes.string,
vehicleStartedAt: PropTypes.string,
vehicleConnection: PropTypes.string,
Expand Down Expand Up @@ -85,7 +79,7 @@ class EonDetail extends Component {
// }, 3000);
}
componentWillUnmount() {
this.props.uninstall();
// this.props.uninstall();
}

// handleInstall = () => {
Expand Down
Binary file modified workbench.zip
Binary file not shown.
39 changes: 39 additions & 0 deletions workbench_api/fingerprint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python

# simple script to get a vehicle fingerprint.

# Instructions:
# - connect to a Panda
# - run selfdrive/boardd/boardd
# - launching this script
# - since some messages are published at low frequency, keep this script running for few
# seconds, until all messages are received at least once

import zmq
import selfdrive.messaging as messaging
from selfdrive.services import service_list

def main():
context = zmq.Context()
logcan = messaging.sub_sock(context, service_list['can'].port)
msgs = {}
while True:
lc = messaging.recv_sock(logcan, True)
for c in lc.can:
# read also msgs sent by EON on CAN bus 0x80 and filter out the
# addr with more than 11 bits
if c.src%0x80 == 0 and c.address < 0x800:
fingerprint_msgs[c.address] = len(c.dat)

fingerprint = ', '.join("\"%d\": %d" % v for v in sorted(fingerprint_msgs.items()))
fingerprint = '{' + fingerprint + '}'

# print "number of messages:", len(msgs)
# print "fingerprint", fingerprint

f = open("/data/workbench/data/fingerprint.json", 'w+')
f.write(json.dumps(data))
time.sleep(0.25)

if __name__ == '__main__':
main()
16 changes: 1 addition & 15 deletions workbench_api/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def main():
data = {}
republish_socks = {}

logcan = messaging.sub_sock(context, service_list['can'].port)
for m in args.socket if len(args.socket) > 0 else service_list:
if m in service_list:
port = service_list[m].port
Expand All @@ -41,31 +40,18 @@ def main():
sock = messaging.sub_sock(context, port, poller, addr=args.addr)
if args.proxy:
republish_socks[sock] = messaging.pub_sock(context, port)
fingerprint_msgs = {}
while 1:
polld = poller.poll(timeout=1000)

for sock, mode in polld:
if mode != zmq.POLLIN:
continue
msg = sock.recv()
lc = messaging.recv_sock(logcan, True)
for c in lc.can:
# read also msgs sent by EON on CAN bus 0x80 and filter out the
# addr with more than 11 bits
if c.src%0x80 == 0 and c.address < 0x800:
fingerprint_msgs[c.address] = len(c.dat)

fingerprint = ', '.join("\"%d\": %d" % v for v in sorted(fingerprint_msgs.items()))
fingerprint = '{' + fingerprint + '}'
# print fingerprint
evt = log.Event.from_bytes(msg)
if sock in republish_socks:
republish_socks[sock].send(msg)
# print evt
fingerprint_json = json.loads(fingerprint)
print fingerprint_json
data['fingerprint'] = json.dumps(fingerprint_json)
service_whitelist = ["thermal","health","gpsLocation"]
# THERMAL
# if evt.which() == 'thermal':
Expand All @@ -90,7 +76,7 @@ def main():
# print '\n'
# pp.pprint(data, depth=3)
if any(data):
f = open("/data//workbench/data/state.json", 'w+')
f = open("/data/workbench/data/state.json", 'w+')
f.write(json.dumps(data))
time.sleep(0.25)
# if not args.no_print:
Expand Down
8 changes: 8 additions & 0 deletions workbench_api/workbenchd.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/usr/bin/env python
from multiprocessing import Process
import sys
import fingerprint
import monitor
import server

def start_fingerprint():
print '[started] Workbench Fingerprinter'
fingerprint.main()
print '[stopped] Workbench Fingerprinter'

def start_monitor():
print '[started] Workbench Monitor'
monitor.main()
Expand All @@ -19,3 +25,5 @@ def start_server():
p1.start()
p2 = Process(target = start_server)
p2.start()
p3 = Process(target = start_fingerprint)
p3.start()

0 comments on commit 94bafd9

Please sign in to comment.