-
Notifications
You must be signed in to change notification settings - Fork 1
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
Device::getAssetInfo() and new format in Device::getFirmwareModuleInfo() #96
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c23409
Device::getAssetInfo() and new format in Device::getFirmwareModuleInfo()
avtolstoy b5fe5c0
fix
avtolstoy d14365f
Update @particle/device-os-protobuf to 2.2.0
keeramis f747ad0
submodule proto updated
keeramis c77b742
Ignore /proto in lint
keeramis ebd8cab
Add test for getAssetInfo
keeramis 61ce881
[tests] for firmware modules
keeramis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,6 @@ module.exports = { | |
mocha: true, | ||
worker: true, | ||
serviceworker: true | ||
} | ||
}, | ||
ignorePatterns: '/proto' | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule proto
updated
from 3fe90e to 16f255
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,7 @@ const proto = require('./protocol'); | |
|
||
const DeviceOSProtobuf = require('@particle/device-os-protobuf'); | ||
|
||
/** | ||
* Firmware module types. | ||
* | ||
* @enum {String} | ||
*/ | ||
const FirmwareModule = fromProtobufEnum(DeviceOSProtobuf.definitions.FirmwareModuleType, { | ||
const FirmwareModuleDeprecated = fromProtobufEnum(DeviceOSProtobuf.definitions.FirmwareModuleType, { | ||
/** Bootloader module. */ | ||
BOOTLOADER: 'BOOTLOADER', | ||
/** System part module. */ | ||
|
@@ -30,18 +25,52 @@ const FirmwareModule = fromProtobufEnum(DeviceOSProtobuf.definitions.FirmwareMod | |
RADIO_STACK: 'RADIO_STACK' | ||
}); | ||
|
||
/** | ||
* Firmware module types. | ||
* | ||
* @enum {String} | ||
*/ | ||
const FirmwareModule = fromProtobufEnum(DeviceOSProtobuf.cloudDefinitions.FirmwareModuleType, { | ||
INVALID: 'INVALID_MODULE', | ||
RESOURCE: 'RESOURCE_MODULE', | ||
BOOTLOADER: 'BOOTLOADER_MODULE', | ||
MONO_FIRMWARE: 'MONO_FIRMWARE_MODULE', | ||
SYSTEM_PART: 'SYSTEM_PART_MODULE', | ||
USER_PART: 'USER_PART_MODULE', | ||
SETTINGS: 'SETTINGS_MODULE', | ||
NCP_FIRMWARE: 'NCP_FIRMWARE_MODULE', | ||
RADIO_STACK: 'RADIO_STACK_MODULE', | ||
ASSET: 'ASSET_MODULE', | ||
}); | ||
|
||
/** | ||
* Firmware module store. | ||
* | ||
* @enum {String} | ||
*/ | ||
const FirmwareModuleStore = fromProtobufEnum(DeviceOSProtobuf.cloudDefinitions.FirmwareModuleStore, { | ||
MAIN: 'MAIN_MODULE_STORE', | ||
FACTORY: 'FACTORY_MODULE_STORE', | ||
BACKUP: 'BACKUP_MODULE_STORE', | ||
SCRATCHPAD: 'SCRATCHPAD_MODULE_STORE', | ||
}); | ||
|
||
/** | ||
* Firmware module readable names | ||
* | ||
* @enum {String} | ||
*/ | ||
const FirmwareModuleDisplayNames = { | ||
[FirmwareModule.BOOTLOADER]: 'Bootloader', | ||
[FirmwareModule.SYSTEM_PART]: 'System Part', | ||
[FirmwareModule.USER_PART]: 'User Part', | ||
[FirmwareModule.MONO_FIRMWARE]: 'Monolithic Firmware', | ||
[FirmwareModule.NCP_FIRMWARE]: 'Network Co-processor Firmware', | ||
[FirmwareModule.RADIO_STACK]: 'Radio Stack Module' | ||
[FirmwareModule.INVALID_MODULE]: 'Invalid', | ||
[FirmwareModule.RESOURCE_MODULE]: 'Resource', | ||
[FirmwareModule.BOOTLOADER_MODULE]: 'Bootloader', | ||
[FirmwareModule.MONO_FIRMWARE_MODULE]: 'Monolithic Firmware', | ||
[FirmwareModule.SYSTEM_PART_MODULE]: 'System Part', | ||
[FirmwareModule.USER_PART_MODULE]: 'User Part', | ||
[FirmwareModule.SETTINGS_MODULE]: 'Settings', | ||
[FirmwareModule.NCP_FIRMWARE_MODULE]: 'Network Co-processor Firmware', | ||
[FirmwareModule.RADIO_STACK_MODULE]: 'Radio Stack Module', | ||
[FirmwareModule.ASSET_MODULE]: 'Asset' | ||
}; | ||
|
||
/** | ||
|
@@ -425,13 +454,50 @@ class Device extends DeviceBase { | |
}); | ||
} | ||
|
||
/** | ||
* Get asset info. | ||
* | ||
* | ||
* Supported platforms: | ||
* - Gen 3+ (since Device OS 5.6.0) | ||
* | ||
* @return {Promise<Array>} List of asssets available on the device. | ||
*/ | ||
async getAssetInfo() { | ||
if (this.isInDfuMode) { | ||
throw new StateError('Cannot get information when the device is in DFU mode'); | ||
} | ||
|
||
const assetInfoResponse = await this.sendProtobufRequest('GetAssetInfoRequest', null); | ||
const available = assetInfoResponse.available.map(asset => { | ||
const { name, size, storageSize } = asset; | ||
const hash = asset.hash.toString('hex'); | ||
return { | ||
name, | ||
hash, | ||
size, | ||
storageSize | ||
}; | ||
}); | ||
const required = assetInfoResponse.required.map(asset => { | ||
const { name } = asset; | ||
const hash = asset.hash.toString('hex'); | ||
return { | ||
name, | ||
hash, | ||
}; | ||
}); | ||
return { available, required }; | ||
} | ||
|
||
/** | ||
* Get firmware module info. | ||
* | ||
* | ||
* Supported platforms: | ||
* - Gen 3 (since Device OS 0.9.0) | ||
* - Gen 2 (since Device OS 0.8.0) | ||
* - New format since 5.6.0 (old format in 'modules_deprecated') | ||
* | ||
* @return {Promise<Array>} List of modules installed into the device and their dependencies | ||
*/ | ||
|
@@ -441,23 +507,53 @@ class Device extends DeviceBase { | |
} | ||
|
||
const moduleInfoResponse = await this.sendProtobufRequest('GetModuleInfoRequest', null); | ||
const { modules } = moduleInfoResponse; | ||
const { modulesDeprecated, modules } = moduleInfoResponse; | ||
|
||
if (modulesDeprecated && modulesDeprecated.length > 0) { | ||
return modulesDeprecated.map(module => { | ||
const { index, type, dependencies, size, version } = module; | ||
|
||
return { | ||
type: FirmwareModuleDeprecated.fromProtobuf(type), | ||
index, | ||
version, | ||
size, | ||
dependencies: dependencies.map(dependency => { | ||
return { | ||
index: dependency.index, | ||
version: dependency.version, | ||
type: FirmwareModuleDeprecated.fromProtobuf(dependency.type) | ||
}; | ||
}), | ||
}; | ||
}); | ||
} | ||
|
||
return modules.map(module => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keeramis can you add a test for this new branch of the method? |
||
const { index, type, dependencies, size, version } = module; | ||
const { index, type, dependencies, size, version, assetDependencies, maxSize, store } = module; | ||
const failedFlags = module.checkedFlags ^ module.passedFlags; | ||
|
||
return { | ||
type: FirmwareModule.fromProtobuf(type), | ||
store: FirmwareModuleStore.fromProtobuf(store), | ||
index, | ||
version, | ||
size, | ||
maxSize, | ||
failedFlags, | ||
dependencies: dependencies.map(dependency => { | ||
return { | ||
index: dependency.index, | ||
version: dependency.version, | ||
type: FirmwareModule.fromProtobuf(dependency.type) | ||
}; | ||
}), | ||
assetDependencies: assetDependencies.map(asset => { | ||
return { | ||
name: asset.name, | ||
hash: asset.hash.toString('hex') | ||
}; | ||
}) | ||
}; | ||
}); | ||
} | ||
|
@@ -982,6 +1078,7 @@ class Device extends DeviceBase { | |
module.exports = { | ||
FirmwareModule, | ||
FirmwareModuleDisplayNames, | ||
FirmwareModuleStore, | ||
DeviceMode, | ||
LogLevel, | ||
Device | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@keeramis can you add a test for this method?