From 972a27ae4b83f831f56423624ead306e56afd46c Mon Sep 17 00:00:00 2001 From: Malaurie Bernard <mbernard@kinouby> Date: Tue, 4 Jul 2023 14:05:21 +0200 Subject: [PATCH] Completely changing the CLI code to make it fit new class and methods. --- cli.cpp | 153 ++++++++++++++++++++++++++++---------------------------- cli.h | 4 +- 2 files changed, 78 insertions(+), 79 deletions(-) diff --git a/cli.cpp b/cli.cpp index 5d76226..2f4c7ab 100644 --- a/cli.cpp +++ b/cli.cpp @@ -79,15 +79,15 @@ void Cli::syntax (const char* cmd) if (!cmd || kw(F("AT"), cmd)) Serial.printf("%sAT -> OK\n", _msgHeader); if (!cmd || kw(F("HELP"), cmd)) Serial.printf("%sHELP [CMD]\n", _msgHeader); if (!cmd || kw(F("RAT"), cmd)) Serial.printf("%sRAT [ C <rate> [<unit>] ] - set or show rate ([UM]/MM/UH/MH)\n", _msgHeader); - if (!cmd || kw(F("VOL"), cmd)) Serial.printf("%sVOL [ <vol> | <unit> ] - set volume or unit (UL / ML)\n", _msgHeader); - if (!cmd || kw(F("RVOL"), cmd)) Serial.printf("%sRVOL <vol> - set relative volume\n", _msgHeader); - if (!cmd || kw(F("MM"), cmd)) Serial.printf("%sMM [ <len> ] - set distance (mm)\n", _msgHeader); - if (!cmd || kw(F("RMM"), cmd)) Serial.printf("%sRMM <len> - set relative distance (mm)\n", _msgHeader); + if (!cmd || kw(F("RVOL"), cmd)) Serial.printf("%sVOL [ <vol> | <unit> ] - set remaining volume or unit (UL / ML)\n", _msgHeader); + if (!cmd || kw(F("EVOL"), cmd)) Serial.printf("%sRVOL <vol> - set exchange volume\n", _msgHeader); + if (!cmd || kw(F("FMM"), cmd)) Serial.printf("%sMM [ <len> ] - set distance from the front (mm)\n", _msgHeader); + if (!cmd || kw(F("EMM"), cmd)) Serial.printf("%sRMM <len> - set exchange distance (mm)\n", _msgHeader); if (!cmd || kw(F("DIA"), cmd)) Serial.printf("%sDIA [ <dia> ] - set or show inside syringe diameter (in mm)\n", _msgHeader); if (!cmd || kw(F("ACC"), cmd)) Serial.printf("%sACC [ <mm/s/s> ] - set or show acceletaration (mm/s/s) (0<=>oo)\n", _msgHeader); if (!cmd || kw(F("RVM"), cmd)) Serial.printf("%sRVM [ <M4|M5> ] - set or show auger size\n", _msgHeader); if (!cmd || kw(F("DIR"), cmd)) Serial.printf("%sDIR [ INF | WDR ] - set or show direction (INFuse / WithDRaw)\n", _msgHeader); - if (!cmd || kw(F("FIL"), cmd)) Serial.printf("%sFIL - start filling using direction at rate for volume\n", _msgHeader); + if (!cmd || kw(F("MOV"), cmd)) Serial.printf("%sFIL - start mmoving using direction at rate for volume\n", _msgHeader); if (!cmd || kw(F("STP"), cmd)) Serial.printf("%sSTP - stop\n", _msgHeader); if (!cmd || kw(F("DIS"), cmd)) Serial.printf("%sDIS - show volume dispensed\n", _msgHeader); if (!cmd || kw(F("ZERO"), cmd)) Serial.printf("%sZERO - go to stopper\n", _msgHeader); @@ -104,12 +104,12 @@ void Cli::answer (bool ok, const String& error_message) const Serial.printf(" (%s)", error_message.c_str()); Serial.printf("\n"); } - +/* VARIABLE EMERGENCY QUI N'EXISTE PLUS, A VOIR S'IL FAUT LA REMETTRE void Cli::checkEmergency () { - if (syringe.emergency()) + if (syringe_filled.emergency()) Serial.printf("%sin EMERGENCY state, try NLCK command\n", _msgHeader); -} +}*/ void Cli::loop (Stream& input) { @@ -127,7 +127,7 @@ void Cli::loop (Stream& input) resetNextWord(); - Syringe::Syringe_configuration_t conf = syringe.configuration(); + //Syringe::Syringe_configuration_t conf = syringe.configuration(); //LES CONFIGURATION DE CE TYPE N'EXISTE PLUS if (findNextWord()) { @@ -143,196 +143,195 @@ void Cli::loop (Stream& input) else syntax(); } - else if (kw(F("RAT"))) + else if (kw(F("RAT"))) //*******************RATE*******************// { copyNextToTemp(); if (_temp.equalsIgnoreCase(F("C"))) { copyNextToTemp(); - conf.rate_ul_per_s = atof(_temp.c_str()); + syringe_filled.set_exchange_throughput_uL_per_sec(atof(_temp.c_str())); copyNextToTemp(); + float exchange_throughput_uL_per_sec = syringe_filled.get_exchange_throughput_uL_per_sec(); if (_temp.length() == 0) - conf.rate_ul_per_s /= 60; // default uL/mn + exchange_throughput_uL_per_sec /= 60; // default uL/mn else if (_temp.equalsIgnoreCase(F("us"))) - conf.rate_ul_per_s /= 1; + exchange_throughput_uL_per_sec /= 1; else if (_temp.equalsIgnoreCase(F("ms"))) - conf.rate_ul_per_s *= 1000; + exchange_throughput_uL_per_sec *= 1000; else if (_temp.equalsIgnoreCase(F("um"))) - conf.rate_ul_per_s /= 60; + exchange_throughput_uL_per_sec /= 60; else if (_temp.equalsIgnoreCase(F("mm"))) - conf.rate_ul_per_s *= 1000 / 60.0; + exchange_throughput_uL_per_sec *= 1000 / 60.0; else if (_temp.equalsIgnoreCase(F("uh"))) - conf.rate_ul_per_s /= 3600; + exchange_throughput_uL_per_sec /= 3600; else if (_temp.equalsIgnoreCase(F("mh"))) - conf.rate_ul_per_s *= 1000 / 3600.0; + exchange_throughput_uL_per_sec *= 1000 / 3600.0; else - conf.rate_ul_per_s = -1; - answer(syringe.configureSyringe(conf), F("invalid 'RAT C rate [unit]'")); + exchange_throughput_uL_per_sec = -1; + answer(syringe_filled.check_configuration(), F("invalid 'RAT C rate [unit]'")); } else if (_temp.length() > 0) answer(false, F("RAT must be followed by C")); Serial.printf("%sRAT: %g ul/mn\n", _msgHeader, - syringe.configuration().rate_ul_per_s * 60); + syringe_filled.get_exchange_throughput_uL_per_sec() * 60); } - else if (kw(F("VOL"))) + else if (kw(F("RVOL"))) //*******************REMAINING_VOLUME*******************// { copyNextToTemp(); while (_temp.length()) { if (isdigit(_temp[0])) - conf.volume_value = atof(_temp.c_str()); + syringe_filled.set_remaining_volume_mL(atof(_temp.c_str())); else if (_temp.equalsIgnoreCase(F("ul"))) - conf.volume_unit_ul = 1; + syringe_filled.set_remaining_volume_mL(atof(_temp.c_str())); else if (_temp.equalsIgnoreCase(F("ml"))) - conf.volume_unit_ul = 1000; + syringe_filled.set_remaining_volume_mL(atof(_temp.c_str())*1000); else if (_temp.equalsIgnoreCase(F("cl"))) - conf.volume_unit_ul = 10000; + syringe_filled.set_remaining_volume_mL(atof(_temp.c_str())*10000); else if (_temp.equalsIgnoreCase(F("dl"))) - conf.volume_unit_ul = 100000; + syringe_filled.set_remaining_volume_mL(atof(_temp.c_str())*100000); else if (_temp.equalsIgnoreCase(F("l"))) - conf.volume_unit_ul = 1000000; - answer(syringe.configureSyringe(conf), F("invalid volume or volume unit")); + syringe_filled.set_remaining_volume_mL(atof(_temp.c_str())*1000000); + answer(syringe_filled.check_configuration(), F("invalid remaining volume")); copyNextToTemp(); } - Serial.printf("%sVOL: %g ul (%g mm) (target)\n", _msgHeader, syringe.confToMm3(), syringe.confToMm()); + Serial.printf("%sRVOL: %g ul (target)\n", _msgHeader, syringe_filled.get_remaining_volume_mL()); } - else if (kw(F("RVOL"))) + else if (kw(F("EVOL"))) //*******************EXCHANGE_VOLUME*******************// { copyNextToTemp(); while (_temp.length()) { if (isdigit(_temp[0]) || _temp[0] == '-') - conf.volume_value += atof(_temp.c_str()); - answer(syringe.configureSyringe(conf), F("invalid relative volume")); + syringe_filled.set_exchange_volume_mL(atof(_temp.c_str())); + answer(syringe_filled.check_configuration(), F("invalid exchange volume")); copyNextToTemp(); } - Serial.printf("%sRVOL: %g ul (%g mm) (target)\n", _msgHeader, syringe.confToMm3(), syringe.confToMm()); + Serial.printf("%sEVOL: %g ul (target)\n", _msgHeader, syringe_filled.get_exchange_volume_mL()); } - else if (kw(F("MM"))) + else if (kw(F("FMM"))) //*******************FRONT_DISTANCE*******************// { copyNextToTemp(); if (_temp.length()) { if (isdigit(_temp[0])) - conf.volume_value = syringe.mmToMm3(atof(_temp.c_str())); - answer(syringe.configureSyringe(conf), F("invalid length")); + syringe_filled.set_remaining_volume_mL(syringe_filled.distance_to_volume(atof(_temp.c_str()), syringe_filled.get_id_syringe())); + answer(syringe_filled.check_configuration(), F("invalid length to the front")); copyNextToTemp(); } - Serial.printf("%sMM: %g ul (%g mm) (target)\n", _msgHeader, syringe.confToMm3(), syringe.confToMm()); + Serial.printf("%sFMM: %g ul (%g mm) (target)\n", _msgHeader, syringe_filled.get_remaining_volume_mL(), syringe_filled.volume_to_distance(syringe_filled.get_remaining_volume_mL(), syringe_filled.get_id_syringe())); } - else if (kw(F("RMM"))) + else if (kw(F("EMM"))) //*******************EXCHANGE_DISTANCE*******************// { copyNextToTemp(); if (_temp.length()) { if (isdigit(_temp[0]) || _temp[0] == '-') - conf.volume_value += syringe.mmToMm3(atof(_temp.c_str())); - answer(syringe.configureSyringe(conf), F("invalid length")); + syringe_filled.set_exchange_volume_mL(syringe_filled.distance_to_volume(atof(_temp.c_str()), syringe_filled.get_id_syringe())); + answer(syringe_filled.check_configuration(), F("invalid exchange length")); copyNextToTemp(); } - Serial.printf("%sRMM: %g ul (%g mm) (target)\n", _msgHeader, syringe.confToMm3(), syringe.confToMm()); + Serial.printf("%sRMM: %g ul (%g mm) (target)\n", _msgHeader, syringe_filled.get_exchange_volume_mL(), syringe_filled.volume_to_distance(syringe_filled.get_exchange_volume_mL(), syringe_filled.get_id_syringe())); } - else if (kw(F("DIA"))) + else if (kw(F("DIA"))) //*******************INTERNAL_DIAMETER*******************// { copyNextToTemp(); if (_temp.length()) { - conf.diameter_mm = atof(_temp.c_str()); - answer(syringe.configureSyringe(conf), F("invalid diameter")); + syringe_filled.get_id_syringe()->set_internal_diameter_mm(atof(_temp.c_str())); + answer(syringe_filled.get_id_syringe()->check_configuration(), F("invalid diameter")); } - Serial.printf("%sDIA: %g mm\n", _msgHeader, syringe.configuration().diameter_mm); + Serial.printf("%sDIA: %g mm\n", _msgHeader, syringe_filled.get_id_syringe()->get_internal_diameter_mm()); } else if (kw(F("RVM"))) { copyNextToTemp(); if (_temp == F("M4")) - syringe.setMmPerRev(M4_MMREV); + syringe_filled.setMmPerRev(M4_MMREV); else if (_temp == F("M5")) - syringe.setMmPerRev(M5_MMREV); + syringe_filled.setMmPerRev(M5_MMREV); else if (_temp.length() > 0) answer(false, F("invalid auger size: M4 or M5 are accepted")); - Serial.printf("%sRVM: %g mm per revolution\n", _msgHeader, syringe.getMmPerRev()); + Serial.printf("%sRVM: %g mm per revolution\n", _msgHeader, syringe_filled.getMmPerRev()); } - else if (kw(F("ACC"))) + else if (kw(F("ACC"))) //*******************ACCELERATION*******************// { copyNextToTemp(); if (_temp.length()) - syringe.setAccelMmPerSecPerSec(atof(_temp.c_str())); - Serial.printf("%sACC: %g mm per second per second\n", _msgHeader, syringe.getAccelMmPerSecPerSec()); + syringe_filled.setAccelMmPerSecPerSec(atof(_temp.c_str())); + Serial.printf("%sACC: %g mm per second per second\n", _msgHeader, syringe_filled.getAccelMmPerSecPerSec()); } - else if (kw(F("DIR"))) + else if (kw(F("DIR"))) //*******************DIRECTION*******************// { copyNextToTemp(); if (_temp.length()) { if (_temp.equalsIgnoreCase(F("inf"))) - conf.direction = 1; + syringe_filled.set_push(true); else if (_temp.equalsIgnoreCase(F("wdr"))) - conf.direction = -1; - else - conf.direction = 0; - answer(syringe.configureSyringe(conf), F("invalid direction -> INF | WDR")); + syringe_filled.set_push(false); + answer(syringe_filled.check_configuration(), F("invalid direction -> INF | WDR")); } Serial.printf("%sDIR: %s\n", _msgHeader, - syringe.configuration().direction > 0? "INFuse": "WithDRaw"); + syringe_filled.get_push()? "INFuse": "WithDRaw"); } - else if (kw(F("FIL"))) + else if (kw(F("MOV"))) //*******************MOUVEMENT*******************// { - checkEmergency(); - syringe.fill(); + //checkEmergency(); + syringe_filled.move(); answer(true); } else if (kw(F("STP"))) { - syringe.stayHere(); + syringe_filled.stayHere(); answer(true); } else if (kw(F("SET0"))) { - syringe.resetPosition(); + syringe_filled.resetPosition(); answer(true); } - else if (kw(F("DIS"))) + else if (kw(F("DIS"))) //*******************DISTANCE_PARCOURU*******************// { Serial.printf("%sDIS: I %g W %g UL\n", _msgHeader, - conf.direction > 0? syringe.mmToMm3(syringe.stepToMm(syringe.whereStep())): 0, - conf.direction > 0? 0 : syringe.mmToMm3(syringe.stepToMm(syringe.whereStep()))); + syringe_filled.get_push()? syringe_filled.distance_to_volume(syringe_filled.stepToMm(syringe_filled.whereStep())): 0, + syringe_filled.get_push()? 0 : syringe_filled.distance_to_volume(syringe_filled.stepToMm(syringe_filled.whereStep()))); } - else if (kw(F("ZERO"))) + else if (kw(F("ZERO"))) //*******************ZERO*******************// { - checkEmergency(); - syringe.findZero(); + //checkEmergency(); + syringe_filled.go_to_zero(); answer(true); } - else if (kw(F("NLCK"))) + /* else if (kw(F("NLCK"))) Fonction que j'ai supprimé en pensant que a servirait pas { syringe.runFromEmergency(); answer(true); - } - else if (kw(F("CLKW"))) + }*/ + else if (kw(F("CLKW"))) //*******************CLOCKWISE_EQUALS_PUSH*******************// { copyNextToTemp(); if (_temp.length() == 1) { if (_temp[0] == '0' || _temp[0] == '1') { - syringe.setPushClockwise(_temp[0] == '1'); + syringe_filled.set_clockwise_equals_push(_temp[0] == '1'); answer(true); } else answer(false, F("CLKW: invalid argument")); } - Serial.printf("%sCLKW: push %sclockwise\n", _msgHeader, syringe.getPushClockwise()? "": "anti-"); + Serial.printf("%sCLKW: push %sclockwise\n", _msgHeader, syringe_filled.get_clockwise_equals_push()? "": "anti-"); } - else if (kw(F("CONF"))) + else if (kw(F("CONF"))) //*******************SHOW_CONFIGURATION*******************// { - syringe.showConfiguration(syringe.configuration()); + syringe_filled.showConfiguration(syringe_filled.show_configuration()); answer(true); } else if (kw(F("FS-LS"))) diff --git a/cli.h b/cli.h index f361efe..b1b1203 100644 --- a/cli.h +++ b/cli.h @@ -8,7 +8,7 @@ class Cli { private: - Syringe& syringe; + SyringeFilled& syringe_filled; String _currentInput; String _temp; @@ -28,7 +28,7 @@ private: public: - Cli (Syringe& syringe, int bufferLen = 32): syringe(syringe) + Cli (SyringeFilled& syringe_filled, int bufferLen = 32): syringe_filled(syringe_filled) { _currentInput.reserve(bufferLen); _temp.reserve(bufferLen); -- GitLab