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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56fd9991ac9ab886355fcce10739897c5ead898c
4
- data.tar.gz: 53cf80a9babac55dd80aebe62741be8d13b3b1f4
3
+ metadata.gz: 36ea360829046ce72e968fe067c38e687bf3de8c
4
+ data.tar.gz: c9c5ab0540425a325cba51a5063b12c4f0416189
5
5
  SHA512:
6
- metadata.gz: 01be6617acec7d215ddf15fdd34e443f6114f6677d5d2de3292298bd7e28c30c90f5a97f66f7aa3b08fd2d4853c3451f0159b41ef09ae1d675fcaa43727006ad
7
- data.tar.gz: be1e122636bf35da1cd884cfaa663bd48539879b8607a96de3c53190045e10307193d84847048e981abe04f727cf621fb9041baa347d02856cbad004ece38ef0
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
- --debug, -d Extra debug output.
15
- --output, -o <target> Redirect payload output. Target can be "-" for
16
- STDOUT or a file path.
17
- --payload, -p <string> Payload for POST and PUT as string.
18
- --payload-file, -f <file> Read payload for POST and PUT from file.
19
- --type, -t <type> Message type (con, non, ack, rst).
20
- --help, -h This usage message.
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
- ['--debug', '-d', GetoptLong::NO_ARGUMENT],
30
- ['--output', '-o', GetoptLong::REQUIRED_ARGUMENT],
31
- ['--payload', '-p', GetoptLong::REQUIRED_ARGUMENT],
32
- ['--payload-file', '-f', GetoptLong::REQUIRED_ARGUMENT],
33
- ['--type', '-t', GetoptLong::REQUIRED_ARGUMENT],
34
- ['--help', '-h', GetoptLong::NO_ARGUMENT]
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
@@ -269,13 +269,15 @@ module CoRE
269
269
  end
270
270
 
271
271
  def initialize_message(method, path, query = nil, payload = nil)
272
- mid = SecureRandom.random_number(0xffff)
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)
@@ -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]
@@ -62,8 +62,6 @@ module CoRE
62
62
  Timeout.timeout(1) { @socket.recvfrom(1152) }
63
63
  end
64
64
 
65
- return if answer.nil?
66
-
67
65
  if answer.tt == :con
68
66
  message = Message.new(:ack, 0, answer.mid, nil,
69
67
  {token: answer.options[:token]})
@@ -1,5 +1,5 @@
1
1
  module CoRE
2
2
  module CoAP
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
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.0
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-01-20 00:00:00.000000000 Z
13
+ date: 2015-02-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler