Skip to content

Commit

Permalink
Merge branch 'sy-1342-console-support-for-labjack-integration' of htt…
Browse files Browse the repository at this point in the history
…ps://github.com/synnaxlabs/synnax into sy-1342-console-support-for-labjack-integration
  • Loading branch information
pjdotson committed Nov 3, 2024
2 parents 25dd8af + 999490d commit 9546a81
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 72 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/deploy.console.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [macos-12, windows-latest]
platform: [macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: MacOS - Import Apple Developer Certificate
# Only notarize on MacOS and on push events, not on PRs. This prevents excessive
# notarization requests and long CI times on PRs.
if: matrix.platform == 'macos-12' && github.event_name == 'push'
if: matrix.platform == 'macos-latest' && github.event_name == 'push'
env:
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
Expand All @@ -124,7 +124,7 @@ jobs:
- name: MacOS - Verify Certificate
# Same as above - only notarize on MacOS and on push events, not on PRs
if: matrix.platform == 'macos-12' && github.event_name == 'push'
if: matrix.platform == 'macos-latest' && github.event_name == 'push'
run: |
CERT_INFO=$(security find-identity -v -p codesigning build.keychain | grep "Developer ID Application")
echo "Cert info"
Expand Down Expand Up @@ -199,7 +199,7 @@ jobs:
run: pnpm build

- name: Upload MacOS Release Asset
if: github.event_name == 'push' && matrix.platform == 'macos-12'
if: github.event_name == 'push' && matrix.platform == 'macos-latest'
run: |
gh release upload --clobber console-v${{ needs.setup.outputs.VERSION }} ./console/src-tauri/target/release/bundle/macos/Synnax.app.tar.gz
gh release upload --clobber console-v${{ needs.setup.outputs.VERSION }} ./console/src-tauri/target/release/bundle/macos/Synnax.app.tar.gz.sig
Expand Down
34 changes: 15 additions & 19 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
# /////////////////////////////////////////////////////////////////////////////////////

http_archive(
name = "com_github_gflags_gflags",
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
strip_prefix = "gflags-2.2.2",
urls = ["https://github.com/gflags/gflags/archive/v2.2.2.tar.gz"],
name = "com_github_gflags_gflags",
sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf",
strip_prefix = "gflags-2.2.2",
urls = ["https://github.com/gflags/gflags/archive/v2.2.2.tar.gz"],
)

# git_repository(
Expand All @@ -24,12 +24,11 @@ http_archive(
# tag = "v0.6.0"
# )


http_archive(
name = "com_github_google_glog",
sha256 = "122fb6b712808ef43fbf80f75c52a21c9760683dae470154f02bddfc61135022",
strip_prefix = "glog-0.6.0",
urls = ["https://github.com/google/glog/archive/v0.6.0.zip"],
name = "com_github_google_glog",
sha256 = "122fb6b712808ef43fbf80f75c52a21c9760683dae470154f02bddfc61135022",
strip_prefix = "glog-0.6.0",
urls = ["https://github.com/google/glog/archive/v0.6.0.zip"],
)

# /////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -67,7 +66,6 @@ http_archive(

# |||||||| END OF MACOS SECTION ||||||||


http_archive(
name = "rules_proto_grpc",
sha256 = "9ba7299c5eb6ec45b6b9a0ceb9916d0ab96789ac8218269322f0124c0c0d24e2",
Expand Down Expand Up @@ -99,16 +97,14 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")

grpc_extra_deps()



# /////////////////////////////////////////////////////////////////////////////////////
# /////////////////////////////////////// NLOHMANN JSON ///////////////////////////////
# /////////////////////////////////////////////////////////////////////////////////////

git_repository(
name = "nlohmann_json",
commit = "9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03",
remote = "https://github.com/nlohmann/json",
commit = "9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03"
)

# /////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -139,14 +135,14 @@ new_local_repository(

git_repository(
name = "nidaqmx",
commit = "e85c66553cd9d0e1b07380a409729adfc71d3d98",
remote = "https://github.com/synnaxlabs/vendor-libraries",
commit = "e85c66553cd9d0e1b07380a409729adfc71d3d98"
)

git_repository(
name = "nisyscfg",
commit = "e85c66553cd9d0e1b07380a409729adfc71d3d98",
remote = "https://github.com/synnaxlabs/vendor-libraries",
commit = "e85c66553cd9d0e1b07380a409729adfc71d3d98"
)

# /////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -155,8 +151,8 @@ git_repository(

new_local_repository(
name = "open62541",
build_file = "@//driver/vendor/open62541:BUILD.bazel",
path = "./driver/vendor/open62541/open62541/out",
build_file="@//driver/vendor/open62541:BUILD.bazel"
)

# /////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -165,20 +161,20 @@ new_local_repository(

new_local_repository(
name = "mbedtls_win",
build_file = "@//driver/vendor/mbedtls:BUILD.bazel",
path = "./driver/vendor/mbedtls/mbedtls-install",
build_file="@//driver/vendor/mbedtls:BUILD.bazel"
)

new_local_repository(
name = "mbedtls_macos",
build_file = "@//driver/vendor/mbedtls:BUILD.bazel",
path = "/opt/homebrew/Cellar/mbedtls/3.6.2",
build_file="@//driver/vendor/mbedtls:BUILD.bazel"
)

new_local_repository(
name = "mbedtls_linux",
build_file = "@//driver/vendor/mbedtls:BUILD.bazel",
path = "/usr/lib/x86_64-linux-gnu/",
build_file="@//driver/vendor/mbedtls:BUILD.bazel"
)

# /////////////////////////////////////////////////////////////////////////////////////
Expand Down
31 changes: 14 additions & 17 deletions driver/labjack/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ namespace labjack{
if(!parser.ok())
LOG(ERROR) << "Failed to parse reader channel config: " << parser.error_json().dump(4);

LOG(INFO) << "Parser config: " << parser.get_json().dump(4); // TODO: remove

parser.iter("channels", [this](config::Parser &channel_parser) {

auto channel = labjack::ReaderChannelConfig(channel_parser);
Expand All @@ -242,7 +240,6 @@ namespace labjack{

this->channel_map[channel.location] = channel.key;
});
LOG(INFO) << "Size of tc_channels: " << tc_channels.size();
}
};

Expand All @@ -258,7 +255,7 @@ class ReaderSource : public pipeline::Source{
) : ctx(ctx),
task(task),
reader_config(reader_config) {
// TODO: default construct breaker?

auto breaker_config = breaker::Config{
.name = task.name,
.base_interval = 1 * SECOND,
Expand All @@ -277,38 +274,38 @@ class ReaderSource : public pipeline::Source{

std::pair<Frame, freighter::Error> read(breaker::Breaker &breaker);

std::pair<Frame, freighter::Error> read_stream(breaker::Breaker &breaker);
freighter::Error stop(const std::string &cmd_key);

std::pair<Frame, freighter::Error> read_cmd_response(breaker::Breaker &breaker);
freighter::Error start(const std::string &cmd_key);

void init();
void stop();

freighter::Error stop(const std::string &cmd_key);
bool ok();

freighter::Error start(const std::string &cmd_key);
private:

void init();

void init_stream();

void init_tcs();

void acquire_data();
void configure_tc_ain_ef(TCConfig tc_config);

int check_err(int err, std::string caller);

void write_to_series(
synnax::Series &series,
double &data,
synnax::DataType data_type
);

void stop();
);

int check_err(int err, std::string caller);
void acquire_data();

void configure_tc_ain_ef(TCConfig tc_config);
std::pair<Frame, freighter::Error> read_stream(breaker::Breaker &breaker);

bool ok();
std::pair<Frame, freighter::Error> read_cmd_response(breaker::Breaker &breaker);

private:
int handle;
ReaderConfig reader_config;
std::shared_ptr<task::Context> ctx;
Expand Down
26 changes: 6 additions & 20 deletions driver/labjack/reader_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void labjack::ReaderSource::stopped_with_err(const freighter::Error &err) {
});
}

// TODO: seperate some of the stuff happening here into a separate function
std::vector<synnax::ChannelKey> labjack::ReaderSource::get_channel_keys() {
std::vector<synnax::ChannelKey> keys;
for (auto &channel : this->reader_config.channels) {
Expand Down Expand Up @@ -131,7 +130,7 @@ void labjack::ReaderSource::init_tcs(){

int msDelay = 1000;
auto err = LJM_StartInterval(
this->handle, // TODO: need to keep unique to device will need to change once i want to define multiple intervals to read data at on a songel device
this->handle,
msDelay * 1000
);

Expand Down Expand Up @@ -180,11 +179,7 @@ void labjack::ReaderSource::init_stream(){
}
}
}
// TODO: figure out if i need to set this
// auto err = LJM_StartInterval(
// this->handle,
// this->reader_config.sample_rate.period().microseconds()
// );

this->port_addresses.resize(this->reader_config.phys_channels.size());

std::vector<const char*> phys_channel_names;
Expand Down Expand Up @@ -217,7 +212,6 @@ freighter::Error labjack::ReaderSource::start(const std::string &cmd_key){
{"message", "Task started successfully"}
}
});
LOG(INFO) << "[labjack.reader] labjack device started successfully";
return freighter::NIL;
};

Expand All @@ -227,7 +221,6 @@ freighter::Error labjack::ReaderSource::stop(const std::string &cmd_key) {

if(this->sample_thread.joinable()) this->sample_thread.join();
check_err(LJM_eStreamStop(handle), "stop.LJM_eStreamStop");

ctx->setState({
.task = task.key,
.key = cmd_key,
Expand All @@ -237,7 +230,6 @@ freighter::Error labjack::ReaderSource::stop(const std::string &cmd_key) {
{"message", "Task stopped successfully"}
}
});
LOG(INFO) << "[labjack.reader] labjack device stopped successfully";
return freighter::NIL;
}

Expand All @@ -262,26 +254,20 @@ std::pair<Frame, freighter::Error> labjack::ReaderSource::read_cmd_response(brea
"read.LJM_eReadNames"
);

// print out the values
// for(int i = 0; i < tc_locations.size(); i++){
// LOG(INFO) << "[labjack.reader] " << tc_locations[i] << ": " << values[i];
// }
//

auto f = synnax::Frame(locations.size() + this->reader_config.index_keys.size());
int index = 0;
for(const auto &loc : locations){
for(const auto &channel : this->reader_config.tc_channels){ // TODO don't need this inner for loop
for(const auto &channel : this->reader_config.tc_channels){
if(channel.location == loc){
auto key = this->reader_config.channel_map[channel.location]; // if we have this map, we don't need the inner for loop
auto key = this->reader_config.channel_map[channel.location];
auto s = synnax::Series(channel.data_type,1);
write_to_series(s, values[index], channel.data_type);
f.add(key, std::move(s));
}
}
for(const auto &channel : this->reader_config.channels){ // TODO don't need this inner for loop
for(const auto &channel : this->reader_config.channels){
if(channel.location == loc){
auto key = this->reader_config.channel_map[channel.location]; // if we have this map, we don't need the inner for loop
auto key = this->reader_config.channel_map[channel.location];
auto s = synnax::Series(channel.data_type,1);
write_to_series(s, values[index], channel.data_type);
f.add(key, std::move(s));
Expand Down
2 changes: 0 additions & 2 deletions driver/labjack/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ void labjack::ScannerTask::scan() {
device_keys.insert(device["key"].get<int>());
}
}

// LOG(INFO) << "devices json: " << devices.dump(4); // TODO: remove once labjack dev is done
}

void labjack::ScannerTask::create_devices() {
Expand Down
4 changes: 0 additions & 4 deletions driver/labjack/test_labjack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,6 @@ int tc() {
WaitForUserIfWindows();
return LJME_NOERROR;
}




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
Expand Down
6 changes: 3 additions & 3 deletions driver/labjack/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class StateSource final : public pipeline::Source {
std::mutex state_mutex;
std::condition_variable waiting_reader;
synnax::Rate state_rate = synnax::Rate(1);
std::map<synnax::ChannelKey, labjack::out_state> state_map; // alll values are
std::map<synnax::ChannelKey, labjack::out_state> state_map;
synnax::ChannelKey state_index_key;
loop::Timer timer;
}; // class StateSource
Expand All @@ -76,7 +76,7 @@ struct WriterChannelConfig{
std::string location;
bool enabled = true;
synnax::DataType data_type;
uint32_t cmd_key; // TODO: change channel type to synanx::channelKEY or whatever it is
uint32_t cmd_key;
uint32_t state_key;
std::string channel_type = "";

Expand All @@ -87,7 +87,7 @@ struct WriterChannelConfig{
data_type(parser.optional<std::string>("data_type", "uint8")),
cmd_key(parser.required<uint32_t>("cmd_key")),
state_key(parser.required<uint32_t>("state_key")),
channel_type(parser.optional<std::string>("channel_type", "")), // TODO: change this
channel_type(parser.optional<std::string>("channel_type", "")),
location(parser.optional<std::string>("port", "")){
if(!parser.ok())
LOG(ERROR) << "Failed to parse writer channel config: " << parser.error_json().dump(4);
Expand Down
4 changes: 2 additions & 2 deletions driver/labjack/writer_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ freighter::Error labjack::WriteSink::start(const std::string &cmd_key){
return freighter::NIL;
}

std::vector<synnax::ChannelKey> labjack::WriteSink::get_cmd_channel_keys(){ // TODO: rename to get_cmd_keys
std::vector<synnax::ChannelKey> labjack::WriteSink::get_cmd_channel_keys(){
std::vector<synnax::ChannelKey> keys;
for (auto &channel: this->writer_config.channels){
if(channel.enabled) keys.push_back(channel.cmd_key);
Expand All @@ -210,7 +210,7 @@ std::vector<synnax::ChannelKey> labjack::WriteSink::get_cmd_channel_keys(){ // T
return keys;
}

std::vector<synnax::ChannelKey> labjack::WriteSink::get_state_channel_keys(){ // TODO: rename to get_state_keys
std::vector<synnax::ChannelKey> labjack::WriteSink::get_state_channel_keys(){
std::vector<synnax::ChannelKey> keys;
for(auto &channel: this->writer_config.channels){
if(channel.enabled) keys.push_back(channel.state_key);
Expand Down
1 change: 0 additions & 1 deletion driver/labjack/writer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ using json = nlohmann::json;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Basic Tests //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

TEST(write_tests, labjack_t4){

LOG(INFO) << "Test labjack writes t4";
Expand Down
2 changes: 2 additions & 0 deletions driver/pipeline/middleware.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ namespace pipeline {
auto it = this->last_raw_value.find(key);
if(it != last_raw_value.end()){
tare_values[key] = it->second;
} else {
LOG(ERROR) << "[driver] Channel " << key << "is not a configured channel to tare.";
}
}
}
Expand Down

0 comments on commit 9546a81

Please sign in to comment.