Subversion Repositories HomeAutomation

Rev

Rev 741 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 741 Rev 742
1
#!/bin/env python
1
#!/bin/env python
2
 
2
 
3
import os
3
import os
4
import sys
4
import sys
5
import logging as log
5
import logging as log
6
import getopt
6
import getopt
7
import atexit
7
import atexit
8
import time
8
import time
9
 
9
 
10
from CanPktHandlerBase import CanPktHandlerBase
10
from CanPktHandlerBase import CanPktHandlerBase
11
from CanPktHandler1 import CanPktHandler1
11
from CanPktHandler1 import CanPktHandler1
12
 
12
 
13
from NodeIfBase import NodeIfBase
13
from NodeIfBase import NodeIfBase
14
from NodeIfCanStim import NodeIfCanStim
14
from NodeIfCanStim import NodeIfCanStim
15
from NodeIfSerial import NodeIfSerial
15
from NodeIfSerial import NodeIfSerial
16
 
16
 
17
from DaemonConfig import DaemonConfig
17
from DaemonConfig import DaemonConfig
18
 
18
 
19
daemonApp = None
19
daemonApp = None
20
 
20
 
21
class CanDaemon():
21
class CanDaemon():
22
   
22
   
23
    cfg = None
23
    cfg = None
24
    nodeIf = None
24
    nodeIf = None
25
    ifNotifier = None
25
    ifNotifier = None
26
    terminated = False
26
    terminated = False
27
   
27
   
28
    command_list = []
28
    command_list = []
29
    command_map = {}
29
    command_map = {}
30
    CMDLIST_NAME = 0
30
    CMDLIST_NAME = 0
31
    CMDLIST_HANDLER = 1
31
    CMDLIST_HANDLER = 1
32
    CMDLIST_PARAMINFO = 2
32
    CMDLIST_PARAMINFO = 2
33
    CMDLIST_HELP = 3
33
    CMDLIST_HELP = 3
34
 
34
 
35
    logHelp = 'usage:\t log [options]\n\n' \
35
    logHelp = 'usage:\t log [options]\n\n' \
36
              '\t options:\n' \
36
              '\t options:\n' \
37
              '\t level <num>, where: 0 < num < 3\n'
37
              '\t level <num>, where: 0 < num < 3\n'
38
    stateHelp = 'usage: state [name/add/rem]'
38
    stateHelp = 'usage: state [name/add/rem]'
39
    filterHelp = 'usage: filter [name/add/rem]'
39
    filterHelp = 'usage: filter [name/add/rem]'
40
    addifHelp = 'usage: addif [name] [options]'
40
    addifHelp = 'usage: addif [name] [options]'
41
    addbridgeHelp = 'usage: addbridge [interface names]'
41
    addbridgeHelp = 'usage: addbridge [interface names]'
42
    tcpdHelp = 'usage: tcpd [start/stop/configure] [options]'
42
    tcpdHelp = 'usage: tcpd [start/stop/configure] [options]'
43
    tlsdHelp = 'usage: tlsd [start/stop/configure] [options]'
43
    tlsdHelp = 'usage: tlsd [start/stop/configure] [options]'
44
    canctldHelp = 'usage: canctld [start/stop/configure] [options]'
44
    canctldHelp = 'usage: canctld [start/stop/configure] [options]'
45
    simHelp = 'usage: sim [record/play/add/rem/save/load] [options]'
45
    simHelp = 'usage: sim [record/play/add/rem/save/load] [options]'
46
    help_command_map = {}
46
    help_command_map = {}
47
   
47
   
48
    logOptions = {}
48
    logOptions = {}
49
    ifOptions = {}
49
    ifOptions = {}
50
    bridgeOptions = {}
50
    bridgeOptions = {}
51
    tcpdOptions = {}
51
    tcpdOptions = {}
52
    tlsdOptions = {}
52
    tlsdOptions = {}
53
    canctldOptions = {}
53
    canctldOptions = {}
54
    simOptions = {}
54
    simOptions = {}
55
 
55
 
56
    logValidOptions = {'level' : ['range', 0, 3]}
