-
Notifications
You must be signed in to change notification settings - Fork 293
feat: Add Binary Import/Export #1229
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
Open
tylerpieper
wants to merge
7
commits into
meshtastic:main
Choose a base branch
from
tylerpieper:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+222
−1
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8466e22
add import/export
tylerpieper b7b61f2
fixes based on automated review
tylerpieper 0e01b6a
Merge branch 'main' into main
danditomaso ccc2009
Merge branch 'meshtastic:main' into main
tylerpieper c428d40
Moved Toast Strings and Refactored to finally block
tylerpieper 2ac7420
Merge branch 'main' of https://github.com/tylerpieper/web
tylerpieper df543fd
Merge branch 'main' into main
tylerpieper 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { create, toBinary, fromBinary } from "@bufbuild/protobuf"; | ||
| import { Protobuf, type ConfigEditor } from "@meshtastic/sdk"; | ||
|
|
||
| export function exportProfile(editor: ConfigEditor) { | ||
| const radio = editor.radio.peek(); | ||
| const modules = editor.modules.peek(); | ||
| const owner = editor.owner.peek(); | ||
|
|
||
| const profile = create(Protobuf.ClientOnly.DeviceProfileSchema, { | ||
| longName: owner?.longName, | ||
| shortName: owner?.shortName, | ||
| // @ts-expect-error fixedPosition is mapped dynamically in some contexts | ||
| fixedPosition: radio.fixedPosition, | ||
| config: { | ||
| device: radio.device, | ||
| position: radio.position, | ||
| power: radio.power, | ||
| network: radio.network, | ||
| display: radio.display, | ||
| lora: radio.lora, | ||
| bluetooth: radio.bluetooth, | ||
| security: radio.security, | ||
| sessionkey: radio.sessionkey, | ||
| }, | ||
| moduleConfig: { | ||
| mqtt: modules.mqtt, | ||
| serial: modules.serial, | ||
| extNotification: modules.extNotification, | ||
| storeForward: modules.storeForward, | ||
| rangeTest: modules.rangeTest, | ||
| telemetry: modules.telemetry, | ||
| cannedMessage: modules.cannedMessage, | ||
| audio: modules.audio, | ||
| neighborInfo: modules.neighborInfo, | ||
| ambientLighting: modules.ambientLighting, | ||
| detectionSensor: modules.detectionSensor, | ||
| paxcounter: modules.paxcounter, | ||
| } | ||
| }); | ||
|
|
||
| const bytes = toBinary(Protobuf.ClientOnly.DeviceProfileSchema, profile); | ||
| const blob = new Blob([bytes], { type: "application/octet-stream" }); | ||
| const url = URL.createObjectURL(blob); | ||
| const a = document.createElement("a"); | ||
| a.href = url; | ||
| a.download = "profile.cfg"; | ||
| a.click(); | ||
| URL.revokeObjectURL(url); | ||
| } | ||
|
|
||
| export function importProfile(bytes: Uint8Array, editor: ConfigEditor) { | ||
| const profile = fromBinary(Protobuf.ClientOnly.DeviceProfileSchema, bytes); | ||
|
|
||
| if (profile.longName || profile.shortName) { | ||
| editor.setOwner({ | ||
| longName: profile.longName || editor.owner.peek()?.longName || "", | ||
| shortName: profile.shortName || editor.owner.peek()?.shortName || "", | ||
| macaddr: editor.owner.peek()?.macaddr || new Uint8Array(), | ||
| id: editor.owner.peek()?.id || "", | ||
| hwModel: editor.owner.peek()?.hwModel || 0, | ||
| isLicensed: editor.owner.peek()?.isLicensed || false, | ||
| role: editor.owner.peek()?.role || 0, | ||
| publicKey: editor.owner.peek()?.publicKey || new Uint8Array(), | ||
| }); | ||
| } | ||
|
|
||
| const config = profile.config; | ||
| if (config) { | ||
| if (config.device) editor.setRadioSection("device", config.device); | ||
| if (config.position) editor.setRadioSection("position", config.position); | ||
| if (config.power) editor.setRadioSection("power", config.power); | ||
| if (config.network) editor.setRadioSection("network", config.network); | ||
| if (config.display) editor.setRadioSection("display", config.display); | ||
| if (config.lora) editor.setRadioSection("lora", config.lora); | ||
| if (config.bluetooth) editor.setRadioSection("bluetooth", config.bluetooth); | ||
| if (config.security) editor.setRadioSection("security", config.security); | ||
| if (config.sessionkey) editor.setRadioSection("sessionkey", config.sessionkey); | ||
| } | ||
|
|
||
| const moduleConfig = profile.moduleConfig; | ||
| if (moduleConfig) { | ||
| if (moduleConfig.mqtt) editor.setModuleSection("mqtt", moduleConfig.mqtt); | ||
| if (moduleConfig.serial) editor.setModuleSection("serial", moduleConfig.serial); | ||
| if (moduleConfig.extNotification) editor.setModuleSection("extNotification", moduleConfig.extNotification); | ||
| if (moduleConfig.storeForward) editor.setModuleSection("storeForward", moduleConfig.storeForward); | ||
| if (moduleConfig.rangeTest) editor.setModuleSection("rangeTest", moduleConfig.rangeTest); | ||
| if (moduleConfig.telemetry) editor.setModuleSection("telemetry", moduleConfig.telemetry); | ||
| if (moduleConfig.cannedMessage) editor.setModuleSection("cannedMessage", moduleConfig.cannedMessage); | ||
| if (moduleConfig.audio) editor.setModuleSection("audio", moduleConfig.audio); | ||
| if (moduleConfig.neighborInfo) editor.setModuleSection("neighborInfo", moduleConfig.neighborInfo); | ||
| if (moduleConfig.ambientLighting) editor.setModuleSection("ambientLighting", moduleConfig.ambientLighting); | ||
| if (moduleConfig.detectionSensor) editor.setModuleSection("detectionSensor", moduleConfig.detectionSensor); | ||
| if (moduleConfig.paxcounter) editor.setModuleSection("paxcounter", moduleConfig.paxcounter); | ||
| } | ||
|
|
||
| if (profile.fixedPosition) { | ||
| editor.queueAdminMessage({ | ||
| payloadVariant: { | ||
| case: "setFixedPosition", | ||
| value: profile.fixedPosition | ||
| } | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.