app_bridge.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * app_bridge.h
  3. *
  4. * Created on: Nov 2, 2023
  5. * Author: juraj
  6. */
  7. #ifndef MODULES_NBUS_INC_APP_BRIDGE_H_
  8. #define MODULES_NBUS_INC_APP_BRIDGE_H_
  9. #include "mcu_platform.h"
  10. #include "nbus_config.h"
  11. typedef enum
  12. {
  13. STATUS_NOT_SUPPORTED = 0xFF,
  14. STATUS_SUCCESS = 0,
  15. STATUS_FAIL = 1
  16. } nBus_statusType_t;
  17. /**
  18. * @brief Definuje formát dát senzora.
  19. * @note Bajtová reprezentácia (Little Endian) bude nasledovná: | unit_multiplier | sign | value_multiplier | samples |
  20. * byte_length
  21. */
  22. typedef struct __attribute__((packed, aligned(1)))
  23. {
  24. /** Bit určujúci či sú dáta znamienkové.
  25. * 0 = ungigned, 1 = signed */
  26. uint8_t sign : 1;
  27. /** Násobok základnej meranej jednotky (mili, micro, kilo, deka, mega, ...)
  28. * uložený v logaritmickom tvare (pr. 2 -> 10^2).
  29. * @note: povolený rozsah [-64 , +63]
  30. */
  31. uint8_t unit_multiplier : 7;
  32. /** Násobok meranej hodnoty uložený v logaritmickom tvare (pr. 1 -> 10^1).
  33. * @note: povolený rozsah [-128 , +127]
  34. */
  35. uint8_t value_multiplier : 8;
  36. /** Počet bajtov meranej hodnoty.
  37. * @note: povolený rozsah [1 , 8]
  38. */
  39. uint8_t byte_length : 4;
  40. /** Počet vzoriek meranej hodnoty.
  41. * @note: povolený rozsah [1 , 16]
  42. */
  43. uint8_t samples : 4;
  44. } nBus_sensorFormat_t;
  45. typedef struct
  46. {
  47. uint8_t read_only_count;
  48. uint8_t read_write_count;
  49. } nBus_sensorCount_t;
  50. #define PARAM_VALUE_NONE 0x7FFFFFFF
  51. typedef struct
  52. {
  53. void (*init)(void *hw_interface, void *hw_config);
  54. void (*reset)();
  55. nBus_sensorType_t (*getType)(uint8_t sensor_index);
  56. nBus_sensorCount_t (*getSensorCount)();
  57. uint8_t (*getData)(uint8_t sensor_index, uint8_t *data);
  58. nBus_statusType_t (*setData)(uint8_t *data, uint8_t count, uint8_t *response);
  59. uint8_t (*hasParam)(uint8_t sensor_index, nBus_param_t param_name);
  60. int32_t (*getParam)(uint8_t sensor_index, nBus_param_t param_name);
  61. nBus_statusType_t (*setParam)(uint8_t sensor_index, nBus_param_t param_name, int32_t param_value);
  62. nBus_statusType_t (*start)(void);
  63. nBus_statusType_t (*stop)(void);
  64. void (*read)(void);
  65. uint8_t (*store)(void);
  66. nBus_statusType_t (*calibrate)(uint8_t sensor_index);
  67. nBus_sensorFormat_t (*getSensorFormat)(uint8_t sensor_index);
  68. nBus_statusType_t (*find)(uint8_t enable);
  69. uint8_t (*device_ready)();
  70. } nBusAppInterface_t;
  71. #endif /* MODULES_NBUS_INC_APP_BRIDGE_H_ */