From aa0b61405bf8f72880a6b75281f590f8b1fd62fb Mon Sep 17 00:00:00 2001 From: saji Date: Fri, 23 Jun 2023 16:20:28 -0500 Subject: [PATCH] add http, store skylab defintions in generated file as string --- cmd/gotelem/cli/client.go | 7 ----- cmd/gotelem/cli/server.go | 43 +++++++++++++++++++++-------- go.mod | 1 - go.sum | 2 -- skylab/make_skylab.go | 48 +++++++++++++++++---------------- skylab/skylab_gen.go | 5 +++- skylab/templates/golang.go.tmpl | 3 +++ 7 files changed, 64 insertions(+), 45 deletions(-) diff --git a/cmd/gotelem/cli/client.go b/cmd/gotelem/cli/client.go index de27081..d34d7e8 100644 --- a/cmd/gotelem/cli/client.go +++ b/cmd/gotelem/cli/client.go @@ -3,7 +3,6 @@ package cli import ( "fmt" - imgui "github.com/AllenDang/cimgui-go" "github.com/kschamplin/gotelem" "github.com/kschamplin/gotelem/mprpc" "github.com/urfave/cli/v2" @@ -31,14 +30,8 @@ Connects to a gotelem server or relay. Can be used to Action: client, } -func loop() { - imgui.ShowDemoWindow() -} func client(ctx *cli.Context) error { - backend := imgui.CreateBackend() - backend.CreateWindow("hi there", 1200, 900, 0) - backend.Run(loop) return nil } diff --git a/cmd/gotelem/cli/server.go b/cmd/gotelem/cli/server.go index e1c9e17..89c44f7 100644 --- a/cmd/gotelem/cli/server.go +++ b/cmd/gotelem/cli/server.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net" + "net/http" "os" "sync" "time" @@ -51,9 +52,10 @@ type service interface { // can be extended on certain platforms (see cli/socketcan.go) // or if certain features are present (see cli/sqlite.go) var serveThings = []service{ - &XBeeService{}, - &CanLoggerService{}, + &xBeeService{}, + &canLoggerService{}, &rpcService{}, + &httpService{}, } func serve(cCtx *cli.Context) error { @@ -141,17 +143,17 @@ func handleCon(conn net.Conn, broker *gotelem.JBroker, l *slog.Logger, done <-ch // this spins up a new can socket on vcan0 and broadcasts a packet every second. for testing. -type CanLoggerService struct { +type canLoggerService struct { } -func (c *CanLoggerService) String() string { +func (c *canLoggerService) String() string { return "CanLoggerService" } -func (c *CanLoggerService) Status() { +func (c *canLoggerService) Status() { } -func (c *CanLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l *slog.Logger) (err error) { +func (c *canLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l *slog.Logger) (err error) { rxCh, err := broker.Subscribe("canDump") if err != nil { return err @@ -182,19 +184,19 @@ func (c *CanLoggerService) Start(cCtx *cli.Context, broker *gotelem.JBroker, l * } } -// XBeeService provides data over an Xbee device, either by serial or TCP +// xBeeService provides data over an Xbee device, either by serial or TCP // based on the url provided in the xbee flag. see the description for details. -type XBeeService struct { +type xBeeService struct { session *xbee.Session } -func (x *XBeeService) String() string { +func (x *xBeeService) String() string { return "hello" } -func (x *XBeeService) Status() { +func (x *xBeeService) Status() { } -func (x *XBeeService) Start(cCtx *cli.Context, broker *gotelem.JBroker, logger *slog.Logger) (err error) { +func (x *xBeeService) Start(cCtx *cli.Context, broker *gotelem.JBroker, logger *slog.Logger) (err error) { if cCtx.String("xbee") == "" { logger.Info("not using xbee") return @@ -233,3 +235,22 @@ func (x *XBeeService) Start(cCtx *cli.Context, broker *gotelem.JBroker, logger * } } + +type httpService struct { +} + +func (h *httpService) String() string { + return "HttpService" +} + +func (h *httpService) Status() { + +} + +func (h *httpService) Start(cCtx *cli.Context, broker *gotelem.JBroker, logger *slog.Logger) (err error) { + + r := gotelem.TelemRouter(logger) + + http.ListenAndServe(":8080", r) + return +} diff --git a/go.mod b/go.mod index d64caae..70007cd 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/kschamplin/gotelem go 1.20 require ( - github.com/AllenDang/cimgui-go v0.0.0-20230502145512-97518c13c52b github.com/go-chi/chi/v5 v5.0.8 github.com/jmoiron/sqlx v1.3.5 github.com/mattn/go-sqlite3 v1.14.16 diff --git a/go.sum b/go.sum index 1111751..12e2f96 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/AllenDang/cimgui-go v0.0.0-20230502145512-97518c13c52b h1:EpLVWHcO5auIf8X0STrno4WAWThu6s6QgJ1ywJa5Tmo= -github.com/AllenDang/cimgui-go v0.0.0-20230502145512-97518c13c52b/go.mod h1:iNfbIyOBN8k3XScMxULbrwYbPsXEAUD0Jb6UwrspQb8= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0= diff --git a/skylab/make_skylab.go b/skylab/make_skylab.go index 9f4ff2e..b4a99f1 100644 --- a/skylab/make_skylab.go +++ b/skylab/make_skylab.go @@ -5,6 +5,7 @@ package main import ( + "encoding/json" "fmt" "os" "path/filepath" @@ -17,36 +18,36 @@ import ( // SkylabFile is a yaml file from skylab. type SkylabFile struct { - Packets []PacketDef - Boards []BoardSpec + Packets []PacketDef `json:"packets"` + Boards []BoardDef `json:"boards"` } -type BoardSpec struct { - Name string - Transmit []string - Recieve []string +type BoardDef struct { + Name string `json:"name"` + Transmit []string `json:"transmit"` + Receive []string `json:"receive"` } // data field. -type DataField struct { - Name string - Type string - Units string // mostly for documentation - Conversion float32 +type FieldDef struct { + Name string `json:"name"` + Type string `json:"type"` + Units string `json:"units"` + Conversion float32 `json:"conversion"` Bits []struct { - Name string - } + Name string `json:"name"` + } `json:"bits"` } // a PacketDef is a full can packet. type PacketDef struct { - Name string - Description string - Id uint32 - BigEndian bool - Repeat int - Offset int - Data []DataField + Name string `json:"name"` + Description string `json:"description"` + Id uint32 `json:"id"` + Endian string `json:"endian"` + Repeat int `json:"repeat"` + Offset int `json:"offset"` + Data []FieldDef `json:"data"` } // we need to generate bitfield types. @@ -83,7 +84,7 @@ func MapType(ctype string) string { return typeMap[ctype] } -func (d *DataField) ToStructMember(parentName string) string { +func (d *FieldDef) ToStructMember(parentName string) string { if d.Type == "bitfield" { bfStructName := parentName + toCamelInitCase(d.Name, true) @@ -93,7 +94,7 @@ func (d *DataField) ToStructMember(parentName string) string { } } -func (d *DataField) MakeMarshal(offset int) string { +func (d *FieldDef) MakeMarshal(offset int) string { fieldName := toCamelInitCase(d.Name, true) if d.Type == "uint8_t" || d.Type == "int8_t" { @@ -117,7 +118,7 @@ func (d *DataField) MakeMarshal(offset int) string { return "panic(\"failed to do it\")\n" } -func (d *DataField) MakeUnmarshal(offset int) string { +func (d *FieldDef) MakeUnmarshal(offset int) string { fieldName := toCamelInitCase(d.Name, true) if d.Type == "uint8_t" || d.Type == "int8_t" { @@ -316,6 +317,7 @@ func main() { "strJoin": strJoin, "mapf": mapf, "maptype": MapType, + "json": json.Marshal, } tmpl, err := template.New("golang.go.tmpl").Funcs(fnMap).ParseGlob("templates/*.go.tmpl") diff --git a/skylab/skylab_gen.go b/skylab/skylab_gen.go index 698d78c..4348f60 100644 --- a/skylab/skylab_gen.go +++ b/skylab/skylab_gen.go @@ -1,4 +1,4 @@ -// generated by gen_skylab.go at 2023-05-29 13:32:54.641838299 -0500 CDT m=+0.002791417 DO NOT EDIT! +// generated by gen_skylab.go at 2023-05-30 21:59:25.165613242 -0500 CDT m=+0.002722998 DO NOT EDIT! package skylab @@ -5362,3 +5362,6 @@ func (p *WslSlipSpeedMeasurement) String() string { +// The json representation that was used to generate this data. +// can be used to share the parsing data for i.e dynamic python gui. +const SkylabDefinitions = `{"packets":[{"name":"bms_measurement","description":"Voltages for main battery and aux pack","id":16,"endian":"little","repeat":0,"offset":0,"data":[{"name":"battery_voltage","type":"uint16_t","units":"V","conversion":0.01,"bits":null},{"name":"aux_voltage","type":"uint16_t","units":"V","conversion":0.001,"bits":null},{"name":"current","type":"float","units":"A","conversion":1,"bits":null}]},{"name":"battery_status","description":"Status bits for the battery","id":17,"endian":"little","repeat":0,"offset":0,"data":[{"name":"battery_state","type":"bitfield","units":"","conversion":0,"bits":[{"name":"startup"},{"name":"precharge"},{"name":"discharging"},{"name":"lv_only"},{"name":"charging"},{"name":"wall_charging"},{"name":"killed"}]},{"name":"contactor_state","type":"bitfield","units":"","conversion":0,"bits":[{"name":"battery_high_contactor"},{"name":"battery_low_contactor"},{"name":"battery_vicor_contactor"},{"name":"battery_pre_contactor"},{"name":"battery_high2_contactor"},{"name":"battery_low2_contactor"},{"name":"charger_high_contactor"},{"name":"charger_pre_contactor"}]},{"name":"lv_channel_status","type":"bitfield","units":"","conversion":0,"bits":[{"name":"aux_fault"},{"name":"main_fault"},{"name":"aux_power_valid"},{"name":"main_power_valid"},{"name":"aux_power_active"},{"name":"main_power_active"}]},{"name":"lv_control_status","type":"bitfield","units":"","conversion":0,"bits":[{"name":"aux_vicor_enable"},{"name":"bat_vicor_enable"},{"name":"aux_relay_held"},{"name":"aux_ref_enable"},{"name":"aux_charging_enable"},{"name":"kill_hv"},{"name":"kill_lv"},{"name":"start_button"}]}]},{"name":"bms_kill_reason","description":"Information for when the car kills","id":18,"endian":"little","repeat":0,"offset":0,"data":[{"name":"reason1","type":"bitfield","units":"","conversion":0,"bits":[{"name":"OVERVOLT"},{"name":"UNDERVOLT"},{"name":"OVERTEMP"},{"name":"TEMP_DISCONNECT"},{"name":"COMM_FAIL"}]},{"name":"reason2","type":"bitfield","units":"","conversion":0,"bits":[{"name":"HARDWARE"},{"name":"KILL_PACKET"},{"name":"UKNOWN"},{"name":"OVERCURRENT"},{"name":"PRECHARGE_FAIL"},{"name":"AUX_OVER_UNDER"}]},{"name":"module","type":"uint16_t","units":"","conversion":0,"bits":null},{"name":"value","type":"float","units":"","conversion":0,"bits":null}]},{"name":"bms_module_min_max","description":"min and max cell voltages and temperatures","id":19,"endian":"little","repeat":0,"offset":0,"data":[{"name":"module_max_temp","type":"int16_t","units":"C","conversion":0.01,"bits":null},{"name":"module_min_temp","type":"int16_t","units":"C","conversion":0.01,"bits":null},{"name":"module_max_voltage","type":"uint16_t","units":"V","conversion":0.001,"bits":null},{"name":"module_min_voltage","type":"uint16_t","units":"V","conversion":0.001,"bits":null}]},{"name":"bms_soc","description":"State of charge","id":20,"endian":"little","repeat":0,"offset":0,"data":[{"name":"soc","type":"float","units":"","conversion":1,"bits":null}]},{"name":"bms_capacity","description":"State of charge","id":21,"endian":"little","repeat":0,"offset":0,"data":[{"name":"Ah","type":"float","units":"","conversion":1,"bits":null},{"name":"Wh","type":"float","units":"","conversion":1,"bits":null}]},{"name":"bms_currentlimit","description":"reports BP params for current","id":24,"endian":"little","repeat":0,"offset":0,"data":[{"name":"current_max","type":"int16_t","units":"A","conversion":0.01,"bits":null},{"name":"current_min","type":"int16_t","units":"A","conversion":0.01,"bits":null}]},{"name":"bms_fan_info","description":"BP Fans","id":25,"endian":"little","repeat":0,"offset":0,"data":[{"name":"fan1","type":"uint16_t","units":"RPM","conversion":1,"bits":null},{"name":"fan2","type":"uint16_t","units":"RPM","conversion":1,"bits":null},{"name":"fan3","type":"uint16_t","units":"RPM","conversion":1,"bits":null},{"name":"fan4","type":"uint16_t","units":"RPM","conversion":1,"bits":null}]},{"name":"bms_set_min_fan_speed","description":"packet which sets a minimum fan speed of BMS for a specific time frame in seconds","id":27,"endian":"little","repeat":0,"offset":0,"data":[{"name":"fan_percentage","type":"float","units":"percent","conversion":0,"bits":null},{"name":"time","type":"uint16_t","units":"s","conversion":0,"bits":null}]},{"name":"bms_module","description":"Voltage and temperature for a single module","id":28,"endian":"little","repeat":36,"offset":1,"data":[{"name":"voltage","type":"float","units":"V","conversion":1,"bits":null},{"name":"temperature","type":"float","units":"C","conversion":1,"bits":null}]},{"name":"bms_charger_response","description":"Response packet from BMS for indicating whether BMS is ready for charging","id":117,"endian":"","repeat":0,"offset":0,"data":[{"name":"response_flags","type":"bitfield","units":"","conversion":0,"bits":[{"name":"charging_ready"}]}]},{"name":"dashboard_pedal_percentages","description":"ADC values from the brake and accelerator pedals.","id":656,"endian":"little","repeat":0,"offset":0,"data":[{"name":"accel_pedal_value","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"brake_pedal_value","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"car_state","description":"Car gear. Forward, neutral, reverse, etc.","id":657,"endian":"little","repeat":0,"offset":0,"data":[{"name":"state","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"dashboard_pedal_fault","description":"Target speed that the driver should maintain.","id":658,"endian":"little","repeat":0,"offset":0,"data":[{"name":"brake_fault_count","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"accel_fault_count","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"dashboard_system_timeout_test","description":"Exposes whether each system that dashboard is supposed to listen for packets from has sent a packet. Used for testing.","id":665,"endian":"little","repeat":0,"offset":0,"data":[{"name":"flag_set_0","type":"bitfield","units":"","conversion":0,"bits":[{"name":"steering_disconnected"},{"name":"vision_front_disconnected"},{"name":"vision_rear_disconnected"},{"name":"telemetry_disconnected"},{"name":"wsl_disconnected"},{"name":"wsr_disconnected"},{"name":"front_mppt_disconnected"},{"name":"rear_mppt_disconnected"}]}]},{"name":"car_speed","description":"speed of car in meters per second","id":666,"endian":"little","repeat":0,"offset":0,"data":[{"name":"speed","type":"float","units":"","conversion":0,"bits":null}]},{"name":"flight_computer_lv_board_disconnect_counts","description":"Number of times a board hasn't been heard from within the allowed timeout.","id":667,"endian":"little","repeat":0,"offset":0,"data":[{"name":"front_lights","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"rear_lights","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"steering","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"vision","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"driver_display","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"center_console","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"flight_computer_hv_board_disconnect_counts","description":"Number of times a board hasn't been heard from within the allowed timeout.","id":668,"endian":"little","repeat":0,"offset":0,"data":[{"name":"bms","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"charger","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"wsl","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"wsr","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"mppt_front","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"mppt_rear","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"flight_computer_internal_state","description":"internal bools","id":669,"endian":"little","repeat":0,"offset":0,"data":[{"name":"bms","type":"bitfield","units":"","conversion":0,"bits":[{"name":"battery_kill"},{"name":"cells_in_charging_threshold"},{"name":"first_packet_received"}]},{"name":"charger","type":"bitfield","units":"","conversion":0,"bits":[{"name":"proximity_detected"}]},{"name":"photon3","type":"bitfield","units":"","conversion":0,"bits":[{"name":"enable"}]},{"name":"wavesculptor","type":"bitfield","units":"","conversion":0,"bits":[{"name":"sending_reset"},{"name":"regen_enable"}]},{"name":"internal","type":"bitfield","units":"","conversion":0,"bits":[{"name":"accel_pedal_disconnect"},{"name":"brake_pedal_disconnect"}]}]},{"name":"power_to_drive","description":"calculated power required to drive the vehicle","id":414,"endian":"little","repeat":0,"offset":0,"data":[{"name":"moving_average_100","type":"int16_t","units":"","conversion":0,"bits":null},{"name":"moving_average_1k","type":"int16_t","units":"","conversion":0,"bits":null},{"name":"moving_average_10k","type":"int16_t","units":"","conversion":0,"bits":null}]},{"name":"array_power","description":"array power calculated from current and voltage measurements","id":415,"endian":"little","repeat":0,"offset":0,"data":[{"name":"front_array_channel_0","type":"uint16_t","units":"","conversion":0,"bits":null},{"name":"front_array_channel_1","type":"uint16_t","units":"","conversion":0,"bits":null},{"name":"rear_array_channel_0","type":"uint16_t","units":"","conversion":0,"bits":null},{"name":"rear_array_channel_1","type":"uint16_t","units":"","conversion":0,"bits":null}]},{"name":"vision_turn_signals_command","description":"Command to have the vision board illuminate or turn off left, right, or both turn signals","id":688,"endian":"","repeat":0,"offset":0,"data":[{"name":"lights","type":"bitfield","units":"","conversion":0,"bits":[{"name":"left_turn_signal"},{"name":"right_turn_signal"},{"name":"spare_1"},{"name":"spare_2"},{"name":"spare_3"}]}]},{"name":"vision_brake_lights_command","description":"Command to have the vision board illuminate or turn off the brake lights","id":689,"endian":"","repeat":0,"offset":0,"data":[{"name":"lights","type":"bitfield","units":"","conversion":0,"bits":[{"name":"brake_lights"},{"name":"spare_1"},{"name":"spare_2"},{"name":"spare_3"}]}]},{"name":"vision_headlights_command","description":"Command to have the vision board illuminate or turn off the headlights and high beams","id":690,"endian":"","repeat":0,"offset":0,"data":[{"name":"lights","type":"bitfield","units":"","conversion":0,"bits":[{"name":"headlights"},{"name":"high_beams"},{"name":"spare_1"},{"name":"spare_2"},{"name":"spare_3"}]},{"name":"brightness","type":"float","units":"","conversion":0,"bits":null}]},{"name":"vision_horn_command","description":"Command the vision board honk the horn, must be repeatedly sent otherwise the vision board will stop honking after a bit. See high_power.h for details.","id":691,"endian":"","repeat":0,"offset":0,"data":[{"name":"horn","type":"bitfield","units":"","conversion":0,"bits":[{"name":"horn"},{"name":"spare"}]}]},{"name":"vision_array_latches_command","description":"Command the vision board to open the array latches","id":692,"endian":"","repeat":0,"offset":0,"data":[{"name":"array_latches","type":"bitfield","units":"","conversion":0,"bits":[{"name":"array_front"},{"name":"array_rear"}]}]},{"name":"vision_rearview_command","description":"Command the vision board turn on the rear view cameras","id":693,"endian":"","repeat":0,"offset":0,"data":[{"name":"cameras","type":"bitfield","units":"","conversion":0,"bits":[{"name":"left"},{"name":"right"},{"name":"rear"}]}]},{"name":"tracker_enable","description":"Enables/disables power trackers. Use 0x610 for the channel transmitting the data packet on 0x600, 0x611 for 0x601, et cetera. Sending 1 in the enable byte turns the tracker on; sending 0 turns it off.","id":1552,"endian":"little","repeat":6,"offset":1,"data":[{"name":"enable","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"distance_traveled","description":"distance of wavesculptor odometer","id":512,"endian":"little","repeat":0,"offset":0,"data":[{"name":"trip_distance","type":"float","units":"m","conversion":0,"bits":null}]},{"name":"charger_state","description":"Notifies whether the J1772 cable is plugged.","id":1395,"endian":"","repeat":0,"offset":0,"data":[{"name":"state_flags","type":"bitfield","units":"","conversion":0,"bits":[{"name":"charger_plugged"}]},{"name":"charger_max_temp","type":"uint16_t","units":"C","conversion":0.001,"bits":null},{"name":"fault","type":"bitfield","units":"","conversion":0,"bits":[{"name":"CHARGER_OVERVOLT"},{"name":"CHARGER_OVERTEMP"},{"name":"CHARGER_CAN_TIMEOUT"},{"name":"BATTERY_HV_KILL"},{"name":"BATTERY_UNDERVOLT"},{"name":"BATTERY_OVERVOLT"},{"name":"BATTERY_CELL_OVERTEMP"},{"name":"BATTERY_CAN_TIMEOUT"}]},{"name":"charging_current","type":"float","units":"A","conversion":0,"bits":null}]},{"name":"charger_bms_request","description":"Request packet for sending contactor commands from the charger to BP.","id":116,"endian":"","repeat":0,"offset":0,"data":[{"name":"request_flags","type":"bitfield","units":"","conversion":0,"bits":[{"name":"charging_requested"}]}]},{"name":"charger_current_voltage","description":"Packet to request charging current/voltage set","id":1398,"endian":"","repeat":0,"offset":0,"data":[{"name":"max_current","type":"float","units":"A","conversion":0,"bits":null},{"name":"max_capacity","type":"float","units":"kWh","conversion":0,"bits":null}]},{"name":"charger_power","description":"Outputs the amount of power that the chargers are delivering.","id":1399,"endian":"","repeat":0,"offset":0,"data":[{"name":"power","type":"float","units":"W","conversion":0,"bits":null}]},{"name":"thunderstruck_control_message","description":"Control packet for thunderstruck chargers","id":417677348,"endian":"little","repeat":0,"offset":0,"data":[{"name":"Enable","type":"uint8_t","units":"V","conversion":1,"bits":null},{"name":"CHARGE_VOLTAGE","type":"uint16_t","units":"V","conversion":1,"bits":null},{"name":"CHARGE_CURRENT","type":"uint16_t","units":"V","conversion":1,"bits":null},{"name":"LED_BLINK_PATTERN","type":"uint8_t","units":"V","conversion":1,"bits":null},{"name":"RESERVED","type":"uint16_t","units":"V","conversion":1,"bits":null}]},{"name":"vision_status_front","description":"Status of the front vision board outputs","id":694,"endian":"","repeat":0,"offset":0,"data":[{"name":"lights","type":"bitfield","units":"","conversion":0,"bits":[{"name":"left_turn_signal"},{"name":"right_turn_signal"},{"name":"brake_lights"},{"name":"headlights"},{"name":"high_beams"},{"name":"spare_1"},{"name":"spare_2"},{"name":"spare_3"}]},{"name":"horn","type":"bitfield","units":"","conversion":0,"bits":[{"name":"horn"},{"name":"spare"}]},{"name":"cameras","type":"bitfield","units":"","conversion":0,"bits":[{"name":"left"},{"name":"right"},{"name":"rear"}]},{"name":"array_latches","type":"bitfield","units":"","conversion":0,"bits":[{"name":"array_front_0"},{"name":"array_front_1"},{"name":"array_rear_0"},{"name":"array_rear_1"}]}]},{"name":"vision_status_rear","description":"Status of the rear vision board outputs","id":695,"endian":"","repeat":0,"offset":0,"data":[{"name":"lights","type":"bitfield","units":"","conversion":0,"bits":[{"name":"left_turn_signal"},{"name":"right_turn_signal"},{"name":"brake_lights"},{"name":"headlights"},{"name":"high_beams"},{"name":"spare_1"},{"name":"spare_2"},{"name":"spare_3"}]},{"name":"horn","type":"bitfield","units":"","conversion":0,"bits":[{"name":"horn"},{"name":"spare"}]},{"name":"cameras","type":"bitfield","units":"","conversion":0,"bits":[{"name":"left"},{"name":"right"},{"name":"rear"}]},{"name":"array_latches","type":"bitfield","units":"","conversion":0,"bits":[{"name":"array_front_0"},{"name":"array_front_1"},{"name":"array_rear_0"},{"name":"array_rear_1"}]}]},{"name":"lights_front_id","description":"Unique identification packet for front lights board","id":768,"endian":"","repeat":0,"offset":0,"data":[{"name":"board_id","type":"uint16_t","units":"","conversion":0,"bits":null},{"name":"mcu_temp","type":"int16_t","units":"C","conversion":0.01,"bits":null},{"name":"bus_voltage","type":"uint16_t","units":"V","conversion":0.001,"bits":null},{"name":"fault_code","type":"uint16_t","units":"","conversion":0,"bits":null}]},{"name":"lights_back_id","description":"Unique identification packet for back lights board","id":769,"endian":"","repeat":0,"offset":0,"data":[{"name":"board_id","type":"uint16_t","units":"","conversion":0,"bits":null},{"name":"mcu_temp","type":"int16_t","units":"C","conversion":0.01,"bits":null},{"name":"bus_voltage","type":"uint16_t","units":"V","conversion":0.001,"bits":null},{"name":"fault_code","type":"uint16_t","units":"","conversion":0,"bits":null}]},{"name":"vision_id","description":"Unique identification packet for vision","id":770,"endian":"","repeat":0,"offset":0,"data":[{"name":"board_id","type":"uint16_t","units":"","conversion":0,"bits":null},{"name":"mcu_temp","type":"int16_t","units":"C","conversion":0.01,"bits":null},{"name":"bus_voltage","type":"uint16_t","units":"V","conversion":0.001,"bits":null},{"name":"fault_code","type":"uint16_t","units":"","conversion":0,"bits":null}]},{"name":"steering_press_count_1","description":"Shows whether each button has been toggled an even (\"on\") or odd (\"off\") number of times.","id":576,"endian":"","repeat":0,"offset":0,"data":[{"name":"button0","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button1","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button2","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button3","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button4","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button5","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button6","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"steering_press_count_2","description":"Shows whether each button has been toggled an even (\"on\") or odd (\"off\") number of times.","id":592,"endian":"","repeat":0,"offset":0,"data":[{"name":"button7","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button8","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button9","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button10","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"steering_button_colors_1","description":"This packet controls each button's color. Each byte is a hex color code.","id":577,"endian":"","repeat":0,"offset":0,"data":[{"name":"button0","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button1","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button2","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button3","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button4","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button5","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button6","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"steering_button_colors_2","description":"This packet controls each button's color. Each byte is a hex color code.","id":593,"endian":"","repeat":0,"offset":0,"data":[{"name":"button7","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button8","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button9","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"button10","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"steering_horn","description":"This packet controls the state of the horn.","id":578,"endian":"","repeat":0,"offset":0,"data":[{"name":"horn","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"thunderstruck_status_message","description":"Status packet for thunderstruck chargers","id":418063424,"endian":"little","repeat":0,"offset":0,"data":[{"name":"STATUS_FLAGS","type":"uint8_t","units":"V","conversion":1,"bits":null},{"name":"CHARGE_FLAGS","type":"uint8_t","units":"V","conversion":1,"bits":null},{"name":"OUTPUT_VOLTAGE","type":"uint16_t","units":"V","conversion":1,"bits":null},{"name":"OUTPUT_CURRENT","type":"uint16_t","units":"V","conversion":1,"bits":null},{"name":"CHARGER_TEMP","type":"uint8_t","units":"V","conversion":1,"bits":null},{"name":"RESERVED","type":"uint8_t","units":"V","conversion":1,"bits":null}]},{"name":"tracker_data","description":"Tracker data. Each channel transmits on a specific ID, which should be specified along with the tracker, most likely 0x600-0x603.","id":1536,"endian":"little","repeat":6,"offset":1,"data":[{"name":"array_voltage","type":"uint16_t","units":"V","conversion":0.01,"bits":null},{"name":"array_current","type":"uint16_t","units":"A","conversion":0.001,"bits":null},{"name":"battery_voltage","type":"uint16_t","units":"V","conversion":0.01,"bits":null},{"name":"temperature","type":"uint16_t","units":"C","conversion":0.01,"bits":null}]},{"name":"tritium_motor_drive","description":"Tritium Motor Drive Command","id":289,"endian":"little","repeat":0,"offset":0,"data":[{"name":"motor_velocity","type":"float","units":"","conversion":0,"bits":null},{"name":"motor_current","type":"float","units":"","conversion":0,"bits":null}]},{"name":"tritium_motor_power","description":"Tritium Motor Power Command","id":290,"endian":"little","repeat":0,"offset":0,"data":[{"name":"reserved","type":"float","units":"","conversion":0,"bits":null},{"name":"bus_current","type":"float","units":"","conversion":0,"bits":null}]},{"name":"tritium_reset","description":"Tritium Reset Command","id":291,"endian":"little","repeat":0,"offset":0,"data":[{"name":"unused1","type":"float","units":"","conversion":0,"bits":null},{"name":"unused2","type":"float","units":"","conversion":0,"bits":null}]},{"name":"bms_ah_set","description":"write state of charge, use with caution","id":22,"endian":"little","repeat":0,"offset":0,"data":[{"name":"ah","type":"uint32_t","units":"","conversion":0.00001,"bits":null}]},{"name":"bms_wh_set","description":"write state of charge, use with caution","id":23,"endian":"little","repeat":0,"offset":0,"data":[{"name":"wh","type":"uint32_t","units":"","conversion":0.00001,"bits":null}]},{"name":"bms_kill","description":"packet to cause BMS kill","id":26,"endian":"little","repeat":0,"offset":0,"data":[{"name":"kill_type","type":"bitfield","units":"","conversion":0,"bits":[{"name":"KILL_HARD"}]}]},{"name":"telemetry_rtc_reset","description":"Reset telemetry's real-time clock (RTC).","id":1792,"endian":"","repeat":0,"offset":0,"data":[{"name":"year","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"month","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"day","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"hour","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"minute","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"second","type":"uint8_t","units":"","conversion":0,"bits":null}]},{"name":"wsr_identification","description":"WS RIGHT Identification Information","id":320,"endian":"little","repeat":0,"offset":0,"data":[{"name":"tritium_id","type":"uint32_t","units":"","conversion":0,"bits":null},{"name":"serial_number","type":"uint32_t","units":"","conversion":0,"bits":null}]},{"name":"wsr_status_information","description":"WS RIGHT Status Information","id":321,"endian":"little","repeat":0,"offset":0,"data":[{"name":"limit_flags","type":"bitfield","units":"","conversion":0,"bits":[{"name":"output_voltage_pwm"},{"name":"motor_current"},{"name":"velocity"},{"name":"bus_current"},{"name":"bus_voltage_upper_limit"},{"name":"bus_voltage_lower_limit"},{"name":"ipm_temperature_or_motor_temperature"},{"name":"reserved"}]},{"name":"limit_flags_reserved","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"error_flags_0","type":"bitfield","units":"","conversion":0,"bits":[{"name":"hardware_over_current"},{"name":"software_over_current"},{"name":"dc_bus_over_voltage"},{"name":"bad_motor_position_hall_sequence"},{"name":"watchdog_caused_last_reset"},{"name":"config_read_error"},{"name":"lv_rail_under_voltage_lock_out"},{"name":"desaturation_fault"}]},{"name":"error_flags_1","type":"bitfield","units":"","conversion":0,"bits":[{"name":"motor_over_speed"},{"name":"reserved_9"},{"name":"reserved_10"},{"name":"reserved_11"},{"name":"reserved_12"},{"name":"reserved_13"},{"name":"reserved_14"},{"name":"reserved_15"}]},{"name":"active_motor","type":"uint16_t","units":"","conversion":0,"bits":null},{"name":"reserved","type":"uint16_t","units":"","conversion":0,"bits":null}]},{"name":"wsr_bus_measurement","description":"WS RIGHT Bus Measurement","id":322,"endian":"little","repeat":0,"offset":0,"data":[{"name":"bus_voltage","type":"float","units":"V","conversion":0,"bits":null},{"name":"bus_current","type":"float","units":"A","conversion":0,"bits":null}]},{"name":"wsr_velocity","description":"WS RIGHT Velocity Measurement","id":323,"endian":"little","repeat":0,"offset":0,"data":[{"name":"motor_velocity","type":"float","units":"rpm","conversion":0,"bits":null},{"name":"vehicle_velocity","type":"float","units":"m/s","conversion":0,"bits":null}]},{"name":"wsr_phase_current","description":"WS RIGHT Phase Current Measurement","id":324,"endian":"little","repeat":0,"offset":0,"data":[{"name":"phase_b_current","type":"float","units":"A rms","conversion":0,"bits":null},{"name":"phase_c_current","type":"float","units":"A rms","conversion":0,"bits":null}]},{"name":"wsr_motor_voltage_vector","description":"WS RIGHT Motor Voltage Vector Measurement","id":325,"endian":"little","repeat":0,"offset":0,"data":[{"name":"vq","type":"float","units":"V","conversion":0,"bits":null},{"name":"vd","type":"float","units":"V","conversion":0,"bits":null}]},{"name":"wsr_motor_current_vector","description":"WS RIGHT Motor Current Vector Measurement","id":326,"endian":"little","repeat":0,"offset":0,"data":[{"name":"iq","type":"float","units":"A","conversion":0,"bits":null},{"name":"id","type":"float","units":"A","conversion":0,"bits":null}]},{"name":"wsr_motor_backemf","description":"WS RIGHT Motor BackEMF Measurement / Prediction","id":327,"endian":"little","repeat":0,"offset":0,"data":[{"name":"bemfq","type":"float","units":"V","conversion":0,"bits":null},{"name":"bemfd","type":"float","units":"V","conversion":0,"bits":null}]},{"name":"wsr_15_165_voltage_rail","description":"WS RIGHT 15 and 1.65 Voltage Rail Measurement","id":328,"endian":"little","repeat":0,"offset":0,"data":[{"name":"reference_165v","type":"float","units":"V","conversion":0,"bits":null},{"name":"supply_15v","type":"float","units":"V","conversion":0,"bits":null}]},{"name":"wsr_25_12_voltage_rail","description":"WS RIGHT 2.5V and 1.2V Voltage Rail Measurement","id":329,"endian":"little","repeat":0,"offset":0,"data":[{"name":"supply_12v","type":"float","units":"V","conversion":0,"bits":null},{"name":"supply_25v","type":"float","units":"V","conversion":0,"bits":null}]},{"name":"wsr_heatsink_motor_temp","description":"WS RIGHT Heat-sink \u0026 Motor Temperature Measurement","id":331,"endian":"little","repeat":0,"offset":0,"data":[{"name":"motor_temp","type":"float","units":"C","conversion":0,"bits":null},{"name":"heatsink_temp","type":"float","units":"C","conversion":0,"bits":null}]},{"name":"wsr_dsp_board_temp","description":"WS RIGHT DPS Board Temperature Measurement","id":332,"endian":"little","repeat":0,"offset":0,"data":[{"name":"dsp_board_temp","type":"float","units":"C","conversion":0,"bits":null},{"name":"reserved","type":"float","units":"C","conversion":0,"bits":null}]},{"name":"wsr_reserved","description":"WS RIGHT Reserved","id":333,"endian":"little","repeat":0,"offset":0,"data":[{"name":"reserved0","type":"float","units":"","conversion":0,"bits":null},{"name":"reserved1","type":"float","units":"","conversion":0,"bits":null}]},{"name":"wsr_odometer_bus_amphours_measurement","description":"WS RIGHT Odometer and Bus AmpHours Measurement","id":334,"endian":"little","repeat":0,"offset":0,"data":[{"name":"odometer","type":"float","units":"m","conversion":0,"bits":null},{"name":"dc_bus_amphours","type":"float","units":"Ah","conversion":0,"bits":null}]},{"name":"wsr_slip_speed_measurement","description":"WS RIGHT Slip Speed Measurement","id":343,"endian":"little","repeat":0,"offset":0,"data":[{"name":"reserved","type":"float","units":"C","conversion":0,"bits":null},{"name":"slip_speed","type":"float","units":"Hz","conversion":0,"bits":null}]},{"name":"wsl_identification","description":"WS LEFT Identification Information","id":256,"endian":"little","repeat":0,"offset":0,"data":[{"name":"tritium_id","type":"uint32_t","units":"","conversion":0,"bits":null},{"name":"serial_number","type":"uint32_t","units":"","conversion":0,"bits":null}]},{"name":"wsl_status_information","description":"WS LEFT Status Information","id":257,"endian":"little","repeat":0,"offset":0,"data":[{"name":"limit_flags","type":"bitfield","units":"","conversion":0,"bits":[{"name":"output_voltage_pwm"},{"name":"motor_current"},{"name":"velocity"},{"name":"bus_current"},{"name":"bus_voltage_upper_limit"},{"name":"bus_voltage_lower_limit"},{"name":"ipm_temperature_or_motor_temperature"},{"name":"reserved"}]},{"name":"limit_flags_reserved","type":"uint8_t","units":"","conversion":0,"bits":null},{"name":"error_flags_0","type":"bitfield","units":"","conversion":0,"bits":[{"name":"hardware_over_current"},{"name":"software_over_current"},{"name":"dc_bus_over_voltage"},{"name":"bad_motor_position_hall_sequence"},{"name":"watchdog_caused_last_reset"},{"name":"config_read_error"},{"name":"lv_rail_under_voltage_lock_out"},{"name":"desaturation_fault"}]},{"name":"error_flags_1","type":"bitfield","units":"","conversion":0,"bits":[{"name":"motor_over_speed"},{"name":"reserved_9"},{"name":"reserved_10"},{"name":"reserved_11"},{"name":"reserved_12"},{"name":"reserved_13"},{"name":"reserved_14"},{"name":"reserved_15"}]},{"name":"active_motor","type":"uint16_t","units":"","conversion":0,"bits":null},{"name":"reserved","type":"uint16_t","units":"","conversion":0,"bits":null}]},{"name":"wsl_bus_measurement","description":"WS LEFT Bus Measurement","id":258,"endian":"little","repeat":0,"offset":0,"data":[{"name":"bus_voltage","type":"float","units":"V","conversion":0,"bits":null},{"name":"bus_current","type":"float","units":"A","conversion":0,"bits":null}]},{"name":"wsl_velocity","description":"WS LEFT Velocity Measurement","id":259,"endian":"little","repeat":0,"offset":0,"data":[{"name":"motor_velocity","type":"float","units":"rpm","conversion":0,"bits":null},{"name":"vehicle_velocity","type":"float","units":"m/s","conversion":0,"bits":null}]},{"name":"wsl_phase_current","description":"WS LEFT Phase Current Measurement","id":260,"endian":"little","repeat":0,"offset":0,"data":[{"name":"phase_b_current","type":"float","units":"A rms","conversion":0,"bits":null},{"name":"phase_c_current","type":"float","units":"A rms","conversion":0,"bits":null}]},{"name":"wsl_motor_voltage_vector","description":"WS LEFT Motor Voltage Vector Measurement","id":261,"endian":"little","repeat":0,"offset":0,"data":[{"name":"vq","type":"float","units":"V","conversion":0,"bits":null},{"name":"vd","type":"float","units":"V","conversion":0,"bits":null}]},{"name":"wsl_motor_current_vector","description":"WS LEFT Motor Current Vector Measurement","id":262,"endian":"little","repeat":0,"offset":0,"data":[{"name":"iq","type":"float","units":"A","conversion":0,"bits":null},{"name":"id","type":"float","units":"A","conversion":0,"bits":null}]},{"name":"wsl_motor_backemf","description":"WS LEFT Motor BackEMF Measurement / Prediction","id":263,"endian":"little","repeat":0,"offset":0,"data":[{"name":"bemfq","type":"float","units":"V","conversion":0,"bits":null},{"name":"bemfd","type":"float","units":"V","conversion":0,"bits":null}]},{"name":"wsl_15_165_voltage_rail","description":"WS LEFT 15 and 1.65 Voltage Rail Measurement","id":264,"endian":"little","repeat":0,"offset":0,"data":[{"name":"reference_165v","type":"float","units":"V","conversion":0,"bits":null},{"name":"supply_15v","type":"float","units":"V","conversion":0,"bits":null}]},{"name":"wsl_25_12_voltage_rail","description":"WS LEFT 2.5V and 1.2V Voltage Rail Measurement","id":265,"endian":"little","repeat":0,"offset":0,"data":[{"name":"supply_12v","type":"float","units":"V","conversion":0,"bits":null},{"name":"supply_25v","type":"float","units":"V","conversion":0,"bits":null}]},{"name":"wsl_heatsink_motor_temp","description":"WS LEFT Heat-sink \u0026 Motor Temperature Measurement","id":267,"endian":"little","repeat":0,"offset":0,"data":[{"name":"motor_temp","type":"float","units":"C","conversion":0,"bits":null},{"name":"heatsink_temp","type":"float","units":"C","conversion":0,"bits":null}]},{"name":"wsl_dsp_board_temp","description":"WS LEFT DPS Board Temperature Measurement","id":268,"endian":"little","repeat":0,"offset":0,"data":[{"name":"dsp_board_temp","type":"float","units":"C","conversion":0,"bits":null},{"name":"reserved","type":"float","units":"C","conversion":0,"bits":null}]},{"name":"wsl_odometer_bus_amphours_measurement","description":"WS LEFT Odometer and Bus AmpHours Measurement","id":270,"endian":"little","repeat":0,"offset":0,"data":[{"name":"odometer","type":"float","units":"m","conversion":0,"bits":null},{"name":"dc_bus_amphours","type":"float","units":"Ah","conversion":0,"bits":null}]},{"name":"wsl_reserved","description":"WS LEFT Reserved","id":269,"endian":"little","repeat":0,"offset":0,"data":[{"name":"reserved0","type":"float","units":"","conversion":0,"bits":null},{"name":"reserved1","type":"float","units":"","conversion":0,"bits":null}]},{"name":"wsl_slip_speed_measurement","description":"WS LEFT Slip Speed Measurement","id":279,"endian":"little","repeat":0,"offset":0,"data":[{"name":"reserved","type":"float","units":"C","conversion":0,"bits":null},{"name":"slip_speed","type":"float","units":"Hz","conversion":0,"bits":null}]}],"boards":[{"name":"bms","transmit":["bms_measurement","bms_capacity","bms_charger_response","battery_status","bms_kill_reason","bms_module_min_max","bms_soc","bms_currentlimit","bms_fan_info","bms_module"],"receive":["bms_kill","bms_wh_set","bms_ah_set","bms_set_min_fan_speed","charger_bms_request"]},{"name":"charger","transmit":["charger_state","charger_bms_request","charger_power"],"receive":["bms_charger_response","battery_status","bms_module_min_max","bms_measurement","charger_current_voltage","bms_capacity"]},{"name":"flight_computer","transmit":["tracker_enable","vision_turn_signals_command","vision_brake_lights_command","vision_headlights_command","vision_horn_command","tritium_motor_drive","steering_button_colors_1","steering_button_colors_2","tritium_reset","dashboard_pedal_percentages","car_state","car_speed","dashboard_pedal_fault","flight_computer_hv_board_disconnect_counts","flight_computer_lv_board_disconnect_counts","flight_computer_internal_state","power_to_drive","array_power","distance_traveled"],"receive":["bms_module_min_max","charger_state","steering_press_count_1","steering_press_count_2","wsl_velocity","wsr_velocity","steering_horn","bms_kill_reason","bms_measurement","tracker_data","vision_status_front","vision_status_rear","wsl_odometer_bus_amphours_measurement","wsr_odometer_bus_amphours_measurement"]},{"name":"g4_example","transmit":["vision_status_front","vision_headlights_command","tracker_data","demo_packet"],"receive":["vision_turn_signals_command","vision_brake_lights_command","vision_headlights_command","vision_horn_command","demo_packet"]},{"name":"lights","transmit":["vision_status_front","vision_status_rear","lights_front_id","lights_back_id"],"receive":["vision_turn_signals_command","vision_brake_lights_command","vision_headlights_command","bms_kill_reason"]},{"name":"skylab2_demo","transmit":["vision_status_front","vision_headlights_command","tracker_data"],"receive":["vision_turn_signals_command","vision_brake_lights_command","vision_headlights_command","vision_horn_command"]},{"name":"steering","transmit":["steering_press_count_1","steering_press_count_2","steering_horn"],"receive":["steering_button_colors_1","steering_button_colors_2"]},{"name":"vision","transmit":["vision_status_front","vision_id"],"receive":["vision_turn_signals_command","vision_brake_lights_command","vision_headlights_command","vision_horn_command","vision_array_latches_command","vision_rearview_command"]}]}` \ No newline at end of file diff --git a/skylab/templates/golang.go.tmpl b/skylab/templates/golang.go.tmpl index f7b6756..1cb219c 100644 --- a/skylab/templates/golang.go.tmpl +++ b/skylab/templates/golang.go.tmpl @@ -165,3 +165,6 @@ func FromJson (id uint32, raw []byte) (Packet, error) { {{template "packet" .}} {{- end}} +// The json representation that was used to generate this data. +// can be used to share the parsing data for i.e dynamic python gui. +const SkylabDefinitions = `{{json . | printf "%s" }}` \ No newline at end of file