Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
mfruge
Date:
Tue Aug 13 14:42:37 2019 +0000
Revision:
142:85b71cfd617e
Parent:
139:f0e0a7976846
Added functions to ROMCommands to add Alarm Search functionality

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 17:b646b1e3970b 1 /******************************************************************//**
j3 17:b646b1e3970b 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 17:b646b1e3970b 3 *
j3 17:b646b1e3970b 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 17:b646b1e3970b 5 * copy of this software and associated documentation files (the "Software"),
j3 17:b646b1e3970b 6 * to deal in the Software without restriction, including without limitation
j3 17:b646b1e3970b 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 17:b646b1e3970b 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 17:b646b1e3970b 9 * Software is furnished to do so, subject to the following conditions:
j3 17:b646b1e3970b 10 *
j3 17:b646b1e3970b 11 * The above copyright notice and this permission notice shall be included
j3 17:b646b1e3970b 12 * in all copies or substantial portions of the Software.
j3 17:b646b1e3970b 13 *
j3 17:b646b1e3970b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 17:b646b1e3970b 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 17:b646b1e3970b 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 17:b646b1e3970b 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 17:b646b1e3970b 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 17:b646b1e3970b 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 17:b646b1e3970b 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 17:b646b1e3970b 21 *
j3 17:b646b1e3970b 22 * Except as contained in this notice, the name of Maxim Integrated
j3 17:b646b1e3970b 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 17:b646b1e3970b 24 * Products, Inc. Branding Policy.
j3 17:b646b1e3970b 25 *
j3 17:b646b1e3970b 26 * The mere transfer of this software does not imply any licenses
j3 17:b646b1e3970b 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 17:b646b1e3970b 28 * trademarks, maskwork rights, or any other form of intellectual
j3 17:b646b1e3970b 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 17:b646b1e3970b 30 * ownership rights.
j3 17:b646b1e3970b 31 **********************************************************************/
j3 17:b646b1e3970b 32
IanBenzMaxim 73:2cecc1372acc 33 #ifndef OneWire_RomId
IanBenzMaxim 73:2cecc1372acc 34 #define OneWire_RomId
j3 17:b646b1e3970b 35
IanBenzMaxim 86:2ce08ca58b9e 36 #include "Utilities/array.h"
IanBenzMaxim 86:2ce08ca58b9e 37 #include "Utilities/crc.h"
j3 17:b646b1e3970b 38
IanBenzMaxim 73:2cecc1372acc 39 namespace OneWire
j3 17:b646b1e3970b 40 {
j3 139:f0e0a7976846 41 /// Standard container for a 1-Wire ROM ID.
j3 139:f0e0a7976846 42 struct RomId
j3 139:f0e0a7976846 43 {
j3 139:f0e0a7976846 44 typedef array<uint8_t, 8> Buffer;
j3 139:f0e0a7976846 45
j3 139:f0e0a7976846 46 /// Direct access to the buffer.
j3 139:f0e0a7976846 47 Buffer buffer;
j3 139:f0e0a7976846 48 /// @}
j3 17:b646b1e3970b 49
j3 139:f0e0a7976846 50 /// @{
j3 139:f0e0a7976846 51 /// Access the Family Code byte.
j3 139:f0e0a7976846 52 uint8_t & familyCode() { return buffer.front(); }
j3 139:f0e0a7976846 53 const uint8_t & familyCode() const { return buffer.front(); }
j3 139:f0e0a7976846 54 /// @}
IanBenzMaxim 62:43039aeca2ab 55
j3 139:f0e0a7976846 56 /// @{
j3 139:f0e0a7976846 57 /// Access the CRC8 byte.
j3 139:f0e0a7976846 58 uint8_t & crc8() { return buffer.back(); }
j3 139:f0e0a7976846 59 const uint8_t & crc8() const { return buffer.back(); }
j3 139:f0e0a7976846 60 /// @}
j3 17:b646b1e3970b 61
j3 139:f0e0a7976846 62 /// Check if the ROM ID is valid (Family Code and CRC8 are both valid).
j3 139:f0e0a7976846 63 /// @returns True if the ROM ID is valid.
j3 139:f0e0a7976846 64 bool valid() const
j3 139:f0e0a7976846 65 {
j3 139:f0e0a7976846 66 return crc::calculateCrc8(buffer.data(), buffer.size() - 1, 0x00) == crc8();
j3 139:f0e0a7976846 67 }
j3 139:f0e0a7976846 68
j3 139:f0e0a7976846 69 bool operator==(const RomId & rhs) const { return (this->buffer == rhs.buffer); }
j3 139:f0e0a7976846 70 bool operator!=(const RomId & rhs) const { return !operator==(rhs); }
j3 139:f0e0a7976846 71 };
IanBenzMaxim 73:2cecc1372acc 72 }
j3 17:b646b1e3970b 73
IanBenzMaxim 49:36954b62f503 74 #endif