180 lines
8.6 KiB
Go
180 lines
8.6 KiB
Go
package meshcore
|
|
|
|
import "fmt"
|
|
|
|
const (
|
|
companionErrCodeUnsupported byte = 1 + iota
|
|
companionErrCodeNotFound
|
|
companionErrCodeTableFull
|
|
companionErrCodeBadState
|
|
companionErrCodeFileIOError
|
|
companionErrCodeIllegalArgument
|
|
)
|
|
|
|
// companion command bytes
|
|
const (
|
|
companionAppStart byte = 1 + iota //
|
|
companionSendTextMessage //
|
|
companionSendChannelTextMessage //
|
|
companionGetContacts // with optional 'since' (for efficient sync)
|
|
companionGetDeviceTime //
|
|
companionSetDeviceTime //
|
|
companionSendSelfAdvert //
|
|
companionSetAdvertName //
|
|
companionAddUpdateContact //
|
|
companionSyncMessages //
|
|
companionSetRadioParams //
|
|
companionSetRadioTXPower //
|
|
companionResetPath //
|
|
companionSetAdvertLatLon //
|
|
companionRemoveContact //
|
|
companionShareContact //
|
|
companionExportContact //
|
|
companionImportContact //
|
|
companionReboot //
|
|
companionGetBatteryAndStorage // was CMD_GetBATTERY_VOLTAGE
|
|
companionSetTuningParams //
|
|
companionDeviceQuery //
|
|
companionExportPrivateKey //
|
|
companionImportPrivateKey //
|
|
companionSendRawData //
|
|
companionSendLogin //
|
|
companionSendStatusRequest //
|
|
companionHasConnection //
|
|
companionLogout // 'Disconnect'
|
|
companionGetContactByKey //
|
|
companionGetChannel //
|
|
companionSetChannel //
|
|
companionSignStart //
|
|
companionSignData //
|
|
companionSignFinish //
|
|
companionSendTracePath //
|
|
companionSetDevicePIN //
|
|
companionSetOtherParams //
|
|
companionSendTelemetryRequest //
|
|
companionGetCustomVars //
|
|
companionSetCustomVar //
|
|
companionGetAdvertPath //
|
|
companionGetTuningParams //
|
|
_ // parked
|
|
_ // parked
|
|
_ // parked
|
|
_ // parked
|
|
_ // parked
|
|
_ // parked
|
|
companionSendBinaryRequest //
|
|
companionFactoryReset //
|
|
companionSendPathDiscoveryRequest //
|
|
_ // parked
|
|
companionSetFloodScope // v8+
|
|
companionSendControlData // v8+
|
|
companionGetStats // v8+, second byte is stats type
|
|
companionSendAnonymousRequest //
|
|
companionSetAutoAddConfig //
|
|
companionGetAutoAddConfig //
|
|
)
|
|
|
|
// companion response bytes
|
|
const (
|
|
companionResponseOK byte = iota
|
|
companionResponseError
|
|
companionResponseContactsStart // first reply to CMD_GetCONTACTS
|
|
companionResponseContact // multiple of these (after CMD_GetCONTACTS)
|
|
companionResponseEndOfContacts // last reply to CMD_GetCONTACTS
|
|
companionResponseSelfInfo // reply to CMD_APP_START
|
|
companionResponseSent // reply to CMD_SEND_TXT_MSG
|
|
companionResponseContactMessageReceived // a reply to CMD_SYNC_NEXT_MESSAGE (ver < 3)
|
|
companionResponseChannelMessageReceived // a reply to CMD_SYNC_NEXT_MESSAGE (ver < 3)
|
|
companionResponseCurrentTime // a reply to CMD_GetDEVICE_TIME
|
|
companionResponseNoMoreMessages // a reply to CMD_SYNC_NEXT_MESSAGE
|
|
companionResponseExportContact //
|
|
companionResponseBatteryAndStorage // a reply to a CMD_GetBATT_AND_STORAGE
|
|
companionResponseDeviceInfo // a reply to CMD_DEVICE_QEURY
|
|
companionResponsePrivateKey // a reply to CMD_EXPORT_PRIVATE_KEY
|
|
companionResponseDisabled //
|
|
companionResponseContactMessageReceivedV3 // a reply to CMD_SYNC_NEXT_MESSAGE (ver >= 3)
|
|
companionResponseChannelMessageReceivedV3 // a reply to CMD_SYNC_NEXT_MESSAGE (ver >= 3)
|
|
companionResponseChannelInfo // a reply to CMD_GetCHANNEL
|
|
companionResponseSignatureStart //
|
|
companionResponseSignature //
|
|
companionResponseCustomVars //
|
|
companionResponseAdvertPath //
|
|
companionResponseTuningParams //
|
|
companionResponseStats // v8+, second byte is stats type
|
|
companionResponseAutoAddConfig //
|
|
)
|
|
|
|
// companion push code bytes
|
|
const (
|
|
companionPushAdvert byte = 0x80 + iota
|
|
companionPushPathUpdated
|
|
companionPushSendConfirmed
|
|
companionPushMessageWaiting
|
|
companionPushRawData
|
|
companionPushLoginSuccess
|
|
companionPushLoginFailure
|
|
companionPushStatusResponse
|
|
companionPushLogRXData
|
|
companionPushTraceData
|
|
companionPushNewAdvert
|
|
companionPushTelemetryResponse
|
|
companionPushBinaryResponse
|
|
companionPushPathDiscoveryResponse
|
|
companionPushControlData
|
|
companionPushContactDeleted
|
|
companionPushContactsFull
|
|
)
|
|
|
|
var companionResponseNames = map[byte]string{
|
|
companionResponseOK: "ok",
|
|
companionResponseError: "error",
|
|
companionResponseContactsStart: "contact start",
|
|
companionResponseContact: "contact",
|
|
companionResponseEndOfContacts: "end of contacts",
|
|
companionResponseSelfInfo: "self info",
|
|
companionResponseSent: "sent",
|
|
companionResponseContactMessageReceived: "contact message received",
|
|
companionResponseChannelMessageReceived: "channel message received",
|
|
companionResponseCurrentTime: "current time",
|
|
companionResponseNoMoreMessages: "no more messages",
|
|
companionResponseExportContact: "export contact",
|
|
companionResponseBatteryAndStorage: "battery and storage",
|
|
companionResponseDeviceInfo: "device info",
|
|
companionResponsePrivateKey: "private key",
|
|
companionResponseDisabled: "disabled",
|
|
companionResponseContactMessageReceivedV3: "contact message received V3",
|
|
companionResponseChannelMessageReceivedV3: "channel message received V3",
|
|
companionResponseChannelInfo: "channel info",
|
|
companionResponseSignatureStart: "signature start",
|
|
companionResponseSignature: "signature",
|
|
companionResponseCustomVars: "custom vars",
|
|
companionResponseAdvertPath: "advert path",
|
|
companionResponseTuningParams: "tuning params",
|
|
companionResponseStats: "stats",
|
|
companionResponseAutoAddConfig: "auto add config",
|
|
companionPushAdvert: "push advert",
|
|
companionPushPathUpdated: "push path updated",
|
|
companionPushSendConfirmed: "push send confirmed",
|
|
companionPushMessageWaiting: "push message waiting",
|
|
companionPushRawData: "push raw data",
|
|
companionPushLoginSuccess: "push login success",
|
|
companionPushLoginFailure: "push login failure",
|
|
companionPushStatusResponse: "push status response",
|
|
companionPushLogRXData: "push log rx data",
|
|
companionPushTraceData: "push trace data",
|
|
companionPushNewAdvert: "push new advert",
|
|
companionPushTelemetryResponse: "push telemetry response",
|
|
companionPushBinaryResponse: "push binary response",
|
|
companionPushPathDiscoveryResponse: "push path discovery response",
|
|
companionPushControlData: "push control data",
|
|
companionPushContactDeleted: "push contact deleted",
|
|
companionPushContactsFull: "push contacts full",
|
|
}
|
|
|
|
func companionResponseName(response byte) string {
|
|
if s, ok := companionResponseNames[response]; ok {
|
|
return s
|
|
}
|
|
return fmt.Sprintf("unknown %02x", response)
|
|
}
|