Skip to content

Commit

Permalink
before travel
Browse files Browse the repository at this point in the history
  • Loading branch information
s-t-a-n committed Aug 31, 2024
1 parent 73b611e commit 3832a59
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 73 deletions.
58 changes: 1 addition & 57 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = sam3x8e, sam3x8e-debug, nucleo_f411re, nucleo_f411re-debug, nucleo_f429zi, nucleo_f429zi-debug, debug
default_envs = nucleo_f429zi, nucleo_f429zi-debug

[env]
monitor_speed = 115200
Expand Down Expand Up @@ -43,9 +43,6 @@ debug_build_flags =
-g3
-ggdb3
-O0
; -u_printf_float
; -u_scanf_float
; -DPIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
-D_GLIBCXX_DEBUG
-D_GLIBCXX_ASSERTIONS
check_tool = clangtidy
Expand All @@ -56,23 +53,16 @@ check_flags =
lib_deps =
symlink:///home/stan/projects/krakakai/Spine
https://github.com/Neargye/magic_enum.git
; https://github.com/fmtlib/fmt.git


[arduino]
extends = hardware_implementations
build_flags =
${env.build_flags}
-DARDUINO=100
lib_deps =
${env.lib_deps}
Wire
OneWire
https://github.com/s-t-a-n/Arduino-Helpers.git
hideakitai/ArxSmartPtr@^0.3.0
paulstoffregen/Time@^1.6.1
https://github.com/s-t-a-n/DS3231-RTC.git
; https://github.com/matmunk/DS18B20
https://github.com/milesburton/Arduino-Temperature-Control-Library.git@^3.9.1
https://github.com/RobTillaart/SHT31.git

Expand Down Expand Up @@ -103,51 +93,6 @@ framework = arduino
upload_protocol = stlink
debug_tool = stlink

[env:nucleo_f411re]
extends = embedded, arduino
platform = ststm32
board = genericSTM32F411RE
framework = arduino
upload_protocol = stlink
debug_tool = stlink

[env:nucleo_f411re-debug]
extends = embedded, arduino
platform = ststm32
build_flags =
${env.build_flags}
-D DEBUG_SPINE
-D DEBUG_KASKAS
board = genericSTM32F411RE
framework = arduino
debug_tool = stlink

[env:sam3x8e]
extends = embedded, arduino
platform = atmelsam
board = due
framework = arduino
lib_deps =
${env.lib_deps}
https://github.com/cloud-rocket/DuePWM.git

[env:sam3x8e-debug]
extends = embedded, arduino
platform = atmelsam
board = due
framework = arduino
build_flags =
${env.build_flags}
-D DEBUG_SPINE
-D DEBUG_KASKAS
debug_build_flags =
${env.debug_build_flags}
-D DEBUG_KASKAS
-D DEBUG_SPINE
lib_deps =
${env.lib_deps}
https://github.com/antodom/pwm_lib.git

[env:debug]
platform = native
build_flags =
Expand All @@ -165,7 +110,6 @@ debug_init_break = tbreak setup
lib_deps =
${env.lib_deps}
fabiobatsilva/ArduinoFake@^0.4.0
nanopb/Nanopb@^0.4.8

[unittest]
build_flags =
Expand Down
3 changes: 1 addition & 2 deletions src/kaskas/kaskas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <spine/eventsystem/eventsystem.hpp>
#include <spine/io/stream/stream.hpp>
#include <spine/platform/hal.hpp>
#include <spine/structure/pointer.hpp>
#include <spine/structure/vector.hpp>

