diff options
25 files changed, 304 insertions, 225 deletions
diff --git a/src/GCodes/GCodeBuffer/ExpressionParser.cpp b/src/GCodes/GCodeBuffer/ExpressionParser.cpp index c9e5ff29..56e6acc0 100644 --- a/src/GCodes/GCodeBuffer/ExpressionParser.cpp +++ b/src/GCodes/GCodeBuffer/ExpressionParser.cpp @@ -57,13 +57,13 @@ ExpressionValue ExpressionParser::Parse(bool evaluate, uint8_t priority) THROWS( case '-': AdvancePointer(); val = Parse(evaluate, UnaryPriority); - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(int32_t): + case TypeCode::Int32: val.iVal = -val.iVal; //TODO overflow check break; - case TYPE_OF(float): + case TypeCode::Float: val.fVal = -val.fVal; break; @@ -75,16 +75,16 @@ ExpressionValue ExpressionParser::Parse(bool evaluate, uint8_t priority) THROWS( case '+': AdvancePointer(); val = Parse(evaluate, UnaryPriority); - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(uint32_t): + case TypeCode::Uint32: // Convert enumeration to integer val.iVal = (int32_t)val.uVal; - val.type = TYPE_OF(int32_t); + val.SetType(TypeCode::Int32); break; - case TYPE_OF(int32_t): - case TYPE_OF(float): + case TypeCode::Int32: + case TypeCode::Float: break; default: @@ -103,12 +103,12 @@ ExpressionValue ExpressionParser::Parse(bool evaluate, uint8_t priority) THROWS( else { val = Parse(evaluate, UnaryPriority); - if (val.type == TYPE_OF(const char*)) + if (val.GetType() == TypeCode::CString) { const char* s = val.sVal; val.Set((int32_t)strlen(s)); stringBuffer.FinishedUsing(s); - val.type = TYPE_OF(int32_t); + val.SetType(TypeCode::Int32); } else { @@ -247,7 +247,7 @@ ExpressionValue ExpressionParser::Parse(bool evaluate, uint8_t priority) THROWS( { case '+': BalanceNumericTypes(val, val2, evaluate); - if (val.type == TYPE_OF(float)) + if (val.GetType() == TypeCode::Float) { val.fVal += val2.fVal; val.param = max(val.param, val2.param); @@ -260,7 +260,7 @@ ExpressionValue ExpressionParser::Parse(bool evaluate, uint8_t priority) THROWS( case '-': BalanceNumericTypes(val, val2, evaluate); - if (val.type == TYPE_OF(float)) + if (val.GetType() == TypeCode::Float) { val.fVal -= val2.fVal; val.param = max(val.param, val2.param); @@ -273,7 +273,7 @@ ExpressionValue ExpressionParser::Parse(bool evaluate, uint8_t priority) THROWS( case '*': BalanceNumericTypes(val, val2, evaluate); - if (val.type == TYPE_OF(float)) + if (val.GetType() == TypeCode::Float) { val.fVal *= val2.fVal; val.param = max(val.param, val2.param); @@ -293,24 +293,24 @@ ExpressionValue ExpressionParser::Parse(bool evaluate, uint8_t priority) THROWS( case '>': BalanceTypes(val, val2, evaluate); - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(int32_t): + case TypeCode::Int32: val.bVal = (val.iVal > val2.iVal); break; - case TYPE_OF(float_t): + case TypeCode::Float: val.bVal = (val.fVal > val2.fVal); break; - case TYPE_OF(bool): + case TypeCode::Bool: val.bVal = (val.bVal && !val2.bVal); break; default: throw ConstructParseException("expected numeric or Boolean operands to comparison operator"); } - val.type = TYPE_OF(bool); + val.SetType(TypeCode::Bool); if (invert) { val.bVal = !val.bVal; @@ -319,24 +319,24 @@ ExpressionValue ExpressionParser::Parse(bool evaluate, uint8_t priority) THROWS( case '<': BalanceTypes(val, val2, evaluate); - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(int32_t): + case TypeCode::Int32: val.bVal = (val.iVal < val2.iVal); break; - case TYPE_OF(float_t): + case TypeCode::Float: val.bVal = (val.fVal < val2.fVal); break; - case TYPE_OF(bool): + case TypeCode::Bool: val.bVal = (!val.bVal && val2.bVal); break; default: throw ConstructParseException("expected numeric or Boolean operands to comparison operator"); } - val.type = TYPE_OF(bool); + val.SetType(TypeCode::Bool); if (invert) { val.bVal = !val.bVal; @@ -345,39 +345,39 @@ ExpressionValue ExpressionParser::Parse(bool evaluate, uint8_t priority) THROWS( case '=': // Before balancing, handle comparisons with null - if (val.type == NoType) + if (val.GetType() == TypeCode::None) { - val.bVal = (val2.type == NoType); + val.bVal = (val2.GetType() == TypeCode::None); } - else if (val2.type == NoType) + else if (val2.GetType() == TypeCode::None) { val.bVal = false; } else { BalanceTypes(val, val2, evaluate); - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(const ObjectModel*): + case TypeCode::ObjectModel: throw ConstructParseException("cannot compare objects"); - case TYPE_OF(int32_t): + case TypeCode::Int32: val.bVal = (val.iVal == val2.iVal); break; - case TYPE_OF(uint32_t): + case TypeCode::Uint32: val.bVal = (val.uVal == val2.uVal); break; - case TYPE_OF(float_t): + case TypeCode::Float: val.bVal = (val.fVal == val2.fVal); break; - case TYPE_OF(bool): + case TypeCode::Bool: val.bVal = (val.bVal == val2.bVal); break; - case TYPE_OF(const char*): + case TypeCode::CString: val.bVal = (strcmp(val.sVal, val2.sVal) == 0); break; @@ -385,7 +385,7 @@ ExpressionValue ExpressionParser::Parse(bool evaluate, uint8_t priority) THROWS( throw ConstructParseException("unexpected operand type to equality operator"); } } - val.type = TYPE_OF(bool); + val.SetType(TypeCode::Bool); if (invert) { val.bVal = !val.bVal; @@ -425,12 +425,12 @@ float ExpressionParser::ParseFloat() THROWS(GCodeException) int32_t ExpressionParser::ParseInteger() THROWS(GCodeException) { ExpressionValue val = Parse(); - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(int32_t): + case TypeCode::Int32: return val.iVal; - case TYPE_OF(uint32_t): + case TypeCode::Uint32: if (val.uVal > (uint32_t)std::numeric_limits<int32_t>::max()) { throw ConstructParseException("unsigned integer too large"); @@ -445,12 +445,12 @@ int32_t ExpressionParser::ParseInteger() THROWS(GCodeException) uint32_t ExpressionParser::ParseUnsigned() THROWS(GCodeException) { ExpressionValue val = Parse(); - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(uint32_t): + case TypeCode::Uint32: return val.uVal; - case TYPE_OF(int32_t): + case TypeCode::Int32: if (val.iVal >= 0) { return (uint32_t)val.iVal; @@ -464,15 +464,15 @@ uint32_t ExpressionParser::ParseUnsigned() THROWS(GCodeException) void ExpressionParser::BalanceNumericTypes(ExpressionValue& val1, ExpressionValue& val2, bool evaluate) const THROWS(GCodeException) { - if (val1.type == TYPE_OF(float)) + if (val1.GetType() == TypeCode::Float) { ConvertToFloat(val2, evaluate); } - else if (val2.type == TYPE_OF(float)) + else if (val2.GetType() == TypeCode::Float) { ConvertToFloat(val1, evaluate); } - else if (val1.type != TYPE_OF(int32_t) || val2.type != TYPE_OF(int32_t)) + else if (val1.GetType() != TypeCode::Int32 || val2.GetType() != TypeCode::Int32) { if (evaluate) { @@ -485,15 +485,15 @@ void ExpressionParser::BalanceNumericTypes(ExpressionValue& val1, ExpressionValu void ExpressionParser::BalanceTypes(ExpressionValue& val1, ExpressionValue& val2, bool evaluate) const THROWS(GCodeException) { - if (val1.type == TYPE_OF(float)) + if (val1.GetType() == TypeCode::Float) { ConvertToFloat(val2, evaluate); } - else if (val2.type == TYPE_OF(float)) + else if (val2.GetType() == TypeCode::Float) { ConvertToFloat(val1, evaluate); } - else if (val1.type != val2.type) + else if (val1.GetType() != val2.GetType()) { if (evaluate) { @@ -506,15 +506,15 @@ void ExpressionParser::BalanceTypes(ExpressionValue& val1, ExpressionValue& val2 void ExpressionParser::EnsureNumeric(ExpressionValue& val, bool evaluate) const THROWS(GCodeException) { - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(uint32_t): - val.type = TYPE_OF(int32_t); + case TypeCode::Uint32: + val.SetType(TypeCode::Int32); val.iVal = val.uVal; break; - case TYPE_OF(int32_t): - case TYPE_OF(float): + case TypeCode::Int32: + case TypeCode::Float: break; default: @@ -528,15 +528,15 @@ void ExpressionParser::EnsureNumeric(ExpressionValue& val, bool evaluate) const void ExpressionParser::ConvertToFloat(ExpressionValue& val, bool evaluate) const THROWS(GCodeException) { - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(int32_t): + case TypeCode::Int32: val.fVal = (float)val.iVal; - val.type = TYPE_OF(float); + val.SetType(TypeCode::Float); val.param = 1; break; - case TYPE_OF(float): + case TypeCode::Float: break; default: @@ -550,7 +550,7 @@ void ExpressionParser::ConvertToFloat(ExpressionValue& val, bool evaluate) const void ExpressionParser::ConvertToBool(ExpressionValue& val, bool evaluate) const THROWS(GCodeException) { - if (val.type != TYPE_OF(bool)) + if (val.GetType() != TypeCode::Bool) { if (evaluate) { @@ -562,7 +562,7 @@ void ExpressionParser::ConvertToBool(ExpressionValue& val, bool evaluate) const void ExpressionParser::ConvertToString(ExpressionValue& val, bool evaluate) THROWS(GCodeException) { - if (val.type != TYPE_OF(const char*)) + if (val.GetType() != TypeCode::CString) { if (evaluate) { @@ -678,7 +678,7 @@ ExpressionValue ExpressionParser::ParseNumber() THROWS(GCodeException) if (isFloat) { - retvalue.type = TYPE_OF(float); + retvalue.SetType(TypeCode::Float); retvalue.param = constrain<long>(digitsAfterPoint, 1, MaxFloatDigitsDisplayedAfterPoint); if (valueAfterPoint != 0) { @@ -698,7 +698,7 @@ ExpressionValue ExpressionParser::ParseNumber() THROWS(GCodeException) } else { - retvalue.type = TYPE_OF(int32_t); + retvalue.SetType(TypeCode::Int32); retvalue.iVal = (int32_t)valueBeforePoint; } @@ -729,7 +729,7 @@ ExpressionValue ExpressionParser::ParseIdentifierExpression(bool evaluate, bool { throw ConstructParseException("expected ']'"); } - if (index.type != TYPE_OF(int32_t)) + if (index.GetType() != TypeCode::Int32) { throw ConstructParseException("expected integer expression"); } @@ -816,13 +816,13 @@ ExpressionValue ExpressionParser::ParseIdentifierExpression(bool evaluate, bool switch (func.RawValue()) { case Function::abs: - switch (rslt.type) + switch (rslt.GetType()) { - case TYPE_OF(int32_t): + case TypeCode::Int32: rslt.iVal = labs(rslt.iVal); break; - case TYPE_OF(float): + case TypeCode::Float: rslt.fVal = fabsf(rslt.fVal); break; @@ -908,7 +908,7 @@ ExpressionValue ExpressionParser::ParseIdentifierExpression(bool evaluate, bool case Function::isnan: ConvertToFloat(rslt, evaluate); - rslt.type = TYPE_OF(bool); + rslt.SetType(TypeCode::Bool); rslt.bVal = (isnan(rslt.fVal) != 0); break; @@ -918,7 +918,7 @@ ExpressionValue ExpressionParser::ParseIdentifierExpression(bool evaluate, bool const float f = floorf(rslt.fVal); if (f <= (float)std::numeric_limits<int32_t>::max() && f >= (float)std::numeric_limits<int32_t>::min()) { - rslt.type = TYPE_OF(int32_t); + rslt.SetType(TypeCode::Int32); rslt.iVal = (int32_t)f; } else @@ -939,7 +939,7 @@ ExpressionValue ExpressionParser::ParseIdentifierExpression(bool evaluate, bool SkipWhiteSpace(); ExpressionValue nextOperand = Parse(evaluate); BalanceNumericTypes(rslt, nextOperand, evaluate); - if (rslt.type == TYPE_OF(float)) + if (rslt.GetType() == TypeCode::Float) { rslt.fVal = fmod(rslt.fVal, nextOperand.fVal); } @@ -966,7 +966,7 @@ ExpressionValue ExpressionParser::ParseIdentifierExpression(bool evaluate, bool SkipWhiteSpace(); ExpressionValue nextOperand = Parse(evaluate); BalanceNumericTypes(rslt, nextOperand, evaluate); - if (rslt.type == TYPE_OF(float)) + if (rslt.GetType() == TypeCode::Float) { rslt.fVal = max<float>(rslt.fVal, nextOperand.fVal); rslt.param = max(rslt.param, nextOperand.param); @@ -990,7 +990,7 @@ ExpressionValue ExpressionParser::ParseIdentifierExpression(bool evaluate, bool SkipWhiteSpace(); ExpressionValue nextOperand = Parse(evaluate); BalanceNumericTypes(rslt, nextOperand, evaluate); - if (rslt.type == TYPE_OF(float)) + if (rslt.GetType() == TypeCode::Float) { rslt.fVal = min<float>(rslt.fVal, nextOperand.fVal); rslt.param = max(rslt.param, nextOperand.param); diff --git a/src/GCodes/GCodes.cpp b/src/GCodes/GCodes.cpp index 66298d24..1068d357 100644 --- a/src/GCodes/GCodes.cpp +++ b/src/GCodes/GCodes.cpp @@ -2680,8 +2680,8 @@ GCodeResult GCodes::ProbeGrid(GCodeBuffer& gb, const StringRef& reply) reprap.GetMove().AccessHeightMap().SetGrid(defaultGrid); ClearBedMapping(); gridXindex = gridYindex = 0; - gb.SetState(GCodeState::gridProbing1); + gb.SetState(GCodeState::gridProbing1); if (platform.GetCurrentZProbeType() != ZProbeType::blTouch) { DeployZProbe(gb, 0); diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp index a7b89354..07a3f5f6 100644 --- a/src/GCodes/GCodes2.cpp +++ b/src/GCodes/GCodes2.cpp @@ -2795,7 +2795,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx else { String<MaxFilenameLength> path; - platform.GetSysDir(path.GetRef()); + platform.AppendSysDir(path.GetRef()); reply.printf("Sys file path is %s", path.c_str()); } break; @@ -2989,7 +2989,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx } else { - platform.GetSysDir(sysDir.GetRef()); + platform.AppendSysDir(sysDir.GetRef()); folder = sysDir.c_str(); defaultFile = CONFIG_FILE; } diff --git a/src/GCodes/GCodes3.cpp b/src/GCodes/GCodes3.cpp index f7167846..3f7e0b85 100644 --- a/src/GCodes/GCodes3.cpp +++ b/src/GCodes/GCodes3.cpp @@ -1333,6 +1333,7 @@ void GCodes::ChangeExtrusionFactor(unsigned int extruder, float factor) noexcept } // Deploy the Z probe unless it has already been deployed explicitly +// The required next state must be set up (e.g. by gb.SetState()) before calling this void GCodes::DeployZProbe(GCodeBuffer& gb, unsigned int probeNumber) noexcept { auto zp = reprap.GetPlatform().GetEndstops().GetZProbe(probeNumber); @@ -1348,6 +1349,7 @@ void GCodes::DeployZProbe(GCodeBuffer& gb, unsigned int probeNumber) noexcept } // Retract the Z probe unless it was deployed explicitly (in which case, wait for the user to retract it explicitly) +// The required next state must be set up (e.g. by gb.SetState()) before calling this void GCodes::RetractZProbe(GCodeBuffer& gb, unsigned int probeNumber) noexcept { auto zp = reprap.GetPlatform().GetEndstops().GetZProbe(probeNumber); diff --git a/src/Heating/Sensors/AdditionalOutputSensor.h b/src/Heating/Sensors/AdditionalOutputSensor.h index 61654479..ef6eeba1 100644 --- a/src/Heating/Sensors/AdditionalOutputSensor.h +++ b/src/Heating/Sensors/AdditionalOutputSensor.h @@ -15,7 +15,7 @@ class AdditionalOutputSensor : public TemperatureSensor public: AdditionalOutputSensor(unsigned int sensorNum, const char *type, bool enforcePollOrder) noexcept; virtual ~AdditionalOutputSensor() noexcept; - GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; + GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override THROWS(GCodeException); void Poll() noexcept override; protected: diff --git a/src/Heating/Sensors/CpuTemperatureSensor.h b/src/Heating/Sensors/CpuTemperatureSensor.h index c7125e24..f40342c1 100644 --- a/src/Heating/Sensors/CpuTemperatureSensor.h +++ b/src/Heating/Sensors/CpuTemperatureSensor.h @@ -17,9 +17,10 @@ class CpuTemperatureSensor : public TemperatureSensor public: CpuTemperatureSensor(unsigned int sensorNum) noexcept; - static constexpr const char *TypeName = "mcutemp"; - void Poll() noexcept override; + const char *GetShortSensorType() const noexcept override { return TypeName; } + + static constexpr const char *TypeName = "mcutemp"; }; #endif diff --git a/src/Heating/Sensors/CurrentLoopTemperatureSensor.h b/src/Heating/Sensors/CurrentLoopTemperatureSensor.h index c1db9f3c..54737986 100644 --- a/src/Heating/Sensors/CurrentLoopTemperatureSensor.h +++ b/src/Heating/Sensors/CurrentLoopTemperatureSensor.h @@ -14,12 +14,12 @@ class CurrentLoopTemperatureSensor : public SpiTemperatureSensor { public: CurrentLoopTemperatureSensor(unsigned int sensorNum) noexcept; - GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; + GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override THROWS(GCodeException); + const char *GetShortSensorType() const noexcept override { return TypeName; } + void Poll() noexcept override; static constexpr const char *TypeName = "currentloop"; - void Poll() noexcept override; - private: TemperatureError TryGetLinearAdcTemperature(float& t) noexcept; void CalcDerivedParameters() noexcept; diff --git a/src/Heating/Sensors/DhtSensor.cpp b/src/Heating/Sensors/DhtSensor.cpp index af295ec2..61814dee 100644 --- a/src/Heating/Sensors/DhtSensor.cpp +++ b/src/Heating/Sensors/DhtSensor.cpp @@ -35,6 +35,17 @@ DhtTemperatureSensor::~DhtTemperatureSensor() noexcept { } +const char *DhtTemperatureSensor::GetShortSensorType() const noexcept +{ + switch (type) + { + case DhtSensorType::Dht11: return TypeNameDht11; + case DhtSensorType::Dht21: return TypeNameDht21; + case DhtSensorType::Dht22: return TypeNameDht22; + default: return "unknown"; + } +} + GCodeResult DhtTemperatureSensor::Configure(GCodeBuffer& gb, const StringRef& reply) { bool seen = false; diff --git a/src/Heating/Sensors/DhtSensor.h b/src/Heating/Sensors/DhtSensor.h index 5cf86c0d..43e320f5 100644 --- a/src/Heating/Sensors/DhtSensor.h +++ b/src/Heating/Sensors/DhtSensor.h @@ -31,12 +31,12 @@ public: DhtTemperatureSensor(unsigned int sensorNum, DhtSensorType type) noexcept; ~DhtTemperatureSensor() noexcept; - GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; + GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override THROWS(GCodeException); TemperatureError GetLatestTemperature(float& t, uint8_t outputNumber = 0) noexcept override; const uint8_t GetNumAdditionalOutputs() const noexcept override { return 1; } - void Poll() noexcept override; bool PollInTask() noexcept override; + const char *GetShortSensorType() const noexcept override; void Interrupt() noexcept; void TakeReading() noexcept; @@ -65,6 +65,8 @@ public: DhtHumiditySensor(unsigned int sensorNum) noexcept; ~DhtHumiditySensor() noexcept; + const char *GetShortSensorType() const noexcept override { return TypeName; } + static constexpr const char *TypeName = "dhthumidity"; }; diff --git a/src/Heating/Sensors/LinearAnalogSensor.h b/src/Heating/Sensors/LinearAnalogSensor.h index 43c7f61b..1e6ae9b2 100644 --- a/src/Heating/Sensors/LinearAnalogSensor.h +++ b/src/Heating/Sensors/LinearAnalogSensor.h @@ -15,12 +15,12 @@ class LinearAnalogSensor : public SensorWithPort public: LinearAnalogSensor(unsigned int sensorNum) noexcept; - GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; + GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override THROWS(GCodeException); + void Poll() noexcept override; + const char *GetShortSensorType() const noexcept override { return TypeName; } static constexpr const char *TypeName = "linearanalog"; - void Poll() noexcept override; - private: void CalcDerivedParameters() noexcept; diff --git a/src/Heating/Sensors/RemoteSensor.h b/src/Heating/Sensors/RemoteSensor.h index 22edb4d4..ac1e231d 100644 --- a/src/Heating/Sensors/RemoteSensor.h +++ b/src/Heating/Sensors/RemoteSensor.h @@ -17,12 +17,11 @@ class RemoteSensor : public TemperatureSensor public: RemoteSensor(unsigned int sensorNum, CanAddress pBoardAddress) noexcept; - GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; + GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override THROWS(GCodeException); CanAddress GetBoardAddress() const noexcept override { return boardAddress; } - void UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report) noexcept override; - - // Try to get a temperature reading void Poll() noexcept override { } // nothing to do here because reception of CAN messages update the reading + void UpdateRemoteTemperature(CanAddress src, const CanSensorReport& report) noexcept override; + const char *GetShortSensorType() const noexcept override { return "remote"; } // TODO save the actual type private: CanAddress boardAddress; diff --git a/src/Heating/Sensors/RtdSensor31865.h b/src/Heating/Sensors/RtdSensor31865.h index bb78a40d..ac2c2150 100644 --- a/src/Heating/Sensors/RtdSensor31865.h +++ b/src/Heating/Sensors/RtdSensor31865.h @@ -14,12 +14,12 @@ class RtdSensor31865 : public SpiTemperatureSensor { public: RtdSensor31865(unsigned int sensorNum) noexcept; - GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; + GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override THROWS(GCodeException); + void Poll() noexcept override; + const char *GetShortSensorType() const noexcept override { return TypeName; } static constexpr const char *TypeName = "rtdmax31865"; - void Poll() noexcept override; - private: TemperatureError TryInitRtd() const noexcept; diff --git a/src/Heating/Sensors/TemperatureSensor.cpp b/src/Heating/Sensors/TemperatureSensor.cpp index 8934d130..aea51e8f 100644 --- a/src/Heating/Sensors/TemperatureSensor.cpp +++ b/src/Heating/Sensors/TemperatureSensor.cpp @@ -39,7 +39,7 @@ constexpr ObjectModelTableEntry TemperatureSensor::objectModelTable[] = // 0. TemperatureSensor members { "lastReading", OBJECT_MODEL_FUNC(self->lastTemperature, 1), ObjectModelEntryFlags::live }, { "name", OBJECT_MODEL_FUNC(self->sensorName), ObjectModelEntryFlags::none }, - { "type", OBJECT_MODEL_FUNC(self->sensorType), ObjectModelEntryFlags::none }, + { "type", OBJECT_MODEL_FUNC(self->GetShortSensorType()), ObjectModelEntryFlags::none }, }; constexpr uint8_t TemperatureSensor::objectModelTableDescriptor[] = { 1, 3 }; diff --git a/src/Heating/Sensors/TemperatureSensor.h b/src/Heating/Sensors/TemperatureSensor.h index 7b561c4f..07a2da0c 100644 --- a/src/Heating/Sensors/TemperatureSensor.h +++ b/src/Heating/Sensors/TemperatureSensor.h @@ -34,6 +34,11 @@ public: // if we find no relevant parameters, report the current parameters to 'reply' and return 'false'. virtual GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply); +#if SUPPORT_OBJECT_MODEL + // Report the sensor type in the form corresponding to the Y parameter of M308. + virtual const char *GetShortSensorType() const noexcept = 0; +#endif + // Return the sensor type const char *GetSensorType() const noexcept { return sensorType; } diff --git a/src/Heating/Sensors/Thermistor.h b/src/Heating/Sensors/Thermistor.h index ccaaaa1c..838329bb 100644 --- a/src/Heating/Sensors/Thermistor.h +++ b/src/Heating/Sensors/Thermistor.h @@ -22,13 +22,13 @@ class Thermistor : public SensorWithPort { public: Thermistor(unsigned int sensorNum, bool p_isPT1000) noexcept; // create an instance with default values - GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; // configure the sensor from M305 parameters + GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override THROWS(GCodeException); // configure the sensor from M305 parameters + void Poll() noexcept override; + const char *GetShortSensorType() const noexcept override { return (isPT1000) ? TypeNamePT1000 : TypeNameThermistor; } static constexpr const char *TypeNameThermistor = "thermistor"; static constexpr const char *TypeNamePT1000 = "pt1000"; - void Poll() noexcept override; - private: // For the theory behind ADC oversampling, see http://www.atmel.com/Images/doc8003.pdf static constexpr unsigned int AdcOversampleBits = 2; // we use 2-bit oversampling diff --git a/src/Heating/Sensors/ThermocoupleSensor31855.h b/src/Heating/Sensors/ThermocoupleSensor31855.h index fdd8de98..7d633dbf 100644 --- a/src/Heating/Sensors/ThermocoupleSensor31855.h +++ b/src/Heating/Sensors/ThermocoupleSensor31855.h @@ -14,11 +14,11 @@ class ThermocoupleSensor31855 : public SpiTemperatureSensor { public: ThermocoupleSensor31855(unsigned int sensorNum) noexcept; - GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; + GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override THROWS(GCodeException); + void Poll() noexcept override; + const char *GetShortSensorType() const noexcept override { return TypeName; } static constexpr const char *TypeName = "thermocouplemax31855"; - - void Poll() noexcept override; }; #endif /* SRC_HEATING_THERMOCOUPLESENSOR31855_H_ */ diff --git a/src/Heating/Sensors/ThermocoupleSensor31856.h b/src/Heating/Sensors/ThermocoupleSensor31856.h index 080a639c..cac1facd 100644 --- a/src/Heating/Sensors/ThermocoupleSensor31856.h +++ b/src/Heating/Sensors/ThermocoupleSensor31856.h @@ -14,12 +14,12 @@ class ThermocoupleSensor31856 : public SpiTemperatureSensor { public: ThermocoupleSensor31856(unsigned int sensorNum) noexcept; - GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override; + GCodeResult Configure(GCodeBuffer& gb, const StringRef& reply) override THROWS(GCodeException); + void Poll() noexcept override; + const char *GetShortSensorType() const noexcept override { return TypeName; } static constexpr const char *TypeName = "thermocouplemax31856"; - void Poll() noexcept override; - private: TemperatureError TryInitThermocouple() const noexcept; diff --git a/src/Heating/Sensors/TmcDriverTemperatureSensor.cpp b/src/Heating/Sensors/TmcDriverTemperatureSensor.cpp index 5eb9cefc..4d387c7f 100644 --- a/src/Heating/Sensors/TmcDriverTemperatureSensor.cpp +++ b/src/Heating/Sensors/TmcDriverTemperatureSensor.cpp @@ -16,6 +16,15 @@ TmcDriverTemperatureSensor::TmcDriverTemperatureSensor(unsigned int sensorNum, u { } +const char *TmcDriverTemperatureSensor::GetShortSensorType() const noexcept +{ +#ifdef DUET_NG + return (channel == 1) ? DuexTypeName : PrimaryTypeName; +#else + return PrimaryTypeName; +#endif +} + void TmcDriverTemperatureSensor::Poll() noexcept { SetResult(reprap.GetPlatform().GetTmcDriversTemperature(channel), TemperatureError::success); diff --git a/src/Heating/Sensors/TmcDriverTemperatureSensor.h b/src/Heating/Sensors/TmcDriverTemperatureSensor.h index e16534fe..a7d842cc 100644 --- a/src/Heating/Sensors/TmcDriverTemperatureSensor.h +++ b/src/Heating/Sensors/TmcDriverTemperatureSensor.h @@ -17,16 +17,15 @@ class TmcDriverTemperatureSensor : public TemperatureSensor public: TmcDriverTemperatureSensor(unsigned int sensorNum, unsigned int chan) noexcept; + int GetSmartDriversChannel() const noexcept override { return (int) channel; } // Get the smart drivers channel that this sensor monitors, or -1 if it doesn't + void Poll() noexcept override; + const char *GetShortSensorType() const noexcept override; + static constexpr const char *PrimaryTypeName = "drivers"; #ifdef DUET_NG static constexpr const char *DuexTypeName = "drivers-duex"; #endif - // Get the smart drivers channel that this sensor monitors, or -1 if it doesn't - int GetSmartDriversChannel() const noexcept override { return (int) channel; } - - void Poll() noexcept override; - private: unsigned int channel; }; diff --git a/src/ObjectModel/ObjectModel.cpp b/src/ObjectModel/ObjectModel.cpp index e7bba1a4..ac885501 100644 --- a/src/ObjectModel/ObjectModel.cpp +++ b/src/ObjectModel/ObjectModel.cpp @@ -9,57 +9,55 @@ #if SUPPORT_OBJECT_MODEL +#include <RepRap.h> +#include <Platform.h> #include <OutputMemory.h> #include <cstring> #include <General/SafeStrtod.h> #include <General/IP4String.h> -ExpressionValue::ExpressionValue(const MacAddress& mac) noexcept : type(TYPE_OF(MacAddress)), param(mac.HighWord()), uVal(mac.LowWord()) +ExpressionValue::ExpressionValue(const MacAddress& mac) noexcept : type((uint32_t)TypeCode::MacAddress), param(mac.HighWord()), uVal(mac.LowWord()) { } // Append a string representation of this value to a string void ExpressionValue::AppendAsString(const StringRef& str) const noexcept { - switch (type) + switch (GetType()) { - case TYPE_OF(char): + case TypeCode::Char: str.cat(cVal); break; - case TYPE_OF(const char*): + case TypeCode::CString: str.cat(sVal); break; - case TYPE_OF(float): + case TypeCode::Float: str.catf(GetFloatFormatString(), (double)fVal); break; - case TYPE_OF(uint32_t): + case TypeCode::Uint32: str.catf("%" PRIu32, uVal); // convert unsigned integer to string break; - case TYPE_OF(int32_t): + case TypeCode::Int32: str.catf("%" PRIi32, uVal); // convert signed integer to string break; - case TYPE_OF(bool): + case TypeCode::Bool: str.cat((bVal) ? "true" : "false"); // convert bool to string break; - case TYPE_OF(IPAddress): + case TypeCode::IPAddress: str.cat(IP4String(uVal).c_str()); break; - case TYPE_OF(const ObjectModel*): - str.cat("{object}"); - break; - - case NoType: + case TypeCode::None: str.cat("null"); break; - case TYPE_OF(DateTime): + case TypeCode::DateTime: { const time_t time = Get56BitValue(); tm timeInfo; @@ -69,7 +67,7 @@ void ExpressionValue::AppendAsString(const StringRef& str) const noexcept } break; - case TYPE_OF(DriverId): + case TypeCode::DriverId: #if SUPPORT_CAN_EXPANSION str.catf("%u.%u", (unsigned int)(uVal >> 8), (unsigned int)(uVal & 0xFF)); #else @@ -77,20 +75,44 @@ void ExpressionValue::AppendAsString(const StringRef& str) const noexcept #endif break; - case TYPE_OF(MacAddress): + case TypeCode::MacAddress: str.catf("%02x:%02x:%02x:%02x:%02x:%02x", (unsigned int)(uVal & 0xFF), (unsigned int)((uVal >> 8) & 0xFF), (unsigned int)((uVal >> 16) & 0xFF), (unsigned int)((uVal >> 24) & 0xFF), (unsigned int)(param & 0xFF), (unsigned int)((param >> 8) & 0xFF)); break; #if SUPPORT_CAN_EXPANSION - case TYPE_OF(CanExpansionBoardDetails): + case TypeCode::CanExpansionBoardDetails: ExtractRequestedPart(str); break; #endif - default: - str.cat("<unknown type>"); + case TypeCode::Special: + switch ((SpecialType)param) + { + case SpecialType::sysDir: + reprap.GetPlatform().AppendSysDir(str); + break; + } + break; + + // We don't fully handle the remaining types + case TypeCode::ObjectModel: + str.cat("{object}"); + break; + + case TypeCode::Array: + str.cat("[array]"); + break; + + case TypeCode::Bitmap16: + case TypeCode::Bitmap32: + case TypeCode::Bitmap64: + str.cat("(Bitmap)"); + break; + + case TypeCode::Enum32: + str.cat("(enumeration)"); break; } } @@ -310,18 +332,18 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& if (context.WantArrayLength() && *filter == 0) { // We have been asked for the length of an array and we have reached the end of the filter, so the value should be an array - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(const ObjectModelArrayDescriptor*): + case TypeCode::Array: buf->catf("%u", val.omadVal->GetNumElements(this, context)); break; - case TYPE_OF(Bitmap<uint16_t>): - case TYPE_OF(Bitmap<uint32_t>): + case TypeCode::Bitmap16: + case TypeCode::Bitmap32: buf->catf("%u", Bitmap<uint32_t>::MakeFromRaw(val.uVal).CountSetBits()); break; - case TYPE_OF(Bitmap<uint64_t>): + case TypeCode::Bitmap64: buf->catf("%u", Bitmap<uint64_t>::MakeFromRaw(val.Get56BitValue()).CountSetBits()); break; @@ -332,9 +354,9 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& } else { - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(const ObjectModelArrayDescriptor*): + case TypeCode::Array: if (*filter == '[') { ++filter; @@ -377,7 +399,7 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& } break; - case TYPE_OF(const ObjectModel*): + case TypeCode::ObjectModel: if (*filter == '.') { ++filter; @@ -390,7 +412,7 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& val.omVal->ReportAsJson(buf, context, val.param, filter); break; - case TYPE_OF(float): + case TypeCode::Float: if (val.fVal == 0.0) { buf->cat('0'); // replace 0.000... in JSON by 0. This is mostly to save space when writing workplace coordinates. @@ -401,26 +423,26 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& } break; - case TYPE_OF(uint32_t): + case TypeCode::Uint32: buf->catf("%" PRIu32, val.uVal); break; - case TYPE_OF(int32_t): + case TypeCode::Int32: buf->catf("%" PRIi32, val.iVal); break; - case TYPE_OF(const char*): + case TypeCode::CString: buf->EncodeString(val.sVal, true); break; #ifdef DUET3 - case TYPE_OF(CanExpansionBoardDetails): + case TypeCode::CanExpansionBoardDetails: ReportExpansionBoardDetail(buf, val); break; #endif - case TYPE_OF(Bitmap<uint16_t>): - case TYPE_OF(Bitmap<uint32_t>): + case TypeCode::Bitmap16: + case TypeCode::Bitmap32: if (*filter == '[') { ++filter; @@ -466,7 +488,7 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& } break; - case TYPE_OF(Bitmap<uint64_t>): + case TypeCode::Bitmap64: if (*filter == '[') { ++filter; @@ -512,7 +534,7 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& } break; - case TYPE_OF(Enum32): + case TypeCode::Enum32: if (context.ShortFormReport()) { buf->catf("%" PRIu32, val.uVal); @@ -524,17 +546,17 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& } break; - case TYPE_OF(bool): + case TypeCode::Bool: buf->cat((val.bVal) ? "true" : "false"); break; - case TYPE_OF(char): + case TypeCode::Char: buf->cat('"'); buf->EncodeChar(val.cVal); buf->cat('"'); break; - case TYPE_OF(IPAddress): + case TypeCode::IPAddress: { const IPAddress ipVal(val.uVal); char sep = '"'; @@ -547,11 +569,11 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& } break; - case TYPE_OF(DateTime): + case TypeCode::DateTime: ReportDateTime(buf, val); break; - case TYPE_OF(DriverId): + case TypeCode::DriverId: #if SUPPORT_CAN_EXPANSION buf->catf("\"%u.%u\"", (unsigned int)(val.uVal >> 8), (unsigned int)(val.uVal & 0xFF)); #else @@ -559,13 +581,22 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext& #endif break; - case TYPE_OF(MacAddress): + case TypeCode::MacAddress: buf->catf("\"%02x:%02x:%02x:%02x:%02x:%02x\"", (unsigned int)(val.uVal & 0xFF), (unsigned int)((val.uVal >> 8) & 0xFF), (unsigned int)((val.uVal >> 16) & 0xFF), (unsigned int)((val.uVal >> 24) & 0xFF), (unsigned int)(val.param & 0xFF), (unsigned int)((val.param >> 8) & 0xFF)); break; - case NoType: + case TypeCode::Special: + switch ((ExpressionValue::SpecialType)val.param) + { + case ExpressionValue::SpecialType::sysDir: + reprap.GetPlatform().EncodeSysDir(buf); + break; + } + break; + + case TypeCode::None: buf->cat("null"); break; } @@ -649,7 +680,7 @@ bool ObjectModelTableEntry::ReportAsJson(OutputBuffer* buf, ObjectExplorationCon { const char * nextElement = ObjectModel::GetNextElement(filter); const ExpressionValue val = func(self, context); - if (val.type != NoType || context.ShouldIncludeNulls()) + if (val.GetType() != TypeCode::None || context.ShouldIncludeNulls()) { if (*filter == 0) { @@ -698,9 +729,9 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, c ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, ExpressionValue val, const char *idString) const { - switch (val.type) + switch (val.GetType()) { - case TYPE_OF(const ObjectModelArrayDescriptor*): + case TypeCode::Array: { if (*idString == 0 && context.WantArrayLength()) { @@ -724,7 +755,7 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, E return GetObjectValue(context, arrayElement, idString + 1); } - case TYPE_OF(const ObjectModel*): + case TypeCode::ObjectModel: switch (*idString) { case 0: @@ -738,15 +769,15 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, E } break; - case NoType: + case TypeCode::None: if (*idString == 0) { return val; // a null value can be compared to null } throw context.ConstructParseException("reached null object before end of selector string"); - case TYPE_OF(Bitmap<uint16_t>): - case TYPE_OF(Bitmap<uint32_t>): + case TypeCode::Bitmap16: + case TypeCode::Bitmap32: if (context.WantArrayLength()) { if (*idString != 0) @@ -776,7 +807,7 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, E } return ExpressionValue((int32_t)val.uVal); - case TYPE_OF(Bitmap<uint64_t>): + case TypeCode::Bitmap64: if (context.WantArrayLength()) { if (*idString != 0) @@ -806,7 +837,7 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, E } return ExpressionValue((int32_t)val.uVal); - case TYPE_OF(MacAddress): + case TypeCode::MacAddress: if (*idString == 0) { return (context.WantArrayLength()) ? ExpressionValue((int32_t)17) : val; @@ -814,7 +845,7 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, E break; #ifdef DUET3 - case TYPE_OF(CanExpansionBoardDetails): + case TypeCode::CanExpansionBoardDetails: if (*idString == 0) { if (context.WantArrayLength()) @@ -826,7 +857,7 @@ ExpressionValue ObjectModel::GetObjectValue(ObjectExplorationContext& context, E break; #endif - case TYPE_OF(const char*): + case TypeCode::CString: if (*idString == 0 && context.WantArrayLength()) { return ExpressionValue((int32_t)strlen(val.sVal)); diff --git a/src/ObjectModel/ObjectModel.h b/src/ObjectModel/ObjectModel.h index 46ee6b8d..db34689d 100644 --- a/src/ObjectModel/ObjectModel.h +++ b/src/ObjectModel/ObjectModel.h @@ -18,13 +18,38 @@ #include <RTOSIface/RTOSIface.h> #include <Networking/NetworkDefs.h> -typedef uint8_t TypeCode; -constexpr TypeCode NoType = 0; // code for an invalid or unknown type +// Type codes to indicate what type of expression we have and how it is represented. +// The "Special" type is for items that we have to evaluate when we are ready to write them out, in particular strings whose storage might disappear. +enum class TypeCode : uint8_t +{ + None = 0, + Bool, + Char, + Uint32, + Int32, + Float, + Bitmap16, + Bitmap32, + Bitmap64, // only 56 bits actually available + Enum32, + ObjectModel, + CString, + IPAddress, + Array, + DateTime, + DriverId, + MacAddress, + Special, +#if SUPPORT_CAN_EXPANSION + CanExpansionBoardDetails +#endif +}; // Dummy types, used to define type codes class Bitmap32; class Bitmap64; class Enum32; +class SpecialString; #if SUPPORT_CAN_EXPANSION @@ -48,33 +73,6 @@ struct DateTime time_t tim; }; -// Function template used to get constexpr type codes -// Each type must return a unique type code in the range 1 to 127 (0 is NoType) -template<class T> constexpr TypeCode TypeOf() noexcept; - -template<> constexpr TypeCode TypeOf<bool> () noexcept { return 1; } -template<> constexpr TypeCode TypeOf<char> () noexcept { return 2; } -template<> constexpr TypeCode TypeOf<uint32_t> () noexcept { return 3; } -template<> constexpr TypeCode TypeOf<int32_t> () noexcept { return 4; } -template<> constexpr TypeCode TypeOf<float> () noexcept { return 5; } -template<> constexpr TypeCode TypeOf<Bitmap<uint16_t>> () noexcept { return 6; } -template<> constexpr TypeCode TypeOf<Bitmap<uint32_t>> () noexcept { return 7; } -template<> constexpr TypeCode TypeOf<Bitmap<uint64_t>> () noexcept { return 8; } -template<> constexpr TypeCode TypeOf<Enum32> () noexcept { return 9; } -template<> constexpr TypeCode TypeOf<const ObjectModel*> () noexcept { return 10; } -template<> constexpr TypeCode TypeOf<const char*> () noexcept { return 11; } -template<> constexpr TypeCode TypeOf<IPAddress> () noexcept { return 12; } -template<> constexpr TypeCode TypeOf<const ObjectModelArrayDescriptor*> () noexcept { return 13; } -template<> constexpr TypeCode TypeOf<DateTime> () noexcept { return 14; } -template<> constexpr TypeCode TypeOf<DriverId> () noexcept { return 15; } -template<> constexpr TypeCode TypeOf<MacAddress> () noexcept { return 16; } - -#if SUPPORT_CAN_EXPANSION -template<> constexpr TypeCode TypeOf<CanExpansionBoardDetails> () noexcept { return 17; } -#endif - -#define TYPE_OF(_t) (TypeOf<_t>()) - // Forward declarations class ObjectModelTableEntry; class ObjectModel; @@ -97,33 +95,42 @@ struct ExpressionValue const ObjectModelArrayDescriptor *omadVal; }; - ExpressionValue() noexcept : type(NoType) { } - explicit constexpr ExpressionValue(bool b) noexcept : type(TYPE_OF(bool)), param(0), bVal(b) { } - explicit constexpr ExpressionValue(char c) noexcept : type(TYPE_OF(char)), param(0), cVal(c) { } - explicit constexpr ExpressionValue(float f) noexcept : type(TYPE_OF(float)), param(MaxFloatDigitsDisplayedAfterPoint), fVal(f) { } - constexpr ExpressionValue(float f, uint8_t numDecimalPlaces) noexcept : type(TYPE_OF(float)), param(numDecimalPlaces), fVal(f) { } - explicit constexpr ExpressionValue(int32_t i) noexcept : type(TYPE_OF(int32_t)), param(0), iVal(i) { } - explicit constexpr ExpressionValue(const ObjectModel *om) noexcept : type((om == nullptr) ? NoType : TYPE_OF(const ObjectModel*)), param(0), omVal(om) { } - constexpr ExpressionValue(const ObjectModel *om, uint8_t tableNumber) noexcept : type((om == nullptr) ? NoType : TYPE_OF(const ObjectModel*)), param(tableNumber), omVal(om) { } - explicit constexpr ExpressionValue(const char *s) noexcept : type(TYPE_OF(const char*)), param(0), sVal(s) { } - explicit constexpr ExpressionValue(const ObjectModelArrayDescriptor *omad) noexcept : type(TYPE_OF(const ObjectModelArrayDescriptor*)), param(0), omadVal(omad) { } - explicit constexpr ExpressionValue(IPAddress ip) noexcept : type(TYPE_OF(IPAddress)), param(0), uVal(ip.GetV4LittleEndian()) { } - explicit constexpr ExpressionValue(nullptr_t dummy) noexcept : type(NoType), param(0), uVal(0) { } - explicit ExpressionValue(DateTime t) noexcept : type((t.tim == 0) ? NoType : TYPE_OF(DateTime)), param(t.tim >> 32), uVal((uint32_t)t.tim) { } - explicit ExpressionValue(DriverId id) noexcept : type(TYPE_OF(DriverId)), param(0), uVal(id.AsU32()) { } - explicit ExpressionValue(Bitmap<uint16_t> bm) noexcept : type(TYPE_OF(Bitmap<uint16_t>)), param(0), uVal(bm.GetRaw()) { } - explicit ExpressionValue(Bitmap<uint32_t> bm) noexcept : type(TYPE_OF(Bitmap<uint32_t>)), param(0), uVal(bm.GetRaw()) { } - explicit ExpressionValue(Bitmap<uint64_t> bm) noexcept : type(TYPE_OF(Bitmap<uint64_t>)), param(bm.GetRaw() >> 32), uVal((uint32_t)bm.GetRaw()) { } + enum class SpecialType : uint32_t + { + sysDir = 0 + }; + + ExpressionValue() noexcept : type((uint32_t)TypeCode::None) { } + explicit constexpr ExpressionValue(bool b) noexcept : type((uint32_t)TypeCode::Bool), param(0), bVal(b) { } + explicit constexpr ExpressionValue(char c) noexcept : type((uint32_t)TypeCode::Char), param(0), cVal(c) { } + explicit constexpr ExpressionValue(float f) noexcept : type((uint32_t)TypeCode::Float), param(MaxFloatDigitsDisplayedAfterPoint), fVal(f) { } + constexpr ExpressionValue(float f, uint8_t numDecimalPlaces) noexcept : type((uint32_t)TypeCode::Float), param(numDecimalPlaces), fVal(f) { } + explicit constexpr ExpressionValue(int32_t i) noexcept : type((uint32_t)TypeCode::Int32), param(0), iVal(i) { } + explicit constexpr ExpressionValue(const ObjectModel *om) noexcept : type((om == nullptr) ? (uint32_t)TypeCode::None : (uint32_t)TypeCode::ObjectModel), param(0), omVal(om) { } + constexpr ExpressionValue(const ObjectModel *om, uint8_t tableNumber) noexcept : type((om == nullptr) ? (uint32_t)TypeCode::None : (uint32_t)TypeCode::ObjectModel), param(tableNumber), omVal(om) { } + explicit constexpr ExpressionValue(const char *s) noexcept : type((uint32_t)TypeCode::CString), param(0), sVal(s) { } + explicit constexpr ExpressionValue(const ObjectModelArrayDescriptor *omad) noexcept : type((uint32_t)TypeCode::Array), param(0), omadVal(omad) { } + explicit constexpr ExpressionValue(IPAddress ip) noexcept : type((uint32_t)TypeCode::IPAddress), param(0), uVal(ip.GetV4LittleEndian()) { } + explicit constexpr ExpressionValue(nullptr_t dummy) noexcept : type((uint32_t)TypeCode::None), param(0), uVal(0) { } + explicit ExpressionValue(DateTime t) noexcept : type((t.tim == 0) ? (uint32_t)TypeCode::None : (uint32_t)TypeCode::DateTime), param(t.tim >> 32), uVal((uint32_t)t.tim) { } + explicit ExpressionValue(DriverId id) noexcept : type((uint32_t)TypeCode::DriverId), param(0), uVal(id.AsU32()) { } + explicit ExpressionValue(Bitmap<uint16_t> bm) noexcept : type((uint32_t)TypeCode::Bitmap16), param(0), uVal(bm.GetRaw()) { } + explicit ExpressionValue(Bitmap<uint32_t> bm) noexcept : type((uint32_t)TypeCode::Bitmap32), param(0), uVal(bm.GetRaw()) { } + explicit ExpressionValue(Bitmap<uint64_t> bm) noexcept : type((uint32_t)TypeCode::Bitmap64), param(bm.GetRaw() >> 32), uVal((uint32_t)bm.GetRaw()) { } explicit ExpressionValue(const MacAddress& mac) noexcept; + explicit ExpressionValue(SpecialType s) noexcept : type((uint32_t)TypeCode::Special), param((uint32_t)s), uVal(0) { } #if SUPPORT_CAN_EXPANSION - ExpressionValue(const char*s, ExpansionDetail p) noexcept : type(TYPE_OF(CanExpansionBoardDetails)), param((uint32_t)p), sVal(s) { } + ExpressionValue(const char*s, ExpansionDetail p) noexcept : type((uint32_t)TypeCode::CanExpansionBoardDetails), param((uint32_t)p), sVal(s) { } #endif - void Set(bool b) noexcept { type = TYPE_OF(bool); bVal = b; } - void Set(char c) noexcept { type = TYPE_OF(char); cVal = c; } - void Set(int32_t i) noexcept { type = TYPE_OF(int32_t); iVal = i; } - void Set(float f) noexcept { type = TYPE_OF(float); fVal = f; param = 1; } - void Set(const char *s) noexcept { type = TYPE_OF(const char*); sVal = s; } + TypeCode GetType() const noexcept { return (TypeCode)type; } + void SetType(TypeCode t) noexcept { type = (uint32_t)t; } + + void Set(bool b) noexcept { type = (uint32_t)TypeCode::Bool; bVal = b; } + void Set(char c) noexcept { type = (uint32_t)TypeCode::Char; cVal = c; } + void Set(int32_t i) noexcept { type = (uint32_t)TypeCode::Int32; iVal = i; } + void Set(float f) noexcept { type = (uint32_t)TypeCode::Float; fVal = f; param = 1; } + void Set(const char *s) noexcept { type = (uint32_t)TypeCode::CString; sVal = s; } // Extract a 56-bit value that we have stored. Used to retrieve date/times and large bitmaps. uint64_t Get56BitValue() const noexcept { return ((uint64_t)param << 32) | uVal; } diff --git a/src/Platform.cpp b/src/Platform.cpp index 9fbfa6c6..ddfd8f25 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -239,7 +239,7 @@ constexpr ObjectModelTableEntry Platform::objectModelTable[] = { "shortName", OBJECT_MODEL_FUNC_NOSELF(BOARD_SHORT_NAME), ObjectModelEntryFlags::none }, # endif #if HAS_12V_MONITOR - { "v12", OBJECT_MODEL_FUNC(self, 6), ObjectModelEntryFlags::live }, + { "v12", OBJECT_MODEL_FUNC(self, 7), ObjectModelEntryFlags::live }, #endif { "vIn", OBJECT_MODEL_FUNC(self, 2), ObjectModelEntryFlags::live }, @@ -280,8 +280,16 @@ constexpr ObjectModelTableEntry Platform::objectModelTable[] = { "b", OBJECT_MODEL_FUNC(self->nonlinearExtrusionB[context.GetLastIndex()], 3), ObjectModelEntryFlags::none }, { "upperLimit", OBJECT_MODEL_FUNC(self->nonlinearExtrusionLimit[context.GetLastIndex()], 2), ObjectModelEntryFlags::none }, + // 6. directories members + { "filaments", OBJECT_MODEL_FUNC_NOSELF(FILAMENTS_DIRECTORY), ObjectModelEntryFlags::verbose }, + { "gcodes", OBJECT_MODEL_FUNC(self->GetGCodeDir()), ObjectModelEntryFlags::verbose }, + { "macros", OBJECT_MODEL_FUNC(self->GetMacroDir()), ObjectModelEntryFlags::verbose }, + { "menu", OBJECT_MODEL_FUNC_NOSELF(MENU_DIR), ObjectModelEntryFlags::verbose }, + { "system", OBJECT_MODEL_FUNC_NOSELF(ExpressionValue::SpecialType::sysDir), ObjectModelEntryFlags::none }, + { "web", OBJECT_MODEL_FUNC(self->GetWebDir()), ObjectModelEntryFlags::verbose }, + #if HAS_12V_MONITOR - // 6. v12 members + // 7. v12 members { "current", OBJECT_MODEL_FUNC(self->GetV12Voltages().current, 1), ObjectModelEntryFlags::live }, { "max", OBJECT_MODEL_FUNC(self->GetV12Voltages().max, 1), ObjectModelEntryFlags::none }, { "min", OBJECT_MODEL_FUNC(self->GetV12Voltages().min, 1), ObjectModelEntryFlags::none }, @@ -291,13 +299,14 @@ constexpr ObjectModelTableEntry Platform::objectModelTable[] = constexpr uint8_t Platform::objectModelTableDescriptor[] = { - 6 + HAS_12V_MONITOR, // number of sections + 7 + HAS_12V_MONITOR, // number of sections 9 + HAS_LINUX_INTERFACE + HAS_12V_MONITOR + SUPPORT_CAN_EXPANSION, // section 0: boards[] 3, // section 1: mcuTemp 3, // section 2: vIn 13, // section 3: move.axes[] 5, // section 4: move.extruders[] 3, // section 5: move.extruders[].nonlinear + 6, // section 6: directories #if HAS_12V_MONITOR 3 // section 7: v12 #endif @@ -3777,10 +3786,16 @@ bool Platform::MakeSysFileName(const StringRef& result, const char *filename) co return MassStorage::CombineName(result, InternalGetSysDir(), filename); } -void Platform::GetSysDir(const StringRef & path) const noexcept +void Platform::AppendSysDir(const StringRef & path) const noexcept +{ + MutexLocker lock(Tasks::GetSysDirMutex()); + path.cat(InternalGetSysDir()); +} + +void Platform::EncodeSysDir(OutputBuffer *buf) const noexcept { MutexLocker lock(Tasks::GetSysDirMutex()); - path.copy(InternalGetSysDir()); + buf->EncodeString(InternalGetSysDir(), false); } #endif diff --git a/src/Platform.h b/src/Platform.h index e5d25762..171e174c 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -359,7 +359,8 @@ public: FileStore* OpenSysFile(const char *filename, OpenMode mode) const noexcept; bool DeleteSysFile(const char *filename) const noexcept; bool MakeSysFileName(const StringRef& result, const char *filename) const noexcept; - void GetSysDir(const StringRef & path) const noexcept; + void AppendSysDir(const StringRef & path) const noexcept; + void EncodeSysDir(OutputBuffer *buf) const noexcept; #endif // Message output (see MessageType for further details) diff --git a/src/RepRap.cpp b/src/RepRap.cpp index 36f81b51..a8817c6f 100644 --- a/src/RepRap.cpp +++ b/src/RepRap.cpp @@ -167,6 +167,7 @@ constexpr ObjectModelTableEntry RepRap::objectModelTable[] = // Within each group, these entries must be in alphabetical order // 0. MachineModel root { "boards", OBJECT_MODEL_FUNC_NOSELF(&boardsArrayDescriptor), ObjectModelEntryFlags::live }, + { "directories", OBJECT_MODEL_FUNC(self->platform, 6), ObjectModelEntryFlags::live }, { "fans", OBJECT_MODEL_FUNC_NOSELF(&fansArrayDescriptor), ObjectModelEntryFlags::live }, { "heat", OBJECT_MODEL_FUNC(self->heat), ObjectModelEntryFlags::live }, { "inputs", OBJECT_MODEL_FUNC_NOSELF(&inputsArrayDescriptor), ObjectModelEntryFlags::live }, @@ -216,7 +217,7 @@ constexpr ObjectModelTableEntry RepRap::objectModelTable[] = { "zProbes", OBJECT_MODEL_FUNC_NOSELF((int32_t)MaxZProbes), ObjectModelEntryFlags::verbose }, }; -constexpr uint8_t RepRap::objectModelTableDescriptor[] = { 3, 11, 5, 20 }; +constexpr uint8_t RepRap::objectModelTableDescriptor[] = { 3, 12, 5, 20 }; DEFINE_GET_OBJECT_MODEL_TABLE(RepRap) @@ -1695,12 +1696,8 @@ OutputBuffer *RepRap::GetConfigResponse() noexcept #if HAS_MASS_STORAGE // System files folder - { - String<MaxFilenameLength> sysdir; - platform->GetSysDir(sysdir.GetRef()); - response->catf(", \"sysdir\":"); - response->EncodeString(sysdir, false); - } + response->catf(", \"sysdir\":"); + platform->EncodeSysDir(response); #endif // Motor idle parameters diff --git a/src/Version.h b/src/Version.h index 1a717162..72c91e09 100644 --- a/src/Version.h +++ b/src/Version.h @@ -19,7 +19,7 @@ #endif #ifndef DATE -# define DATE "2020-03-09b2" +# define DATE "2020-03-10b1" #endif #define AUTHORS "reprappro, dc42, chrishamm, t3p3, dnewman, printm3d" |