56
    logValidOptions = {'level' : ['range', 0, 3]}
57
    ifValidOptions = {'type' : ['alt', 'serial','udp']}
57
    ifValidOptions = {'type' : ['alt', 'serial','udp']}
58
   
58
   
59
    ifSerialOptions = {'' : []}
59
    ifSerialOptions = {'' : []}
60
    ifCanStimOptions = {'' : []}
60
    ifCanStimOptions = {'' : []}
61
    ifTelnetOptions = {'' : []}
61
    ifTelnetOptions = {'' : []}
62
    ifTcpTlsOptions = {'' : []}
62
    ifTcpTlsOptions = {'' : []}
63
    ifUDPOptions = {'' : []}
63
    ifUDPOptions = {'' : []}
64
   
64
   
65
    bridgeValidOptions = {'' : ['']}
65
    bridgeValidOptions = {'' : ['']}
66
    tcpdValidOptions = {'' : []}
66
    tcpdValidOptions = {'' : []}
67
    tlsdValidOptions = {'' : []}
67
    tlsdValidOptions = {'' : []}
68
    canctldValidOptions = {'' : []}
68
    canctldValidOptions = {'' : []}
69
    simValidOptions = {'' : []}
69
    simValidOptions = {'' : []}
70
 
70
 
71
    def __init__ (self):
71
    def __init__ (self):
72
       
72
       
73
        self.command_list = [['help', self.helpCmd, '', 'display help'],
73
        self.command_list = [['help', self.helpCmd, '', 'display help'],
74
                       ['log', self.logCmd, '<options>', 'log control: \"help log\"'],
74
                       ['log', self.logCmd, '<options>', 'log control: \"help log\"'],
75
                       ['exec', self.execCmd, '<filename>', 'run command listing\n'],
75
                       ['exec', self.execCmd, '<filename>', 'run command listing\n'],
76
                       ['filter', self.filterCmd, '<cmd>', 'filter commands: \"help filter\"'],
76
                       ['filter', self.filterCmd, '<cmd>', 'filter commands: \"help filter\"'],
77
                       ['state', self.stateCmd, '<cmd>', 'state commands: \"help state\"\n'],
77
                       ['state', self.stateCmd, '<cmd>', 'state commands: \"help state\"\n'],
78
                       ['addif', self.ifAddCmd, '<options>', 'add interface: \"help addif\"'],
78
                       ['addif', self.ifAddCmd, '<options>', 'add interface: \"help addif\"'],
79
                       ['remif', self.ifRemCmd, '<name>', 'remove interface'],
79
                       ['remif', self.ifRemCmd, '<name>', 'remove interface'],
80
                       ['ifup', self.ifUpCmd, '<name>', 'bring up interface'],
80
                       ['ifup', self.ifUpCmd, '<name>', 'bring up interface'],
81
                       ['ifdown', self.ifDownCmd, '<name>', 'bring down interface\n'],
81
                       ['ifdown', self.ifDownCmd, '<name>', 'bring down interface\n'],
82
                       ['addbrigde', self.addBridgeCmd, '<options>', 'add bridge: \"help addbridge\"'],
82
                       ['addbrigde', self.addBridgeCmd, '<options>', 'add bridge: \"help addbridge\"'],
83
                       ['rembridge', self.remBridgeCmd, '<id>', 'remove bridge\n'],
83
                       ['rembridge', self.remBridgeCmd, '<id>', 'remove bridge\n'],
84
                       ['tcpd', self.tcpdCmd, '<cmd>', 'tcpd server control: \"help tcpd\"'],
84
                       ['tcpd', self.tcpdCmd, '<cmd>', 'tcpd server control: \"help tcpd\"'],
85
                       ['tlsd', self.tlsdCmd, '<cmd>', 'tlsd server control: \"help tlsd\"'],
85
                       ['tlsd', self.tlsdCmd, '<cmd>', 'tlsd server control: \"help tlsd\"'],
86
                       ['canctld', self.canCtldCmd, '<cmd>', 'canctld server control: \"help canctld\"\n'],
86
                       ['canctld', self.canCtldCmd, '<cmd>', 'canctld server control: \"help canctld\"\n'],
87
                       ['status', self.statusCmd, '', 'show daemon status'],
87
                       ['status', self.statusCmd, '', 'show daemon status'],
88
                       ['stats', self.statsCmd, '', 'show statistics\n'],
88
                       ['stats', self.statsCmd, '', 'show statistics\n'],
89
                       ['nodelist', self.nodesCmd, '', 'list can nodes'],
89
                       ['nodelist', self.nodesCmd, '', 'list can nodes'],
90
                       ['filterlist', self.filterlistCmd, '', 'list active filters\n'],
90
                       ['filterlist', self.filterlistCmd, '', 'list active filters\n'],
91
                       ['sim', self.simCmd, '<cmd>', 'simulator commands: \"help sim\"']]
91
                       ['sim', self.simCmd, '<cmd>', 'simulator commands: \"help sim\"']]
