Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SoftEeprom.h 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * The MySensors Arduino library handles the wireless radio link and protocol
  3. * between your home built sensors/actuators and HA controller of choice.
  4. * The sensors forms a self healing radio network with optional repeaters. Each
  5. * repeater and gateway builds a routing tables in EEPROM which keeps track of the
  6. * network topology allowing messages to be routed to nodes.
  7. *
  8. * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
  9. * Copyright (C) 2013-2018 Sensnology AB
  10. * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
  11. *
  12. * Documentation: http://www.mysensors.org
  13. * Support Forum: http://forum.mysensors.org
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * version 2 as published by the Free Software Foundation.
  18. */
  19. /**
  20. * This a software emulation of EEPROM that uses a file for data storage.
  21. * A copy of the eeprom values are also held in memory for faster reading.
  22. */
  23. #ifndef SoftEeprom_h
  24. #define SoftEeprom_h
  25. #include <stdint.h>
  26. /**
  27. * SoftEeprom class
  28. */
  29. class SoftEeprom
  30. {
  31. public:
  32. /**
  33. * @brief SoftEeprom constructor.
  34. */
  35. SoftEeprom();
  36. /**
  37. * @brief SoftEeprom copy constructor.
  38. */
  39. SoftEeprom(const SoftEeprom& other);
  40. /**
  41. * @brief SoftEeprom destructor.
  42. */
  43. ~SoftEeprom();
  44. /**
  45. * @brief Initializes the eeprom class.
  46. *
  47. * @param fileName filepath where the data is saved.
  48. * @param length eeprom size in bytes.
  49. * @return 0 if SUCCESS or -1 if FAILURE.
  50. */
  51. int init(const char *fileName, size_t length);
  52. /**
  53. * @brief Clear all allocated memory variables.
  54. *
  55. */
  56. void destroy();
  57. /**
  58. * @brief Read a block of bytes from eeprom.
  59. *
  60. * @param buf buffer to copy to.
  61. * @param addr eeprom address to read from.
  62. * @param length number of bytes to read.
  63. */
  64. void readBlock(void* buf, void* addr, size_t length);
  65. /**
  66. * @brief Write a block of bytes to eeprom.
  67. *
  68. * @param buf buffer to read from.
  69. * @param addr eeprom address to write to.
  70. * @param length number of bytes to write.
  71. */
  72. void writeBlock(void* buf, void* addr, size_t length);
  73. /**
  74. * @brief Read a byte from eeprom.
  75. *
  76. * @param addr eeprom address to read from.
  77. * @return the read byte.
  78. */
  79. uint8_t readByte(int addr);
  80. /**
  81. * @brief Write a byte to eeprom.
  82. *
  83. * @param addr eeprom address to write to.
  84. * @param value to write.
  85. */
  86. void writeByte(int addr, uint8_t value);
  87. /**
  88. * @brief Overloaded assign operator.
  89. *
  90. */
  91. SoftEeprom& operator=(const SoftEeprom& other);
  92. private:
  93. size_t _length; //!< @brief Eeprom max size.
  94. char *_fileName; //!< @brief file where the eeprom values are stored.
  95. uint8_t *_values; //!< @brief copy of the eeprom values held in memory for a faster reading.
  96. };
  97. #endif