emitter

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package emitter emits the translated trice strings.

Index

Examples

Constants

View Source
const SyncPacketPattern = "inf:[TRICE_SYNC_PACKET 0x89abcdef]"

SyncPacketPattern is used if a sync packet arrives

Variables

View Source
var (
	// Verbose gives mor information on output if set. The value is injected from main packages.
	Verbose bool

	// TimestampFormat is used tor line timestamps.
	// off = no timestamp
	// none = no timestamp
	// LOCmicro = local time with microseconds
	// UTCmicro = universal time with microseconds
	// zero = fixed "2006-01-02_1504-05" timestamp (for tests)
	TimestampFormat string

	// Prefix starts lines. It follows line timestamp, if any.
	Prefix string

	// Suffix lollows lines. Usually empty.
	Suffix string

	// ColorPalette determines the way color is handled.
	// off = no color handling at all. Lower case color prefixes are not removed. Use with care.
	// none = no colors. Lower case color prefixes are removed.
	// default = color codes added (TODO: change to ANSI)
	ColorPalette string

	// IPAddr ist the remote display IP address.
	IPAddr string

	// IPPort ist the remote display port number.
	IPPort string

	// DisplayRemote if set, sends trice lines over TCP.
	DisplayRemote bool

	// Autostart if set, starts an additional trice instance as displayserver.
	Autostart bool

	// TestTableMode is set externally to avoid Prefix overwrite
	TestTableMode bool

	// NextLine is set true as help for decoder.TestTableMode, where it is clreared at line start.
	NextLine bool
)

Functions

func ScDisplayServer

func ScDisplayServer() error

ScDisplayServer is the endless function called when trice tool acts as remote display. All in Server struct registered RPC functions are reachable, when displayServer runs.

func ScShutdownRemoteDisplayServer

func ScShutdownRemoteDisplayServer(timeStamp int64, args ...string) error

ScShutdownRemoteDisplayServer connects to a client to send shutdown message to display server. 0==timeStamp -> no timestamp in shutdown message, use for tests. 1==timeStamp -> timestamp in shutdown message, use normally. It accepts 0 to 2 string arguments as args. More arguments are ignored. For not given parameters default values are taken. The parameters are in the following order. args[0] (ipa) is the IP address to be used to connect to the remote display. args[1] (ipp) is the IP port to be used to connect to the remote display.

func SetPrefix

func SetPrefix()

SetPrefix changes "source:" to e.g., "JLINK:". to do: better implementation for example with strings.Split

Types

type ColorDisplay

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

ColorDisplay is an object used for displaying. It implements the Linewriter interface. It embeds a local display and a line transformer

func NewColorDisplay

func NewColorDisplay(colorPalette string) *ColorDisplay

NewColorDisplay creates a ColorlDisplay. It provides a Linewriter. It uses internally a local display combined with a line transformer.

Example
p := NewColorDisplay("none")
l1 := []string{"msg:This is ", "the 1st ", "line"}
l2 := []string{"MSG:This is ", "the 2nd ", "line"}
p.writeLine(l1)
p.writeLine(l2)
Output:

This is the 1st line
MSG:This is the 2nd line

type LineTransformerANSI

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

LineTransformerANSI imnplements a Linewriter interface. It uses an internal Linewriter lw to write to. It converts the channel information to color data using colorPalette. In case of a remote display the lineTranslator should be used there.

func NewLineTransformerANSI

func NewLineTransformerANSI(lw LineWriter, colorPalette string) *LineTransformerANSI

NewLineTransformerANSI translates lines to ANSI colors according to colorPalette. It provides a Linewriter interface and uses internally a Linewriter.

type LineWriter

type LineWriter interface {
	// contains filtered or unexported methods
}

LineWriter is the common interface for output devices. The string slice `line` contains all string parts of one line including prefix and suffix. The last string part is without newline char and must be handled by the output device.

type LocalDisplay

type LocalDisplay struct {
	Err error
}

LocalDisplay is an object used for displaying. LocalDisplay implements the Linewriter interface.

func NewLocalDisplay

