Class: Simms::Beacon

Inherits:
Object
  • Object
show all
Defined in:
lib/simms/beacon.rb

Constant Summary collapse

CG_GLOBAL =

Command group codes

0xFFFF
CG_SENSOR =
0x0001
CG_ELECTRIC =
0x0002
CG_HVAC =
0x0004
CG_PULSER =
0x0005
CG_IRRIGATION =
0x0007
DC_DATA =

Device commands

0x0001
DC_GLOBAL_CONFIG =
0x000B
DC_CONFIG =
0x0022

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes) ⇒ Beacon

Returns a new instance of Beacon.



46
47
48
# File 'lib/simms/beacon.rb', line 46

def initialize(bytes)
  @bytes = bytes
end

Instance Attribute Details

#command_group_idObject

Attributes



7
8
9
# File 'lib/simms/beacon.rb', line 7

def command_group_id
  @command_group_id
end

#device_command_idObject

Attributes



7
8
9
# File 'lib/simms/beacon.rb', line 7

def device_command_id
  @device_command_id
end

#timestampObject

Attributes



7
8
9
# File 'lib/simms/beacon.rb', line 7

def timestamp
  @timestamp
end

#uuidObject

Attributes



7
8
9
# File 'lib/simms/beacon.rb', line 7

def uuid
  @uuid
end

Class Method Details

.class_for(group, command) ⇒ Object

Find the appropriate beacon class for a given group + command tuple



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/simms/beacon.rb', line 23

def self.class_for(group, command)
  case group
    
  when CG_GLOBAL then
    case command
    when DC_GLOBAL_CONFIG then
      return Simms::GlobalConfigBeacon
    end
    
  when CG_ELECTRIC then
    case command
    when DC_DATA then
      return Simms::ElectricityDataBeacon
    when DC_CONFIG then
      return Simms::ElectricityConfigBeacon
    end
    
  end
  
  # None found!
  nil
end

Instance Method Details

#config?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/simms/beacon.rb', line 76

def config?
  type == :config
end

#data?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/simms/beacon.rb', line 72

def data?
  type == :data
end

#groupObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/simms/beacon.rb', line 50

def group
  case @command_group_id
  when CG_GLOBAL then :global
  when CG_SENSOR then :sensor
  when CG_ELECTRIC then :electric
  when CG_HVAC then :hvac
  when CG_PULSER then :pulser
  when CG_IRRIGATION then :irrigation
  else
    :unknown
  end
end

#typeObject



63
64
65
66
67
68
69
70
# File 'lib/simms/beacon.rb', line 63

def type
  case @device_command_id
  when DC_DATA then :data
  when DC_CONFIG, DC_GLOBAL_CONFIG then :config
  else
    :unknown
  end
end