92
       
92
       
93
        index = 0
93
        index = 0
94
        for cmd in self.command_list:
94
        for cmd in self.command_list:
95
            self.command_map[cmd[0]] = index
95
            self.command_map[cmd[0]] = index
96
            index += 1
96
            index += 1
97
 
97
 
98
        self.help_command_map = {'log' : self.logHelp,
98
        self.help_command_map = {'log' : self.logHelp,
99
                                'filter' : self.filterHelp,
99
                                'filter' : self.filterHelp,
100
                                'state' : self.stateHelp,
100
                                'state' : self.stateHelp,
101
                                'addif' : self.addifHelp,
101
                                'addif' : self.addifHelp,
102
                                'addbridge' : self.addbridgeHelp,
102
                                'addbridge' : self.addbridgeHelp,
103
                                'tcpd' : self.tcpdHelp,
103
                                'tcpd' : self.tcpdHelp,
104
                                'tlsd' : self.tlsdHelp,
104
                                'tlsd' : self.tlsdHelp,
105
                                'canctld' : self.canctldHelp,
105
                                'canctld' : self.canctldHelp,
106
                                'sim' : self.simHelp}
106
                                'sim' : self.simHelp}
107
 
107
 
108
        self.cfg = DaemonConfig()
108
        self.cfg = DaemonConfig()
109
   
109
   
110
    class IfNotifier():
110
    class IfNotifier():
111
        """ Used by if threads to send messages to the main program thread """
111
        """ Used by if threads to send messages to the main program thread """
-
 
112
       
-
 
113
        parent = None
112
        UNDEFINED = 0
114
        UNDEFINED = 0
113
        TERMINATE = 1
115
        TERMINATE = 1
-
 
116
       
-
 
117
        def __init__(self, parent):
-
 
118
            self.parent = parent
114
   
119
   
115
        def notify(self, msg):
120
        def notify(self, msg):
116
            if msg == self.TERMINATE:
121
            if msg == self.TERMINATE:
117
                print 'Main terminate notify'
122
                print 'Main terminate notify'
118
                self.terminated = True
-
 
119
            else:
123
            else:
120
                print 'UNDEFINED NOTIFY'
124
                print 'UNDEFINED NOTIFY'
121
       
125
       
122
   
126
   
123
    def __rightAdjust(self, refstr, str):
127
    def __rightAdjust(self, refstr, str):
124
        spcstr = ''
128
        spcstr = ''
125
        endpos = 25-len(refstr)
129
        endpos = 25-len(refstr)
126
        for i in range(1,endpos):
130
        for i in range(1,endpos):
127
            if i == endpos-5:
131
            if i == endpos-5:
128
                spcstr += ':'
132
                spcstr += ':'
129
            else:
133
            else:
130
                spcstr += ' '
134
                spcstr += ' '
131
        return (spcstr+str)
135
        return (spcstr+str)
132
   
136
   
133
    def helpCmd(self, *args):
137
    def helpCmd(self, *args):
134
        try:
138
        try:
135
            args = args[0]
139
            args = args[0]
136
        except:
140
        except:
137
            args = []
141
            args = []
138
        if len(args) < 1:
142
        if len(args) < 1:
