hamnet 0.0.1 → 0.0.3
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 +15 -0
- data/lib/hamnet.rb +53 -31
- metadata +5 -7
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODNkZjQzN2NhODYyZWM2NWVhNzlmMmIwZDE5MjIxMDg5YWE0Mzk0Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWMyODJmMDFlOTc0Njk0YTQ5MGNjMzA4OWMyYzUzODE1YWY5ZWIzMQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YThmNDRiMzM2ZDk4ZmExODVmODA1MDA1OGE4NWQzZjg0NmVmOTk0OTNhOWY2
|
10
|
+
YzA2ZTA4N2UzNDlhNjY4NTZmMDllZGEyNzE0NzFkYzQ0MDBhMWQxOTA3Yzg3
|
11
|
+
NmE3Y2E0ODFmYmE2NzNlNjYwZGVhZWUzZmJlYWNkYjkwYTkzNzc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZTg0OTAxNjgwNjcxODYwZjhkNjRmNjJjNGI5MTNiZTgzYWM0YzhiYWFmMGYw
|
14
|
+
Nzg5ODExZDJhMzkxMDNmNDAyMGQ5YWViMjYwZmNkYjhjOGFhNzI2NzBkOGU5
|
15
|
+
YjZkNWJiYmU0NmJmMzJlZTc5NjY4MWU2ODcxNTAyZTNmYTc5M2Q=
|
data/lib/hamnet.rb
CHANGED
@@ -4,19 +4,24 @@
|
|
4
4
|
# Jeff Francis, N0GQ, jeff@gritch.org
|
5
5
|
# http://fldigi.gritch.org
|
6
6
|
|
7
|
+
# ToDo:
|
8
|
+
#
|
9
|
+
# Escape <<< >>> from data field.
|
10
|
+
|
7
11
|
require 'zlib'
|
8
12
|
require 'base64'
|
9
13
|
require 'time'
|
10
14
|
require 'thread'
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
HAMNET_FRAME_ACK=0
|
17
|
+
HAMNET_FRAME_SIMPLE=1
|
18
|
+
HAMNET_FRAME_BASE64=2
|
19
|
+
HAMNET_FRAME_COMPRESSED_BASE64=3
|
15
20
|
# To do.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
HAMNET_FRAME_PING=4
|
22
|
+
HAMNET_FRAME_PING_REPLY=5
|
23
|
+
HAMNET_FRAME_TELEMETRY=6
|
24
|
+
HAMNET_FRAME_POSITION=7
|
20
25
|
|
21
26
|
# This defines a basic frame of data for use with fldigi. The frame
|
22
27
|
# consists of:
|
@@ -24,27 +29,32 @@ FRAME_POSITION=6
|
|
24
29
|
# Header field. Three bytes, consisting of "<<<"
|
25
30
|
# From field. Eight bytes (allowing for "WA0AAA-0")
|
26
31
|
# To field. Eight bytes (allowing for "WB0BBB-0")
|
27
|
-
#
|
32
|
+
# Sequence field. Two bytes (two hex digits) specifying sequence number.
|
33
|
+
# Type field. Two bytes (two hex digits) specifying encoding, compression.
|
28
34
|
# Data field. Arbitrary number of bytes of payload.
|
29
35
|
# CRC field. Last eight bytes, CRC32 checksum of From, To, Type, Data fields.
|
30
36
|
# Trailer field. Three bytes, consisting of ">>>"
|
31
37
|
class Frame
|
32
|
-
attr_accessor :from, :to, :type, :valid
|
38
|
+
attr_accessor :from, :to, :type, :sequence, :valid, :frompad, :topad
|
33
39
|
|
34
|
-
def initialize(from, to, type)
|
40
|
+
def initialize(from, to, type, sequence)
|
35
41
|
@from=from.downcase
|
36
42
|
@to=to.downcase
|
37
43
|
@type=type
|
44
|
+
@sequence=sequence
|
38
45
|
@wiredata=nil
|
39
46
|
@userdata=nil
|
40
47
|
@crc=nil
|
41
48
|
@valid=nil
|
42
49
|
|
43
|
-
|
44
|
-
|
50
|
+
@frompad=@from
|
51
|
+
while @frompad.length<8
|
52
|
+
@frompad=@frompad+":"
|
45
53
|
end
|
46
|
-
|
47
|
-
|
54
|
+
|
55
|
+
@topad=@to
|
56
|
+
while @topad.length<8
|
57
|
+
@topad=@topad+":"
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
@@ -58,24 +68,33 @@ end
|
|
58
68
|
# (to), the type of frame (see constants above), and the actual data
|
59
69
|
# to be transmitted.
|
60
70
|
class TxFrame < Frame
|
61
|
-
attr_accessor :from, :to, :type, :userdata, :wiredata
|
71
|
+
attr_accessor :from, :to, :type, :sequence, :userdata, :wiredata
|
62
72
|
|
63
|
-
def initialize(from, to, type, userdata)
|
73
|
+
def initialize(from, to, type, sequence, userdata)
|
64
74
|
# Create the object.
|
65
|
-
super(from, to, type)
|
75
|
+
super(from, to, type, sequence)
|
66
76
|
@userdata=userdata
|
67
77
|
|
68
78
|
# Do the needful with the payload.
|
69
79
|
case @type
|
70
|
-
when
|
71
|
-
message=@
|
80
|
+
when HAMNET_FRAME_SIMPLE
|
81
|
+
message=@frompad+@topad+sprintf("%02x",@type).upcase+sprintf("%02x",@sequence).upcase+@userdata
|
72
82
|
@crc=Zlib::crc32(message).to_s(16).downcase
|
73
|
-
|
74
|
-
|
83
|
+
while @crc.length<8
|
84
|
+
@crc="0"+@crc
|
85
|
+
end
|
86
|
+
when HAMNET_FRAME_BASE64
|
87
|
+
message=@frompad+@topad+sprintf("%02x",@type).upcase+sprintf("%02x",@sequence).upcase+Base64::strict_encode64(@userdata)
|
75
88
|
@crc=Zlib::crc32(message).to_s(16).downcase
|
76
|
-
|
77
|
-
|
89
|
+
while @crc.length<8
|
90
|
+
@crc="0"+@crc
|
91
|
+
end
|
92
|
+
when HAMNET_FRAME_COMPRESSED_BASE64
|
93
|
+
message=@frompad+@topad+sprintf("%02x",@type).upcase+sprintf("%02x",@sequence).upcase+Base64::strict_encode64(Zlib::Deflate.deflate(@userdata,Zlib::BEST_COMPRESSION))
|
78
94
|
@crc=Zlib::crc32(message).to_s(16).downcase
|
95
|
+
while @crc.length<8
|
96
|
+
@crc="0"+@crc
|
97
|
+
end
|
79
98
|
else
|
80
99
|
return false
|
81
100
|
end
|
@@ -90,7 +109,7 @@ end
|
|
90
109
|
# frame (delimited with "<<<" and ">>>", and it validates the frame,
|
91
110
|
# then creates and populates an object with the fields of that frame.
|
92
111
|
class RxFrame < Frame
|
93
|
-
attr_accessor :from, :to, :type, :userdata, :wiredata
|
112
|
+
attr_accessor :from, :to, :type, :sequence, :userdata, :wiredata
|
94
113
|
|
95
114
|
def initialize(wiredata)
|
96
115
|
# First, make sure it's properly delimited.
|
@@ -109,21 +128,24 @@ class RxFrame < Frame
|
|
109
128
|
to=tmp[0,8].gsub(":","")
|
110
129
|
tmp=tmp[8,tmp.length-8]
|
111
130
|
# Extract the frame type.
|
112
|
-
type=tmp[0,
|
113
|
-
tmp=tmp[
|
131
|
+
type=tmp[0,2].to_i(16)
|
132
|
+
tmp=tmp[2,tmp.length-2]
|
133
|
+
# Extract the sequence number.
|
134
|
+
sequence=tmp[0,2].to_i(16)
|
135
|
+
tmp=tmp[2,tmp.length-2]
|
114
136
|
# Create and populate the object.
|
115
|
-
super(from, to, type)
|
137
|
+
super(from, to, type, sequence)
|
116
138
|
@wiredata=wiredata
|
117
139
|
# Decode the payload.
|
118
140
|
case @type
|
119
|
-
when
|
141
|
+
when HAMNET_FRAME_SIMPLE
|
120
142
|
@userdata=tmp
|
121
|
-
when
|
143
|
+
when HAMNET_FRAME_BASE64
|
122
144
|
@userdata=Base64::strict_decode64(tmp)
|
123
|
-
when
|
145
|
+
when HAMNET_FRAME_COMPRESSED_BASE64
|
124
146
|
@userdata=Zlib::Inflate.inflate(Base64::strict_decode64(tmp))
|
125
147
|
end
|
126
|
-
# Calculate
|
148
|
+
# Calculate and check the CRC.
|
127
149
|
@crc=Zlib::crc32(crcstring).to_s(16).downcase
|
128
150
|
if crc==@crc
|
129
151
|
@valid=true
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jeff Francis, N0GQ
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: A library for constructing fldigi network packets.
|
15
14
|
email: jeff@gritch.org
|
@@ -21,26 +20,25 @@ files:
|
|
21
20
|
homepage: http://fldigi.gritch.org/
|
22
21
|
licenses:
|
23
22
|
- MIT
|
23
|
+
metadata: {}
|
24
24
|
post_install_message:
|
25
25
|
rdoc_options: []
|
26
26
|
require_paths:
|
27
27
|
- lib
|
28
28
|
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '0'
|
34
33
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
34
|
requirements:
|
37
35
|
- - ! '>='
|
38
36
|
- !ruby/object:Gem::Version
|
39
37
|
version: '0'
|
40
38
|
requirements: []
|
41
39
|
rubyforge_project:
|
42
|
-
rubygems_version:
|
40
|
+
rubygems_version: 2.4.1
|
43
41
|
signing_key:
|
44
|
-
specification_version:
|
42
|
+
specification_version: 4
|
45
43
|
summary: A library for constructing fldigi network packets.
|
46
44
|
test_files: []
|