Skip to content

Commit

Permalink
[driver/labjack] checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Lham42 committed Oct 21, 2024
1 parent 6945d78 commit d97e3ca
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 118 deletions.
2 changes: 1 addition & 1 deletion driver/labjack/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,4 @@ void labjack::Source::acquire_data(){
data_queue.enqueue(data_packet);
}
auto err = LJM_eStreamStop(handle);
}
}
217 changes: 101 additions & 116 deletions driver/labjack/reader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,123 +24,108 @@ using json = nlohmann::json;
// Basic Tests //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//TEST(read_tests, labjack_t4){
// auto client = std::make_shared<synnax::Synnax>(new_test_client());
//
// auto [time, tErr] = client->channels.create("idx", synnax::TIMESTAMP, 0, true);
// ASSERT_FALSE(tErr) << tErr.message();
//
// auto [data, dErr] = client->channels.create("ai", synnax::FLOAT32, time.key, false);
// ASSERT_FALSE(dErr) << dErr.message();
//
// auto config = json{
// {"sample_rate", 10000},
// {"stream_rate", 30},
// {"device_type", "T4"},
// {"device_key", "440022190"},
// {"serial_number", "440022190"},
// {"connection_type", "USB"},
// {"data_saving", true},
// {"channels", json::array({
// {
// {"location", "AIN0"},
// {"enabled", true},
// {"data_type", "float32"},
// {"channel_key", data.key},
// {"range", 10.0},
// {"channel_types", "AIN"}
// }//,
//// {
//// {"location", "AIN1"},
//// {"enabled", true},
//// {"data_type", "float32"},
//// {"channel_key", data.key},
//// {"range", 10.0},
//// {"channel_types", "AIN"}
//// }//,
//// {
//// {"location", "FIO4"},
//// {"enabled", true},
//// {"data_type", "uint8"},
//// {"channel_key", data.key},
//// {"channel_types", "DIN"}
//// }
// })},
// {"index_keys", json::array({time.key})},
// {"channel_map", {
// {"AIN0", data.key}
// }}
// };
//
// auto task = synnax::Task("my_task", "labjack_read", to_string(config));
// auto mockCtx = std::make_shared<task::MockContext>(client);
//
// auto reader_task = labjack::ReaderTask::configure(mockCtx, task);
// // create commands
// auto start_cmd = task::Command{task.key, "start", {}};
// auto stop_cmd = task::Command{task.key, "stop", {}};
// reader_task->exec(start_cmd);
// std::this_thread::sleep_for(std::chrono::seconds(30000));
//// std::this_thread::sleep_for(std::chrono::seconds(2));
// reader_task->exec(stop_cmd);
//
//}
TEST(read_tests, labjack_t4){
auto client = std::make_shared<synnax::Synnax>(new_test_client());

//TEST(read_tests, labjack_t4_multi_ain){
// auto client = std::make_shared<synnax::Synnax>(new_test_client());
//
// auto [time, tErr] = client->channels.create("idx", synnax::TIMESTAMP, 0, true);
// ASSERT_FALSE(tErr) << tErr.message();
//
// auto [data1, dErr1] = client->channels.create("ai_1", synnax::FLOAT32, time.key, false);
// ASSERT_FALSE(dErr1) << dErr1.message();
//
// auto [data2, dErr2] = client->channels.create("ai_2", synnax::FLOAT32, time.key, false);
// ASSERT_FALSE(dErr2) << dErr2.message();
//
//
// auto config = json{
// {"sample_rate", 10000},
// {"stream_rate", 30},
// {"device_type", "T4"},
// {"device_key", "440022190"},
// {"serial_number", "440022190"},
// {"connection_type", "USB"},
// {"data_saving", true},
// {"channels", json::array({
// {
// {"location", "AIN0"},
// {"enabled", true},
// {"data_type", "float32"},
// {"channel_key", data1.key},
// {"range", 10.0},
// {"channel_types", "AIN"}
// },
// {
// {"location", "AIN1"},
// {"enabled", true},
// {"data_type", "float32"},
// {"channel_key", data2.key},
// {"range", 10.0},
// {"channel_types", "AIN"}
// }
// })},
// {"index_keys", json::array({time.key})},
// };
//
// auto task = synnax::Task("my_task", "labjack_read", to_string(config));
// auto mockCtx = std::make_shared<task::MockContext>(client);
//
// auto reader_task = labjack::ReaderTask::configure(mockCtx, task);
// // create commands
// auto start_cmd = task::Command{task.key, "start", {}};
// auto stop_cmd = task::Command{task.key, "stop", {}};
// reader_task->exec(start_cmd);
// std::this_thread::sleep_for(std::chrono::seconds(30000));
// // std::this_thread::sleep_for(std::chrono::seconds(2));
// reader_task->exec(stop_cmd);
//
//}
auto [time, tErr] = client->channels.create("idx", synnax::TIMESTAMP, 0, true);
ASSERT_FALSE(tErr) << tErr.message();

auto [data, dErr] = client->channels.create("ai", synnax::FLOAT32, time.key, false);
ASSERT_FALSE(dErr) << dErr.message();

auto config = json{
{"sample_rate", 10000},
{"stream_rate", 30},
{"device_type", "T4"},
{"device_key", "440022190"},
{"serial_number", "440022190"},
{"connection_type", "USB"},
{"data_saving", true},
{"channels", json::array({
{
{"location", "AIN0"},
{"enabled", true},
{"data_type", "float32"},
{"channel_key", data.key},
{"range", 10.0},
{"channel_types", "AIN"}
}
})},
{"index_keys", json::array({time.key})},
{"channel_map", {
{"AIN0", data.key}
}}
};

auto task = synnax::Task("my_task", "labjack_read", to_string(config));
auto mockCtx = std::make_shared<task::MockContext>(client);

auto reader_task = labjack::ReaderTask::configure(mockCtx, task);
// create commands
auto start_cmd = task::Command{task.key, "start", {}};
auto stop_cmd = task::Command{task.key, "stop", {}};
reader_task->exec(start_cmd);
std::this_thread::sleep_for(std::chrono::seconds(30000));
// std::this_thread::sleep_for(std::chrono::seconds(2));
reader_task->exec(stop_cmd);

}

