Skip to content

Commit 56eee9e

Browse files
committed
Add default and event support
1 parent 01b9f62 commit 56eee9e

5 files changed

Lines changed: 108 additions & 11 deletions

File tree

polyxdr/backends/telem-dict/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
from polyxdr.parser import *
44
from collections import namedtuple
55

6+
def enumToVal(ir, name):
7+
for x in ir:
8+
if isinstance(x, XDREnum):
9+
for m in x.members:
10+
if m.name == name:
11+
return m.value
12+
return "NA"
13+
614
def generateHeader(ir, out, parent, p_unit, p_name, type_filter):
715

816
# if isinstance(x, XDRStruct) or isinstance(x, XDRBitfield):
917
for x in ir:
10-
if isinstance(x, XDRStruct):
18+
if isinstance(x, XDREvent):
19+
render_template(out, "event", dict(st=x,proc_name=x.proc_name,port=x.port,id=enumToVal(ir, x.id),desc=x.summary,name=x.name))
20+
elif isinstance(x, XDRStruct):
1121
#print(x)
1222
if type_filter != None and x.name != type_filter:
1323
continue
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<EVENT>
2+
PORT_NAME=${proc_name}
3+
PORT=${port}
4+
ID=${id}
5+
DESCRIPTION=${desc}
6+
NAME=${name}
7+
</EVENT>

polyxdr/ir.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
XDRTypedef = namedtuple("XDRTypedef", ["declaration"])
1616
XDRUnion = namedtuple("XDRUnion", ["name", "discriminant", "members"])
1717
XDRUnionMember = namedtuple("XDRUnionMember", ["case", "declaration"])
18-
XDRNamespace = namedtuple("XDRNamespace", ["name"])
18+
XDRNamespace = namedtuple("XDRNamespace", ["name", "location", "subsystem", "group", "dl_name", "dl_path", "lproc_name", "lproc_port"])
1919
XDRFieldDocumentation = namedtuple("XDRFieldDocs", ["key", "name", "description", "offset", "divisor", "conversion", "inverse", "unit", "computed_by", "true_label", "false_label", "location", "subsystem", "group", "export"])
2020
XDRCommand = namedtuple("XDRCommand", ["name", "id", "summary", "param", "response", "types", "autoname"])
21+
XDREvent = namedtuple("XDREvent", ["name", "id", "summary", "proc_name", "port"])
2122
XDRError = namedtuple("XDRError", ["id", "name", "description"])
2223

2324
__all__ = [
2425
'XDRStruct', 'XDRDeclaration', 'XDREnum', 'XDREnumMember',
2526
'XDRConst', 'XDRTypedef', 'XDRUnion', 'XDRUnionMember', 'XDRBitfield',
26-
'XDRNamespace', 'XDRFieldDocumentation', 'XDRCommand', 'XDRError'
27+
'XDRNamespace', 'XDRFieldDocumentation', 'XDRCommand', 'XDRError',
28+
'XDREvent'
2729
]

polyxdr/parser.py

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ def __init__(self, filename, parentParser):
9595
self.cmdcnt = 0
9696
self.enumNamespace = ''
9797
self.scopeMap = {}
98+
self.dfl_location = ''
99+
self.dfl_subsystem = ''
100+
self.dfl_group = ''
101+
self.dl_name = ''
102+
self.dl_path = ''
103+
self.lproc_name = ''
104+
self.lproc_port = ''
98105
kw = P.Keyword
99106
s = P.Suppress
100107
lit = P.Literal
@@ -194,6 +201,17 @@ def __init__(self, filename, parentParser):
194201
P.Optional(g(kw("false_label") + P.QuotedString('"') + s(";"))) \
195202
) + s("}")
196203

204+
namespacedefaults = \
205+
s("{") + ( \
206+
P.Optional(g(kw("location") + P.QuotedString('"') + s(";"))) & \
207+
P.Optional(g(kw("subsystem") + P.QuotedString('"') + s(";"))) & \
208+
P.Optional(g(kw("group") + P.QuotedString('"') + s(";"))) & \
209+
P.Optional(g(kw("dl_name") + P.QuotedString('"') + s(";"))) & \
210+
P.Optional(g(kw("dl_path") + P.QuotedString('"') + s(";"))) & \
211+
P.Optional(g(kw("lproc_name") + P.QuotedString('"') + s(";"))) & \
212+
P.Optional(g(kw("lproc_port") + decimal_literal + s(";"))) \
213+
) + s("}")
214+
197215
bitfield_member = bitfield_declaration + g(P.Optional(fielddocumentation))
198216

199217
declaration = \
@@ -219,10 +237,10 @@ def __init__(self, filename, parentParser):
219237
struct_body << s("{") + P.OneOrMore(struct_member) + s("}")
220238

221239
constant_def = kw("const") - scopedUpperIdentifier - s("=") - numeric_literal - s(";")
222-
namespace_def = kw("namespace") - identifier - s(";")
240+
namespace_def = kw("namespace") - identifier - P.Optional(namespacedefaults) - s(";")
223241
namespace_def.setParseAction(self.namespaceParse)
224242

