Skip to content

Commit

Permalink
bridge builds with services.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Comma Device committed Nov 20, 2019
1 parent 2b0cb60 commit f8e5327
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ __pycache__
.*.swo
libcereal*.a
libmessaging.a
services.h

6 changes: 6 additions & 0 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ env.Library('messaging', [
])

env.Program('messaging/bridge', ['messaging/bridge.cc'], LIBS=['messaging', 'yaml-cpp', 'zmq'])

env.Command(
['services.h'],
['service_list.yaml', 'services.py'],
'python3 cereal/services.py > $TARGET')

21 changes: 3 additions & 18 deletions messaging/bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
#include <csignal>
#include <map>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#include <yaml-cpp/yaml.h>
#pragma GCC diagnostic pop
#include "services.h"

#include "impl_msgq.hpp"
#include "impl_zmq.hpp"
Expand All @@ -18,27 +15,15 @@ void sigpipe_handler(int sig) {
}

static std::vector<std::string> get_services() {
char * base_dir_ptr = std::getenv("BASEDIR");

if (base_dir_ptr == NULL){
base_dir_ptr = std::getenv("PYTHONPATH");
}

assert(base_dir_ptr);
std::string base_dir = base_dir_ptr;
std::string service_list_path = base_dir + "/cereal/service_list.yaml";
YAML::Node service_list = YAML::LoadFile(service_list_path);

std::vector<std::string> name_list;

for (const auto& it : service_list) {
auto name = it.first.as<std::string>();
for (const auto& it : services) {
std::string name = it.name;
if (name == "plusFrame" || name == "uiLayoutState") continue;
name_list.push_back(name);
}

return name_list;

}


Expand Down
10 changes: 10 additions & 0 deletions services.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import os
import yaml

Expand All @@ -18,3 +19,12 @@ def __init__(self, port, should_log, frequency, decimation=None):
decimation = v[3]

service_list[k] = Service(v[0], v[1], v[2], decimation)

if __name__ == "__main__":
print("/* THIS IS AN AUTOGENERATED FILE, PLEASE EDIT service_list.yaml */")
print("struct service { int port; bool should_log; int frequency; int decimation; char name[0x100]; };")
print("struct service services[] = {")
for k, v in service_list.items():
print(' { .name = "%s", .port = %d, .should_log = %s, .frequency = %d, .decimation = %d },' % (k, v.port, "true" if v.should_log else "false", v.frequency, -1 if v.decimation is None else v.decimation))
print("};")

0 comments on commit f8e5327

Please sign in to comment.