Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bool mux types handling: cannot use 0 (type untyped int) as type bool #39

Open
d4l3k opened this issue Aug 15, 2021 · 0 comments · May be fixed by #52
Open

bool mux types handling: cannot use 0 (type untyped int) as type bool #39

d4l3k opened this issue Aug 15, 2021 · 0 comments · May be fixed by #52

Comments

@d4l3k
Copy link
Contributor

d4l3k commented Aug 15, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant