-
Notifications
You must be signed in to change notification settings - Fork 10
/
gsat-server.py
executable file
·130 lines (93 loc) · 3.89 KB
/
gsat-server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
"""----------------------------------------------------------------------------
gsat-server.py:
Copyright (C) 2018 Wilhelm Duembeg
This file is part of gsat. gsat is a cross-platform GCODE debug/step for
Grbl like GCODE interpreters. With features similar to software debuggers.
Features such as breakpoint, change current program counter, inspection
and modification of variables.
gsat is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
gsat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with gsat. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------"""
import os
import sys
import logging
import argparse
import modules.config as gc
import modules.remote_server as remote_server
import modules.version_info as vinfo
def get_cli_params():
"""
define, retrieve and error check command line interface (cli) params
"""
# parser = argparse.ArgumentParser(description=__description__)
parser = argparse.ArgumentParser()
parser.add_argument(
'-V', '--version',
action='version',
version=f"{sys.argv[0]} {vinfo.__revision__} ({vinfo.__appname__})")
parser.add_argument(
"-c", "--config",
dest="config",
default=None,
help="Use alternate configuration file name",
metavar="FILE")
mask_str = str(sorted(gc.VERBOSE_MASK_DICT.keys()))
parser.add_argument(
"--vm", "--verbose_mask",
dest="verbose_mask",
default=None,
help="select verbose mask(s) separated by ',' options are {}".format(mask_str),
metavar="MASK")
options = parser.parse_args()
if options.verbose_mask is not None:
options.verbose_mask = gc.decode_verbose_mask_string(options.verbose_mask)
if sys.version_info < (3, 8, 0):
parser.error("** Required Python 3.8.2 or grater.")
sys.exit(1)
return options
"""----------------------------------------------------------------------------
main
----------------------------------------------------------------------------"""
class GsatServer(gc.EventQueueIf):
def __init__(self):
gc.EventQueueIf.__init__(self)
self.logger = logging.getLogger()
if gc.VERBOSE_MASK & gc.VERBOSE_MASK_UI_ALL:
self.logger.info("init logging id:0x%x" % id(self))
def __del__(self):
pass
def run(self):
try:
server = remote_server.RemoteServerThread(None)
# wait for server events
while True:
e = self._eventQueue.get()
if e.event_id == gc.EV_HELLO:
if gc.VERBOSE_MASK & gc.VERBOSE_MASK_UI_EV:
self.logger.info("EV_HELLO from 0x{:x}".format(id(e.sender)))
elif e.event_id == gc.EV_GOOD_BYE:
if gc.VERBOSE_MASK & gc.VERBOSE_MASK_UI_EV:
self.logger.info("EV_GOOD_BYE from 0x{:x}".format(id(e.sender)))
finally:
if server is not None:
server.add_event(gc.EV_CMD_EXIT, 0, -1)
def main():
cli_options = get_cli_params()
config_fname = cli_options.config
if config_fname is None:
config_fname = os.path.abspath(os.path.abspath(os.path.expanduser("~/.gsat.json")))
gc.init_config(cli_options, config_fname, "log_file")
server = GsatServer()
server.run()
print("gsat-server: exiting")
if __name__ == '__main__':
main()