Documentation
¶
Index ¶
- Constants
- func BinmeDecode(data []byte) (headerJSON []byte, bodyData []byte, err error)
- func BinmeEncode(jsonData []byte, bodyData []byte, seqNum uint16) ([]byte, error)
- func BinmeEncodeRawBody(jsonData []byte, bodyData []byte, seqNum uint16) ([]byte, error)
- func BinmeEncodeStringBody(jsonData []byte, bodyData []byte, seqNum uint16) ([]byte, error)
- func NextRequestID() (string, uint16)
- type APIRequest
- type APIResponse
- type DeviceInfo
- type ResponseData
Constants ¶
const ( TypeHeader = 0x01 // Header section type (standard binme) TypeBody = 0x02 // Body section type (standard binme) )
Standard binme section type constants (from upstream binme library)
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
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 ¶
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 ¶
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 ¶
BinmeEncodeRawBody wraps JSON header with a raw binary body (format=FormatBinary). Used for XSFP write operations that send binary EEPROM data.
func BinmeEncodeStringBody ¶
BinmeEncodeStringBody wraps JSON header with a string body (format=FormatString). Used for form-encoded data like "name=value".
func NextRequestID ¶
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