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

Add command constants to generated code #2

Open
lukescott opened this issue Jun 5, 2017 · 1 comment
Open

Add command constants to generated code #2

lukescott opened this issue Jun 5, 2017 · 1 comment
Assignees

Comments

@lukescott
Copy link
Contributor

Command classes have define parameter values for commands. Rather than defining them with generic types, such as byte, create a enum type.

The switch binary command class for example:

<cmd_class key="0x25" version="1" name="COMMAND_CLASS_SWITCH_BINARY" help="Command Class Switch Binary" read_only="false" comment="">
    <cmd key="0x02" name="SWITCH_BINARY_GET" help="Switch Binary Get" comment="" />
    <cmd key="0x03" name="SWITCH_BINARY_REPORT" help="Switch Binary Report" comment="">
      <param key="0x00" name="Value" type="BYTE" typehashcode="0x01" comment="">
        <valueattrib key="0x00" hasdefines="true" showhex="true" />
        <bitflag key="0x01" flagname="off/disable" flagmask="0x00" />
        <bitflag key="0x02" flagname="on/enable" flagmask="0xFF" />
      </param>
    </cmd>
    <cmd key="0x01" name="SWITCH_BINARY_SET" help="Switch Binary Set" comment="">
      <param key="0x00" name="Switch Value" type="BYTE" typehashcode="0x01" comment="">
        <valueattrib key="0x00" hasdefines="true" showhex="true" />
        <bitflag key="0x01" flagname="off/disable" flagmask="0x00" />
        <bitflag key="0x02" flagname="on/enable" flagmask="0xFF" />
      </param>
    </cmd>
  </cmd_class>

It currently generates:

type Set struct {
	SwitchValue byte
}

It should generate something like:

type SwitchValueType byte

const (
	Off SwitchValueType = 0x00
	On SwitchValueType = 0xFF
)

func (v SwitchValueType) Validate() bool {
	switch (v) {
	case On, Off:
		return true
	default:
		return false
	} 
}

type Set struct {
	SwitchValue SwitchValueType
}
@lukescott lukescott self-assigned this Jun 5, 2017
@bjyoungblood
Copy link
Contributor

bjyoungblood commented Jun 6, 2017

I looked at doing this, but it's hard to do programmatically due to the flagname parameter. For this specific example, you could split on / and title-case the first match, but there are some command classes where avoiding naming conflicts will be difficult (see https://github.com/gozwave/gozw/blob/master/gen/data/zwave-defs.xml#L8468).

My original intention was for gozw to act as a library that specifically understood zwave, and to create an additional library that was focused on abstracting these types of application-level concerns without requiring much specific knowledge of zwave. I never got around to figuring out how that fits in with everything else, so it's probably worth discussing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants