Subversion Repositories HomeAutomation

Rev

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