139
            quitStr = 'quit, exit'
143
            quitStr = 'quit, exit'
140
            print quitStr, self.__rightAdjust(quitStr, 'shutdown pyCanDaemon')
144
            print quitStr, self.__rightAdjust(quitStr, 'shutdown pyCanDaemon')
141
            for cmd in self.command_list:
145
            for cmd in self.command_list:
142
                cmdstr = cmd[self.CMDLIST_NAME] + ' ' + cmd[self.CMDLIST_PARAMINFO]
146
                cmdstr = cmd[self.CMDLIST_NAME] + ' ' + cmd[self.CMDLIST_PARAMINFO]
143
                print cmdstr, \
147
                print cmdstr, \
144
                      self.__rightAdjust(cmdstr, cmd[self.CMDLIST_HELP])
148
                      self.__rightAdjust(cmdstr, cmd[self.CMDLIST_HELP])
145
        elif len(args) < 2:
149
        elif len(args) < 2:
146
            subCmd = args[0]
150
            subCmd = args[0]
147
            if self.help_command_map.has_key(subCmd):
151
            if self.help_command_map.has_key(subCmd):
148
                print self.help_command_map[subCmd]
152
                print self.help_command_map[subCmd]
149
            else:
153
            else:
150
                print 'no help for ' + subCmd
154
                print 'no help for ' + subCmd
151
        else:
155
        else:
152
            print 'usage: help [topic]'
156
            print 'usage: help [topic]'
153
 
157
 
154
    def filterCmd(self, *args):
158
    def filterCmd(self, *args):
155
        try:
159
        try:
156
            args = args[0]
160
            args = args[0]
157
        except:
161
        except:
158
            args = []
162
            args = []
159
        log.debug('filterCmd ' + str(args))
163
        log.debug('filterCmd ' + str(args))
160
        if len(args) < 2:
164
        if len(args) < 2:
161
            print 'Invalid arguments\n' + self.filterHelp
165
            print 'Invalid arguments\n' + self.filterHelp
162
            return
166
            return
163
        cmd = args[0]
167
        cmd = args[0]
164
        filterName = args[1]
168
        filterName = args[1]
165
        # FIXME: verify 
169
        # FIXME: verify 
166
        if cmd == 'add':
170
        if cmd == 'add':
167
            print 'Importing filter: ' + filterName
171
            print 'Importing filter: ' + filterName
168
            self.cfg.filterCfg.importFilter(filterName)
172
            self.cfg.filterCfg.importFilter(filterName)
169
        elif cmd == 'rem' or cmd == 'remove':
173
        elif cmd == 'rem' or cmd == 'remove':
170
            print 'Deleting filter: ' + filterName
174
            print 'Deleting filter: ' + filterName
171
            # FIXME: actually delete
175
            # FIXME: actually delete
172
            raise 'Not implemented'
176
            raise 'Not implemented'
173
   
177
   
174
    def stateCmd(self, *args):
178
    def stateCmd(self, *args):
175
        try:
179
        try:
176
            args = args[0]
180
            args = args[0]
177
        except:
181
        except:
178
            args = []
182
            args = []
179
        log.debug('stateCmd ' + str(args))
183
        log.debug('stateCmd ' + str(args))
180
        if len(args) < 2:
184
        if len(args) < 2:
181
            print 'Invalid arguments\n' + self.stateHelp
185
            print 'Invalid arguments\n' + self.stateHelp
182
            return
186
            return
183
        cmd = args[0]
187
        cmd = args[0]
184
        spaceName = args[1]
188
        spaceName = args[1]
185
        # FIXME: verify 
189
        # FIXME: verify 
186
        if cmd == 'add':
190
        if cmd == 'add':
187
            print 'Importing state space: ' + spaceName
191
            print 'Importing state space: ' + spaceName
188
            self.cfg.stateSpaceCfg.importSpace(spaceName)
192
            self.cfg.stateSpaceCfg.importSpace(spaceName)
189
        elif cmd == 'rem' or cmd == 'remove':
193
        elif cmd == 'rem' or cmd == 'remove':
190
            print 'Deleting state space: ' + spaceName
