goNTCore

package module
v0.0.0-...-e2d6eb3 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2017 License: BSD-3-Clause Imports: 9 Imported by: 0

README

ntcore

Currently under development. Help is wanted. Read TODO list below for a better understanding what needs to get done.

GoLang implementation of WPILibs ntcore package. This repository should stay private until it has been fully tested and implemented properly.

Network Table V3

To view the standards that this package follows read NetworkTable3

TODO

  • Create all the possible Entry types
    • Include a way to Marshal and Unmarshal them
  • Create all the possible Message types
    • Include a way to Marshal and Unmarshal them
  • Create a NetworkTable interface that should be used for anything to talk on the Network
  • Create a Data interface for NetworkTable interface to use for manipulating data
  • Create a NetworkTable struct that implements the NetworkTable interface but consumes the Data interface
  • Create a Server that can listen to multiple clients as well as broadcast to them
    • Cleanup old connections
  • Create a Client that can listen to a server for messages
    • Should be able to initiate handshake
  • Create a data struct to implament Data that is connected to a Key Value store
    • Has to handle keys, IDs and SNs correctly
    • Should handle persistent flag correctly
  • Server needs to have NetworkTabler methods so that it can send the appropriate messages
  • Client needs to have NetworkTabler methods so that it can send the appropriate messages
  • Fix the Server handshake to return EntryAssign for all entries it knows about
  • Fix the Client handshake to return what is different between what the server has and what it has
  • Modify Server handler method to manipulate data on the server side
  • Modify Client handler method to manipulate data on the client side

Documentation

Index

Constants

View Source
const (
	//PORT is the port on which all clients and servers communicate on.
	PORT = 1735
	//PENDING is the client status used to make sure that the handshake has been completed.
	PENDING = "pending"
	//LISTENING is used during the handshake to specify it if looking to see what the server has.
	LISTENING = "listening"
	//READY is used to state that the client has finished the handshake.
	READY = "ready"
)

Variables

View Source
var (
	//ProtocolVersion is what protocol this package supports
	ProtocolVersion = [2]byte{0x03, 0x00}
)

Functions

func SendMsg

func SendMsg(msg message.Messager, writer io.Writer) error

SendMsg adds a buffer to the Marshaling before sending so the whole message is sent at once.

Types

type Client

type Client struct {
	net.Conn

	Log chan LogMessage
	// contains filtered or unexported fields
}

Client is a Network Table client.

func NewClient

func NewClient(serverHost string, name string, data Data) (*Client, error)

NewClient creates a new client to communicate to a Network Table server.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection to the Network Table server.

func (*Client) Listen

func (c *Client) Listen()

Listen for messages sent from the server. Best to start this in a go routine.

func (*Client) SendMsg

func (c *Client) SendMsg(msg message.Messager) error

SendMsg to the connected server

func (*Client) StartHandshake

func (c *Client) StartHandshake() error

StartHandshake starts the handshake with the server.

type Data

type Data interface {
	PutEntry(ent *Entry) error //Creates if new, updates otherwise
	GetEntries(root string) ([]string, error)
	GetEntry(key string) (*Entry, error)
	DeleteEntry(key string) error
	DeleteAll(root string) error
	IsTable(key string) bool
	IsKey(key string) bool
}

Data is the interface implemented by types that can read and write Network Table at a low level.

type DataTable

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

DataTable implements NetworkTabler based on a backend that needs to exist on create.

func NewTable

func NewTable(d Data, root string) *DataTable

NewTable creates a new Network Table that is based off of the data and root passed in. Pass in an empty string or "/" for root table.

func (*DataTable) ContainsKey

func (t *DataTable) ContainsKey(key string) bool

ContainsKey returns true if the key exist in the table.

func (*DataTable) ContainsTable

func (t *DataTable) ContainsTable(key string) bool

ContainsTable return true if the table exist in the table.

func (*DataTable) Delete

func (t *DataTable) Delete(key string)

Delete deletes the given key from the table.

func (*DataTable) DeleteAll

func (t *DataTable) DeleteAll()

DeleteAll deletes all keys from the table.

func (*DataTable) GetBoolean

func (t *DataTable) GetBoolean(key string, def bool) bool

GetBoolean gets the value of key as a boolean. If the value is not of type boolean it returns the default value passed in.

func (*DataTable) GetBooleanArray

func (t *DataTable) GetBooleanArray(key string, def []bool) []bool

GetBooleanArray gets the value of key as a slice of booleans. If the value is not of type boolean slice it returns the default value passed in.

func (*DataTable) GetKeys

func (t *DataTable) GetKeys() []string

GetKeys returns all the keys in the table.

func (*DataTable) GetNumber

func (t *DataTable) GetNumber(key string, def float64) float64

GetNumber gets the value of key as a float64. If the value is not of type float64 it returns the default value passed in.

func (*DataTable) GetNumberArray

func (t *DataTable) GetNumberArray(key string, def []float64) []float64

GetNumberArray gets the value of key as a slice of float64s. If the value is not of type float64 slice it returns the default value passed in.

func (*DataTable) GetRaw

func (t *DataTable) GetRaw(key string, def []byte) []byte

GetRaw gets the value of key as a slice of bytes. If the value is not of type byte slice it returns the default value passed in.

func (*DataTable) GetString

func (t *DataTable) GetString(key string, def string) string

GetString gets the value of key as a string. If the value is not of type string it returns the default value passed in.

func (*DataTable) GetStringArray

func (t *DataTable) GetStringArray(key string, def []string) []string

GetStringArray gets the value of key as a slice of strings. If the value is not of type string slice it returns the default value passed in.

func (*DataTable) GetTable

func (t *DataTable) GetTable(key string) NetworkTabler

GetTable gets a table with the specified key. If table does not exist it creates a new one.

func (*DataTable) IsPersisted

func (t *DataTable) IsPersisted(key string) bool

IsPersisted returns true if the key is to be persisted. Returns false if the key does not exist.

func (*DataTable) PutBoolean

func (t *DataTable) PutBoolean(key string, val bool) bool

PutBoolean puts the boolean value in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.

func (*DataTable) PutBooleanArray

func (t *DataTable) PutBooleanArray(key string, val []bool) bool

PutBooleanArray puts the slice of boolean in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.

func (*DataTable) PutNumber

func (t *DataTable) PutNumber(key string, val float64) bool

PutNumber puts the float64 value in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.

func (*DataTable) PutNumberArray

func (t *DataTable) PutNumberArray(key string, val []float64) bool

PutNumberArray puts the slice of float64 in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.

func (*DataTable) PutRaw

func (t *DataTable) PutRaw(key string, val []byte) bool

PutRaw puts the taw value in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.

func (*DataTable) PutString

func (t *DataTable) PutString(key string, val string) bool

PutString puts the string value in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.

func (*DataTable) PutStringArray

func (t *DataTable) PutStringArray(key string, val []string) bool

PutStringArray puts the slice of string in the table. If value exist it updates it. If value doesn't exist it will add it. Returns false if key exist of a different type.

type Entry

type Entry struct {
	ID        uint16
	SN        uint16
	Persitant bool
	Key       string
	Type      byte
	Value     interface{}
}

Entry is a key value in the network table.

type LogMessage

type LogMessage struct {
	Message string
	Err     error
}

LogMessage is used to send information back to the running process about the server.

func NewErrorMessage

func NewErrorMessage(err error) LogMessage

NewErrorMessage creates a new log message with the error filled out.

func NewLogMessage

func NewLogMessage(msg string) LogMessage

NewLogMessage creates a log message with the message filled out.

type NetworkTabler

type NetworkTabler interface {
	ContainsKey(key string) bool
	ContainsTable(key string) bool
	Delete(key string)
	DeleteAll()
	IsPersisted(key string) bool
	GetKeys() []string
	GetTable(key string) NetworkTabler
	GetBoolean(key string, def bool) bool
	PutBoolean(key string, val bool) bool
	GetNumber(key string, def float64) float64
	PutNumber(key string, val float64) bool
	GetString(key string, def string) string
	PutString(key string, val string) bool
	GetRaw(key string, def []byte) []byte
	PutRaw(key string, val []byte) bool
	GetBooleanArray(key string, def []bool) []bool
	PutBooleanArray(key string, val []bool) bool
	GetNumberArray(key string, def []float64) []float64
	PutNumberArray(key string, val []float64) bool
	GetStringArray(key string, def []string) []string
	PutStringArray(key string, val []string) bool
}

NetworkTabler is the interface implemented by types that can read and write Network Table at a high level.

type Server

type Server struct {
	Log chan LogMessage
	// contains filtered or unexported fields
}

Server is an instance of a Network Table server.

func NewServer

func NewServer(name string, data Data) (*Server, error)

NewServer creates a new Network Table server.

func (*Server) Close

func (s *Server) Close() error

Close closes all connections to the server and the listener.

func (*Server) Listen

func (s *Server) Listen()

Listen starts listening on the network for messages. Spin off a new goroutine to connect to the client. Keep the connection to the client open to allow for communication in both directions.

func (*Server) SendMsg

func (s *Server) SendMsg(msg message.Messager) error

SendMsg sends a message to each connected client that is ready. Never returns an error and does not wait for execution to finish.

func (*Server) StartPeriodicClean

func (s *Server) StartPeriodicClean(d time.Duration)

StartPeriodicClean cleans up instances of connections that have been closed. It cleans every d (durtaion).

Directories

Path Synopsis
cmd
NTClient command
NTServer command

Jump to

Keyboard shortcuts

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