diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-02-14 16:12:33 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-02-14 16:12:33 +0300 |
commit | 4f593f75c86cc035d7cdcd744e6a52ca940aa2d5 (patch) | |
tree | f5b48208f940c191b937f8b3efed0281ae942146 | |
parent | 252f7739eb448c4a24bfb000a01f72facfe8e019 (diff) |
Added SD card partition size to M39 response and object model
-rw-r--r-- | src/GCodes/GCodes2.cpp | 28 | ||||
-rw-r--r-- | src/Storage/MassStorage.cpp | 36 | ||||
-rw-r--r-- | src/Storage/MassStorage.h | 11 | ||||
-rw-r--r-- | src/Version.h | 2 |
4 files changed, 46 insertions, 31 deletions
diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp index cb42348e..43b7dcc0 100644 --- a/src/GCodes/GCodes2.cpp +++ b/src/GCodes/GCodes2.cpp @@ -1237,16 +1237,15 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx gb.TryGetUIValue('P', slot, dummy); int32_t format = 0; gb.TryGetIValue('S', format, dummy); - uint64_t capacity, freeSpace; - uint32_t speed; - uint32_t clSize; - const MassStorage::InfoResult res = MassStorage::GetCardInfo(slot, capacity, freeSpace, speed, clSize); + MassStorage::SdCardReturnedInfo returnedInfo; + const MassStorage::InfoResult res = MassStorage::GetCardInfo(slot, returnedInfo); if (format == 2) { reply.printf("{\"SDinfo\":{\"slot\":%" PRIu32 ",\"present\":", slot); if (res == MassStorage::InfoResult::ok) { - reply.catf("1,\"capacity\":%" PRIu64 ",\"free\":%" PRIu64 ",\"speed\":%" PRIu32 ",\"clsize\":%" PRIu32 "}}", capacity, freeSpace, speed, clSize); + reply.catf("1,\"capacity\":%" PRIu64 ",\"partitionSize\":%" PRIu64 ",\"free\":%" PRIu64 ",\"speed\":%" PRIu32 ",\"clsize\":%" PRIu32 "}}", + returnedInfo.cardCapacity, returnedInfo.partitionSize, returnedInfo.freeSpace, returnedInfo.speed, returnedInfo.clSize); } else { @@ -1269,16 +1268,15 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx break; case MassStorage::InfoResult::ok: - reply.printf("SD card in slot %" PRIu32 ": capacity %.2fGb, free space %.2fGb, speed %.2fMBytes/sec, cluster size ", - slot, (double)capacity/(1000*1000*1000), (double)freeSpace/(1000*1000*1000), (double)speed/(1000*1000)); - if (clSize < 1024) - { - reply.catf("%" PRIu32 " bytes", clSize); - } - else - { - reply.catf("%" PRIu32 "kb", clSize/1024); - } + reply.printf("SD card in slot %" PRIu32 ": capacity %.2fGb, partition size %.2fGb, free space %.2fGb, speed %.2fMBytes/sec, cluster size %" PRIu32 "%s", + slot, + (double)((float)returnedInfo.cardCapacity * 1e-9), + (double)((float)returnedInfo.partitionSize * 1e-9), + (double)((float)returnedInfo.freeSpace * 1e-9), + (double)((float)returnedInfo.speed * 1e-6), + (returnedInfo.clSize < 1024) ? returnedInfo.clSize : returnedInfo.clSize/1024, + (returnedInfo.clSize < 1024) ? " bytes" : "kb" + ); break; } } diff --git a/src/Storage/MassStorage.cpp b/src/Storage/MassStorage.cpp index 8529c02d..d67ac669 100644 --- a/src/Storage/MassStorage.cpp +++ b/src/Storage/MassStorage.cpp @@ -85,13 +85,19 @@ void SdCardInfo::Clear(unsigned int card) noexcept #define OBJECT_MODEL_FUNC(...) OBJECT_MODEL_FUNC_BODY(SdCardInfo, __VA_ARGS__) #define OBJECT_MODEL_FUNC_IF(_condition,...) OBJECT_MODEL_FUNC_IF_BODY(SdCardInfo, _condition,__VA_ARGS__) -static uint64_t GetFreeSpace(size_t slot) +// These two functions are only called from one place each in the OM table, hence inlined +static inline uint64_t GetFreeSpace(size_t slot) { - uint64_t capacity, freeSpace; - uint32_t speed; - uint32_t clSize; - (void)MassStorage::GetCardInfo(slot, capacity, freeSpace, speed, clSize); - return freeSpace; + MassStorage::SdCardReturnedInfo returnedInfo; + (void)MassStorage::GetCardInfo(slot, returnedInfo); + return returnedInfo.freeSpace; +} + +static inline uint64_t GetPartitionSize(size_t slot) +{ + MassStorage::SdCardReturnedInfo returnedInfo; + (void)MassStorage::GetCardInfo(slot, returnedInfo); + return returnedInfo.partitionSize; } static const char * const VolPathNames[] = { "0:/", "1:/" }; @@ -109,6 +115,7 @@ constexpr ObjectModelTableEntry SdCardInfo::objectModelTable[] = { "freeSpace", OBJECT_MODEL_FUNC_IF(self->isMounted, GetFreeSpace(context.GetLastIndex())), ObjectModelEntryFlags::none }, { "mounted", OBJECT_MODEL_FUNC(self->isMounted), ObjectModelEntryFlags::none }, { "openFiles", OBJECT_MODEL_FUNC_IF(self->isMounted, MassStorage::AnyFileOpen(&(self->fileSystem))), ObjectModelEntryFlags::none }, + { "partitionSize", OBJECT_MODEL_FUNC_IF(self->isMounted, GetPartitionSize(context.GetLastIndex())), ObjectModelEntryFlags::none }, { "path", OBJECT_MODEL_FUNC_NOSELF(VolPathNames[context.GetLastIndex()]), ObjectModelEntryFlags::verbose }, { "speed", OBJECT_MODEL_FUNC_IF(self->isMounted, (int32_t)sd_mmc_get_interface_speed(context.GetLastIndex())), ObjectModelEntryFlags::none }, }; @@ -119,7 +126,7 @@ constexpr ObjectModelTableEntry SdCardInfo::objectModelTable[] = path = null */ -constexpr uint8_t SdCardInfo::objectModelTableDescriptor[] = { 1, 6 }; +constexpr uint8_t SdCardInfo::objectModelTableDescriptor[] = { 1, 7 }; DEFINE_GET_OBJECT_MODEL_TABLE(SdCardInfo) @@ -1207,7 +1214,7 @@ void MassStorage::RecordSimulationTime(const char *printingFilePath, uint32_t si } // Get information about the SD card and interface speed -MassStorage::InfoResult MassStorage::GetCardInfo(size_t slot, uint64_t& capacity, uint64_t& freeSpace, uint32_t& speed, uint32_t& clSize) noexcept +MassStorage::InfoResult MassStorage::GetCardInfo(size_t slot, SdCardReturnedInfo& returnedInfo) noexcept { if (slot >= GetNumVolumes()) { @@ -1220,8 +1227,8 @@ MassStorage::InfoResult MassStorage::GetCardInfo(size_t slot, uint64_t& capacity return InfoResult::noCard; } - capacity = (uint64_t)sd_mmc_get_capacity(slot) * 1024; - speed = sd_mmc_get_interface_speed(slot); + returnedInfo.cardCapacity = (uint64_t)sd_mmc_get_capacity(slot) * 1024; + returnedInfo.speed = sd_mmc_get_interface_speed(slot); String<StringLength50> path; path.printf("%u:/", slot); uint32_t freeClusters; @@ -1229,13 +1236,14 @@ MassStorage::InfoResult MassStorage::GetCardInfo(size_t slot, uint64_t& capacity const FRESULT fr = f_getfree(path.c_str(), &freeClusters, &fs); if (fr == FR_OK) { - clSize = fs->csize * 512; - freeSpace = (uint64_t)freeClusters * clSize; + returnedInfo.clSize = fs->csize * 512; + returnedInfo.partitionSize = (uint64_t)(fs->n_fatent - 2) * returnedInfo.clSize; + returnedInfo.freeSpace = (uint64_t)freeClusters * returnedInfo.clSize; } else { - clSize = 0; - freeSpace = 0; + returnedInfo.clSize = 0; + returnedInfo.cardCapacity = returnedInfo.partitionSize = returnedInfo.freeSpace = 0; } return InfoResult::ok; } diff --git a/src/Storage/MassStorage.h b/src/Storage/MassStorage.h index 551bbe6a..2d351569 100644 --- a/src/Storage/MassStorage.h +++ b/src/Storage/MassStorage.h @@ -102,7 +102,16 @@ namespace MassStorage ok = 2 }; - InfoResult GetCardInfo(size_t slot, uint64_t& capacity, uint64_t& freeSpace, uint32_t& speed, uint32_t& clSize) noexcept; + struct SdCardReturnedInfo + { + uint64_t cardCapacity; + uint64_t partitionSize; + uint64_t freeSpace; + uint32_t clSize; + uint32_t speed; + }; + + InfoResult GetCardInfo(size_t slot, SdCardReturnedInfo& returnedInfo) noexcept; # ifdef DUET3_MB6HC GCodeResult ConfigureSdCard(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException); // Configure additional SD card slots diff --git a/src/Version.h b/src/Version.h index c7c080fd..b5f732a3 100644 --- a/src/Version.h +++ b/src/Version.h @@ -10,7 +10,7 @@ #ifndef VERSION // Note: the complete VERSION string must be in standard version number format and must not contain spaces! This is so that DWC can parse it. -# define MAIN_VERSION "3.4.0rc1+1" +# define MAIN_VERSION "3.4.0rc1+2" # ifdef USE_CAN0 # define VERSION_SUFFIX "(CAN0)" # else |