hamnet 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/hamnet.rb +47 -38
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDE2N2FlYTBiZjE3YTQyOTA0ZmMyZTBmNWI1YWE3YTIzZGVhYzk1Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTc4N2YwNWIyMTIzZjY0OGJiMmM1MTk0YzI3ODlmZDFjODc5OWUyYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Zjk5MTZmZTE2YmRhOTg5YzM5ZTZhNTE2ZTYyYTMwZjUzMjZmZWY1YWU0NGUw
|
10
|
+
MTlhNjZhYjE4MDk3ZGJjYTlkZDAzMWMyOTVmNWY4MGUzOGJiMGU3MmQ2ZDAz
|
11
|
+
NzY3MjMzYWQyNmVkNzA2YzhhNzhjYWM3MDhiZjRmMjkyMmZkZGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODFjYzIzM2E5ZDBhODVkNDc3ODk4N2FhZmY0NjhmNGJiZjFhYzQxZTkyNzYx
|
14
|
+
ODdkNjNkMjk3NTUzZjI3NjAwNjQ5NmMyZmZmYmVjOTM4N2ZjYmI3NWI2Mjcy
|
15
|
+
OTc4NjczNDRiZTQ0YzAxYWYzMTYxOTQ3MzM3ZmQ0NTFmMjYyZDQ=
|
data/lib/hamnet.rb
CHANGED
@@ -6,7 +6,9 @@
|
|
6
6
|
|
7
7
|
# ToDo:
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# - escape <<< and >>> from data field.
|
10
|
+
# - implement mutex-locked sequence numbers
|
11
|
+
# - sequence number should not be arbitrary and/or user-supplied
|
10
12
|
|
11
13
|
require 'zlib'
|
12
14
|
require 'base64'
|
@@ -18,43 +20,44 @@ HAMNET_FRAME_SIMPLE=1
|
|
18
20
|
HAMNET_FRAME_BASE64=2
|
19
21
|
HAMNET_FRAME_COMPRESSED_BASE64=3
|
20
22
|
# To do.
|
21
|
-
HAMNET_FRAME_PING=4
|
22
|
-
HAMNET_FRAME_PING_REPLY=5
|
23
|
-
HAMNET_FRAME_TELEMETRY=6
|
24
|
-
HAMNET_FRAME_POSITION=7
|
23
|
+
#HAMNET_FRAME_PING=4
|
24
|
+
#HAMNET_FRAME_PING_REPLY=5
|
25
|
+
#HAMNET_FRAME_TELEMETRY=6
|
26
|
+
#HAMNET_FRAME_POSITION=7
|
25
27
|
|
26
28
|
# This defines a basic frame of data for use with fldigi. The frame
|
27
29
|
# consists of:
|
28
30
|
#
|
29
31
|
# Header field. Three bytes, consisting of "<<<"
|
30
|
-
# From field.
|
31
|
-
# To field.
|
32
|
+
# From field. Nine bytes (allowing for "WA0AAA-0")
|
33
|
+
# To field. Nine bytes (allowing for "WB0BBB-0")
|
34
|
+
# Type field. Two bytes (two hex digits) specifying encoding, compression. If the high-order bit is set, this is the last frame of a sequence (ie, wait for the other side).
|
32
35
|
# Sequence field. Two bytes (two hex digits) specifying sequence number.
|
33
|
-
# Type field. Two bytes (two hex digits) specifying encoding, compression.
|
34
36
|
# Data field. Arbitrary number of bytes of payload.
|
35
37
|
# CRC field. Last eight bytes, CRC32 checksum of From, To, Type, Data fields.
|
36
38
|
# Trailer field. Three bytes, consisting of ">>>"
|
37
39
|
class Frame
|
38
|
-
attr_accessor :from, :to, :type, :sequence, :valid, :frompad, :topad
|
40
|
+
attr_accessor :from, :to, :type, :sequence, :valid, :frompad, :topad, :done
|
39
41
|
|
40
|
-
def initialize(from, to, type, sequence)
|
42
|
+
def initialize(from, to, type, sequence, done)
|
41
43
|
@from=from.downcase
|
42
44
|
@to=to.downcase
|
43
45
|
@type=type
|
44
46
|
@sequence=sequence
|
47
|
+
@done=done
|
45
48
|
@wiredata=nil
|
46
49
|
@userdata=nil
|
47
50
|
@crc=nil
|
48
51
|
@valid=nil
|
49
52
|
|
50
53
|
@frompad=@from
|
51
|
-
while @frompad.length<
|
52
|
-
@frompad=@frompad+"
|
54
|
+
while @frompad.length<9
|
55
|
+
@frompad=@frompad+" "
|
53
56
|
end
|
54
57
|
|
55
58
|
@topad=@to
|
56
|
-
while @topad.length<
|
57
|
-
@topad=@topad+"
|
59
|
+
while @topad.length<9
|
60
|
+
@topad=@topad+" "
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
@@ -68,37 +71,35 @@ end
|
|
68
71
|
# (to), the type of frame (see constants above), and the actual data
|
69
72
|
# to be transmitted.
|
70
73
|
class TxFrame < Frame
|
71
|
-
attr_accessor :from, :to, :type, :sequence, :userdata, :wiredata
|
74
|
+
attr_accessor :from, :to, :type, :sequence, :userdata, :wiredata, :done
|
72
75
|
|
73
|
-
def initialize(from, to, type, sequence, userdata)
|
76
|
+
def initialize(from, to, type, sequence, userdata, done)
|
74
77
|
# Create the object.
|
75
|
-
super(from, to, type, sequence)
|
78
|
+
super(from, to, type, sequence, done)
|
76
79
|
@userdata=userdata
|
77
80
|
|
81
|
+
sendtype=type
|
82
|
+
if @done or @type==HAMNET_FRAME_ACK
|
83
|
+
sendtype=(sendtype|128)
|
84
|
+
end
|
85
|
+
|
78
86
|
# Do the needful with the payload.
|
79
87
|
case @type
|
88
|
+
when HAMNET_FRAME_ACK
|
89
|
+
message=@frompad+@topad+sprintf("%02x",sendtype).downcase+sprintf("%02x",@sequence).downcase
|
80
90
|
when HAMNET_FRAME_SIMPLE
|
81
|
-
message=@frompad+@topad+sprintf("%02x"
|
82
|
-
@crc=Zlib::crc32(message).to_s(16).downcase
|
83
|
-
while @crc.length<8
|
84
|
-
@crc="0"+@crc
|
85
|
-
end
|
91
|
+
message=@frompad+@topad+sprintf("%02x",sendtype).downcase+sprintf("%02x",@sequence).downcase+@userdata
|
86
92
|
when HAMNET_FRAME_BASE64
|
87
|
-
message=@frompad+@topad+sprintf("%02x"
|
88
|
-
@crc=Zlib::crc32(message).to_s(16).downcase
|
89
|
-
while @crc.length<8
|
90
|
-
@crc="0"+@crc
|
91
|
-
end
|
93
|
+
message=@frompad+@topad+sprintf("%02x",sendtype).downcase+sprintf("%02x",@sequence).downcase+Base64::strict_encode64(@userdata)
|
92
94
|
when HAMNET_FRAME_COMPRESSED_BASE64
|
93
|
-
message=@frompad+@topad+sprintf("%02x"
|
94
|
-
@crc=Zlib::crc32(message).to_s(16).downcase
|
95
|
-
while @crc.length<8
|
96
|
-
@crc="0"+@crc
|
97
|
-
end
|
95
|
+
message=@frompad+@topad+sprintf("%02x",sendtype).downcase+sprintf("%02x",@sequence).downcase+Base64::strict_encode64(Zlib::Deflate.deflate(@userdata,Zlib::BEST_COMPRESSION))
|
98
96
|
else
|
99
97
|
return false
|
100
98
|
end
|
101
99
|
|
100
|
+
# Calculate the CRC.
|
101
|
+
@crc=sprintf("%08x",Zlib::crc32(message)).downcase
|
102
|
+
|
102
103
|
# Set the rest of the fields, and done.
|
103
104
|
@wiredata="<<<#{message}#{@crc}>>>"
|
104
105
|
@valid=true
|
@@ -109,7 +110,7 @@ end
|
|
109
110
|
# frame (delimited with "<<<" and ">>>", and it validates the frame,
|
110
111
|
# then creates and populates an object with the fields of that frame.
|
111
112
|
class RxFrame < Frame
|
112
|
-
attr_accessor :from, :to, :type, :sequence, :userdata, :wiredata
|
113
|
+
attr_accessor :from, :to, :type, :sequence, :userdata, :wiredata, :done
|
113
114
|
|
114
115
|
def initialize(wiredata)
|
115
116
|
# First, make sure it's properly delimited.
|
@@ -122,22 +123,30 @@ class RxFrame < Frame
|
|
122
123
|
# Save this for checking CRC later.
|
123
124
|
crcstring=tmp
|
124
125
|
# Extract and clean the from field.
|
125
|
-
from=tmp[0,
|
126
|
-
tmp=tmp[
|
126
|
+
from=tmp[0,9].gsub(" ","")
|
127
|
+
tmp=tmp[9,tmp.length-9]
|
127
128
|
# Extract and clean the to field.
|
128
|
-
to=tmp[0,
|
129
|
-
tmp=tmp[
|
129
|
+
to=tmp[0,9].gsub(" ","")
|
130
|
+
tmp=tmp[9,tmp.length-9]
|
130
131
|
# Extract the frame type.
|
131
132
|
type=tmp[0,2].to_i(16)
|
132
133
|
tmp=tmp[2,tmp.length-2]
|
133
134
|
# Extract the sequence number.
|
134
135
|
sequence=tmp[0,2].to_i(16)
|
135
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
|
136
143
|
# Create and populate the object.
|
137
|
-
super(from, to, type, sequence)
|
144
|
+
super(from, to, type, sequence, done)
|
138
145
|
@wiredata=wiredata
|
139
146
|
# Decode the payload.
|
140
147
|
case @type
|
148
|
+
when HAMNET_FRAME_ACK
|
149
|
+
@userdata=""
|
141
150
|
when HAMNET_FRAME_SIMPLE
|
142
151
|
@userdata=tmp
|
143
152
|
when HAMNET_FRAME_BASE64
|