http

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const API_VERSION = "1.0"
View Source
const MAX_SEQUENCE_NB = 2<<31 - 1
View Source
const PDO_COMMAND_URI_PATTERN = `(r|read|w|write)/(p|pdo)/(0x[0-9a-f]{1,3}|\d{1,4})`
View Source
const SDO_COMMAND_URI_PATTERN = `(r|read|w|write)/(all|0x[0-9a-f]{1,4}|\d{1,5})/?(0x[0-9a-f]{1,2}|\d{1,3})?`
View Source
const TOKEN_ALL = -1
View Source
const TOKEN_DEFAULT = -2
View Source
const TOKEN_NONE = -3
View Source
const URI_PATTERN = `/cia309-5/(\d+\.\d+)/(\d{1,10})/(0x[0-9a-f]{1,4}|\d{1,10}|default|none|all)/(0x[0-9a-f]{1,2}|\d{1,3}|default|none|all)/(.*)`

Variables

View Source
var (
	ErrGwRequestNotSupported         = &GatewayError{Code: 100}
	ErrGwSyntaxError                 = &GatewayError{Code: 101}
	ErrGwRequestNotProcessed         = &GatewayError{Code: 102}
	ErrGwTimeout                     = &GatewayError{Code: 103}
	ErrGwNoDefaultNetSet             = &GatewayError{Code: 104}
	ErrGwNoDefaultNodeSet            = &GatewayError{Code: 105}
	ErrGwUnsupportedNet              = &GatewayError{Code: 106}
	ErrGwUnsupportedNode             = &GatewayError{Code: 107}
	ErrGwCommandCancellationFailed   = &GatewayError{Code: 108}
	ErrGwEmergencyConsumerNotEnabled = &GatewayError{Code: 109}
	ErrGwWrongNMTState               = &GatewayError{Code: 204}
	ErrGwWrongPassword               = &GatewayError{Code: 300}
	ErrGwSuperUsersExceeded          = &GatewayError{Code: 301}
	ErrGwNodeAccessDenied            = &GatewayError{Code: 302}
	ErrGwNoSessionAvailable          = &GatewayError{Code: 303}
	ErrGwPDOAlreadyUsed              = &GatewayError{Code: 400}
	ErrGwPDOLengthExceeded           = &GatewayError{Code: 401}
	ErrGwLSSImplementationError      = &GatewayError{Code: 501}
	ErrGwLSSNodeIDNotSupported       = &GatewayError{Code: 502}
	ErrGwLSSBitRateNotSupported      = &GatewayError{Code: 503}
	ErrGwLSSParameterStoringFailed   = &GatewayError{Code: 504}
	ErrGwLSSCommandFailed            = &GatewayError{Code: 505}
	ErrGwRunningOutOfMemory          = &GatewayError{Code: 600}
	ErrGwCANInterfaceNotAvailable    = &GatewayError{Code: 601}
	ErrGwSizeLowerThanSDOBufferSize  = &GatewayError{Code: 602}
	ErrGwManufacturerSpecificError   = &GatewayError{Code: 900}
)
View Source
var DATATYPE_MAP = map[string]uint8{
	"b":   od.BOOLEAN,
	"u8":  od.UNSIGNED8,
	"u16": od.UNSIGNED16,
	"u32": od.UNSIGNED32,
	"u64": od.UNSIGNED64,
	"i8":  od.INTEGER8,
	"i16": od.INTEGER16,
	"i32": od.INTEGER32,
	"i64": od.INTEGER64,
	"r32": od.REAL32,
	"r64": od.REAL64,
	"vs":  od.VISIBLE_STRING,
}
View Source
var ERROR_GATEWAY_DESCRIPTION_MAP = map[int]string{
	100: "Request not supported",
	101: "Syntax error",
	102: "Request not processed due to internal state",
	103: "Time-out (where applicable)",
	104: "No default net set",
	105: "No default node set",
	106: "Unsupported net",
	107: "Unsupported node",
	108: "Command cancellation failed or ignored",
	109: "Emergency consumer not enabled",
	204: "Wrong NMT state",
	300: "Wrong password (User management)",
	301: "Number of super users exceeded (User management)",
	302: "Node access denied (User management)",
	303: "No session available (User management)",
	400: "PDO already used",
	401: "PDO length exceeded",
	501: "LSS implementation-/manufacturer-specific error",
	502: "LSS node-ID not supported",
	503: "LSS bit-rate not supported",
	504: "LSS parameter storing failed",
	505: "LSS command failed because of media error",
	600: "Running out of memory",
	601: "CAN interface currently not available",
	602: "Size to be set lower than minimum SDO buffer size",
	900: "Manufacturer-specific error",
}

