channel.c 631 B

1234567891011121314151617181920212223242526
  1. //
  2. // Created by 李建 on 2023/12/6.
  3. //
  4. #include "channel.h"
  5. #include <stdio.h>
  6. #define MAX_CHAN_LEN 8
  7. struct sparrow_channel
  8. {
  9. sparrow_channel_port name;
  10. channel_recv_callback sub_device_cb;
  11. };
  12. static struct sparrow_channel channels[MAX_CHAN_LEN];
  13. void register_sub_device_channel_recv(sparrow_channel_port name, channel_recv_callback callback) {
  14. channels[name].sub_device_cb = callback;
  15. }
  16. void channel_send_to_sub_device(sparrow_channel_port name, char * payload, sparrow_topic_type topicType ) {
  17. if(channels[name].sub_device_cb != NULL) {
  18. channels[name].sub_device_cb(payload, topicType);
  19. }
  20. }