common

package
v0.0.0-...-5449bc4 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SlipHeader     byte = 0xC0
	SlipEscapeChar byte = 0xDB
)

Variables

This section is empty.

Functions

func BytesToUint16

func BytesToUint16(value []byte) uint16

func SlipEncode

func SlipEncode(b []byte) []byte

func Uint16ToBytes

func Uint16ToBytes(value uint16) []byte

func Uint32ToBytes

func Uint32ToBytes(value uint32) []byte

Types

type Command

type Command struct {
	Direction Direction
	Opcode    Opcode
	Data      []byte
	Checksum  []byte
}

func NewAttachSpiFlashCommand

func NewAttachSpiFlashCommand() *Command

func NewBeginFlashCommand

func NewBeginFlashCommand(eraseSize uint32, numBlocks uint32, blockSize uint32, offset uint32) *Command

func NewBeginFlashDeflCommand

func NewBeginFlashDeflCommand(eraseSize uint32, numBlocks uint32, blockSize uint32, offset uint32) *Command

func NewChangeBaudrateCommand

func NewChangeBaudrateCommand(newBaudrate uint32, oldBaudrate uint32) *Command

func NewCommand

func NewCommand(opcode Opcode, data []byte) *Command

func NewFlashDataCommand

func NewFlashDataCommand(data []byte, sequence uint32) *Command

func NewFlashDataDeflCommand

func NewFlashDataDeflCommand(data []byte, sequence uint32) *Command

func NewFlashEndCommand

func NewFlashEndCommand(reboot bool) *Command

func NewReadFlashCommand

func NewReadFlashCommand(offset uint32, size uint32) *Command

func NewReadRegisterCommand

func NewReadRegisterCommand(register uint32) *Command

func NewSyncCommand

func NewSyncCommand() *Command

func (*Command) ToBytes

func (c *Command) ToBytes() []byte

type Direction

type Direction byte
const (
	DirectionRequest  Direction = 0x00
	DirectionResponse Direction = 0x01
)

type ErrorCode

type ErrorCode byte

ErrorCode - ROM Loader Error Codes

const (
	// ReceivedMessageInvalid parameters or length field is invalid
	ReceivedMessageInvalid ErrorCode = 0x05
	// FailedToActOnReceivedMessage
	FailedToActOnReceivedMessage ErrorCode = 0x06
	// InvalidCRC Invalid CRC in message
	InvalidCRC ErrorCode = 0x07
	// FlashWriteError - after writing a block of data to flash, the ROM loader reads the value back and the 8-bit CRC is compared to the data read from flash. If they don't match, this error is returned.
	FlashWriteError ErrorCode = 0x08
	// FlashReadError SPI read failed
	FlashReadError ErrorCode = 0x09
	// FlashReadLengthError SPI read request length is too long
	FlashReadLengthError ErrorCode = 0x0A
	// DeflateError (ESP32 compressed uploads only)
	DeflateError ErrorCode = 0x0B
)

func (ErrorCode) String

func (e ErrorCode) String() string

String returns a string representation of the ErrorCode

type Opcode

type Opcode byte
const (
	OpcodeFlashBegin Opcode = 0x02
	OpcodeFlashData  Opcode = 0x03
	OpcodeFlashEnd   Opcode = 0x04
	OpcodeMemBegin   Opcode = 0x05
	OpcodeMemEnd     Opcode = 0x06
	OpcodeMemData    Opcode = 0x07
	OpcodeSync       Opcode = 0x08
	OpcodeWriteReg   Opcode = 0x09
	OpcodeReadReg    Opcode = 0x0A

	OpcodeSpiSetParams   Opcode = 0x0B
	OpcodeSpiAttachFlash Opcode = 0x0D
	OpcodeReadFlash      Opcode = 0x0E
	OpcodeChangeBaudrate Opcode = 0x0F
	OpcodeFlashDeflBegin Opcode = 0x10
	OpcodeFlashDeflData  Opcode = 0x11
	OpcodeFlashDeflEnd   Opcode = 0x12
	OpcodeSpiFlashMd5    Opcode = 0x13

	OpcodeEraseFlash    Opcode = 0xD0
	OpcodeEraseRegion   Opcode = 0xD1
	OpcodeReadFlashFast Opcode = 0xD2
	OpcodeRunUserCode   Opcode = 0xD3
)

func (Opcode) String

func (o Opcode) String() string

type Response

type Response struct {
	Direction Direction
	Opcode    Opcode
	Size      uint16
	Value     [4]byte
	Data      []byte
	Status    *ResponseStatus
}

func NewResponse

func NewResponse(data []byte) (*Response, error)

type ResponseStatus

type ResponseStatus struct {
	Success   bool
	ErrorCode ErrorCode
}

func NewResponseStatus

func NewResponseStatus(data []byte) (*ResponseStatus, error)

func (*ResponseStatus) String

func (r *ResponseStatus) String() string

type SlipReadWriter

type SlipReadWriter struct {
	BaseReadWriter io.ReadWriter
	Timeout        time.Duration
	// contains filtered or unexported fields
}

func NewSlipReadWriter

func NewSlipReadWriter(base io.ReadWriter, logger *log.Logger) *SlipReadWriter

func (*SlipReadWriter) Read

func (s *SlipReadWriter) Read(timeout time.Duration) ([]byte, error)

func (*SlipReadWriter) Write

func (s *SlipReadWriter) Write(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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