pando_channel.c 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "pando_channel.h"
  2. #include "pando_sys.h"
  3. #define MAX_CHAN_LEN 8
  4. struct pando_channel
  5. {
  6. PANDO_CHANNEL_NAME name;
  7. channel_recv_callback subdevice_cb;
  8. channel_recv_callback device_cb;
  9. };
  10. static struct pando_channel channels[MAX_CHAN_LEN];
  11. void FUNCTION_ATTRIBUTE
  12. on_subdevice_channel_recv(PANDO_CHANNEL_NAME name, channel_recv_callback cb)
  13. {
  14. channels[name].subdevice_cb = cb;
  15. }
  16. void FUNCTION_ATTRIBUTE
  17. on_device_channel_recv(PANDO_CHANNEL_NAME name, channel_recv_callback cb)
  18. {
  19. channels[name].device_cb = cb;
  20. }
  21. void FUNCTION_ATTRIBUTE
  22. channel_send_to_subdevice(PANDO_CHANNEL_NAME name, uint8_t * buffer, uint16_t length)
  23. {
  24. if(channels[name].subdevice_cb != NULL ){
  25. channels[name].subdevice_cb(buffer, length);
  26. }
  27. }
  28. void FUNCTION_ATTRIBUTE
  29. channel_send_to_device(PANDO_CHANNEL_NAME name, uint8_t * buffer, uint16_t length)
  30. {
  31. pd_printf("send package to device\n");
  32. if(channels[name].device_cb != NULL ){
  33. channels[name].device_cb(buffer, length);
  34. }
  35. }