hamnet 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/hamnet.rb +88 -52
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDE2N2FlYTBiZjE3YTQyOTA0ZmMyZTBmNWI1YWE3YTIzZGVhYzk1Nw==
4
+ NTAxZTNiMmI2NmRlY2I5ZDVkNGJkNjVjMDRkY2IxYmY3YWI2N2FlYQ==
5
5
  data.tar.gz: !binary |-
6
- OTc4N2YwNWIyMTIzZjY0OGJiMmM1MTk0YzI3ODlmZDFjODc5OWUyYQ==
6
+ NWEzN2Y4ODVkY2YwZjU0Y2U0YTQ3OWJmMTgyYTk1MGM3OTMzNjIwMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Zjk5MTZmZTE2YmRhOTg5YzM5ZTZhNTE2ZTYyYTMwZjUzMjZmZWY1YWU0NGUw
10
- MTlhNjZhYjE4MDk3ZGJjYTlkZDAzMWMyOTVmNWY4MGUzOGJiMGU3MmQ2ZDAz
11
- NzY3MjMzYWQyNmVkNzA2YzhhNzhjYWM3MDhiZjRmMjkyMmZkZGY=
9
+ ZTgzNDY1M2Y4OWQ2ZWVkNzU3MTU4Y2YxNDg1YWI3M2ZjZWRjMDgwNzcxMGM1
10
+ N2RlYzYxMTc5OGFkZDdhZWE3MWU3OTlmODU1NmI1YWU1OWMzMGVhNDA4ODEy
11
+ Y2E3YTJlNmM4ZmUyOTk0OWNmNzI4MGYzYWViNTNkYzc1OGZlYzg=
12
12
  data.tar.gz: !binary |-
13
- ODFjYzIzM2E5ZDBhODVkNDc3ODk4N2FhZmY0NjhmNGJiZjFhYzQxZTkyNzYx
14
- ODdkNjNkMjk3NTUzZjI3NjAwNjQ5NmMyZmZmYmVjOTM4N2ZjYmI3NWI2Mjcy
15
- OTc4NjczNDRiZTQ0YzAxYWYzMTYxOTQ3MzM3ZmQ0NTFmMjYyZDQ=
13
+ ZTJmMmJhYzRlMWY1ZWI0NmFhMzM2NzJlNjM1NTg3MDY0YTZiNmU4MDBjZWVl
14
+ YjVmMTJlMWZjMTMzN2UyYTM2MzI1NmJjMDliZWUwMWQ1OWVkY2M2YzBmOGE5
15
+ NmQ2YTI4ZDZjYzVmZTYzNmMzZTI1ZTI1OTIzMjJlOTFkNjQ3NmM=
@@ -20,8 +20,8 @@ HAMNET_FRAME_SIMPLE=1
20
20
  HAMNET_FRAME_BASE64=2
21
21
  HAMNET_FRAME_COMPRESSED_BASE64=3
22
22
  # To do.
23
- #HAMNET_FRAME_PING=4
24
- #HAMNET_FRAME_PING_REPLY=5
23
+ HAMNET_FRAME_PING=4
24
+ HAMNET_FRAME_PING_REPLY=5
25
25
  #HAMNET_FRAME_TELEMETRY=6
26
26
  #HAMNET_FRAME_POSITION=7
27
27
 
@@ -48,16 +48,16 @@ class Frame
48
48
  @wiredata=nil
49
49
  @userdata=nil
50
50
  @crc=nil
51
- @valid=nil
51
+ @valid=false
52
52
 
53
53
  @frompad=@from
54
54
  while @frompad.length<9
55
- @frompad=@frompad+" "
55
+ @frompad=@frompad+":"
56
56
  end
57
57
 
58
58
  @topad=@to
59
59
  while @topad.length<9
60
- @topad=@topad+" "
60
+ @topad=@topad+":"
61
61
  end
62
62
  end
63
63
 
@@ -79,12 +79,16 @@ class TxFrame < Frame
79
79
  @userdata=userdata
80
80
 
81
81
  sendtype=type
82
- if @done or @type==HAMNET_FRAME_ACK
82
+ if @done or @type==HAMNET_FRAME_ACK or @type==HAMNET_FRAME_PING or @type==HAMNET_FRAME_PING_REPLY
83
83
  sendtype=(sendtype|128)
84
84
  end
85
85
 
86
86
  # Do the needful with the payload.
87
87
  case @type
88
+ when HAMNET_FRAME_PING
89
+ message=@frompad+@topad+sprintf("%02x",sendtype).downcase+sprintf("%02x",@sequence).downcase
90
+ when HAMNET_FRAME_PING_REPLY
91
+ message=@frompad+@topad+sprintf("%02x",sendtype).downcase+sprintf("%02x",@sequence).downcase+@userdata
88
92
  when HAMNET_FRAME_ACK
89
93
  message=@frompad+@topad+sprintf("%02x",sendtype).downcase+sprintf("%02x",@sequence).downcase
90
94
  when HAMNET_FRAME_SIMPLE
@@ -101,7 +105,7 @@ class TxFrame < Frame
101
105
  @crc=sprintf("%08x",Zlib::crc32(message)).downcase
102
106
 
103
107
  # Set the rest of the fields, and done.
104
- @wiredata="<<<#{message}#{@crc}>>>"
108
+ @wiredata="----------<<<#{message}#{@crc}>>>"
105
109
  @valid=true