194
            print 'Deleting state space: ' + spaceName
191
            # FIXME: actually delete statespace
195
            # FIXME: actually delete statespace
192
            raise 'Not implemented'
196
            raise 'Not implemented'
193
   
197
   
194
    def ifAddCmd(self, *args):
198
    def ifAddCmd(self, *args):
195
        raise 'not implemented'
199
        raise 'not implemented'
196
   
200
   
197
    def ifRemCmd(self, *args):
201
    def ifRemCmd(self, *args):
198
        raise 'not implemented'
202
        raise 'not implemented'
199
 
203
 
200
    def ifUpCmd(self, *args):
204
    def ifUpCmd(self, *args):
201
        raise 'not implemented'
205
        raise 'not implemented'
202
 
206
 
203
    def ifDownCmd(self, *args):
207
    def ifDownCmd(self, *args):
204
        raise 'not implemented'
208
        raise 'not implemented'
205
   
209
   
206
    def addBridgeCmd(self, *args):
210
    def addBridgeCmd(self, *args):
207
        raise 'not implemented'
211
        raise 'not implemented'
208
 
212
 
209
    def remBridgeCmd(self, *args):
213
    def remBridgeCmd(self, *args):
210
        raise 'not implemented'
214
        raise 'not implemented'
211
   
215
   
212
    def tcpdCmd(self, *args):
216
    def tcpdCmd(self, *args):
213
        raise 'not implemented'
217
        raise 'not implemented'
214
   
218
   
215
    def tlsdCmd(self, *args):
219
    def tlsdCmd(self, *args):
216
        raise 'not implemented'
220
        raise 'not implemented'
217
   
221
   
218
    def canCtldCmd(self, *args):
222
    def canCtldCmd(self, *args):
219
        raise 'not implemented'
223
        raise 'not implemented'
220
   
224
   
221
    def statusCmd(self, *args):
225
    def statusCmd(self, *args):
222
        raise 'not implemented'
226
        raise 'not implemented'
223
   
227
   
224
    def statsCmd(self, *args):
228
    def statsCmd(self, *args):
225
        raise 'not implemented'
229
        raise 'not implemented'
226
   
230
   
227
    def nodesCmd(self, *args):
231
    def nodesCmd(self, *args):
228
        raise 'not implemented'
232
        raise 'not implemented'
229
   
233
   
230
    def filterlistCmd(self, *args):
234
    def filterlistCmd(self, *args):
231
        raise 'not implemented'
235
        raise 'not implemented'
232
   
236
   
233
    def simCmd(self, *args):
237
    def simCmd(self, *args):
234
        raise 'not implemented'
238
        raise 'not implemented'
235
   
239
   
236
    def logCmd(self, *args):
240
    def logCmd(self, *args):
237
        raise 'not implemented'
241
        raise 'not implemented'
238
 
242
 
239
    def execCmd(self, *args):
243
    def execCmd(self, *args):
240
        raise 'not implemented'
244
        raise 'not implemented'
241
   
245
   
242
    def parseCommand(self, cmdstr):
246
    def parseCommand(self, cmdstr):
243
        incmd = cmdstr.strip()
247
        incmd = cmdstr.strip()
244
        cmd = incmd.split(' ')
248
        cmd = incmd.split(' ')
245
        if len(cmd[0]) < 2:
249
        if len(cmd[0]) < 2:
246
            return
250
            return
247
        cmd[0] = cmd[0].lower()
251
        cmd[0] = cmd[0].lower()
248
        if cmd[0] == 'quit' or cmd[0] == 'exit':
252
        if cmd[0] == 'quit' or cmd[0] == 'exit':
249
            self.terminated = True
253
            self.terminated = True
250
        elif self.command_map.has_key(cmd[0]):
254
        elif self.command_map.has_key(cmd[0]):
251
            self.command_list[self.command_map[cmd[0]]][self.CMDLIST_HANDLER](cmd[1:])
255
            self.command_list[self.command_map[cmd[0]]][self.CMDLIST_HANDLER](cmd[1:])
252
        else:
256
        else:
253
            print 'unknown command: ' + cmd[0]
