proto.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Copyright (C) 2022-2023 Salvatore Sanfilippo -- All Rights Reserved
  2. * See the LICENSE file for information about the license. */
  3. #include <inttypes.h>
  4. #include <lib/flipper_format/flipper_format_i.h>
  5. #include <furi/core/string.h>
  6. #include <lib/subghz/registry.h>
  7. #include <lib/subghz/protocols/base.h>
  8. #include "app_buffer.h"
  9. #define TAG "PROTOVIEW-protocol"
  10. const SubGhzProtocol subghz_protocol_protoview;
  11. /* The feed() method puts data in the RawSamples global (protected by
  12. * a mutex). */
  13. extern RawSamplesBuffer *RawSamples;
  14. /* This is totally dummy: we just define the decoder base for the async
  15. * system to work but we don't really use it if not to collect raw
  16. * data via the feed() method. */
  17. typedef struct SubGhzProtocolDecoderprotoview {
  18. SubGhzProtocolDecoderBase base;
  19. } SubGhzProtocolDecoderprotoview;
  20. void* subghz_protocol_decoder_protoview_alloc(SubGhzEnvironment* environment) {
  21. UNUSED(environment);
  22. SubGhzProtocolDecoderprotoview* instance =
  23. malloc(sizeof(SubGhzProtocolDecoderprotoview));
  24. instance->base.protocol = &subghz_protocol_protoview;
  25. return instance;
  26. }
  27. void subghz_protocol_decoder_protoview_free(void* context) {
  28. furi_assert(context);
  29. SubGhzProtocolDecoderprotoview* instance = context;
  30. free(instance);
  31. }
  32. void subghz_protocol_decoder_protoview_reset(void* context) {
  33. furi_assert(context);
  34. }
  35. /* That's the only thig we really use of the protocol decoder
  36. * implementation. We avoid the subghz provided abstractions and put
  37. * the data in our simple abstraction: the RawSamples circular buffer. */
  38. void subghz_protocol_decoder_protoview_feed(void* context, bool level, uint32_t duration) {
  39. furi_assert(context);
  40. UNUSED(context);
  41. /* Add data to the circular buffer. */
  42. raw_samples_add(RawSamples, level, duration);
  43. // FURI_LOG_E(TAG, "FEED: %d %d", (int)level, (int)duration);
  44. return;
  45. }
  46. /* The only scope of this method is to avoid duplicated messages in the
  47. * Subghz history, which we don't use. */
  48. uint8_t subghz_protocol_decoder_protoview_get_hash_data(void* context) {
  49. furi_assert(context);
  50. return 123;
  51. }
  52. /* Not used. */
  53. bool subghz_protocol_decoder_protoview_serialize(
  54. void* context,
  55. FlipperFormat* flipper_format,
  56. SubGhzRadioPreset* preset)
  57. {
  58. UNUSED(context);
  59. UNUSED(flipper_format);
  60. UNUSED(preset);
  61. return false;
  62. }
  63. /* Not used. */
  64. bool subghz_protocol_decoder_protoview_deserialize(void* context, FlipperFormat* flipper_format)
  65. {
  66. UNUSED(context);
  67. UNUSED(flipper_format);
  68. return false;
  69. }
  70. void subhz_protocol_decoder_protoview_get_string(void* context, FuriString* output)
  71. {
  72. furi_assert(context);
  73. furi_string_cat_printf(output, "Protoview");
  74. }
  75. const SubGhzProtocolDecoder subghz_protocol_protoview_decoder = {
  76. .alloc = subghz_protocol_decoder_protoview_alloc,
  77. .free = subghz_protocol_decoder_protoview_free,
  78. .reset = subghz_protocol_decoder_protoview_reset,
  79. .feed = subghz_protocol_decoder_protoview_feed,
  80. .get_hash_data = subghz_protocol_decoder_protoview_get_hash_data,
  81. .serialize = subghz_protocol_decoder_protoview_serialize,
  82. .deserialize = subghz_protocol_decoder_protoview_deserialize,
  83. .get_string = subhz_protocol_decoder_protoview_get_string,
  84. };
  85. /* Well, we don't really target a specific protocol. So let's put flags
  86. * that make sense. */
  87. const SubGhzProtocol subghz_protocol_protoview = {
  88. .name = "Protoview",
  89. .type = SubGhzProtocolTypeStatic,
  90. .flag = SubGhzProtocolFlag_AM | SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable,
  91. .decoder = &subghz_protocol_protoview_decoder,
  92. };
  93. /* Our table has just the single dummy protocol we defined for the
  94. * sake of data collection. */
  95. const SubGhzProtocol* protoview_protocol_registry_items[] = {
  96. &subghz_protocol_protoview,
  97. };
  98. const SubGhzProtocolRegistry protoview_protocol_registry = {
  99. .items = protoview_protocol_registry_items,
  100. .size = COUNT_OF(protoview_protocol_registry_items)
  101. };