myrtio

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 1 Imported by: 0

README

MyrtIO Go library Quality assurance GitHub release

Library for MyrtIO protocol support in Golang.

Allows you to format and parse messages, as well as use ready-made transports.

Transports
  • Serial
  • UDP — not ready yet

Usage

func main() {
    port, err := serial.New(serialPath, serialBaudRate)
	if err != nil {
		log.Panic(err)
	}
    // Send ping
    response, err := m.port.RunAction(&myrtio.Message{
		Feature: 0,
		Action:  0,
	})
	if err != nil {
		log.Printf("Error: %v\n", err.Error())
	}
	defer port.Close()
}

Documentation

Overview

Package myrtio adds support for MyrtIO APIs

Index

Constants

View Source
const (
	// MaxMessageLength represents the maximum allowed length for a message.
	MaxMessageLength = 128
	// MetaHeaderPadding represents header size (header (2) + length)
	MetaHeaderPadding = 3
	// MinMessageLength represents the minimum allowed message length.
	// header + feature + action + tail
	MinMessageLength = MetaHeaderPadding + 3
)
View Source
const (
	// FirstHeaderCode represents the first header code.
	FirstHeaderCode byte = 0xFE
	// SecondHeaderCode represents the second header code.
	SecondHeaderCode byte = 0xEF
	// TailCode represents the tail code.
	TailCode byte = 0xAF
	// SuccessCode represents the success code.
	SuccessCode byte = 0xEE
	// ErrorCode represents the error code.
	ErrorCode byte = 0xFF
)

Variables

View Source
var ErrWrongHeader = errors.New("unexpected header codes")

ErrWrongHeader is returned when given message contains wrong header codes

View Source
var ErrWrongLength = errors.New("message length is not correct")

ErrWrongLength is returned when given message has incorrect length

View Source
var ErrWrongTail = errors.New("unexpected tail code")

ErrWrongTail is returned when given message contains wrong tail code

Functions

This section is empty.

Types

type Message

type Message struct {
	Feature byte
	Action  byte
	Payload []byte
}

Message represent MyrtIO message

func ParseMessage

func ParseMessage(message []byte) (*Message, error)

ParseMessage parses message from raw bytes slice

func (*Message) Bytes

func (m *Message) Bytes() []byte

Bytes returns message as byte slice

func (*Message) SkipStatus added in v0.0.4

func (m *Message) SkipStatus() []byte

SkipStatus returns payload without first status value

func (*Message) Success added in v0.0.4

func (m *Message) Success() bool

Success checks status value and returns it as bool

type Transport

type Transport interface {
	// RunAction sends command to device and return response
	RunAction(message *Message) (*Message, error)
	// Close connection with device
	Close() error
}

Transport represent MyrtIO transport

Directories

Path Synopsis
cmd
load_testing command
MyrtIO terminal example
MyrtIO terminal example
terminal command
MyrtIO terminal example
MyrtIO terminal example
terminal/color
Package color adds CLI coloring
Package color adds CLI coloring
terminal/repl
Package repl contains MyrtIO REPL core
Package repl contains MyrtIO REPL core
Package serial contains utilities for MyrtIO API through serial connection
Package serial contains utilities for MyrtIO API through serial connection

Jump to

Keyboard shortcuts

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