Skip to content

Commit

Permalink
Put frontend on the car (#4)
Browse files Browse the repository at this point in the history
frontend finally here bby!
  • Loading branch information
BANANAPEEL202 authored Apr 27, 2024
1 parent b2c2c05 commit e9a4a15
Show file tree
Hide file tree
Showing 64 changed files with 47,417 additions and 228 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ result/
.env
.idea/
*.mat
*.log
*.log
.DS_Store
*.mat
py_data_acq/.DS_Store
*.DS_Store
.idea/
**/.idea/
py_data_acq/py_data_acq.egg-info/*
py_data_acq/py_data_acq.egg-info/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ usage notes:
by default, it uses a fixed version of the hytech CAN library and it must be manually updated. downstream usage of this can update this too via specifying it in the flake input as well if need be.
### for kevin's new frontend
1. in one devshell (call `nix develop`):
```npm run start --prefix $FRONT```
2. in a second devshell:
```runner.py```
### TODO:
- [x] write test script for creating a cantools constructed hytech CAN msg and sends it over a virtual CAN line
Expand Down
3 changes: 2 additions & 1 deletion dbc_proto_gen_script.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ python311Packages.buildPythonApplication {
version = "1.0.0";


propagatedBuildInputs = [ python311Packages.cantools python311Packages.protobuf python311Packages.requests ];
propagatedBuildInputs = [ (python311Packages.cantools.overridePythonAttrs (_: { doCheck = false; }))
python311Packages.protobuf python311Packages.requests ];

src = ./py_dbc_proto_gen;
}
13 changes: 10 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
, asyncudp_pkg
, hytech_np_proto_py
, proto_gen_pkg
, py_foxglove_protobuf_schemas
, vn_protos_np_proto_py
}:

python311Packages.buildPythonApplication {
pname = "py_data_acq";
version = "1.0.1";

propagatedBuildInputs = [
python311Packages.cantools
python311Packages.systemd

(python311Packages.cantools.overridePythonAttrs (_: { doCheck = false; }))
#python311Packages.cantools
#python311Packages.systemd #commented out cuz linux only
python311Packages.websockets
python311Packages.pprintpp
python311Packages.can
Expand All @@ -28,6 +30,11 @@ python311Packages.buildPythonApplication {
py_mcap_pkg
hytech_np_proto_py
proto_gen_pkg
py_foxglove_protobuf_schemas
vn_protos_np_proto_py
python311Packages.flask
python311Packages.flask-cors
python311Packages.hypercorn
];

src = ./py_data_acq;
Expand Down
36 changes: 36 additions & 0 deletions fix_mcaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
from mcap.writer import Writer
from mcap.reader import make_reader

def fix_mcap_file(input_file_path, output_file_path):
with open(input_file_path, "rb") as input_file:
reader = make_reader(input_file)

with open(output_file_path, "wb") as output_file:
writer = Writer(output_file)

# Iterate through all schemas and channels in the original file
for schema in reader.schemas.values():
writer.register_schema(schema.name, schema.encoding, schema.data)

for channel in reader.channels.values():
writer.register_channel(channel.id, channel.topic, channel.message_encoding, channel.schema_id)

# Reading and writing all messages
for message in reader.read_messages():
writer.add_message(
log_time=message.log_time,
publish_time=message.publish_time,
channel_id=message.channel_id,
data=message.data
)

print(f"Processed and copied messages to {output_file_path}")

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py <path_to_input_mcap>")
else:
input_file_path = sys.argv[1]
output_file_path = sys.argv[1] + "_fixed"
fix_mcap_file(input_file_path, output_file_path)
32 changes: 16 additions & 16 deletions flake.lock

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

74 changes: 55 additions & 19 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/40";
ht_can_pkg_flake.url = "github:hytech-racing/ht_can/41";
nix-proto = { url = "github:notalltim/nix-proto"; };
};

Expand All @@ -34,7 +34,9 @@
py_dbc_proto_gen_pkg = pkgs.py_dbc_proto_gen_pkg;
proto_gen_pkg = pkgs.proto_gen_pkg;
hytech_np = pkgs.hytech_np;
vn_protos_np = pkgs.vn_protos_np;
hytech_np_proto_py = pkgs.hytech_np_proto_py;
vn_protos_np_proto_py = pkgs.vn_protos_np_proto_py;
default = pkgs.py_data_acq_pkg;
};

Expand All @@ -47,30 +49,54 @@
proto_gen_overlay = final: prev: {
proto_gen_pkg = final.callPackage ./dbc_proto_bin_gen.nix { };
};
py_foxglove_protobuf_schemas_overlay = final: prev: {
py_foxglove_protobuf_schemas = final.callPackage ./py_foxglove_protobuf_schemas.nix { };
};

nix_protos_overlays = nix-proto.generateOverlays' {
hytech_np = { proto_gen_pkg }:
nix-proto.mkProtoDerivation {
name = "hytech_np";
buildInputs = [ proto_gen_pkg ];
src = proto_gen_pkg.out + "/proto";
version = "1.0.0";
};
frontend_overlay = final: prev: {
frontend_pkg = final.callPackage ./frontend.nix { };
};



nix_protos_overlays = nix-proto.generateOverlays'
{
hytech_np = { proto_gen_pkg }:
nix-proto.mkProtoDerivation {
name = "hytech_np";
buildInputs = [ proto_gen_pkg ];
src = proto_gen_pkg.out + "/proto";
version = "1.0.0";
};
vn_protos_np = { hytech_np }:
nix-proto.mkProtoDerivation {
name = "vn_protos_np";
src = nix-proto.lib.srcFromNamespace {
root = ./proto;
namespace = "vectornav_proto";
};
version = "1.0.0";
protoDeps = [ hytech_np ];
};
};
my_overlays = [
(self: super: {
cantools = super.cantools.overridePythonAttrs (old: rec {
version = "39.4.5";
src = old.fetchPypi {
pname = "cantools";
inherit version;
# hash = "sha256-JQn+rtpy/OA2deLszSKEuxyttqBzcAil50H+JDHUdCE=";
};
});
})
cantools = super.cantools.overridePythonAttrs (old: rec {
version = "39.4.5";
src = old.fetchPypi {
pname = "cantools";
inherit version;
# hash = "sha256-JQn+rtpy/OA2deLszSKEuxyttqBzcAil50H+JDHUdCE=";
};
});
})

py_dbc_proto_gen_overlay
py_data_acq_overlay
proto_gen_overlay
py_foxglove_protobuf_schemas_overlay

frontend_overlay
ht_can_pkg_flake.overlays.default
mcap-protobuf.overlays.default
mcap.overlays.default
Expand All @@ -80,6 +106,9 @@
pkgs = import nixpkgs {
overlays = my_overlays;
inherit system;
config = {
allowUnsupportedSystem = true;
};
};

shared_shell = pkgs.mkShell rec {
Expand All @@ -92,7 +121,9 @@
ht_can_pkg
cmake
can-utils
nodejs
python311Packages.scipy
frontend_pkg.frontend
];
# Setting up the environment variables you need during
# development.
Expand All @@ -102,9 +133,10 @@
path=${pkgs.proto_gen_pkg}
bin_path=$path"/bin"
dbc_path=${pkgs.ht_can_pkg}
frontend_path=${pkgs.frontend_pkg.frontend}
export BIN_PATH=$bin_path
export DBC_PATH=$dbc_path
export FRONT=$frontend_path
echo -e "PYTHONPATH=$PYTHONPATH\nBIN_PATH=$bin_path\nDBC_PATH=$dbc_path\n" > .env
export PS1="$(echo -e '\u${icon}') {\[$(tput sgr0)\]\[\033[38;5;228m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\]} (${name}) \\$ \[$(tput sgr0)\]"
'';
Expand All @@ -118,6 +150,7 @@
py_dbc_proto_gen_pkg
proto_gen_pkg
ht_can_pkg
frontend_pkg
protobuf
];
shellHook =
Expand All @@ -139,11 +172,14 @@
};

packages = rec {
frontend_pkg = pkgs.frontend_pkg.frontend;
default = pkgs.py_data_acq_pkg;
py_dbc_proto_gen_pkg = pkgs.py_data_acq_pkg;
proto_gen_pkg = pkgs.proto_gen_pkg;
hytech_np = pkgs.hytech_np;
vn_protos_np = pkgs.vn_protos_np;
hytech_np_proto_py = pkgs.hytech_np_proto_py;
vn_protos_np_proto_py = pkgs.vn_protos_np_proto_py;
};

});
Expand Down
45 changes: 45 additions & 0 deletions frontend.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{ pkgs, stdenv, system, callPackage, nodejs, nodePackages, writeShellScriptBin }:
let
# Import & invoke the generated files from node2nix
generated = callPackage ./frontend/nix { inherit pkgs system nodejs; };

# node2nix wrapper to update nix files on npm changes
node2nix = writeShellScriptBin "node2nix" ''
${nodePackages.node2nix}/bin/node2nix \
--development \
-l package-lock.json \
-c ./frontend/nix/default.nix \
-o ./frontend/nix/node-packages.nix \
-e ./frontend/nix/node-env.nix
'';

in
{
inherit (generated) nodeDependencies;
frontend = pkgs.stdenv.mkDerivation
{
name = "frontend";
version = "0.1.0";
src = ./frontend; #gitignore.lib.gitignoreSource ./.; # uses the gitignore in the repo to only copy files git would see
buildInputs = [ pkgs.nodejs ];
buildPhase = ''
export HOME=$TMP
ln -s ${generated.nodeDependencies}/lib/node_modules ./node_modules
export PATH="${generated.nodeDependencies}/bin:$PATH"
npm run build
'';
installPhase = ''
ls
mkdir -p $out/build
cp tailwind.config.js $out/
cp tsconfig.json $out/
cp -r public $out/
cp -r src $out/
cp -r build $out/
cp package.json $out/
ln -sf ${generated.nodeDependencies}/lib/node_modules $out/node_modules
'';
};
}
Loading

0 comments on commit e9a4a15

Please sign in to comment.