257
            print 'unknown command: ' + cmd[0]
254
   
258
   
255
    def exitHelper(self):
259
    def exitHelper(self):
256
        if self.nodeIf is not None and self.nodeIf.running():
260
        if self.nodeIf is not None and self.nodeIf.running():
257
            self.nodeIf.stop()
261
            self.nodeIf.stop()
258
           
262
           
259
    def exceptHelper(self, type, value, tb):
263
    def exceptHelper(self, type, value, tb):
260
        import traceback
264
        import traceback
261
        traceback.print_exception(type, value, tb)
265
        traceback.print_exception(type, value, tb)
262
        print '\nException in main program, shutting down threads'
266
        print '\nException in main program, shutting down threads'
263
        self.terminated = True
267
        self.terminated = True
264
        self.exitHelper()
268
        self.exitHelper()
265
 #       sys.exit(-1)
269
 #       sys.exit(-1)
266
 
270
 
267
    def run(self):
271
    def run(self):
268
        try:
272
        try:
269
            myPath = os.path.dirname(__file__)
273
            myPath = os.path.dirname(__file__)
270
            os.chdir(myPath)
274
            os.chdir(myPath)
271
        except:
275
        except:
272
            return
276
            return
273
       
277
       
274
        print 'INIT: Start logging'
278
        print 'INIT: Start logging'
275
        log.basicConfig(level=log.DEBUG)
279
        log.basicConfig(level=log.DEBUG)
276
       
280
       
277
        """command parameters only dictate verbosity and use of config file"""
281
        """command parameters only dictate verbosity and use of config file"""
278
        print 'INIT: Get config options from command line / config file'
282
        print 'INIT: Get config options from command line / config file'
279
        try:
283
        try:
280
            opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
284
            opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
281
        except getopt.GetoptError:
285
        except getopt.GetoptError:
282
            print 'Invalid usage'
286
            print 'Invalid usage'
283
            usage()
287
            usage()
284
            sys.exit(2)
288
            sys.exit(2)
285
     #   output = None
289
     #   output = None
286
     #   verbose = False
290
     #   verbose = False
287
        for o, a in opts:
291
        for o, a in opts:
288
            if o == "-v":
292
            if o == "-v":
289
                pass
293
                pass
290
     #           verbose = True
294
     #           verbose = True
291
            if o in ("-h", "--help"):
295
            if o in ("-h", "--help"):
292
                usage()
296
                usage()
293
                sys.exit()
297
                sys.exit()
294
            if o in ("-o", "--output"):
298
            if o in ("-o", "--output"):
295
                pass
299
                pass
296
    #            output = a
300
    #            output = a
297
 
301
 
298
        """load config defaults, or last config if exists"""
302
        """load config defaults, or last config if exists"""
299
        """run startup.cfg"""
303
        """run startup.cfg"""
300
       
304
       
301
#        print 'INIT: Loading filters and spaces'
305
#        print 'INIT: Loading filters and spaces'
302
#       self.cfg.filterCfg.importFilter('DefaultFilter')
306
#       self.cfg.filterCfg.importFilter('DefaultFilter')
303
#       self.cfg.stateSpaceCfg.importSpace('DefaultStateSpace')
307
#       self.cfg.stateSpaceCfg.importSpace('DefaultStateSpace')
304
#        self.cfg.stateSpaceCfg.loadSpaces()
308
#        self.cfg.stateSpaceCfg.loadSpaces()
305
#        self.cfg.filterCfg.loadFilters()
309
#        self.cfg.filterCfg.loadFilters()
306
#        self.cfg.setupFilterBindings()
310
#        self.cfg.setupFilterBindings()
307
#        self.cfg.setupFilterChain()
311
#        self.cfg.setupFilterChain()
308
 
312
 