Functions

func NewGatewayError

func NewGatewayError(code int) error

func NewResponseError

func NewResponseError(sequence int, error error) []byte

func NewResponseSuccess

func NewResponseSuccess(sequence int) []byte

Types

type GatewayClient

type GatewayClient struct {
	http.Client
	// contains filtered or unexported fields
}

func NewGatewayClient

func NewGatewayClient(baseURL string, apiVersion string, networkId int) *GatewayClient

func (*GatewayClient) Do

func (client *GatewayClient) Do(method string, uri string, body io.Reader, response GatewayResponse) error

HTTP request to CiA endpoint Does error checking : http related errors, json decode errors or actual gateway errors

func (*GatewayClient) GetVersion

func (client *GatewayClient) GetVersion() (*gateway.GatewayVersion, error)

Read gateway version

func (*GatewayClient) ReadRaw

func (client *GatewayClient) ReadRaw(nodeId uint8, index uint16, subIndex uint8) (data string, length int, err error)

ReadRaw via SDO

func (*GatewayClient) SetSDOTimeout

func (client *GatewayClient) SetSDOTimeout(timeoutMs uint16) error

Update SDO client timeout

func (*GatewayClient) WriteRaw

func (client *GatewayClient) WriteRaw(nodeId uint8, index uint16, subIndex uint8, value string, datatype string) error

WriteRaw via SDO

type GatewayError

type GatewayError struct {
	Code int // Can be either an sdo abort code or a gateway error code
}

func (*GatewayError) Error

func (e *GatewayError) Error() string

type GatewayRequest

type GatewayRequest struct {
	// contains filtered or unexported fields
}

HTTP request to the server

func NewGatewayRequestFromRaw

func NewGatewayRequestFromRaw(r *http.Request) (*GatewayRequest, error)

Create a new sanitized api request object from raw http request This function also checks that values are within bounds etc.

type GatewayRequestHandler

type GatewayRequestHandler func(w doneWriter, req *GatewayRequest) error

Handle a GatewayRequest according to CiA 309-5

type GatewayResponse

type GatewayResponse interface {
	GetError() error
	GetSequenceNb() int
}

type GatewayResponseBase

type GatewayResponseBase struct {
	// Sequence number corresponding to a request
	Sequence string `json:"sequence"`
	// Response, can be "OK", "NEXT", or "ERROR:x"
	Response string `json:"response"`
}

HTTP response base

func NewResponseBase

func NewResponseBase(sequence int, response string) *GatewayResponseBase

func (*GatewayResponseBase) GetError

func (resp *GatewayResponseBase) GetError() error

Extract error if any inside of reponse

func (*GatewayResponseBase) GetSequenceNb

func (resp *GatewayResponseBase) GetSequenceNb() int

type GatewayServer

type GatewayServer struct {
	*gateway.BaseGateway
	// contains filtered or unexported fields
}

func NewGatewayServer

func NewGatewayServer(network *network.Network, defaultNetworkId uint16, defaultNodeId uint8, sdoUploadBufferSize int) *GatewayServer

Create a new gateway

func (*GatewayServer) ListenAndServe

func (gateway *GatewayServer) ListenAndServe(addr string) error

Process server, blocking

type SDOReadResponse

type SDOReadResponse struct {
	*GatewayResponseBase
	Data   string `json:"data"`
	Length int    `json:"length,omitempty"`
}

type SDOSetTimeoutRequest

type SDOSetTimeoutRequest struct {
	Value string `json:"value"`
}

type SDOWriteRequest

type SDOWriteRequest struct {
	Value    string `json:"value"`
	Datatype string `json:"datatype"`
}

type SetDefaultNetOrNode

type SetDefaultNetOrNode struct {
	Value string `json:"value"`
}

type VersionInfo

type VersionInfo struct {
	*GatewayResponseBase
	*gateway.GatewayVersion
}

Jump to

Keyboard shortcuts

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