225-
nonamespace_def = kw("nonamespace") + s(";")
243+
nonamespace_def = kw("nonamespace") + P.Optional(namespacedefaults) + s(";")
226244
nonamespace_def.setParseAction(self.nonamespace)
227245

228246
struct_def = kw("struct") - newscopedidentifier - g(struct_body) + P.Optional(s('=') - type_name) - s(";")
@@ -238,6 +256,12 @@ def __init__(self, filename, parentParser):
238256

239257
command_def = kw("command") - P.QuotedString('"') - g(command_body) - P.Optional(s('=') + type_name) - s(";")
240258

259+
event_options = \
260+
P.Optional(g(kw("summary") + P.QuotedString('"') + s(";")))
261+
262+
event_body = s("{") + event_options + s("}")
263+
event_def = kw("event") - P.QuotedString('"') - g(event_body) - P.Optional(s('=') + type_name) - s(";")
264+
241265
union_def = kw("union") - newscopedidentifier - s('{') + s('}') - s(";")
242266

243267
error_def = kw("error") - type_name - s('=') + P.QuotedString('"') + s(";")
@@ -247,6 +271,7 @@ def __init__(self, filename, parentParser):
247271
union_def | \
248272
struct_def | \
249273
command_def | \
274+
event_def | \
250275
error_def
251276

252277
import_def = kw("import") - P.QuotedString('"') - s(";")
@@ -287,9 +312,9 @@ def xdr_parse_fielddoc(self, x):
287312
offset = 0
288313
true_label = ''
289314
false_label = ''
290-
location = ''
291-
subsystem = ''
292-
group = ''
315+
location = self.dfl_location
316+
subsystem = self.dfl_subsystem
317+
group = self.dfl_group
293318
export = True
294319
for field in x:
295320
if field[0] == 'key':
@@ -424,7 +449,36 @@ def xdr_parse_declaration(self, x):
424449

425450
def xdr_parse_definition(self, x):
426451
if x[0] == 'namespace':
427-
return [XDRNamespace(x[1])]
452+
location = ''
453+
subsystem = ''
454+
group = ''
455+
dl_name = ''
456+
dl_path = ''
457+
lproc_name = ''
458+
lproc_port = ''
459+
for i in x[2:]:
460+
if i[0] == 'location':
461+
location = i[1]
462+
self.dfl_location = location
463+
if i[0] == 'subsystem':
464+
subsystem = i[1]
465+
self.dfl_subsystem = subsystem
466+
if i[0] == 'group':
467+
group = i[1]
468+
self.dfl_group = group
469+
if i[0] == 'dl_name':
470+
dl_name = i[1]
471+
self.dl_name = dl_name
472+
if i[0] == 'dl_path':
473+
dl_path = i[1]
474+
self.dl_path = dl_path
475+
if i[0] == 'lproc_name':
476+
lproc_name = i[1]
477+
self.lproc_name = lproc_name
478+
if i[0] == 'lproc_port':
479+
lproc_port = i[1]
480+
self.lproc_port = lproc_port
481+
return [XDRNamespace(x[1], location, subsystem, group, dl_name, dl_path, lproc_name, lproc_port)]
428482
elif x[0] == 'nonamespace':
429483
return []
430484
elif x[0] == 'import':
@@ -450,7 +504,15 @@ def xdr_parse_definition(self, x):
450504
# [XDRUnionMember(y[0], self.xdr_parse_declaration(y[1])) for y in x[3]])
451505
elif x[0] == 'error':
452506
return [XDRError(x[1], x[1].split('::')[-1], x[2])]
453-
507+
elif x[0] == 'event':
508+
summary = ''
509+
num = '0'
510+
for field in x[2]:
511+
if field[0] == 'summary':
512+
summary = field[1]
513+
if len(x) >= 4:
514+
num = x[3]
515+
return [XDREvent(x[1], num, summary, self.lproc_name, self.lproc_port)]
454516
elif x[0] == 'command':
455517
summary = None
456518
param = '0'

tests/xp_schema.xp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
namespace ade;
1+
namespace ade {
2+
subsystem "payload";
3+
group "pl";
4+
location "Test Loc";
5+
dl_name "foo";
6+
dl_path "/usr/local/sbin/util";
7+
lproc_name "payload";
8+
lproc_port 12345;
9+
};
210

311
const CMD_BASE = 0x400;
412
const TYPE_BASE = 0x01000400;
@@ -115,3 +123,11 @@ command "deploy" {
115123
summary "Deploy the drag sail after a specified delay";
116124
param types::DEPLOY_PARAMS;
117125
} = Cmds::DEPLOY;
126+
127+
enum Events {
128+
TEST = 1
129+
};
130+
131+
event "test-event" {
132+
summary "Some useful description";
133+
} = Events::TEST;

0 commit comments

Comments
 (0)