Skip to content

Commit

Permalink
doing some desktop testing
Browse files Browse the repository at this point in the history
  • Loading branch information
RCMast3r committed May 4, 2024
1 parent ec4b211 commit bff2a77
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 32 deletions.
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
mcap.url = "github:RCMast3r/py_mcap_nix";
foxglove-websocket.url = "github:RCMast3r/py_foxglove_webserver_nix";
asyncudp.url = "github:RCMast3r/asyncudp_nix";
ht_can_pkg_flake.url = "github:hytech-racing/ht_can/41";
ht_can_pkg_flake.url = "github:hytech-racing/ht_can/80";
nix-proto = { url = "github:notalltim/nix-proto"; };
};

Expand Down Expand Up @@ -60,7 +60,9 @@
frontend_pkg = final.callPackage ./frontend.nix { };
};


# mcap_cli_overlay = final: prev: {
# mcap_cli_pkg = final.callPackage ./mcap_cli.nix { };
# };

nix_protos_overlays = nix-proto.generateOverlays'
{
Expand Down Expand Up @@ -100,6 +102,7 @@
py_foxglove_protobuf_schemas_overlay
frontend_config_overlay
frontend_overlay
# mcap_cli_overlay
ht_can_pkg_flake.overlays.default
mcap-protobuf.overlays.default
mcap.overlays.default
Expand All @@ -119,6 +122,7 @@
packages = with pkgs; [
jq
py_data_acq_pkg
# mcap_cli_pkg
py_dbc_proto_gen_pkg
proto_gen_pkg
ht_can_pkg
Expand Down Expand Up @@ -178,6 +182,7 @@
};

packages = rec {
mcap_cli_pkg = pkgs.mcap_cli_pkg;
frontend_config_pkg = pkgs.frontend_config_pkg;
frontend_pkg = pkgs.frontend_pkg.frontend;
default = pkgs.py_data_acq_pkg;
Expand Down
21 changes: 21 additions & 0 deletions mcap_cli.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ lib, pkgs }:

pkgs.buildGoPackage rec {
pname = "mcap_cli";
version = "0.0.44";
goPackagePath = "github.com/foxglove/mcap";
src = pkgs.fetchFromGitHub {
owner = "foxglove";
repo = "mcap";
rev = "releases/mcap-cli/v${version}";
hash = "sha256-OAL2z28FhMXlyVzgmLCzHNCpCeK7hIkQB6jd7v3WHHA=";
};

meta = with lib; {
description = "mcap commandline interface";
homepage = "https://github.com/foxglove/mcap";
license = licenses.mit;
};

goDeps = ./mcap_go_deps.nix;
}
84 changes: 84 additions & 0 deletions mcap_go_deps.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[
# # goDeps is a list of Go dependencies.
{
# goPackagePath specifies Go package import path.
goPackagePath = "github.com/spf13/cobra";
fetch = {
# `fetch type` that needs to be used to get package source.
# If `git` is used there should be `url`, `rev` and `hash` defined next to it.
type = "git";
url = "https://github.com/spf13/cobra";
rev = "5a1acea3210649f3d70002818ec04b09f6347062";
sha256= "sha256-i0y1wnj7gfKlsU9cC9Bhj7v6lZBph4Ooa3fcWR4s6YE=";
};
}
{
# goPackagePath specifies Go package import path.
goPackagePath = "github.com/spf13/pflag";
fetch = {
# `fetch type` that needs to be used to get package source.
# If `git` is used there should be `url`, `rev` and `hash` defined next to it.
type = "git";
url = "https://github.com/spf13/pflag";
rev = "d5e0c0615acee7028e1e2740a11102313be88de1";
sha256= "sha256-g5g7TLXxTNlFA48alv5SKUW+YvoLJyV87Bu+Wn3YvC0=";
};
}
{
# goPackagePath specifies Go package import path.
goPackagePath = "github.com/spf13/viper";
fetch = {
# `fetch type` that needs to be used to get package source.
# If `git` is used there should be `url`, `rev` and `hash` defined next to it.
type = "git";
url = "https://github.com/spf13/viper";
rev = "v1.18.2";
sha256= "sha256-MXYbK6w1LEaoZ2/L/STF3WU1tbK+7NwGVxUCLKPkwks=";
};
}
# {
# goPackagePath = "google.golang.org/protobuf/encoding/protojson";
# fetch = {
# type = "git";
# url = "https://google.golang.org/protobuf/encoding/protojson";
# rev = "784ddc588536785e7299f7272f39101f7faccc3f";
# hash = "sha256-Uo89zjE+v3R7zzOq/gbQOHj3SMYt2W1nDHS7RCUin3M=";
# };
# }
# {
# goPackagePath = "google.golang.org/protobuf/reflect/protodesc";
# fetch = {
# type = "git";
# url = "https://google.golang.org/protobuf/reflect/protodesc";
# rev = "784ddc588536785e7299f7272f39101f7faccc3f";
# hash = "sha256-Uo89zjE+v3R7zzOq/gbQOHj3SMYt2W1nDHS7RCUin3M=";
# };
# }
# {
# goPackagePath = "google.golang.org/protobuf/reflect/protoreflect";
# fetch = {
# type = "git";
# url = "https://google.golang.org/protobuf/reflect/protoreflect";
# rev = "784ddc588536785e7299f7272f39101f7faccc3f";
# hash = "sha256-Uo89zjE+v3R7zzOq/gbQOHj3SMYt2W1nDHS7RCUin3M=";
# };
# }
# {
# goPackagePath = "google.golang.org/protobuf/types/descriptorpb";
# fetch = {
# type = "git";
# url = "https://google.golang.org/protobuf/types/descriptorpb";
# rev = "784ddc588536785e7299f7272f39101f7faccc3f";
# hash = "sha256-Uo89zjE+v3R7zzOq/gbQOHj3SMYt2W1nDHS7RCUin3M=";
# };
# }
# {
# goPackagePath = "google.golang.org/protobuf/types/dynamicpb";
# fetch = {
# type = "git";
# url = "https://google.golang.org/protobuf/types/dynamicpb";
# rev = "784ddc588536785e7299f7272f39101f7faccc3f";
# hash = "sha256-Uo89zjE+v3R7zzOq/gbQOHj3SMYt2W1nDHS7RCUin3M=";
# };
# }
]
29 changes: 11 additions & 18 deletions py_data_acq/broadcast-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import socket
import time
import can
from py_data_acq.common import protobuf_helpers
from can.interfaces.udp_multicast import UdpMulticastBus
import cantools
from pprint import pprint
import os

import os, sys
from mcap_protobuf.reader import read_protobuf_messages
from hytech_np_proto_py import hytech_pb2

# Define the IP and port for the UDP socket
Expand All @@ -17,26 +18,18 @@ def main():
full_path = os.path.join(path_to_dbc, "hytech.dbc")
# Serialize the message to bytes
db = cantools.database.load_file(full_path)

msg = db.get_message_by_name("MC1_TORQUE_COMMAND")
rpm = db.get_message_by_name("MC4_SETPOINTS_COMMAND")
data = msg.encode({'torque_command': 100})

msg = can.Message(arbitration_id=msg.frame_id, is_extended_id=False, data=data)

rpm_set = 100
while(1):
try:
rpm_set= rpm_set+1
bus1.send(msg)
rpm_data = rpm.encode({'negative_torque_limit': 1, 'positive_torque_limit': 1, 'speed_setpoint_rpm': rpm_set, 'remove_error': 1, 'driver_enable': 1, 'hv_enable': 1, 'inverter_enable': 1})
rpm_msg = can.Message(arbitration_id=rpm.frame_id, is_extended_id=False, data=rpm_data)
bus1.send(rpm_msg)

print("Message sent on {}".format(bus1.channel_info))
for msg in read_protobuf_messages(sys.argv[1], log_time_order=True):
# print(f"{msg.topic}: {msg.proto_msg}")
# print(msg.topic[:-5])
can_msg, can_msg_data = protobuf_helpers.pack_cantools_msg(msg.proto_msg, msg.topic[:-5], db)
msg_out = can.Message(arbitration_id=can_msg.frame_id, is_extended_id=False, data=can_msg_data)
bus1.send(msg_out)
# time.sleep(0.00001)
# print("Message sent on {}".format(bus1.channel_info))
except can.CanError:
print("Message NOT sent! Please verify can0 is working first")
time.sleep(0.1)

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions py_data_acq/py_data_acq/can_interface/can_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async def continuous_can_receiver(can_msg_decoder: cantools.db.Database, message
await queue.put(data)
await q2.put(data)
except Exception as e:
print("uh")
pass

# Don't forget to stop the notifier to clean up resources.
Expand Down
18 changes: 13 additions & 5 deletions py_data_acq/py_data_acq/common/protobuf_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def pack_protobuf_msg(cantools_dict: dict, msg_name: str, message_classes):
pb_msg = message_classes[msg_name]()
for key in cantools_dict.keys():
if(type(cantools_dict[key]) is namedsignalvalue.NamedSignalValue):
print(msg_name)
# print(msg_name)
setattr(pb_msg, key, str(cantools_dict[key].value))
else:
setattr(pb_msg, key, cantools_dict[key])
Expand All @@ -43,10 +43,18 @@ def pack_cantools_msg(pb_msg_in, msg_name: str, cantools_db):

# 2. populate dict with values
msg_dict = {}
for sig in msg_sigs:
print(sig)
msg_dict[sig.name] = getattr(pb_msg_in, sig.name)

# print("message signals: ", msg_sigs)

for sig in msg_sigs:
# print("sig name ", sig.name)
# print(dir(pb_msg_in))
if(sig.choices is not None):
msg_dict[sig.name] = int(getattr(pb_msg_in, sig.name))
else:
# print(dir(pb_msg_in))
# print(getattr(pb_msg_in, sig.name))
msg_dict[sig.name] = getattr(pb_msg_in, sig.name)
# print(msg_out)

out_data = msg_out.encode(msg_dict)
return msg_out, out_data
4 changes: 2 additions & 2 deletions py_data_acq/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ async def run(logger):
# and schema in the foxglove websocket server.

# await asyncio.gather(receiver_task, fx_task, mcap_task, srv_task, vn_receiver_task)
await asyncio.gather(receiver_task, fx_task, mcap_task, srv_task)
# await asyncio.gather(srv_task, mcap_task, receiver_task)
# await asyncio.gather(receiver_task)
await asyncio.gather(srv_task, mcap_task, receiver_task)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion test_mcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mcap_protobuf.reader import read_protobuf_messages

def main():
for msg in read_protobuf_messages(sys.argv[1], log_time_order=False):
for msg in read_protobuf_messages(sys.argv[1], log_time_order=True):
print(f"{msg.topic}: {msg.proto_msg}")

if __name__ == "__main__":
Expand Down

0 comments on commit bff2a77

Please sign in to comment.