Skip to content

Commit

Permalink
Some LDF grammar improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Dec 29, 2018
1 parent 190d4f0 commit 787e4eb
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 239 deletions.
12 changes: 9 additions & 3 deletions pydbc/ldf.g4
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ lin_description_file:
'LIN_description_file' ';'
pv = lin_protocol_version_def
lv = lin_language_version_def
fr = lin_file_revision_def?
ls = lin_speed_def
cn = channel_name_def?
ndef = node_def
Expand All @@ -108,6 +109,11 @@ lin_language_version_def:
'LIN_language_version' '=' s = stringValue ';'
;

lin_file_revision_def:
'LDF_file_revision' '=' s = stringValue ';' // ISO17987
;


lin_speed_def:
'LIN_speed' '=' n = number 'kbps' ';'
;
Expand Down Expand Up @@ -159,8 +165,8 @@ diag_address:
;

attributes_def:
'product_id' '=' sid = supplier_id ',' fid = function_id (',' v = variant)? ';'
'response_error' '=' sn0 = signal_name ';'
('product_id' '=' sid = supplier_id ',' fid = function_id (',' v = variant)? ';')? // Mandatory for LIN >= 2.2.
('response_error' '=' sn0 = signal_name ';')? // Mandatory for LIN >= 2.2.
('fault_state_signals' '=' sn1s += signal_name (',' sn1s += signal_name)* ';')?
('P2_min' '=' p2Min = number 'ms' ';')?
('ST_min' '=' stMin = number 'ms' ';')?
Expand Down Expand Up @@ -370,7 +376,7 @@ event_triggered_frame_def:
;

event_triggered_frame_item:
e = event_trig_frm_name ':' c = collision_resolving_schedule_table ',' fid = frame_id (',' items += frame_name ';')*
e = event_trig_frm_name ':' c = collision_resolving_schedule_table ',' fid = frame_id (',' items += frame_name)* ';'
;

