Skip to content

Commit

Permalink
working version; pc/reader.py shows accelerations; pc will contain pc…
Browse files Browse the repository at this point in the history
… diagnosys and other sw
  • Loading branch information
Alon committed Feb 25, 2010
1 parent 7f2fabd commit efb7e2c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
*.sym
sourceLineMap.txt
tags
*.pyc
*.sw?
7 changes: 5 additions & 2 deletions juggled/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ U32 adxl_transmit_count = 0;
READ_WRITE_FLAG__FLAG_IMP(read_adxl_flag);
READ_WRITE_FLAG__FLAG_IMP_DEFAULT(adxl_flag, false);
READ_WRITE_FLAG__FLAG_IMP_DEFAULT(print_flag, false);
READ_WRITE_FLAG__FLAG_IMP(transmit_flag);
READ_WRITE_FLAG__FLAG_IMP_DEFAULT(transmit_flag, true);

static bool transmit_adxl = true;
static U16 time_to_transmit = false;
Expand Down Expand Up @@ -271,5 +271,8 @@ void cmd_send_test_message(U8 argc, char **argv)
chb_write(STATIONARY_SHORT_ADDRESS, str, strlen(str));
}

READ_WRITE_FLAG__CMD_IMPL(read_adxl_flag)
READ_WRITE_FLAG__CMD_IMPL(read_adxl_flag);
READ_WRITE_FLAG__CMD_IMPL(adxl_flag);
READ_WRITE_FLAG__CMD_IMPL(print_flag);
READ_WRITE_FLAG__CMD_IMPL(transmit_flag);

File renamed without changes.
85 changes: 85 additions & 0 deletions pc/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/python

"""
Serve a single serial port to multiple clients. That's it - no parsing
is done here.
"""

import sys
import os
import time
from twisted.internet import reactor, protocol
from twisted.protocols import basic
from twisted.internet import task
from twisted.internet.serialport import SerialPort

import pdb
brk = pdb.set_trace

JUGGLING_SERVER_PORT = 7500

class LineBasedTeeProtocol(basic.LineReceiver):

delimiter='\n' # I always fall on this point. grrr!

def connectionMade(self):
print "connected"
self.factory.clients.append(self)

def lineReceived(self, line):
print "got", repr(line)
self.factory.client_commands.append(line) # hope this is atomic :\
reactor.callLater(0.0, self.factory.flush_lines_from_clients)


class TeeFactory(protocol.ServerFactory):
""" Protocol for all connectors, and a convenient place for our single serial
port, or rather serial protocol.
"""

debug = False
protocol = LineBasedTeeProtocol
serial = None
clients = []
client_commands = []

def on_line_from_serial(self, line):
if self.debug:
print "serial said", repr(line)
for c in self.clients:
c.transport.write(line+'\n')

def flush_lines_from_clients(self):
for cmd in self.client_commands:
cmd = cmd.strip()+'\r'
print "sending", repr(cmd)
self.serial.transport.write(cmd)
self.client_commands = []

class StationaryProtocol(basic.LineReceiver):
delimiter = '\r' # extremely important.

def __init__(self, teefactory):
self.tee = teefactory
self.tee.serial = self
def connectionMade(self):
pass
def lineReceived(self, line):
print line
reactor.callLater(0.0, self.tee.on_line_from_serial, line)
def request_full_scan(self):
self.transport.write(self.full_scan_request)

def listenToTCPAndSerial(device):
teefactory = TeeFactory()
protocol = StationaryProtocol(teefactory)
SerialPort(protocol, device, reactor, baudrate=115200)
reactor.listenTCP(JUGGLING_SERVER_PORT, teefactory)
return protocol

if __name__ == '__main__':
device = '/dev/ttyACM0' if len(sys.argv) == 1 or not os.path.exists(sys.argv[-1]) else sys.argv[-1]
print "Reading stationary from %s" % device
protocol = listenToTCPAndSerial(device)
reactor.run()

File renamed without changes.

0 comments on commit efb7e2c

Please sign in to comment.