func NewLocalDisplay() *LocalDisplay

NewLocalDisplay creates a LocalDisplay. It provides a Linewriter. It uses internally

Example
p := NewLocalDisplay()
l1 := []string{"This is ", "the 1st ", "line"}
l2 := []string{"This is ", "the 2nd ", "line"}
p.writeLine(l1)
p.writeLine(l2)
Output:

This is the 1st line
This is the 2nd line

func (*LocalDisplay) ErrorFatal

func (p *LocalDisplay) ErrorFatal()

ErrorFatal ends in osExit(1) if err not nil.

type RemoteDisplay

type RemoteDisplay struct {
	Err    error
	Cmd    string      // remote server executable
	Params string      // remote server additional parameters (despite "ds -ipa a.b.c.d -ipp nnnn")
	IPAddr string      // IP addr
	IPPort string      // IP port
	PtrRPC *rpc.Client // PtrRPC is a pointer for remote calls valid after a successful rpc.Dial()
}

RemoteDisplay is transferring to a remote display object.

func NewRemoteDisplay

func NewRemoteDisplay(args ...string) *RemoteDisplay

NewRemoteDisplay creates a connection to a remote Display and implements the Linewriter inteface. It accepts 0 to 4 string arguments. More arguments are ignored. For not given parameters default values are taken. The parameters are in the following order. args[0] (exe), is a programm started to create a remote server instance if not already running. If the remote server is already running on ips:ipp than a start of a 2nd instace is not is possible. This is silently ignored. If args[0] is empty, a running display server is assumed and a connection is established if possible. args[1] (params) contains additional remote display (=trice) command parameters. This value is used only if the remote server gets started. args[2] (ipa) is the IP address to be used to connect to the remote display. args[3] (ipp) is the IP port to be used to connect to the remote display.

func (*RemoteDisplay) Connect

func (p *RemoteDisplay) Connect()

Connect is called by the client and tries to dial. On success PtrRpc is valid afterwards and the output is re-directed. Otherwise an error code is stored inside remotDisplay.

func (*RemoteDisplay) ErrorFatal

func (p *RemoteDisplay) ErrorFatal()

ErrorFatal ends in osExit(1) if p.Err not nil.

type Server

type Server struct {
	Display ColorDisplay // todo: LineWriter?
}

Server is the RPC struct for registered server dunctions

func (*Server) ColorPalette

func (p *Server) ColorPalette(s []string, reply *int64) error

ColorPalette is the exported server function for color palette, if trice tool acts as display server. By declaring it as a Server struct method it is registered as RPC destination.

func (*Server) LogSetFlags

func (p *Server) LogSetFlags(f []int64, r *int64) error

LogSetFlags is called remotely to ...

func (*Server) Shutdown

func (p *Server) Shutdown(ts []int64, _ *int64) error

Shutdown is called remotely to shutdown display server

func (*Server) WriteLine

func (p *Server) WriteLine(line []string, reply *int64) error

WriteLine is the exported server method for string display, if trice tool acts as display server. By declaring it as a Server struct method it is registered as RPC destination.

type TriceLineComposer

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

TriceLineComposer collects all partial strings forming one line.

func New

func New() *TriceLineComposer

New creates the emitter instance and returns a string writer to be used for emitting.

func (*TriceLineComposer) Write added in v0.18.4

func (p *TriceLineComposer) Write(b []byte) (n int, err error)

Write treats received buffer as a string.

func (*TriceLineComposer) WriteString

func (p *TriceLineComposer) WriteString(s string) (n int, err error)

WriteString implements the io.StringWriter interface. The triceLineComposer can use it. WriteString uses the internal line writer p.lw for writing out full lines. If s is empty, WriteString returns 0, nil. If p.line is empty, the actual timestamp and the prefix are added to p.line. If s is without newline it is added to p.line and WriteString returns. If s ends with newline it is added to p.line and also the suffix is added to p.line and pline is written to p.lw. If s contains several newlines it is split there and the substrings are handled accordingly. That means it writes internally a separate line for each substring (in s) ending with a newline.

Jump to

Keyboard shortcuts

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