-
Notifications
You must be signed in to change notification settings - Fork 1
Introduce low level way to interact directly with Device OS control requests over USB #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9c6b7fc
to
5030e02
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good apart from a minor bug that I noticed, thank you!
r = DeviceOSProtobuf.decode( | ||
protobufDefinition.replyMessage, | ||
rep.data | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will overwrite the existing object with the result code when the dontThrow
option is used. Same for the other assignment below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right on @sergeuz , thanks for the review.
dontThrow
is an undocumented, untested construct that only enterListeningMode
uses. (and sendRequest
, but we want to eliminate that anyway).
I feel like it'd be better to eliminate it and instead gracefully catch the error there. That approach work for you? If so, I'll add test coverage for enterListeningMode
that ensures it works correctly when an error is thrown (and port enterListeningMode
to use sendProtobufRequest instead of sendRequest)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would work too 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sergeuz I eliminated dontThrow
option in the last couple of commits. Also managed to get 100% test coverage over enterListeningMode + sendProtobufRequest and changed CI build to be test:ci
which includes linter, tests, and code coverage minimums.
Hope this will work for ya, I'll check for your input first thing Monday and merge after if everything is cool and cut a 2.1.0 release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look great!
@@ -742,6 +742,11 @@ function addAssetTracker(options) { | |||
return addDevice(opts); | |||
} | |||
|
|||
function addP2(options) { | |||
const opts = Object.assign({}, options, { type: deviceConstants.p2.name }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little JS style thing: you can use the spread operator to combine objects more concisely than with Object.assign
. No need to change it here, just sharing a trick.
const opts = Object.assign({}, options, { type: deviceConstants.p2.name }); | |
const opts = { ...options, type: deviceConstants.p2.name }; |
…st() Also some linter fixes
…-protobuf npm run coverage style)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work @joegoggins 🙌 👍
Overview
This PR introduces the ability to interact with Device OS via USB control requests even if the there isn't a corresponding high level method in
particle-usb
. For example, Device OS exposes awifi.JoinNewNetworkRequest
protobuf message, but it cannot be used because there is no corresponding high level method likejoinNewWifiNetwork()
implemented yet onparticle-usb
. In this situation, with this code, you can interact directly via the newsendProtobufRequest
if need to.Change summary
device.sendProtobufRequest()
introducedgetSerialNumber
implementation usessendProtobufRequest
under the hood. no longer depends onsendRequest
getSerialNumber
and different mocking strategy that will allow us to add test coverage for all other high level methods like it. (device.js test coverage goes from 11% to 15%)request.js
implements and the git submodule todevice-os-protobuf
See sc-95109 for more context/details.
Script used to validate photon, p1, boron enterListeningMode still works
out of scope
This PR is deliberately small. Hoping to align, address feedback, merge on this first, then pursue this work in other PRs:
git submodule
tofirmware-protobuf
, etc sc-95947