309
#        print 'INIT: Starting selected can interface'
313
#        print 'INIT: Starting selected can interface'
310
#        ''' nodeif thread launch '''
314
#        ''' nodeif thread launch '''
311
#        self.ifNotifier = self.IfNotifier()
315
#        self.ifNotifier = self.IfNotifier()
312
#        pktHandler = CanPktHandler1(self.cfg)
316
#        pktHandler = CanPktHandler1(self.cfg)
313
#        
317
#        
314
#        ifConfig = NodeIfCanStim.DEFAULT_CONFIG
318
#        ifConfig = NodeIfCanStim.DEFAULT_CONFIG
315
#        self.nodeIf = NodeIfCanStim(ifConfig, pktHandler, self.ifNotifier)
319
#        self.nodeIf = NodeIfCanStim(ifConfig, pktHandler, self.ifNotifier)
316
# #       ifConfig = NodeIfSerial.DEFAULT_CONFIG
320
# #       ifConfig = NodeIfSerial.DEFAULT_CONFIG
317
#    
321
#    
318
#        atexit.register(self.exitHelper)
322
#        atexit.register(self.exitHelper)
319
#        sys.excepthook = self.exceptHelper
323
#        sys.excepthook = self.exceptHelper
320
 #       self.nodeIf = NodeIfSerial(pktHandler, ifConfig)
324
 #       self.nodeIf = NodeIfSerial(pktHandler, ifConfig)
321
#        
325
#        
322
#        if not self.nodeIf.start():
326
#        if not self.nodeIf.start():
323
#            print 'FATAL: Failed to initialize node interface.'
327
#            print 'FATAL: Failed to initialize node interface.'
324
#            print 'This may indicate that the interface is unavailable, ' \
328
#            print 'This may indicate that the interface is unavailable, ' \
325
#                  'or that you do not have permission to access it.'
329
#                  'or that you do not have permission to access it.'
326
#            sys.exit(-1)
330
#            sys.exit(-1)
327
 
331
 
328
        print 'Initialize/gather info on connected can nodes and load associated state'
332
        print 'Initialize/gather info on connected can nodes and load associated state'
329
        print 'Start selected TCP and UDP server(s)'
333
        print 'Start selected TCP and UDP server(s)'
330
        # server threads launch
334
        # server threads launch
331
       
335
       
332
        print 'CanDaemon v1 ready'
336
        print 'CanDaemon v1 ready'
333
        print 'Enter command or type \"help\" for a list of commands'
337
        print 'Enter command or type \"help\" for a list of commands'
334
        while not self.terminated:
338
        while not self.terminated:
335
            input = raw_input('> ')
339
            input = raw_input('> ')
336
            self.parseCommand(input)
340
            self.parseCommand(input)
337
 
341
 
338
        print 'Shutdown'
342
        print 'Shutdown'
339
#        if self.nodeIf.running():
343
#        if self.nodeIf.running():
340
#            print 'Stopping If thread'
344
#            print 'Stopping If thread'
341
#            self.nodeIf.stop()
345
#            self.nodeIf.stop()
342
 
346
 
343
#        self.cfg.stateSpaceCfg.saveSpaces()
347
#        self.cfg.stateSpaceCfg.saveSpaces()
344
#        self.cfg.filterCfg.saveFilters()
348
#        self.cfg.filterCfg.saveFilters()
345
       
349
       
346
        print 'Waiting 0.1..'
350
        print 'Waiting 0.1..'
347
        time.sleep(0.1) # wait for threads
351
        time.sleep(0.1) # wait for threads
348
        print 'Terminating'
352
        print 'Terminating'
349
        sys.exit(0) # will except if there are threads remaining
353
        sys.exit(0) # will except if there are threads remaining
350
 
354
 
351
#---------------------------------------------------------------------------
355
#---------------------------------------------------------------------------
352
 
356
 
353
def main():
357
def main():
354
    daemonApp = CanDaemon()
358
    daemonApp = CanDaemon()
355
#    install_thread_excepthook()
359
#    install_thread_excepthook()
356
    daemonApp.run()
360
    daemonApp.run()
357
 
361
 
358
#---------------------------------------------------------------------------
362
#---------------------------------------------------------------------------
359
 
363
 
360
if __name__ == '__main__':
364
if __name__ == '__main__':
361
    __name__ = 'Main'
365
    __name__ = 'Main'
362
    main()
366
    main()
363
 
367