Skip to content

Commit

Permalink
Merge pull request #42 from avency/feature/supportHexCoapOption
Browse files Browse the repository at this point in the history
Feature/support hex coap option
  • Loading branch information
BlueBeN82 authored Sep 4, 2019
2 parents 755d645 + 395a6b6 commit 9ad4518
Show file tree
Hide file tree
Showing 4 changed files with 2,784 additions and 5 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js
sudo: false
node_js:
- "6"
- "8"
- "10"
- "11"
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function collectOptions (val, memo) {
} else {
console.log('Error: Option \'%s\' is invalid.', val)
console.log('Please provide options in this way:')
console.log('-O [Key]" + coapOptionSeperator + "[Value]')
console.log('OR --coap-option [Key]' + coapOptionSeperator + '[Value]')
console.log('-O 2048' + coapOptionSeperator + 'HelloWorld')
console.log('OR --coap-option 2048' + coapOptionSeperator + 'HelloWorld')
process.exit(-1)
}
return memo
Expand All @@ -35,7 +35,7 @@ program
.option('-c, --non-confirmable', 'non-confirmable', 'boolean', false)
.option('-t, --timeout <seconds>', 'The maximum send time in seconds')
.option('-T, --show-timing', 'Print request time, handy for simple performance tests', 'boolean', false)
.option('-O, --coap-option <option>', 'Add COAP-Options to the request (repeatable)', collectOptions, [])
.option('-O, --coap-option <option>', 'Add COAP-Options to the request, e.q. -O 2048,HelloWorld (repeatable)', collectOptions, [])
.usage('[command] [options] url')

;['GET', 'PUT', 'POST', 'DELETE'].forEach(function (name) {
Expand Down Expand Up @@ -86,7 +86,8 @@ if (program.block2) {
if (typeof program.coapOption !== 'undefined' && program.coapOption.length > 0) {
program.coapOption.forEach(function (singleOption) {
var kvPair = singleOption.split(coapOptionSeperator, 2)
req.setOption(kvPair[0], Buffer.from(kvPair[1]))
var optionValueBuffer = kvPair[1].startsWith('0x') ? Buffer.from(kvPair[1].substr(2), 'hex') : Buffer.from(kvPair[1])
req.setOption(kvPair[0], optionValueBuffer)
})
}

Expand Down
Loading

0 comments on commit 9ad4518

Please sign in to comment.