coap 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/coap +26 -13
- data/lib/core/coap/client.rb +6 -4
- data/lib/core/coap/message.rb +1 -3
- data/lib/core/coap/transmission.rb +0 -2
- data/lib/core/coap/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36ea360829046ce72e968fe067c38e687bf3de8c
|
4
|
+
data.tar.gz: c9c5ab0540425a325cba51a5063b12c4f0416189
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c341257f415a5cf47b59c4878898984e5e9adfd8d14a696c0d9cc4678f621e8912e5b8ba79df52b735e39eccf2a300f9c4ef5ea688fc9d752a19cb06fdde5a7
|
7
|
+
data.tar.gz: f4b6bcb900c0130c53a2f234d111a0c2af0022811f425b02a36e3145a84d0aaf2d1e8645a238bd9037fdbe8dd5283718a1decc9669d39fc68954d774e92af740
|
data/bin/coap
CHANGED
@@ -11,13 +11,14 @@ def usage
|
|
11
11
|
$stderr.puts <<EOF
|
12
12
|
Usage: #{File.basename($0)} [options] <method> <uri>
|
13
13
|
|
14
|
-
--
|
15
|
-
--
|
16
|
-
|
17
|
-
|
18
|
-
--payload
|
19
|
-
--
|
20
|
-
--
|
14
|
+
--content-format, -c <string> Content format.
|
15
|
+
--debug, -d Extra debug output.
|
16
|
+
--output, -o <target> Redirect payload output. Target can be "-" for
|
17
|
+
STDOUT or a file path.
|
18
|
+
--payload, -p <string> Payload for POST and PUT as string.
|
19
|
+
--payload-file, -f <file> Read payload for POST and PUT from file.
|
20
|
+
--type, -t <type> Message type (con, non, ack, rst).
|
21
|
+
--help, -h This usage message.
|
21
22
|
|
22
23
|
EOF
|
23
24
|
exit 1
|
@@ -26,12 +27,13 @@ end
|
|
26
27
|
METHODS = CoAP::METHODS + [:observe]
|
27
28
|
|
28
29
|
opts = GetoptLong.new(
|
29
|
-
['--
|
30
|
-
['--
|
31
|
-
['--
|
32
|
-
['--payload
|
33
|
-
['--
|
34
|
-
['--
|
30
|
+
['--content-format', '-c', GetoptLong::REQUIRED_ARGUMENT],
|
31
|
+
['--debug', '-d', GetoptLong::NO_ARGUMENT],
|
32
|
+
['--output', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
33
|
+
['--payload', '-p', GetoptLong::REQUIRED_ARGUMENT],
|
34
|
+
['--payload-file', '-f', GetoptLong::REQUIRED_ARGUMENT],
|
35
|
+
['--type', '-t', GetoptLong::REQUIRED_ARGUMENT],
|
36
|
+
['--help', '-h', GetoptLong::NO_ARGUMENT]
|
35
37
|
)
|
36
38
|
|
37
39
|
$DEBUG = false
|
@@ -41,6 +43,9 @@ options = {}
|
|
41
43
|
|
42
44
|
opts.each do |opt, arg|
|
43
45
|
case opt
|
46
|
+
when '--content-format'
|
47
|
+
cf = CoAP::Registry.convert_content_format(arg)
|
48
|
+
options[:content_format] = cf
|
44
49
|
when '--debug'
|
45
50
|
$DEBUG = true
|
46
51
|
when '--output'
|
@@ -108,4 +113,12 @@ if output
|
|
108
113
|
output.puts answer.payload
|
109
114
|
else
|
110
115
|
pp answer
|
116
|
+
case answer.options[:content_format]
|
117
|
+
when 50
|
118
|
+
require 'json'
|
119
|
+
pp JSON.parse(answer.payload)
|
120
|
+
when 60
|
121
|
+
require 'cbor'
|
122
|
+
pp CBOR.load(answer.payload)
|
123
|
+
end
|
111
124
|
end
|
data/lib/core/coap/client.rb
CHANGED
@@ -269,13 +269,15 @@ module CoRE
|
|
269
269
|
end
|
270
270
|
|
271
271
|
def initialize_message(method, path, query = nil, payload = nil)
|
272
|
-
mid
|
273
|
-
token = SecureRandom.random_number(0xff)
|
272
|
+
mid = SecureRandom.random_number(0xffff)
|
274
273
|
|
275
274
|
options = {
|
276
|
-
uri_path: CoAP.path_decode(path)
|
277
|
-
token: token
|
275
|
+
uri_path: CoAP.path_decode(path)
|
278
276
|
}
|
277
|
+
|
278
|
+
unless @options[:token] == false
|
279
|
+
options[:token] = SecureRandom.random_number(0xffffffff)
|
280
|
+
end
|
279
281
|
|
280
282
|
unless query.nil?
|
281
283
|
options[:uri_query] = CoAP.query_decode(query)
|
data/lib/core/coap/message.rb
CHANGED
@@ -77,16 +77,14 @@ module CoRE
|
|
77
77
|
path = CoAP.path_encode(self.options[:uri_path])
|
78
78
|
query = CoAP.query_encode(self.options[:uri_query])
|
79
79
|
|
80
|
-
[mcode_readable, path, query].join(' ')
|
80
|
+
[tt, mcode_readable, path, query].join(' ').rstrip
|
81
81
|
end
|
82
82
|
|
83
83
|
def to_wire
|
84
84
|
# check and encode option values
|
85
85
|
prepared_options = prepare_options
|
86
|
-
# puts "prepared_options: #{prepared_options}"
|
87
86
|
|
88
87
|
token = (prepared_options.delete(CoAP::TOKEN_ON) || [nil])[0] || ''
|
89
|
-
puts "TOKEN: #{token.inspect}" unless token
|
90
88
|
|
91
89
|
b1 = 0x40 | TTYPES_I[tt] << 4 | token.bytesize
|
92
90
|
b2 = METHODS_I[mcode] || (mcode[0] << 5) + mcode[1]
|
data/lib/core/coap/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|