#include <utility>
Expand Down Expand Up @@ -56,7 +55,7 @@ class KasKas {
auto dl = std::make_shared<Datalink>(uart,
Datalink::Config{.input_buffer_size = _cfg.prompt_cfg->io_buffer_size,
.output_buffer_size = _cfg.prompt_cfg->io_buffer_size,
.delimiters = "\r\n"});
.delimiters = _cfg.prompt_cfg->line_delimiters});
// using prompt::MockDatalink;
// auto prompt_cfg = Prompt::Config{.message_length = 64, .pool_size = 20};
// auto dl = std::make_shared<MockDatalink>(
Expand Down
2 changes: 1 addition & 1 deletion src/kaskas/prompt/incoming_message_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class IncomingMessageFactory {

static ParseResult parse_usage_request(ParseContext& ctx) {
if (spn::core::utils::starts_with(ctx.view, Dialect::OPERANT_PRINT_USAGE)) {
DBG("usage request detected");
// DBG("usage request detected");
return Message(Dialect::OPERANT_PRINT_USAGE, Dialect::OPERANT_PRINT_USAGE);
}
return ParseResult::intermediary(ctx);
Expand Down
7 changes: 3 additions & 4 deletions src/kaskas/prompt/prompt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ class Prompt {
_dl->pull();

if (auto transaction = _dl->incoming_transaction()) {
// DBG("Prompt: New transaction coming over the wire: {%s}", std::string(transaction->incoming()).c_str());
// DBG("Prompt: new transaction: {%s}", std::string(transaction->incoming()).c_str());
if (auto message = IncomingMessageFactory::from_view(transaction->incoming())) {
// DBG("message: {%s}!", message->as_string().c_str());
// DBG("message!");
// DBG("Prompt: valid message: {%s}!", message->as_string().c_str());
// transaction->outgoing(message->as_string());
// transaction->abort();

if (const auto rpc = _rpc_factory.from_message(*message)) {
auto res = rpc->invoke();

// DBG("invoke: res: {%s}", res.return_value->c_str());
// DBG("Prompt: invoked RPC, result: {%s}", res.return_value->c_str());

if (const auto reply = OutgoingMessageFactory::from_result(std::move(res), message->module);
reply) {
Expand Down
2 changes: 1 addition & 1 deletion src/kaskas/prompt/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class RPCFactory {
return build_rpc_for_request(**recipe, optype, msg);
}
case Dialect::OP::PRINT_USAGE: {
DBG("rpc: usage request");
// DBG("rpc: usage request");
return build_rpc_for_usage(msg);
}
default: DBG("no optype found for message: {%s}", msg.as_string().c_str()); return {};
Expand Down
15 changes: 12 additions & 3 deletions src/kaskas/subsystems/fluidsystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Fluidsystem final : public Component {

float ground_moisture_target;

uint16_t calibration_dosis_ml;
uint16_t max_dosis_ml;
time_s time_of_injection;
time_s delay_before_effect_evaluation;
Expand Down Expand Up @@ -110,9 +111,9 @@ class Fluidsystem final : public Component {

auto target_amount = _ml_per_percent_of_moisture.value() * error;
if (_ml_per_percent_of_moisture.value() == 0) {
LOG("Fluidsystem: WaterInjectCheck: First injection since startup; injecting maximum dosis to "
LOG("Fluidsystem: WaterInjectCheck: First injection since startup; injecting calibration dosis to "
"calibrate.");
target_amount = _cfg.max_dosis_ml;
target_amount = _cfg.calibration_dosis_ml;
}

if (target_amount > _cfg.max_dosis_ml) {
Expand Down Expand Up @@ -237,9 +238,17 @@ class Fluidsystem final : public Component {
RPCModel(
"injectionEffect",
[this](const OptStringView& _) {
return RPCResult(std::to_string(_ml_per_percent_of_moisture.value()), RPCResult::Status::OK);
return RPCResult(std::to_string(_ml_per_percent_of_moisture.value()));
},
"tracks amount of moisture raised per mL of fluid dosed"),
RPCModel(
"calibrationDosis",
[this](const OptStringView& _) { return RPCResult(std::to_string(_cfg.calibration_dosis_ml)); },
"The calibration dosage used when no fluid effect is known"),
RPCModel(
"maxDosis",
[this](const OptStringView& _) { return RPCResult(std::to_string(_cfg.max_dosis_ml)); },
"The maximum allowed dosage."),
}));
return std::move(model);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,9 @@ void setup() {
auto fluidsystem_cfg = Fluidsystem::Config{.pump_cfg = pump_cfg, //
.ground_moisture_sensor_idx = ENUM_IDX(DataProviders::SOIL_MOISTURE),
.clock_idx = ENUM_IDX(DataProviders::CLOCK),
.ground_moisture_target = 65, // target moisture percentage
.max_dosis_ml = 250,
.ground_moisture_target = 55, // target moisture percentage
.calibration_dosis_ml = 250,
.max_dosis_ml = 500,
.time_of_injection = time_h(6),
.delay_before_effect_evaluation = time_h(2)};
auto fluidsystem = std::make_unique<Fluidsystem>(*hws, fluidsystem_cfg);
Expand Down
13 changes: 10 additions & 3 deletions test/test_prompt/test_prompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "kaskas/prompt/rpc.hpp"

#include <spine/eventsystem/eventsystem.hpp>
#include <spine/io/stream/implementations/mock.hpp>
#include <spine/platform/hal.hpp>
#include <unity.h>

Expand Down Expand Up @@ -54,11 +55,17 @@ class MockController {

void ut_prompt_basics() {
using namespace kaskas::prompt;
using namespace spn::io;

auto prompt_cfg = Prompt::Config{.message_length = 64, .pool_size = 20};
const auto buffer_size = 1024;

auto dl = std::make_shared<MockDatalink>(
MockDatalink::Config{.message_length = prompt_cfg.message_length, .pool_size = prompt_cfg.pool_size});
auto stream = std::make_shared<MockStream>(
MockStream(MockStream::Config{.input_buffer_size = buffer_size, .output_buffer_size = buffer_size}));

auto prompt_cfg = Prompt::Config{.io_buffer_size = buffer_size, .line_delimiters = "\r\n"};
auto dl = std::make_shared<Datalink>(
stream,
Datalink::Config{.input_buffer_size = buffer_size, .output_buffer_size = buffer_size, .delimiters = "\r\n"});
auto prompt = Prompt(std::move(prompt_cfg));
prompt.hotload_datalink(dl);

Expand Down

0 comments on commit 3832a59

Please sign in to comment.