protocol

package
v0.0.0-...-36f9b4c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeHeader = 0x01 // Header section type (standard binme)
	TypeBody   = 0x02 // Body section type (standard binme)
)

Standard binme section type constants (from upstream binme library)

View Source
const (
	DeviceTypeHeader = 0x03 // Header section type (device uses 0x03, not standard 0x01)
	DeviceTypeBody   = 0x02 // Body section type (matches standard binme)
)

Device-specific section type constants The SFP Wizard device uses a modified binme format with different type values

View Source
const (
	FormatJSON   = 0x01 // JSON data
	FormatString = 0x02 // UTF-8 string
	FormatBinary = 0x03 // Raw binary data
)

Binme format constants (from upstream binme library)

Variables

This section is empty.

Functions

func BinmeDecode

func BinmeDecode(data []byte) (headerJSON []byte, bodyData []byte, err error)

BinmeDecode extracts JSON data from a device binme binary envelope with zlib decompression. Returns the header JSON and body data.

Expected format (device-specific modified binme):

[Device Transport Header - 4 bytes]
  bytes 0-1: total message length (big-endian)
  bytes 2-3: sequence number (big-endian)

[Header Section - 9 bytes + data] (device-specific format)
  byte 0: type (0x03 = DeviceTypeHeader)
  byte 1: format
  byte 2: isCompressed
  byte 3: flags (0x00 for responses)
  bytes 4-7: reserved (0x00 0x00 0x00 0x00)
  byte 8: length (single byte)
  bytes 9+: header data

[Body Section - 8 bytes + data] (standard binme format)
  byte 0: type (0x02 = TypeBody)
  byte 1: format
  byte 2: isCompressed
  byte 3: reserved
  bytes 4-7: length (big-endian uint32)
  bytes 8+: body data

func BinmeEncode

func BinmeEncode(jsonData []byte, bodyData []byte, seqNum uint16) ([]byte, error)

BinmeEncode wraps JSON data in the device's modified binme binary envelope format.

Note: The SFP Wizard device uses a modified binme format that differs from the standard binme library. Key differences:

  • Header section uses type 0x03 instead of standard 0x01
  • Header section is 9 bytes (vs standard 8), with single-byte length at byte 8
  • Body section matches standard format (8 bytes, type 0x02)

Device message format:

[Device Transport Header - 4 bytes]
  bytes 0-1: total message length (big-endian, includes this header)
  bytes 2-3: sequence number (big-endian, matches request ID)

[Header Section - 9 bytes + data] (device-specific format)
  byte 0: type (0x03 = DeviceTypeHeader)
  byte 1: format (0x01 = FormatJSON)
  byte 2: isCompressed (0x01 = zlib compressed)
  byte 3: flags (0x01 for requests)
  bytes 4-7: reserved (0x00 0x00 0x00 0x00)
  byte 8: length (single byte)
  bytes 9+: compressed header data

[Body Section - 8 bytes + data] (standard binme format)
  byte 0: type (0x02 = TypeBody)
  byte 1: format (0x01 = FormatJSON)
  byte 2: isCompressed (0x01 = zlib compressed)
  byte 3: reserved (0x00)
  bytes 4-7: length (big-endian uint32)
  bytes 8+: compressed body data

func BinmeEncodeRawBody

func BinmeEncodeRawBody(jsonData []byte, bodyData []byte, seqNum uint16) ([]byte, error)

BinmeEncodeRawBody wraps JSON header with a raw binary body (format=FormatBinary). Used for XSFP write operations that send binary EEPROM data.

func BinmeEncodeStringBody

func BinmeEncodeStringBody(jsonData []byte, bodyData []byte, seqNum uint16) ([]byte, error)

BinmeEncodeStringBody wraps JSON header with a string body (format=FormatString). Used for form-encoded data like "name=value".

func NextRequestID

func NextRequestID() (string, uint16)

NextRequestID returns the next incrementing request ID in UUID format and sequence number

Types

type APIRequest

type APIRequest struct {
	Type      string   `json:"type"`
	ID        string   `json:"id"`
	Timestamp int64    `json:"timestamp"`
	Method    string   `json:"method"` // HTTP method: GET or POST
	Path      string   `json:"path"`   // API endpoint path
	Headers   struct{} `json:"headers"`
}

APIRequest is the JSON envelope for API requests The firmware requires "type": "httpRequest" to route to the API handler

type APIResponse

type APIResponse struct {
	Type       string          `json:"type"`
	ID         string          `json:"id"`
	Timestamp  int64           `json:"timestamp"`
	StatusCode int             `json:"statusCode"`
	Headers    struct{}        `json:"headers"`
	Body       json.RawMessage `json:"body"`
}

APIResponse is the JSON envelope for API responses The firmware sends "type": "httpResponse" for API responses

type DeviceInfo

type DeviceInfo struct {
	ID         string `json:"id"`
	FWVersion  string `json:"fwv"`
	APIVersion string `json:"apiVersion"`
	Voltage    string `json:"voltage"`
	Level      string `json:"level"`
}

DeviceInfo represents the JSON response from the device info characteristic

type ResponseData

type ResponseData struct {
	Envelope APIResponse
	Body     []byte
}

ResponseData holds the parsed response envelope and body

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL