Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Diff: RomId.hpp
- Revision:
- 33:a4c015046956
- Parent:
- 24:8942d8478d68
- Child:
- 49:36954b62f503
diff -r bce180b544ed -r a4c015046956 RomId.hpp --- a/RomId.hpp Wed Mar 30 16:50:29 2016 -0500 +++ b/RomId.hpp Thu Mar 31 11:56:01 2016 -0500 @@ -35,13 +35,14 @@ #define _ROMID_HPP #include <cstdint> -#include <cstring> + +#include "array.hpp" class RomId { public: static const std::size_t byteLen = 8; - typedef std::uint8_t ByteBuffer[byteLen]; + typedef array<std::uint8_t, byteLen>::Buffer ByteBuffer; static std::uint8_t calculateCRC8(std::uint8_t crc8, std::uint8_t data); static std::uint8_t calculateCRC8(const std::uint8_t * data, std::size_t data_len, std::uint8_t crc = 0); @@ -51,15 +52,15 @@ static const std::size_t crc8Idx = 7; static const std::uint8_t defaultByteVal = 0x00; - ByteBuffer m_romId; + array<std::uint8_t, byteLen> m_romId; public: const RomId & operator=(const RomId & rhs) { - std::memcpy(this->m_romId, rhs.m_romId, byteLen); + this->m_romId = rhs.m_romId; return rhs; } bool operator==(const RomId & rhs) const { - return (std::memcmp(this->m_romId, rhs.m_romId, byteLen) == 0); + return (this->m_romId == rhs.m_romId); } bool operator!=(const RomId & rhs) const { return !operator==(rhs); @@ -75,15 +76,9 @@ std::memset(m_romId, defaultByteVal, byteLen); } - RomId() { - reset(); - } - RomId(const RomId & romId) { - operator=(romId); - } - RomId(const ByteBuffer & romIdBytes) { - std::memcpy(m_romId, romIdBytes, byteLen); - } + RomId() { reset(); } + RomId(const RomId & romId) : m_romId(romId.m_romId) { } + RomId(const ByteBuffer & romIdBytes) : m_romId(romIdBytes) { } std::uint8_t familyCode() const { return m_romId[familyCodeIdx];