106
110
  end
107
111
  end
@@ -114,53 +118,85 @@ class RxFrame < Frame
114
118
 
115
119
  def initialize(wiredata)
116
120
  # First, make sure it's properly delimited.
117
- if wiredata=~/^<<<.*>>>$/ and wiredata.length>=31
118
- # Remove the "<<<" and ">>>"
119
- tmp=wiredata[3,wiredata.length-6]
120
- # Extract the crc field.
121
- crc=tmp[tmp.length-8,8]
122
- tmp=tmp[0,tmp.length-8]
123
- # Save this for checking CRC later.
124
- crcstring=tmp
125
- # Extract and clean the from field.
126
- from=tmp[0,9].gsub(" ","")
127
- tmp=tmp[9,tmp.length-9]
128
- # Extract and clean the to field.
129
- to=tmp[0,9].gsub(" ","")
130
- tmp=tmp[9,tmp.length-9]
131
- # Extract the frame type.
132
- type=tmp[0,2].to_i(16)
133
- tmp=tmp[2,tmp.length-2]
134
- # Extract the sequence number.
135
- sequence=tmp[0,2].to_i(16)
136
- tmp=tmp[2,tmp.length-2]
137
- # See if this is a "done" frame.
138
- done=false
139
- if type!=(type&127)
140
- done=true
141
- type=(type&127)
142
- end
143
- # Create and populate the object.
144
- super(from, to, type, sequence, done)
145
- @wiredata=wiredata
146
- # Decode the payload.
147
- case @type
148
- when HAMNET_FRAME_ACK
149
- @userdata=""
150
- when HAMNET_FRAME_SIMPLE
151
- @userdata=tmp
152
- when HAMNET_FRAME_BASE64
153
- @userdata=Base64::strict_decode64(tmp)
154
- when HAMNET_FRAME_COMPRESSED_BASE64
155
- @userdata=Zlib::Inflate.inflate(Base64::strict_decode64(tmp))
156
- end
157
- # Calculate and check the CRC.
158
- @crc=Zlib::crc32(crcstring).to_s(16).downcase
159
- if crc==@crc
160
- @valid=true
121
+ if wiredata=~/^<<<.*?>>>$/ and wiredata.length>=31
122
+ begin
123
+ # Remove the "<<<" and ">>>"
124
+ tmp=wiredata[3,wiredata.length-6]
125
+ # Extract the crc field.
126
+ crc=tmp[tmp.length-8,8]
127
+ tmp=tmp[0,tmp.length-8]
128
+ # Save this for checking CRC later.
129
+ crcstring=tmp
130
+ # Extract and clean the from field.
131
+ from=tmp[0,9].gsub(":","")
132
+ tmp=tmp[9,tmp.length-9]
133
+ # Extract and clean the to field.
134
+ to=tmp[0,9].gsub(":","")
135
+ tmp=tmp[9,tmp.length-9]
136
+ # Extract the frame type.
137
+ type=tmp[0,2].to_i(16)
138
+ tmp=tmp[2,tmp.length-2]
139
+ # Extract the sequence number.
140
+ sequence=tmp[0,2].to_i(16)
141
+ tmp=tmp[2,tmp.length-2]
142
+ # See if this is a "done" frame.
143
+ done=false
144
+ if type!=(type&127)
145
+ done=true
146
+ type=(type&127)
147
+ end
148
+ # Create and populate the object.
149
+ super(from, to, type, sequence, done)
150
+ @wiredata=wiredata
151
+ # Decode the payload.
152
+ case @type
153
+ when HAMNET_FRAME_PING
154
+ @userdata=""
155
+ when HAMNET_FRAME_PING_REPLY
156
+ @userdata=tmp
157
+ when HAMNET_FRAME_ACK
158
+ @userdata=""
159
+ when HAMNET_FRAME_SIMPLE
160
+ @userdata=tmp
161
+ when HAMNET_FRAME_BASE64
162
+ @userdata=Base64::strict_decode64(tmp)
163
+ when HAMNET_FRAME_COMPRESSED_BASE64
164
+ @userdata=Zlib::Inflate.inflate(Base64::strict_decode64(tmp))
165
+ end
166
+ # Calculate and check the CRC.
167
+ @crc=Zlib::crc32(crcstring).to_s(16).downcase
168
+ if crc==@crc
169
+ @valid=true
170
+ end
171
+ rescue
172
+ # This is bad.
173
+ return nil
161
174
  end
162
175
  else
163
- return false
176
+ return nil
177
+ end
178
+ end
179
+ end
180
+
181
+ def sendstring(from, to, type, text, max)
182
+ sequence=0
183
+ frames=Array.new()
184
+ done=false
185
+
186
+ while text.length > max
187
+ chunk=text[0,max]
188
+ text=text[max,text.length-max]
189
+ if text.length==0
190
+ done=true
164
191
  end
192
+ frames.push(TxFrame.new(from, to, type, sequence, chunk, done))
193
+ sequence=sequence+1
194
+ end
195
+
196
+ if text.length > 0
197
+ frames.push(TxFrame.new(from, to, type, sequence, text, true))
198
+ sequence=sequence+1
165
199
  end
200
+
201
+ return frames
166
202
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamnet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Francis, N0GQ
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-05 00:00:00.000000000 Z
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library for constructing fldigi network packets.
14
14
  email: jeff@gritch.org