bool mux types handling: cannot use 0 (type untyped int) as type bool
d4l3k opened this issue · 0 comments
d4l3k commented
Ran into a bug with mux types
BO_ 123 a: 8 Vector__XXX
SG_ b m0 : 58|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ c m0 : 57|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ d m0 : 56|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ e m0 : 55|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ f m0 : 48|7@1+ (1,0) [0|0] "%" Vector__XXX
SG_ g m0 : 47|1@1+ (1,0) [0|0] "" Vector__XXX
SG_ h m0 : 40|7@1+ (1,0) [0|0] "%" Vector__XXX
SG_ i m1 : 32|16@1+ (1,0) [0|0] "" Vector__XXX
SG_ j m0 : 24|16@1+ (1,0) [0|0] "MB" Vector__XXX
SG_ k m1 : 8|24@1+ (1,0) [0|0] "" Vector__XXX
SG_ l m0 : 8|16@1+ (1,0) [0|0] "MB" Vector__XXX
SG_ mux M : 0|1@1+ (1,0) [0|0] "" Vector__XXX
VAL_ 123 mux 0 "0" 1 "1" ;
generates some invalid code since bools can't be compared to 0/1
// a_mux models the mux signal of the a message.
type a_mux bool
// Value descriptions for the mux signal of the a message.
const (
a_mux_0 a_mux = false
a_mux_1 a_mux = true
)
func (v a_mux) String() string {
switch bool(v) {
case false:
return "0"
case true:
return "1"
}
return fmt.Sprintf("a_mux(%t)", v)
}
// Frame returns a CAN frame representing the message.
func (m *a) Frame() can.Frame {
md := Messages().a
f := can.Frame{ID: md.ID, IsExtended: md.IsExtended, Length: md.Length}
md.mux.MarshalBool(&f.Data, bool(m.xxx_mux))
if m.xxx_mux == 0 {
md.l.MarshalUnsigned(&f.Data, uint64(m.xxx_l))
}
if m.xxx_mux == 1 {
md.k.MarshalUnsigned(&f.Data, uint64(m.xxx_k))
}
if m.xxx_mux == 0 {
md.j.MarshalUnsigned(&f.Data, uint64(m.xxx_j))
}
if m.xxx_mux == 1 {
md.i.MarshalUnsigned(&f.Data, uint64(m.xxx_i))
}
if m.xxx_mux == 0 {
md.h.MarshalUnsigned(&f.Data, uint64(m.xxx_h))
}
if m.xxx_mux == 0 {
md.g.MarshalBool(&f.Data, bool(m.xxx_g))
}
if m.xxx_mux == 0 {
md.f.MarshalUnsigned(&f.Data, uint64(m.xxx_f))
}
if m.xxx_mux == 0 {
md.e.MarshalBool(&f.Data, bool(m.xxx_e))
}
if m.xxx_mux == 0 {
md.d.MarshalBool(&f.Data, bool(m.xxx_d))
}
if m.xxx_mux == 0 {
md.c.MarshalBool(&f.Data, bool(m.xxx_c))
}
if m.xxx_mux == 0 {
md.b.MarshalBool(&f.Data, bool(m.xxx_b))
}
return f
}
<file>:<line>: cannot use 0 (type untyped int) as type bool