From 2dab308907dd284f3e78ccf6c20ae94ba68ed9b5 Mon Sep 17 00:00:00 2001 From: saji Date: Wed, 10 May 2023 00:44:46 -0500 Subject: [PATCH] add some things --- gen_skylab.go | 77 +++++++++++++++++++++++++++++++++++++++++++ mprpc/rpcconntrack.go | 2 +- 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 gen_skylab.go diff --git a/gen_skylab.go b/gen_skylab.go new file mode 100644 index 0000000..2d8adf8 --- /dev/null +++ b/gen_skylab.go @@ -0,0 +1,77 @@ +//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. + } + +*/ \ No newline at end of file diff --git a/mprpc/rpcconntrack.go b/mprpc/rpcconntrack.go index d18595b..708c21d 100644 --- a/mprpc/rpcconntrack.go +++ b/mprpc/rpcconntrack.go @@ -47,7 +47,7 @@ func (c *rpcConnTrack) Claim() (uint32, chan Response) { // Clear deletes the connection from the tracker and returns the channel // associated with it. The caller can use the channel afterwards -// to send the response. +// to send the response. It is the caller's responsibility to close the channel. func (c *rpcConnTrack) Clear(val uint32) (chan Response, error) { c.mu.RLock() ch, ok := c.ct[val]