Class: RxFrame
Overview
This defines a frame received using fldigi. You supply it with the frame (delimited with “<<<” and “>>>”, and it validates the frame, then creates and populates an object with the fields of that frame.
Instance Attribute Summary collapse
-
#done ⇒ Object
Returns the value of attribute done.
-
#from ⇒ Object
Returns the value of attribute from.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#to ⇒ Object
Returns the value of attribute to.
-
#type ⇒ Object
Returns the value of attribute type.
-
#userdata ⇒ Object
Returns the value of attribute userdata.
-
#wiredata ⇒ Object
Returns the value of attribute wiredata.
Attributes inherited from Frame
Instance Method Summary collapse
-
#initialize(wiredata) ⇒ RxFrame
constructor
A new instance of RxFrame.
Methods inherited from Frame
Constructor Details
#initialize(wiredata) ⇒ RxFrame
Returns a new instance of RxFrame.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/hamnet.rb', line 120 def initialize(wiredata) # First, make sure it's properly delimited. if wiredata=~/^<<<.*?>>>$/ and wiredata.length>=31 begin # Remove the "<<<" and ">>>" tmp=wiredata[3,wiredata.length-6] # Extract the crc field. crc=tmp[tmp.length-8,8] tmp=tmp[0,tmp.length-8] # Save this for checking CRC later. crcstring=tmp # Extract and clean the from field. from=tmp[0,9].gsub(":","") tmp=tmp[9,tmp.length-9] # Extract and clean the to field. to=tmp[0,9].gsub(":","") tmp=tmp[9,tmp.length-9] # Extract the frame type. type=tmp[0,2].to_i(16) tmp=tmp[2,tmp.length-2] # Extract the sequence number. sequence=tmp[0,2].to_i(16) tmp=tmp[2,tmp.length-2] # See if this is a "done" frame. done=false if type!=(type&127) done=true type=(type&127) end # Create and populate the object. super(from, to, type, sequence, done) @wiredata=wiredata # Decode the payload. case @type when HAMNET_FRAME_PING @userdata="" when HAMNET_FRAME_PING_REPLY @userdata=tmp when HAMNET_FRAME_ACK @userdata="" when HAMNET_FRAME_SIMPLE @userdata=tmp when HAMNET_FRAME_BASE64 @userdata=Base64::strict_decode64(tmp) when HAMNET_FRAME_COMPRESSED_BASE64 @userdata=Zlib::Inflate.inflate(Base64::strict_decode64(tmp)) end # Calculate and check the CRC. @crc=Zlib::crc32(crcstring).to_s(16).downcase if crc==@crc @valid=true end rescue # This is bad. return nil end else return nil end end |
Instance Attribute Details
#done ⇒ Object
Returns the value of attribute done.
118 119 120 |
# File 'lib/hamnet.rb', line 118 def done @done end |
#from ⇒ Object
Returns the value of attribute from.
118 119 120 |
# File 'lib/hamnet.rb', line 118 def from @from end |
#sequence ⇒ Object
Returns the value of attribute sequence.
118 119 120 |
# File 'lib/hamnet.rb', line 118 def sequence @sequence end |
#to ⇒ Object
Returns the value of attribute to.
118 119 120 |
# File 'lib/hamnet.rb', line 118 def to @to end |
#type ⇒ Object
Returns the value of attribute type.
118 119 120 |
# File 'lib/hamnet.rb', line 118 def type @type end |
#userdata ⇒ Object
Returns the value of attribute userdata.
118 119 120 |
# File 'lib/hamnet.rb', line 118 def userdata @userdata end |
#wiredata ⇒ Object
Returns the value of attribute wiredata.
118 119 120 |
# File 'lib/hamnet.rb', line 118 def wiredata @wiredata end |