Manage a Network of ZigBee Devices
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Node.hs 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. {-
  2. This file is part of the zigbee-commander package. It is subject to
  3. the license terms in the LICENSE file found in the top-level directory
  4. of this distribution and at git://pmade.com/zbc/LICENSE. No part of
  5. the zigbee-commander package, including this file, may be copied,
  6. modified, propagated, or distributed except according to the terms
  7. contained in the LICENSE file.
  8. -}
  9. --------------------------------------------------------------------------------
  10. module Network.XXX.ZigBee.Commander.Node
  11. ( Node (..)
  12. , NodeType (..)
  13. , NodeName
  14. , GPIOs
  15. , newNode
  16. , nodeTypeFromDeviceType
  17. ) where
  18. --------------------------------------------------------------------------------
  19. -- Package Imports:
  20. import Data.Map.Strict (Map)
  21. import qualified Data.Map.Strict as Map
  22. import Data.Text (Text)
  23. import Data.Time.Clock
  24. import Data.Word (Word8)
  25. --------------------------------------------------------------------------------
  26. -- Local Imports:
  27. import Network.XXX.ZigBee.Commander.Address
  28. import Network.XXX.ZigBee.Commander.GPIO
  29. --------------------------------------------------------------------------------
  30. data Node = Node
  31. { nodeAddress :: Address
  32. , nodeType :: NodeType
  33. , nodeGPIOs :: GPIOs
  34. , nodeMutedUntil :: Maybe UTCTime
  35. }
  36. --------------------------------------------------------------------------------
  37. data NodeType = NetworkCoordinator
  38. | NetworkRouter
  39. | NetworkEndpoint
  40. deriving (Show)
  41. --------------------------------------------------------------------------------
  42. type NodeName = Text
  43. --------------------------------------------------------------------------------
  44. -- | Mapping between GPIO names and the GPIO value that represents them.
  45. type GPIOs = Map Text GPIO
  46. --------------------------------------------------------------------------------
  47. newNode :: Address -> Node
  48. newNode addr = Node { nodeAddress = addr
  49. , nodeType = NetworkEndpoint
  50. , nodeGPIOs = Map.empty
  51. , nodeMutedUntil = Nothing
  52. }
  53. --------------------------------------------------------------------------------
  54. nodeTypeFromDeviceType :: Word8 -> NodeType
  55. nodeTypeFromDeviceType 0 = NetworkCoordinator
  56. nodeTypeFromDeviceType 1 = NetworkRouter
  57. nodeTypeFromDeviceType _ = NetworkEndpoint