Aleksandrs Gumenuks / MaximInterface_Extended

Dependents:   mbed_DS28EC20_GPIO

Revision:
8:211d1b8f730c
Parent:
7:471901a04573
--- a/Utilities/RomId.hpp	Tue Jul 24 08:33:31 2018 +0000
+++ b/Utilities/RomId.hpp	Wed Apr 03 12:33:10 2019 +0000
@@ -33,36 +33,48 @@
 #ifndef MaximInterface_RomId
 #define MaximInterface_RomId
 
-#include "array.hpp"
+#include "array_span.hpp"
 #include "crc.hpp"
 
 namespace MaximInterface {
 
 /// Standard container for a 1-Wire ROM ID.
-typedef array<uint_least8_t, 8> RomId;
+typedef array_span<uint_least8_t, 8> RomId;
 
+/// @name Family Code
 /// @{
-/// Access the Family Code byte.
-inline RomId::value_type familyCode(const RomId & romId) {
-  return romId.front();
+
+/// Get the Family Code byte.
+inline RomId::element familyCode(RomId::const_span romId) {
+  return romId[0];
 }
-inline void setFamilyCode(RomId & romId, RomId::value_type familyCode) {
-  romId.front() = familyCode;
+
+/// Set the Family Code byte.
+inline void setFamilyCode(RomId::span romId, RomId::element familyCode) {
+  romId[0] = familyCode;
 }
+
 /// @}
 
+/// @name CRC8
 /// @{
-/// Access the CRC8 byte.
-inline RomId::value_type crc8(const RomId & romId) { return romId.back(); }
-inline void setCrc8(RomId & romId, RomId::value_type crc8) {
-  romId.back() = crc8;
+
+/// Get the CRC8 byte.
+inline RomId::element crc8(RomId::const_span romId) { 
+  return *romId.last<1>().data();
 }
+
+/// Set the CRC8 byte.
+inline void setCrc8(RomId::span romId, RomId::element crc8) {
+  *romId.last<1>().data() = crc8;
+}
+
 /// @}
 
-/// Check if the ROM ID is valid (Family Code and CRC8 are both valid).
+/// @brief Check if the ROM ID is valid (Family Code and CRC8 are both valid).
 /// @returns True if the ROM ID is valid.
-inline bool valid(const RomId & romId) {
-  return calculateCrc8(romId.data(), romId.size() - 1) == crc8(romId);
+inline bool valid(RomId::const_span romId) {
+  return calculateCrc8(romId.first(romId.size() - 1)) == crc8(romId);
 }
 
 } // namespace MaximInterface