HardwareSerializer.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * TI Voxel Lib component.
  3. *
  4. * Copyright (c) 2016 Texas Instruments Inc.
  5. */
  6. #include "Common.h"
  7. #include "USBIO.h"
  8. #include "SerializedObject.h"
  9. /**
  10. * \ingroup Util
  11. */
  12. namespace Voxel
  13. {
  14. class VOXEL_EXPORT HardwareSerializer
  15. {
  16. uint8_t _ioRequestCode, _sizeRequestCode;
  17. USBIOPtr _usbIO;
  18. public:
  19. HardwareSerializer() {}
  20. /**
  21. *
  22. * @param usbIO -- Pointer to USBIO class object which supports control transfers
  23. * @param ioRequestCode -- request code to read/write serialized data from/to hardware
  24. * @param sizeRequestCode -- request code to read size of serialized data in hardware
  25. *
  26. */
  27. HardwareSerializer(USBIOPtr &usbIO, uint8_t ioRequestCode, uint8_t sizeRequestCode):
  28. _usbIO(usbIO), _ioRequestCode(ioRequestCode), _sizeRequestCode(sizeRequestCode) {}
  29. /**
  30. * @param version is the version info of format of 'so'
  31. * @param knownTimestamp is the last known timestamp of data written. This is used to see whether an exist local copy of the
  32. * serialized data is same as that in hardware or not. If same, then nothing is read from hardware improving run-time performance.
  33. * @param so is the object to hold serialized data to read from hardware
  34. */
  35. bool read(Version &version, TimeStampType &knownTimestamp, SerializedObject &so);
  36. /**
  37. * @param version is the version info of format of 'so'
  38. * @param timestamp is the timestamp of data to be written. This is used by read() to see whether an exist local copy of the
  39. * serialized data is same as that in hardware or not.
  40. * @param so is the object holding serialized data to write to hardware
  41. */
  42. bool write(Version &version, TimeStampType &timestamp, SerializedObject &so);
  43. /**
  44. * Save to local file 'filename'
  45. */
  46. bool writeToFile(const String &filename, Version &version, TimeStampType &timestamp, SerializedObject &so);
  47. inline void setUSBIO(USBIOPtr &usbIO) { _usbIO = usbIO; }
  48. inline operator bool () { return _usbIO.get() != nullptr; }
  49. /**
  50. * Serialized size in hardware is assumed to be 4 bytes long in big endian format
  51. */
  52. bool getSize(uint32_t &size);
  53. virtual ~HardwareSerializer() {}
  54. };
  55. typedef Ptr<HardwareSerializer> HardwareSerializerPtr;
  56. }