hamnet 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/hamnet.rb +88 -52
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTAxZTNiMmI2NmRlY2I5ZDVkNGJkNjVjMDRkY2IxYmY3YWI2N2FlYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWEzN2Y4ODVkY2YwZjU0Y2U0YTQ3OWJmMTgyYTk1MGM3OTMzNjIwMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTgzNDY1M2Y4OWQ2ZWVkNzU3MTU4Y2YxNDg1YWI3M2ZjZWRjMDgwNzcxMGM1
|
10
|
+
N2RlYzYxMTc5OGFkZDdhZWE3MWU3OTlmODU1NmI1YWU1OWMzMGVhNDA4ODEy
|
11
|
+
Y2E3YTJlNmM4ZmUyOTk0OWNmNzI4MGYzYWViNTNkYzc1OGZlYzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTJmMmJhYzRlMWY1ZWI0NmFhMzM2NzJlNjM1NTg3MDY0YTZiNmU4MDBjZWVl
|
14
|
+
YjVmMTJlMWZjMTMzN2UyYTM2MzI1NmJjMDliZWUwMWQ1OWVkY2M2YzBmOGE5
|
15
|
+
NmQ2YTI4ZDZjYzVmZTYzNmMzZTI1ZTI1OTIzMjJlOTFkNjQ3NmM=
|
data/lib/hamnet.rb
CHANGED
@@ -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
|
-
|
24
|
-
|
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=
|
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="
|
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
|
118
|
-
|
119
|
-
|
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
|
-
|
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
|
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
|
+
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-
|
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
|