Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorClean(err error) error
- func ErrorContains(err error, errKeyword string) bool
- func ErrorJSON(message string, err error) (rspJSON []byte)
- func ErrorString(err error, rsp map[string]interface{}) string
- func IsError(err error, rsp map[string]interface{}) bool
- func JSONToObject(objectJSON []byte) (object map[string]interface{}, err error)
- func NewBody() (body map[string]interface{})
- func NewCommand(reqType string) (cmd map[string]interface{})
- func NewRequest(reqType string) (req map[string]interface{})
- func ObjectToJSON(object map[string]interface{}) (objectJSON []byte, err error)
- type Context
- func (context *Context) Close()
- func (context *Context) DebugOutput(enabled bool) (wasEnabled bool)
- func (context *Context) Identify() (name string)
- func (context *Context) Request(req map[string]interface{}) (err error)
- func (context *Context) RequestResponse(req map[string]interface{}) (rsp map[string]interface{}, err error)
- func (context *Context) Reset() (err error)
- func (context *Context) Response() (rsp map[string]interface{}, err error)
- func (context *Context) Transaction(req map[string]interface{}) (rsp map[string]interface{}, err error)
- func (context *Context) TransactionJSON(reqJSON []byte) (rspJSON []byte, err error)
- func (context *Context) UserAgent() (ua map[string]interface{})
- type I2CTxFn
- type UARTReadFn
- type UARTWriteFn
Constants ¶
const CardI2CMax = 253
CardI2CMax controls chunk size that's socially appropriate on the I2C bus. It must be 1-253 bytes as per spec (which allows space for the 2-byte header in a 255-byte read)
const CardRequestI2CSegmentDelayMs = 250
CardRequestI2CSegmentDelayMs (golint)
const CardRequestI2CSegmentMaxLen = 250
CardRequestI2CSegmentMaxLen (golint)
const CardRequestSerialSegmentDelayMs = 250
CardRequestSerialSegmentDelayMs (golint)
const CardRequestSerialSegmentMaxLen = 250
CardRequestSerialSegmentMaxLen (golint)
const DefaultI2CAddress = 0x17
DefaultI2CAddress is Our default I2C address
const ErrCardIo = "{io}"
ErrCardIo is the card I/O error suffix
const ErrTimeout = "{timeout}"
ErrTimeout is the card timeout error suffix
Variables ¶
var InitialDebugMode = false
InitialDebugMode is the debug mode that the context is initialized with
var RequestSegmentDelayMs = -1
RequestSegmentDelayMs (golint)
var RequestSegmentMaxLen = -1
RequestSegmentMaxLen (golint)
var SerialTimeoutMs = 10000
SerialTimeoutMs is the response timeout for Notecard serial communications.
Functions ¶
func ErrorClean ¶
ErrorClean removes all error keywords from an error string
func ErrorContains ¶
ErrorContains tests to see if an error contains an error keyword that we might expect
func ErrorJSON ¶
ErrorJSON returns a JSON object with nothing but an error code, and with an optional message
func ErrorString ¶
ErrorString returns the error within a response
func JSONToObject ¶
JSONToObject unmarshals the specified JSON and returns it as a map[string]interface{}
func NewBody ¶
func NewBody() (body map[string]interface{})
NewBody creates a new body. Note that this method is provided merely as syntactic sugar, as of the form body := note.NewBody()
func NewCommand ¶
NewCommand creates a new command that requires no response from the notecard.
func NewRequest ¶
NewRequest creates a new request that is guaranteed to get a response from the Notecard. Note that this method is provided merely as syntactic sugar, as of the form req := tinynote.NewRequest("note.add")
func ObjectToJSON ¶
ObjectToJSON converts an object to JSON
Types ¶
type Context ¶
type Context struct { // True to emit trace output Debug bool // Disable generation of User Agent object DisableUA bool // Class functions CloseFn func(context *Context) ResetFn func(context *Context) (err error) TransactionFn func(context *Context, noResponse bool, reqJSON []byte) (rspJSON []byte, err error) // contains filtered or unexported fields }
Context for the port that is open
func OpenUART ¶
func OpenUART(uartReadFn UARTReadFn, uartWriteFn UARTWriteFn) (context *Context, err error)
OpenUART opens the card on the specified uart
func (*Context) DebugOutput ¶
DebugOutput enables/disables debug output
func (*Context) Request ¶
Request performs a card transaction with a JSON structure and doesn't return a response (This is for semantic compatibility with other languages.)
func (*Context) RequestResponse ¶
func (context *Context) RequestResponse(req map[string]interface{}) (rsp map[string]interface{}, err error)
RequestResponse performs a card transaction with a JSON structure and doesn't return a response (This is for semantic compatibility with other languages.)
func (*Context) Response ¶
Response is used in rare cases where there is a transaction that returns multiple responses
func (*Context) Transaction ¶
func (context *Context) Transaction(req map[string]interface{}) (rsp map[string]interface{}, err error)
Transaction performs a card transaction with a JSON structure
func (*Context) TransactionJSON ¶
TransactionJSON performs a card transaction using raw JSON []bytes
type UARTReadFn ¶
UARTReadFn is the function to read from the UART port
type UARTWriteFn ¶
UARTWriteFn is the function to write to the UART port