esp_eddystone_protocol.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_EDDYSTONE_PROTOCOL_H__
  14. #define __ESP_EDDYSTONE_PROTOCOL_H__
  15. #include "stdbool.h"
  16. #include "stdint.h"
  17. /* Eddystone definitions */
  18. #define EDDYSTONE_SERVICE_UUID 0xFEAA
  19. #define EDDYSTONE_FRAME_TYPE_UID 0x00
  20. #define EDDYSTONE_FRAME_TYPE_URL 0x10
  21. #define EDDYSTONE_FRAME_TYPE_TLM 0x20
  22. #define EDDYSTONE_FRAME_TYPE_EID 0x30
  23. #define EDDYSTONE_UID_FRAME_LEN 0x17
  24. #define EDDYSTONE_TLM_FRAME_LEN 0x11
  25. #define EDDYSTONE_URL_MAX_LEN 18
  26. /* Eddystone UID frame */
  27. typedef struct {
  28. int8_t ranging_data; /*<! calibrated Tx power at 0m */
  29. uint8_t namespace_id[10];
  30. uint8_t instance_id[6];
  31. uint8_t reserved[2];
  32. } __attribute__((packed))esp_eddystone_uid_t;
  33. /* Eddystone URL frame */
  34. typedef struct {
  35. int8_t tx_power; /*<! calibrated Tx power at 0m */
  36. uint8_t url_scheme; /*<! encoded scheme prefix */
  37. uint8_t encoded_url[0]; /*<! length 1-17 */
  38. } __attribute__((packed))esp_eddystone_url_t;
  39. /* Eddystone TLM frame */
  40. typedef struct {
  41. uint8_t version; /*<! TLM version,0x00 for now */
  42. uint16_t batt; /*<! battery voltage, 1mV/bit */
  43. uint16_t temp; /*<! beacon temperature */
  44. uint32_t adv_count; /*<! adv pdu count since power-on or reboot */
  45. uint32_t time; /*<! time sence power-on or reboot, a 0.1 second resolution counter */
  46. } __attribute__((packed)) esp_eddystone_tlm_t;
  47. /* AD Structure of flags */
  48. typedef struct {
  49. uint8_t len;
  50. uint8_t type;
  51. uint8_t flags;
  52. } __attribute__((packed)) esp_eddystone_flags_t;
  53. /* AD Structure of complete 16-bit service uuid */
  54. typedef struct {
  55. uint8_t len;
  56. uint8_t type;
  57. uint16_t uuid; /*<! complete list of 16-bit service UUIDs data type value */
  58. } __attribute__((packed)) esp_eddystone_uuid_t;
  59. /* AD Structure of eddystone frame*/
  60. typedef struct {
  61. uint8_t len; /*<! length of eddystone data */
  62. uint8_t type; /*<! service data type,must be 0x16 */
  63. uint16_t uuid; /*<! 16-bit eddystone uuid */
  64. uint8_t frame_type;
  65. union {
  66. esp_eddystone_uid_t uid;
  67. esp_eddystone_url_t url;
  68. esp_eddystone_tlm_t tlm;
  69. } u[0];
  70. } __attribute__((packed)) esp_eddystone_frame_t;
  71. /* eddystone packet type */
  72. typedef struct {
  73. esp_eddystone_flags_t flags;
  74. esp_eddystone_uuid_t uuid;
  75. esp_eddystone_frame_t frame;
  76. } __attribute__((packed)) esp_eddystone_packet_t;
  77. /*
  78. * URLs are written only with the graphic printable characters of the US-ASCII coded character set.
  79. * The octets 00-20 and 7F-FF hexadecimal are not used.
  80. * See “Excluded US-ASCII Characters” in RFC 2936.
  81. *
  82. */
  83. static inline bool esp_eddystone_is_char_invalid(int ch)
  84. {
  85. return (ch >= 0x00 && ch <= 0x20) || (ch >= 0x7f && ch <= 0xff);
  86. }
  87. #endif /* __ESP_EDDYSTONE_PROTOCOL_H__ */