TEST(read_tests, labjack_t4_multi_ain){
auto client = std::make_shared<synnax::Synnax>(new_test_client());

auto [time, tErr] = client->channels.create("idx", synnax::TIMESTAMP, 0, true);
ASSERT_FALSE(tErr) << tErr.message();

auto [data1, dErr1] = client->channels.create("ai_1", synnax::FLOAT32, time.key, false);
ASSERT_FALSE(dErr1) << dErr1.message();

auto [data2, dErr2] = client->channels.create("ai_2", synnax::FLOAT32, time.key, false);
ASSERT_FALSE(dErr2) << dErr2.message();


auto config = json{
{"sample_rate", 10000},
{"stream_rate", 30},
{"device_type", "T4"},
{"device_key", "440022190"},
{"serial_number", "440022190"},
{"connection_type", "USB"},
{"data_saving", true},
{"channels", json::array({
{
{"location", "AIN0"},
{"enabled", true},
{"data_type", "float32"},
{"channel_key", data1.key},
{"range", 10.0},
{"channel_types", "AIN"}
},
{
{"location", "AIN1"},
{"enabled", true},
{"data_type", "float32"},
{"channel_key", data2.key},
{"range", 10.0},
{"channel_types", "AIN"}
}
})},
{"index_keys", json::array({time.key})},
};

auto task = synnax::Task("my_task", "labjack_read", to_string(config));
auto mockCtx = std::make_shared<task::MockContext>(client);

auto reader_task = labjack::ReaderTask::configure(mockCtx, task);
// create commands
auto start_cmd = task::Command{task.key, "start", {}};
auto stop_cmd = task::Command{task.key, "stop", {}};
reader_task->exec(start_cmd);
std::this_thread::sleep_for(std::chrono::seconds(30000));
// std::this_thread::sleep_for(std::chrono::seconds(2));
reader_task->exec(stop_cmd);

}

TEST(read_tests, labjack_t4_ai_fio){
auto client = std::make_shared<synnax::Synnax>(new_test_client());
Expand Down
31 changes: 30 additions & 1 deletion driver/labjack/writer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,33 @@ using json = nlohmann::json;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Basic Tests //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

TEST(write_tests, labjack_t4){

LOG(INFO) << "Test labjack writes t4";

auto client std::make_shared<synnax::Synnax>(new_test_client());

auto [state_idx, tErr1] = client->channels.create("do_state_idx", synnax::TIMESTAMP, 0, true);
ASSERT_FALSE(tErr1) << tErr1.message();

auto [cmd_idx, tErr2] = channel->channels.create("do_cmd_idx", synnax::INT32, true);
ASSERT_FALSE(tErr2) << tErr2.message();

// TODO: test schematic using a float channel
auto [state, aErr] = client->channels.create("do_state", synnax::SY_UINT8, state_idx.key, false);
ASSERT_FALSE(aErr) << aErr.message();

auto [cmd, cErr] = client->channels.create("do_cmd", synnax::SY_UINT8, cmd_idx.key, false);
ASSERT_FALSE(cErr) << cErr.message();

// create a writer to write commands out the cmd pipe
auto cmd_writer_config = synnax::WriterConfig{
.channels = std::vector<synnax::ChannelKey>{cmd_idx.key, cmd.key},
.start = TimeStamp::now(),
.mode = synnax::StreamOnly
};


}

0 comments on commit d97e3ca

Please sign in to comment.