gotelem/gen_skylab.go

92 lines
1.6 KiB
Go
Raw Normal View History

2023-05-10 05:44:46 +00:00
//go:build ignore
// this file is a generator for skylab code.
package main
import (
"gopkg.in/yaml.v3"
)
type Field interface {
Name() string
2023-05-10 18:58:46 +00:00
Size() int // the size of the data.
// returns something like
// AuxVoltage uint16
// used inside the packet struct
Embed() string
// returns
Marshal() string
Decode() string
2023-05-10 05:44:46 +00:00
}
2023-05-10 18:58:46 +00:00
// this is a standard field, not a bitfield.
type DataField struct {
2023-05-10 05:44:46 +00:00
Name string
Type string
2023-05-10 18:58:46 +00:00
Units string // mostly for documentation
Conversion float32
2023-05-10 05:44:46 +00:00
}
2023-05-10 18:58:46 +00:00
// a PacketDef is a full can packet.
2023-05-10 05:44:46 +00:00
type PacketDef struct {
Name string
Description string
Id uint32
BigEndian bool
2023-05-10 18:58:46 +00:00
data: []Field
2023-05-10 05:44:46 +00:00
}
2023-05-10 18:58:46 +00:00
2023-05-10 05:44:46 +00:00
// we need to generate bitfield types.
// packet structs per each packet
// constancts for packet IDs or a map.
/*
example for a simple packet type
it also needs a json marshalling.
type BMSMeasurement struct {
BatteryVoltage uint16
AuxVoltage uint16
Current float32
}
func (b *BMSMeasurement)MarshalPacket() ([]byte, error) {
pkt := make([]byte, b.Size())
2023-05-10 18:58:46 +00:00
binary.LittleEndian.PutUint16(pkt[0:], b.BatteryVoltage * 0.01)
binary.LittleEndian.PutUint16(pkt[2:],b.AuxVoltage * 0.001)
2023-05-10 05:44:46 +00:00
binary.LittleEndian.PutFloat32(b.Current) // TODO: make float function
}
func (b *BMSMeasurement)UnmarshalPacket(p []byte) error {
}
func (b *BMSMeasurement) Id() uint32 {
return 0x010
}
func (b *BMSMeasurement) Size() int {
return 8
}
func (b *BMSMeasurement) String() string {
2023-05-10 18:58:46 +00:00
return "blah blah"
2023-05-10 05:44:46 +00:00
}
we also need some kind of mechanism to lookup data type.
func getPkt (id uint32, data []byte) (Packet, error) {
// insert really massive switch case statement here.
}
2023-05-10 18:58:46 +00:00
*/