gotelem/gen_skylab.go

77 lines
1.3 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
}
type PacketField struct {
Name string
Type string
Units string
Conversion float32
}
type PacketDef struct {
Name string
Description string
Id uint32
BigEndian bool
data: []PacketField
}
// 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())
binary.LittleEndian.PutUint16(b.BatteryVoltage * 0.01)
binary.LittleEndian.PutUint16(b.AuxVoltage * 0.001)
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 {
return 'blah blah"
}
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.
}
*/