feat: Generalize SetOtherParams, add per-field setters, sync requestTelemetry, and re-export constants#25
Open
Yeraze wants to merge 3 commits into
Open
Conversation
The existing sendCommandSetOtherParams only carried manualAddContacts, but the firmware's SetOtherParams (opcode 38) payload also packs telemetry_mode (base/loc/env in one byte, 2 bits each) and adv_loc_policy. This brings meshcore.js to parity with python-meshcore's set_other_params and the new set_*_from_infos helpers. Changes: - sendCommandSetOtherParams accepts (manualAddContacts, telemetryModeBase, telemetryModeLoc, telemetryModeEnv, advLocPolicy) and packs the three telemetry mode fields into a single byte as the firmware expects. - setOtherParams accepts either the legacy boolean or a full options object, so existing callers (setAutoAddContacts / setManualAddContacts) keep working. - onSelfInfoResponse now decodes the three bytes that used to be 'reserved' into multiAcks, advLocPolicy, and telemetryMode (plus unpacked telemetryModeBase/Loc/Env), matching python-meshcore's SELF_INFO parser. The original 'reserved' field is kept for backward compatibility. - New convenience methods setTelemetryModeBase / setTelemetryModeLoc / setTelemetryModeEnv / setAdvertLocPolicy mirror python-meshcore: each reads current SelfInfo via getSelfInfo() (AppStart), patches the one field, and replays all fields. setAutoAddContacts / setManualAddContacts now use the same read-modify-write pattern so they no longer wipe the telemetry/adv_loc settings. - Added Constants.TelemetryMode and Constants.AdvLocPolicy enums.
Mirrors python-meshcore's req_telemetry_sync. Sends a binary request of type REQ_TYPE_GET_TELEMETRY_DATA (0x03) to the given contact via the existing sendBinaryRequest plumbing (which correlates Sent → tagged BinaryResponse push), then decodes the response payload using the existing CayenneLpp.parse. Accepts a contact object (uses its .publicKey), a 32-byte Uint8Array public key, or a hex string. Returns the parsed Cayenne LPP sensor array.
Constants.TelemetryMode / AdvLocPolicy / BinaryRequestTypes (and the
existing CommandCodes / ResponseCodes / PushCodes) are now also exposed
as named top-level exports from src/index.js, so downstream consumers
can write `import { TelemetryMode } from 'meshcore.js'` instead of
reaching through `Constants.TelemetryMode`. Constants itself is still
exported for backward compatibility.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Three additions to support MeshMonitor's native JS integration, matching capabilities already present in python-meshcore. All follow existing code style and patterns.
Changes
1. Generalize
sendCommandSetOtherParams+ per-field convenience setterssendCommandSetOtherParamspreviously only carriedmanualAddContacts. The firmware's opcode 38 (SetOtherParams) actually carries the full field set:manualAddContacts(bool)telemetryModeBase(uint8, 2-bit)telemetryModeLoc(uint8, 2-bit)telemetryModeEnv(uint8, 2-bit)advLocPolicy(uint8)This PR generalizes the method to pack all fields (telemetry modes into the single byte the firmware expects:
base | loc<<2 | env<<4), matching python-meshcore's wire format.New convenience methods using a read-modify-write pattern (AppStart read → patch one field → replay all):
setTelemetryModeBase(mode)setTelemetryModeLoc(mode)setTelemetryModeEnv(mode)setAdvertLocPolicy(policy)Also reworked
setAutoAddContacts/setManualAddContactsto use the same safe read-modify-write pattern so they don't wipe sibling settings.onSelfInfoResponsenow decodes the 3 previously-reserved bytes intomultiAcks,advLocPolicy, andtelemetryMode(+ unpackedtelemetryModeBase/Loc/Env). Thereservedfield is kept for backward compatibility.New constants:
Constants.TelemetryModeandConstants.AdvLocPolicyenums.2. Sync
requestTelemetryhelperrequestTelemetry(contactOrPublicKey, timeoutMs = 10000)— sendsBinaryRequestTypes.GetTelemetryData(0x03) via existingsendBinaryRequest, awaits the taggedBinaryResponsepush, and returns parsed Cayenne LPP data. Accepts contact object, Uint8Array, or hex string.This mirrors python-meshcore's
req_telemetry_sync().3. Top-level constant re-exports
TelemetryMode,BinaryRequestTypes,AdvLocPolicy,CommandCodes,ResponseCodes,PushCodesare now also exported as named top-level exports fromsrc/index.jsfor cleaner imports.Constantsitself is still exported.Verification
node --checkon all modified files