event_trig_frm_name:
Expand Down
38 changes: 23 additions & 15 deletions pydbc/ldfListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def exitLin_description_file(self, ctx):
self.value = dict(
protocolVersion = ctx.pv.value,
languageVersion = ctx.lv.value,
fileRevision = ctx.fr.value if ctx.fr else None,
speed = ctx.ls.value,
channelName = ctx.cn.value if ctx.cn else None,
nodes = ctx.ndef.value,
Expand All @@ -60,9 +61,14 @@ def exitLin_protocol_version_def(self, ctx):

def exitLin_language_version_def(self, ctx):
ctx.value = ctx.s.value
print("Language-Ver:", ctx.value)

def exitLin_file_revision_def(self, ctx):
ctx.value = ctx.s.value
print("File_Revision:", ctx.value)

def exitLin_speed_def(self, ctx):
ctx.value = ctx.n.value
ctx.value = ctx.n.value if ctx.n else None

def exitChannel_name_def(self, ctx):
ctx.value = ctx.i.value
Expand Down Expand Up @@ -90,9 +96,9 @@ def exitNode_attributes_def(self, ctx):
def exitNode_attribute(self, ctx):
name = ctx.name.value
version = ctx.version.value
n0 = ctx.n0.value
n1 = ctx.n1.value
attrs = ctx.attrs.value
n0 = ctx.n0.value if ctx.n0 else None
n1 = ctx.n1.value if ctx.n1 else None
attrs = ctx.attrs.value if ctx.attrs else None
ctx.value = dict(name = name, version = version, configuredNAD = n0, initialNAD = n1, attrs = attrs)

def exitProtocol_version(self, ctx):
Expand All @@ -105,13 +111,13 @@ def exitAttributes_def(self, ctx):
sid = ctx.sid.value
fid = ctx.fid.value
v = ctx.v.value if ctx.v else None
sn0 = ctx.sn0.value
sn0 = ctx.sn0.value if ctx.sn0 else None
sn1s = [x.value for x in ctx.sn1s]
cf = ctx.cf.value
p2Min = ctx.p2Min.value
stMin = ctx.stMin.value
nAs = ctx.nAs.value
nCr = ctx.nCr.value
cf = ctx.cf.value if ctx.cf else None
p2Min = ctx.p2Min.value if ctx.p2Min else None
stMin = ctx.stMin.value if ctx.stMin else None
nAs = ctx.nAs.value if ctx.nAs else None
nCr = ctx.nCr.value if ctx.nCr else None
ctx.value = dict(supplierID = sid, functionID = fid, variant = v, responseErrorSignal = sn0, faultStateSignals = sn1s,
p2Min = p2Min, stMin = stMin, nAs = nAs, nCr = nCr, configurableFrames = cf
)
Expand Down Expand Up @@ -311,7 +317,7 @@ def exitCommand(self, ctx):
if ctx.frameName:
cmd = ctx.frameName.value
else:
cmd = ctx.c.value
cmd = ctx.c.text
if cmd == 'AssignNAD':
nodeName = ctx.nodeName.value
elif cmd == 'ConditionalChangeNAD':
Expand All @@ -333,7 +339,7 @@ def exitCommand(self, ctx):
elif cmd == 'AssignFrameIdRange':
nodeName = ctx.nodeName.value
frameIndex = ctx.frameIndex.value
pids = [p.value for p in ctx.p]
pids = [p.value for p in ctx.pids]
elif cmd == 'FreeFormat':
d1 = ctx.d1.value
d2 = ctx.d2.value
Expand Down Expand Up @@ -376,10 +382,10 @@ def exitSignal_encoding_value(self, ctx):
value = ctx.p.value
vtype = "range"
elif ctx.b:
value = ctx.b.value
value = None
vtype = "bcd"
elif ctx.a:
value = ctx.a.name
value = None
vtype = "ascii"
ctx.value = dict(value = value, valueType = vtype)

Expand All @@ -388,7 +394,9 @@ def exitSignal_encoding_type_name(self, ctx):
ctx.value = ctx.i.value

def exitLogical_value(self, ctx):
pass
s = ctx.s.value
t = ctx.t.value if ctx.t else None
ctx.value = dict(signalValue = s, text = t)

def exitPhysical_range(self, ctx):
minValue = ctx.minValue.value
Expand Down
22 changes: 11 additions & 11 deletions pydbc/ncfListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ def exitToplevel(self, ctx):
self.value = dict(version = v, nodes = nodes)

def exitLanguage_version(self, ctx):
s = ctx.s.value
s = ctx.s.value if ctx.s else None
ctx.value = s

def exitNode_definition(self, ctx):
name = ctx.name.value
g = ctx.g.value
d = ctx.d.value
f = ctx.f.value
e = ctx.e.value
s = ctx.s.value
g = ctx.g.value if ctx.g else None
d = ctx.d.value if ctx.d else None
f = ctx.f.value if ctx.d else None
e = ctx.e.value if ctx.e else None
s = ctx.s.value if ctx.s else None
t = ctx.t.value if ctx.t else None
ctx.value = dict(name = name, general = g, diagnostic = d, frames= f, encodings = e, status = s, freeText = t)

Expand Down Expand Up @@ -167,28 +167,28 @@ def exitEncoding_definition_entry(self, ctx):
items = [x.value for x in ctx.items]
ctx.value = dict(name = name, values = items)

def exitEncoding_definition_value(self, ctx):
def exitSignal_encoding_value(self, ctx):
if ctx.l:
value = ctx.l.value
vtype = "logical"
elif ctx.p:
value = ctx.p.value
vtype = "range"
elif ctx.b:
value = ctx.b.value
value = None
vtype = "bcd"
elif ctx.a:
value = ctx.a.name
value = None
vtype = "ascii"
ctx.value = dict(value = value, valueType = vtype)

def exitEncoding_name(self, ctx):
def exitSignal_encoding_type_name(self, ctx):
ctx.value = ctx.i.value

def exitLogical_value(self, ctx):
s = ctx.s.value
t = ctx.t.value if ctx.t else None
ctx.value = dict(signal = s, text = t)
ctx.value = dict(signalValue = s, text = t)

def exitPhysical_range(self, ctx):
#'physical_value' ',' minValue = min_value ',' maxValue = max_value ',' s = scale ',' o = offset (',' t = text_info)? ';'
Expand Down
Loading

0 comments on commit 787e4eb

Please sign in to comment.