Subversion Repositories HomeAutomation

Rev

Rev 595 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /**********************************************************
  2.  * Channel based subsystem for HomeAutomation
  3.  *
  4.  * Author: Max Sikstrom
  5.  *
  6.  **********************************************************/
  7.  
  8. #ifndef CHANNEL_H_
  9. #define CHANNEL_H_
  10.  
  11. /**********************************************************
  12.  * Includes
  13.  **********************************************************/
  14. #include <inttypes.h>
  15. #include <bios.h>
  16.  
  17. /**********************************************************
  18.  * Constants
  19.  **********************************************************/
  20. #define CHANNEL_FAIL    0
  21. #define CHANNEL_OK      1
  22.  
  23. #define CHANNEL_MASK_SUBCLASS   0x01F00000
  24. #define CHANNEL_SHIFT_SUBCLASS  20
  25. #define CHANNEL_MASK_CHANNEL    0x000FFF00
  26. #define CHANNEL_SHIFT_CHANNEL   8
  27. #define CHANNEL_MASK_NODEID     0x000000FF
  28. #define CHANNEL_SHIFT_NODEID    0
  29.  
  30. #define CHANNEL_SUBCLASS_DATA       0x1UL
  31. #define CHANNEL_SUBCLASS_IDENTIFY   0x2UL
  32. #define CHANNEL_SUBCLASS_CHN_BIND   0x3UL
  33. #define CHANNEL_SUBCLASS_CHN_NAME   0x4UL
  34. #define CHANNEL_SUBCLASS_CHN_TYPE   0x5UL
  35.  
  36. /**********************************************************
  37.  * Internal storage structure
  38.  **********************************************************/
  39. typedef struct {
  40.     uint16_t    channel;
  41.     uint16_t    value;
  42.  
  43. #if CHANNEL_ENABLE_NAME
  44.     char        name[9];
  45. #endif
  46.  
  47. #if CHANNEL_ENABLE_TYPE
  48.     uint16_t    type_k;
  49.     uint16_t    type_m;
  50.  
  51. #   if CHANNEL_ENABLE_TYPE_NAME
  52.     char        type[5];
  53. #   endif
  54. #endif
  55.  
  56. } Channel_Info_t;
  57.  
  58. /**********************************************************
  59.  * Functions
  60.  **********************************************************/
  61.  
  62. /* Initialize channel subsystem
  63.  *
  64.  * Must be done after can initializes.
  65.  */
  66. uint8_t Channel_Init( void );
  67.  
  68. /* Handle a channel CAN-message.
  69.  *
  70.  * Returns CHANNEL_OK if ok, CHANNEL_FAIL otherwise
  71.  */
  72. uint8_t Channel_HandleMsg( Can_Message_t *msg );
  73.  
  74. /* Bind a channel to function id
  75.  *
  76.  * This can, and should, be done from a macronode through the bus
  77.  */
  78. void Channel_Bind( uint8_t id, uint8_t channel );
  79.  
  80. /* Get a value unscaled from a channel referenced by a function id.
  81.  */
  82. uint16_t Channel_GetValue( uint8_t id );
  83.  
  84. /* Set a value unscaled to a channeld referenced by a function id.
  85.  */
  86. uint8_t Channel_SetValue( uint8_t id, uint16_t value );
  87.  
  88. /* Get internal storage for function id
  89.  */
  90. Channel_Info_t *Channel_GetStorage( uint8_t id );
  91.  
  92. /**********************************************************
  93.  * Callbacks
  94.  **********************************************************/
  95.  
  96. /* A callback routine for handling a valuechange in a channel
  97.  */
  98. void Channel_Callback_Value( uint8_t id, uint16_t value );
  99.  
  100. #endif
  101.