| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package hth6400
- import (
- "context"
- "fmt"
- "prod2u6400-uartkit/internal/i2creg"
- "prod2u6400-uartkit/internal/protocol"
- "prod2u6400-uartkit/internal/transport"
- )
- type SetAll = protocol.SetAll
- type Frame = protocol.Frame
- type Ack = protocol.Ack
- type I2CTransaction = i2creg.Transaction
- type UARTTransport = transport.UARTTransport
- type I2CRegisterTransport interface {
- WriteSetAll(context.Context, SetAll) error
- GetSnapshot(context.Context) ([]byte, error)
- }
- type MockTransport = transport.MockTransport
- type ReplayTransport = transport.ReplayTransport
- // EncodeFrame is the shared A5 5A + CRC codec for response/replay fixtures.
- func EncodeFrame(frameType byte, payload []byte) []byte {
- return protocol.Encode(frameType, payload)
- }
- // DecodeFrame validates framing and CRC without assigning application meaning.
- func DecodeFrame(raw []byte) (Frame, error) {
- return protocol.Decode(raw)
- }
- func SetAllFrame(s SetAll) ([]byte, error) { return protocol.EncodeSetAll(s) }
- func GetSnapshotFrame() []byte { return protocol.EncodeGetSnapshot() }
- func DecodeAckNack(raw []byte) (Ack, error) {
- f, err := protocol.Decode(raw)
- if err != nil {
- return Ack{}, err
- }
- return protocol.DecodeAck(f)
- }
- func DecodeSnapshot(raw []byte) ([]byte, error) {
- f, err := protocol.Decode(raw)
- if err != nil {
- return nil, err
- }
- if f.Type != protocol.TypeSnapshot {
- return nil, fmt.Errorf("unexpected snapshot type 0x%02X", f.Type)
- }
- return f.Payload, nil
- }
- func SetAllI2C(s SetAll) ([]I2CTransaction, error) { return i2creg.SetAllTransactions(s) }
- func GetSnapshotI2C() I2CTransaction { return i2creg.GetSnapshotTransactions()[0] }
- func SnapshotReadI2C(length uint16, chunk int) ([]I2CTransaction, error) {
- return i2creg.SnapshotReads(length, chunk)
- }
|