Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2020-01-19 02:03:39 +0300
committerDavid Crocker <dcrocker@eschertech.com>2020-01-19 02:03:39 +0300
commitc812ce5e14cf476526d955edbce2effa9d922902 (patch)
treeda67dc55e46efdd38a0647318977a342da730345 /src/ObjectModel
parente0bbf71357b07c22e6d43be3cca5c7422163be32 (diff)
Major refactoring, bug fixes in function evaluation
Changed all bitmaps to use the bitmap class from RRFLibraries Fixed bugs in functoin evaluation
Diffstat (limited to 'src/ObjectModel')
-rw-r--r--src/ObjectModel/ObjectModel.cpp94
-rw-r--r--src/ObjectModel/ObjectModel.h50
2 files changed, 113 insertions, 31 deletions
diff --git a/src/ObjectModel/ObjectModel.cpp b/src/ObjectModel/ObjectModel.cpp
index 74fe3af0..d6d448a1 100644
--- a/src/ObjectModel/ObjectModel.cpp
+++ b/src/ObjectModel/ObjectModel.cpp
@@ -14,6 +14,14 @@
#include <cstring>
#include <General/SafeStrtod.h>
+// Get the format string to use assuming this is a floating point number
+const char *ExpressionValue::GetFloatFormatString() const noexcept
+{
+ static constexpr const char *FormatStrings[] = { "%.7f", "%.1f", "%.2f", "%.3f", "%.4f", "%.5f", "%.6f", "%.7f" };
+ static_assert(ARRAY_SIZE(FormatStrings) == MaxFloatDigitsDisplayedAfterPoint + 1);
+ return FormatStrings[min<unsigned int>(param, MaxFloatDigitsDisplayedAfterPoint)];
+}
+
void ObjectExplorationContext::AddIndex(int32_t index)
{
if (numIndicesCounted == MaxIndices)
@@ -225,7 +233,7 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext&
break;
case TYPE_OF(float):
- buf->catf((val.param == 3) ? "%.3f" : (val.param == 2) ? "%.2f" : "%.1f", (double)val.fVal);
+ buf->catf(val.GetFloatFormatString(), (double)val.fVal);
break;
case TYPE_OF(uint32_t):
@@ -240,22 +248,86 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext&
buf->EncodeString(val.sVal, true);
break;
- case TYPE_OF(Bitmap32):
+ case TYPE_OF(Bitmap<uint16_t>):
+ if (context.ShortFormReport())
+ {
+ buf->catf("%" PRIu16, (uint16_t)val.uVal);
+ }
+ else
+ {
+ Bitmap<uint16_t> bm = Bitmap<uint16_t>::MakeFromRaw((uint16_t)val.uVal);
+ buf->cat('[');
+ bool first = true;
+ bm.Iterate
+ ([buf, &first](unsigned int bn)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ buf->cat(',');
+ }
+ buf->catf("%u", bn);
+ }
+ );
+ buf->cat(']');
+ }
+ break;
+
+ case TYPE_OF(Bitmap<uint32_t>):
if (context.ShortFormReport())
{
buf->catf("%" PRIu32, val.uVal);
}
else
{
- uint32_t v = val.uVal;
+ Bitmap<uint32_t> bm = Bitmap<uint32_t>::MakeFromRaw(val.uVal);
buf->cat('[');
- buf->cat((v & 1) ? '1' : '0');
- for (unsigned int i = 1; i < 32; ++i)
- {
- v >>= 1;
- buf->cat(',');
- buf->cat((v & 1) ? '1' : '0');
- }
+ bool first = true;
+ bm.Iterate
+ ([buf, &first](unsigned int bn)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ buf->cat(',');
+ }
+ buf->catf("%u", bn);
+ }
+ );
+ buf->cat(']');
+ }
+ break;
+
+ case TYPE_OF(Bitmap<uint64_t>):
+ if (context.ShortFormReport())
+ {
+ buf->catf("%" PRIu64, val.Get56BitValue());
+ }
+ else
+ {
+ Bitmap<uint64_t> bm = Bitmap<uint64_t>::MakeFromRaw(val.Get56BitValue());
+ buf->cat('[');
+ bool first = true;
+ bm.Iterate
+ ([buf, &first](unsigned int bn)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ buf->cat(',');
+ }
+ buf->catf("%u", bn);
+ }
+ );
buf->cat(']');
}
break;
@@ -297,7 +369,7 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext&
case TYPE_OF(DateTime):
{
- const time_t time = val.Get40BitValue();
+ const time_t time = val.Get56BitValue();
tm timeInfo;
gmtime_r(&time, &timeInfo);
buf->catf("\"%04u-%02u-%02uT%02u:%02u:%02u\"",
diff --git a/src/ObjectModel/ObjectModel.h b/src/ObjectModel/ObjectModel.h
index f6514d8d..eac396fc 100644
--- a/src/ObjectModel/ObjectModel.h
+++ b/src/ObjectModel/ObjectModel.h
@@ -14,6 +14,7 @@
#if SUPPORT_OBJECT_MODEL
#include <General/IPAddress.h>
+#include <General/Bitmap.h>
#include <RTOSIface/RTOSIface.h>
typedef uint8_t TypeCode;
@@ -21,6 +22,7 @@ constexpr TypeCode NoType = 0; // code for an invalid or unknown type
// Dummy types, used to define type codes
class Bitmap32;
+class Bitmap64;
class Enum32;
class ObjectModel; // forward declaration
class ObjectModelArrayDescriptor; // forward declaration
@@ -37,19 +39,21 @@ struct DateTime
// 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<Bitmap32>() noexcept { return 6; }
-template<> constexpr TypeCode TypeOf<Enum32>() noexcept { return 7; }
-template<> constexpr TypeCode TypeOf<const ObjectModel*>() noexcept { return 8; }
-template<> constexpr TypeCode TypeOf<const char*>() noexcept { return 9; }
-template<> constexpr TypeCode TypeOf<IPAddress>() noexcept { return 10; }
-template<> constexpr TypeCode TypeOf<const ObjectModelArrayDescriptor*>() noexcept { return 11; }
-template<> constexpr TypeCode TypeOf<DateTime>() noexcept { return 12; }
-template<> constexpr TypeCode TypeOf<DriverId>() noexcept { return 13; }
+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; }
#define TYPE_OF(_t) (TypeOf<_t>())
@@ -61,9 +65,9 @@ class StringParser;
// Struct used to hold the expressions with polymorphic types
struct ExpressionValue
{
- TypeCode type; // what type is stored in the union
- uint8_t param; // additional parameter, e.g. number of usual displayed decimal places for a float,
- // or table # for an ObjectModel, or 8 extra bits for a date/time
+ uint32_t type : 8, // what type is stored in the union
+ param : 24; // additional parameter, e.g. number of usual displayed decimal places for a float,
+ // or table # for an ObjectModel, or 24 extra bits for a date/time or a long bitmap
union
{
bool bVal;
@@ -72,14 +76,14 @@ struct ExpressionValue
int32_t iVal;
uint32_t uVal; // used for enumerations, bitmaps and IP addresses (not for integers, we always use int32_t for those)
const char *sVal;
- const ObjectModel *omVal; // object of some class derived form ObkectModel
+ const ObjectModel *omVal; // object of some class derived form ObjectModel
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(1), fVal(f) { }
+ 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(TYPE_OF(const ObjectModel*)), param(0), omVal(om) { }
@@ -90,6 +94,9 @@ struct ExpressionValue
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()) { }
void Set(bool b) noexcept { type = TYPE_OF(bool); bVal = b; }
void Set(char c) noexcept { type = TYPE_OF(char); cVal = c; }
@@ -98,8 +105,11 @@ struct ExpressionValue
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; }
- // Extract a 40-bit value that we have stored. Used to retrieve date/times.
- uint64_t Get40BitValue() const noexcept { return ((uint64_t)param << 32) | uVal; }
+ // 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; }
+
+ // Get the format string to use assuming this is a floating point number
+ const char *GetFloatFormatString() const noexcept;
};
// Flags field of a table entry