annotate zbmux.tac @ 25:2a1cea865cc0

Add EventGhost module.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 16 Apr 2013 08:23:00 +0930
parents 08535b12504f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
1 #
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
2 # Mux the ZB module to TCP ports
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
3 #
18
0baf9538a1b6 Add line to tell the user how to run it.
darius@Inchoate
parents: 17
diff changeset
4 # Run me like so...
0baf9538a1b6 Add line to tell the user how to run it.
darius@Inchoate
parents: 17
diff changeset
5 # twistd -l zbmux.log --pidfile=zbmux.pid -y zbmux.tac
0baf9538a1b6 Add line to tell the user how to run it.
darius@Inchoate
parents: 17
diff changeset
6 #
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
7 # Copyright (c) 2009
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
8 # Daniel O'Connor <darius@dons.net.au>. All rights reserved.
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
9 #
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
10 # Redistribution and use in source and binary forms, with or without
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
11 # modification, are permitted provided that the following conditions
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
12 # are met:
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
13 # 1. Redistributions of source code must retain the above copyright
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
14 # notice, this list of conditions and the following disclaimer.
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
15 # 2. Redistributions in binary form must reproduce the above copyright
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
16 # notice, this list of conditions and the following disclaimer in the
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
17 # documentation and/or other materials provided with the distribution.
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
18 #
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
19 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
22 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
29 # SUCH DAMAGE.
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
30 #
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
31
17
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
32 from twisted.application import internet, service
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
33 from twisted.internet.serialport import SerialPort
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
34 from twisted.internet.protocol import Protocol
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
35 from twisted.conch.telnet import TelnetTransport, TelnetBootstrapProtocol
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
36 from twisted.conch.insults import insults
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
37 from twisted.protocols import basic
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
38 from twisted.internet import protocol, reactor
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
39 from twisted.python import log
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
40 import sys, zb, logging, logging.handlers, string
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
41
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
42 portname = '/dev/cuaU0'
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
43 baudrate = 38400
20
7a2ce1c1f176 Move log file into work directory.
darius@midget.dons.net.au
parents: 18
diff changeset
44 lognamebase = '/home/darius/projects/ZigBee/zbmux-%d.log'
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
45 baseport = 1080
23
08535b12504f Add 3rd module (should be a config file)
Daniel O'Connor <darius@dons.net.au>
parents: 22
diff changeset
46 zbids = [1, 2, 3]
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
47
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
48 class ZBClient(insults.TerminalProtocol):
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
49 """Client for the TCP connection"""
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
50 #: Time to wait before sending pending data (seconds)
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
51 QUEUE_TIME = 0.1
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
52
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
53 def connectionMade(self):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
54 log.msg("Got new client")
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
55 self.terminal.eraseDisplay()
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
56 self.terminal.resetPrivateModes([])
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
57
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
58 # Send the last whole line we've seen out
15
a472d6eab97e Play back the last 5 lines to newly connected clients rather than 1.
darius@Inchoate
parents: 14
diff changeset
59 for l in self.factory.lastlines:
a472d6eab97e Play back the last 5 lines to newly connected clients rather than 1.
darius@Inchoate
parents: 14
diff changeset
60 self.message(l + '\n')
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
61
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
62 self.pending = ""
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
63 self.pendtimer = None
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
64 self.factory.clients.append(self)
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
65
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
66 def connectionLost(self, reason):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
67 log.msg("Lost a client")
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
68 self.factory.clients.remove(self)
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
69
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
70 def keystrokeReceived(self, keyID, modifier):
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
71 """Got some data, add it to the pending output queue"""
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
72 if modifier != None:
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
73 print "Received unhandled modifier: %s" % (str(modifier))
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
74 return
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
75 #if keyID not in string.printable:
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
76 # print "Received unhandled keyID: %r" % (keyID,)
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
77 # return
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
78 #log.msg("Got key ->%s<-" % (keyID))
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
79 self.pending = self.pending + keyID
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
80 if self.pendtimer == None:
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
81 self.pendtimer = reactor.callLater(self.QUEUE_TIME, self.sendData)
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
82
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
83 def sendData(self):
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
84 """Send pending data to module"""
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
85 #log.msg("sending " + self.pending)
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
86 self.factory.zbproto.sendData(self.factory.zbid, self.pending)
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
87 self.pending = ""
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
88 self.pendtimer = None
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
89
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
90 def message(self, message):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
91 """Called to write a mesage to our client"""
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
92 self.terminal.write(message)
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
93
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
94 class ZBFactory(protocol.ServerFactory):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
95 """Factory for a ZB module
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
96
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
97 Represents a remote ZB module and has zero or more clients and a log file.
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
98 """
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
99 protocol = ZBClient
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
100
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
101 def __init__(self, zbid, lognamebase):
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
102 self.zbid = zbid
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
103 self.clients = []
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
104 self.tmpline = ""
15
a472d6eab97e Play back the last 5 lines to newly connected clients rather than 1.
darius@Inchoate
parents: 14
diff changeset
105 self.lastlines = []
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
106
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
107 # Open logger
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
108 self.logger = logging.getLogger('Zigbee-%d' % (zbid))
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
109 self.logger.setLevel(logging.DEBUG)
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
110
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
111 # Add the log message handler to the logger
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
112 handler = logging.handlers.RotatingFileHandler(
22
c26eaa20b70d Keep 10 5MB log files.
Daniel O'Connor <darius@dons.net.au>
parents: 20
diff changeset
113 lognamebase % (zbid), maxBytes = 5 * 1024 * 1024, backupCount = 10)
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
114
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
115 self.logger.addHandler(handler)
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
116
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
117 def message(self, zbid, message):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
118 """Called when we get a message, check it's for us - if it is log it and write to our clients"""
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
119 if zbid != self.zbid:
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
120 return
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
121
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
122 for c in self.clients:
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
123 c.message(message)
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
124
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
125 # Logger is line oriented, convert from packet oriented here
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
126 self.tmpline = self.tmpline + message
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
127 tmp = self.tmpline.split('\n')
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
128 for l in tmp[0:-1]:
15
a472d6eab97e Play back the last 5 lines to newly connected clients rather than 1.
darius@Inchoate
parents: 14
diff changeset
129 self.lastlines.append(l)
a472d6eab97e Play back the last 5 lines to newly connected clients rather than 1.
darius@Inchoate
parents: 14
diff changeset
130 self.lastlines = self.lastlines[-5:]
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
131 self.logger.debug(l.replace('\n', ''))
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
132 self.tmpline = tmp[-1]
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
133
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
134 class ZBProto(Protocol):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
135 """Protocol to handle packets from the ZB module on the serial port"""
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
136 def __init__(self):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
137 self.pkts = zb.Packets()
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
138 self.factories = []
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
139
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
140 def dataReceived(self, data):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
141 """Parses data from ZB module into packets, calls each factory if a RX packet is received"""
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
142 #log.msg("Read data " + data)
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
143 if self.pkts.processstr(data) > 0:
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
144 while len(self.pkts.pktq) > 0:
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
145 a = self.pkts.pktq.pop(0)
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
146 #log.msg("type is " + str(type(a)))
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
147 if type(a) == type(zb.RX_16_Bit()):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
148 #log.msg("Rx'd from %d => %s" % (a.sender, a.payloadstr))
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
149 for f in self.factories:
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
150 f.message(a.sender, a.payloadstr)
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
151 if type(a) == type(zb.TX_Status()):
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
152 #log.msg("Tx status for frame %d is %s" % (a.frameid, a.statusMsg))
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
153 pass
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
154
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
155 def sendData(self, zbid, data):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
156 """Sends a chunk of data to our ZB module"""
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
157 #log.msg("%d <= %s" % (zbid, data))
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
158
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
159 # Chop up data into pieces the module can handle
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
160 maxsz = zb.TX_16_Bit.PKT_MAX_PAYLOAD
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
161 for i, j in zip(range(0, len(data), maxsz), range(maxsz, len(data) + maxsz, maxsz)):
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
162 p = zb.TX_16_Bit(zbid, data[i:j])
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
163 self.transport.write(p.Pack())
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
164 #log.msg("sent " + str(p))
14
ac60a9244bdf Use proper telnet protocol classes.
darius@Inchoate
parents: 12
diff changeset
165
17
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
166 application = service.Application('zbmux')
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
167
17
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
168 # ZigBee serial protocol handler
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
169 zbproto = ZBProto()
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
170 SerialPort(zbproto, portname, reactor, baudrate = 38400)
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
171
17
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
172 # Per-module TCP listener
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
173 for id in zbids:
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
174 f = ZBFactory(id, lognamebase)
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
175 f.zbproto = zbproto
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
176 f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol,
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
177 insults.ServerProtocol,
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
178 ZBClient)
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
179 zbproto.factories.append(f)
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
180 internet.TCPServer(baseport + id, f).setServiceParent(
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
181 service.IServiceCollection(application))
12
a3ec3f2988ac Initial commit of zbmux.
darius@Inchoate
parents:
diff changeset
182
17
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
183 ######################################################################
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
184 #
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
185 # These lines tell Emacs to edit this file in Python mode
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
186 #;;; Local Variables: ***
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
187 #;;; mode:python ***
b0fc5f8da118 Rename to zbmux.tac, and use application framework.
darius@Inchoate
parents: 16
diff changeset
188 #;;; End: ***