Class: CresIP
- Inherits:
-
Object
- Object
- CresIP
- Defined in:
- lib/cresip/echo.rb,
lib/cresip.rb,
lib/cresip/action.rb,
lib/cresip/header.rb,
lib/cresip/serial.rb,
lib/cresip/register.rb
Overview
server:
0f 0001 02 (request IP ID Register, switch should send IPID)
switch:
0a 000a 00 05 a34240 02 00000000
(IPID: 0x03 to 0xFE === 05) (byte 5)
(RESP: 0x02)
server:
02 0004 00000003 (IP ID registry success)
failed response: 02 0003 ffff02
Defined Under Namespace
Classes: Action, ActionHeader, Echo, PacketHeader, Register, SerialData
Constant Summary collapse
- HeartBeatRate =
ms
5000
- DefaultPort =
41794
- TLSPort =
41796
- PayloadType =
{ 0x00 => :digital_feedback, 0x01 => :analog_feedback, 0x02 => :serial_feedback, 0x03 => :update_request_incomming, # seems pointless and can be ignored 0x08 => :date_and_time, 0x27 => :digital_set, 0x14 => :analog_set, 0x12 => :serial_set #0x20 => :?? }
- PacketTypes =
{ # Registering 0x0f => :register, 0x01 => :register_response, # panel 0x0a => :register_response, # device 0x02 => :register_success, 0x03 => :program_stopping, # Feeback and requests 0x05 => :action_info, 0x12 => :serial_data, # Used for heartbeat 0x0d => :echo_request, 0x0e => :echo_response }
Instance Method Summary collapse
-
#initialize(callback = nil, &block) ⇒ CresIP
constructor
A new instance of CresIP.
- #parse_packet(header, payload) ⇒ Object
- #read(data) ⇒ Object
Constructor Details
#initialize(callback = nil, &block) ⇒ CresIP
Returns a new instance of CresIP.
25 26 27 28 |
# File 'lib/cresip.rb', line 25 def initialize(callback = nil, &block) @callback = callback || block @buffer = String.new end |
Instance Method Details
#parse_packet(header, payload) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cresip.rb', line 46 def parse_packet(header, payload) case header.type when :register, :register_response, :register_success @callback.call Register.new(header, payload) when :program_stopping # Should we bother with a callback? when :echo_request, :echo_response @callback.call Echo.new(header, payload) when :action_info action_header = ActionHeader.new action_header.read(payload) @callback.call Action.new(header, action_header) when :serial_data @callback.call SerialData.new(header, payload) end end |
#read(data) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cresip.rb', line 30 def read(data) @buffer << data while @buffer.length >= 3 do header = PacketHeader.new header.read(@buffer[0..2]) length = header.packet_size + 3 break if @buffer.length < length payload = @buffer[3...length] @buffer = @buffer[length..-1] parse_packet(header, payload) end end |