server

package
v0.0.0-...-3d3156d Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Float64frombytes

func Float64frombytes(bytes []byte) float64

Float64frombytes function converts a byte slice to a float64 Args:

bytes: the byte slice to be converted

Returns:

float: the converted float64

func PayloadBuf2Float

func PayloadBuf2Float(buf []byte) []float64

PayloadBuf2Float function converts a byte slice to a float64 slice Args:

buf: the byte slice to be converted

Returns:

data64: the converted float64 slice

func PayloadFloat2Buf

func PayloadFloat2Buf(payload []float64) []byte

PayloadFloat2Buf function converts a float64 slice to a byte slice Args:

payload: the float64 slice to be converted

Returns:

buft: the converted byte slice

Types

type MohsenMsg

type MohsenMsg struct {
	Value0 uint64 `json:"value0"`
	Value1 uint64 `json:"value1"`
	Value2 uint64 `json:"value2"`
	Value3 uint64 `json:"value3"`
	Value4 uint64 `jaso:"value4"`
}

type Packet

type Packet struct {
	Src          uint8  `json:"src"`
	Dst          uint8  `json:"dst"`
	MessageType  uint8  `json:"message_type"`
	Priority     uint8  `json:"priority"`
	Version      uint8  `json:"version"`
	Reserved     uint8  `json:"reserved"`
	PhysicalTime uint32 `json:"physical_time"`
	SimulinkTime uint32 `json:"simulink_time"`
	Sequence     uint16 `json:"sequence"`
	Length       uint16 `json:"length"`
	Payload      []byte `json:"-"`

	// for visualization
	Data []float64 `json:"data"`
}

func FromBuf

func FromBuf(buf []byte) Packet

FromBuf function converts a byte slice to a Packet struct Args:

buf: the byte slice to be converted

Returns:

pkt: the converted Packet struct

func (Packet) ToBuf

func (pkt Packet) ToBuf() []byte

ToBuf function converts a Packet struct to a byte slice Args:

pkt: the Packet struct to be converted

Returns:

buf: the converted byte slice

type Server

type Server struct {
	utils.JsonStandard
	utils.ServiceStandard

	Type string
	Src  string

	LocalSystemID uint8
	AllLocalAddr  []*net.UDPAddr

	UDPProcduerNums uint16
	UDPConsumerNums uint16

	AllClientSystemID []uint8
	AllClientAddr     map[uint8]*net.UDPAddr

	Buffer   chan *[utils.PKTLEN]byte
	Sequence uint16
	// contains filtered or unexported fields
}

func (*Server) Init

func (server *Server) Init(src uint8) error

Init function initializes the server by setting its source, client sources, and client source map. It also sets the PacketBuffer, the sequence, and the publisher and subscriber register. Args:

src: the source of the server

Returns:

error: the error message

func (*Server) Publish

func (server *Server) Publish(id uint16, dst uint8, rows uint8, cols uint8, synt uint32, physical_time uint32, rawData []float64) error

Publish Service: Receive the data stream from the subsystems and store the data into the database Args:

id: the data id
dst: the destination of the data
rows: the number of rows
cols: the number of columns
synt: the simulink time stamp
physical_time: the physical time stamp
rawData: the data

Returns:

error: the error message

func (*Server) Request

func (server *Server) Request(id uint16, synt uint32, dst uint8, priority uint8) error

Request Service: Request the data from the database based on the simulink time stamp. Return the 1 * M data

Args:

id: the data id
synt: the simulink time stamp
dst: the destination of the data
priority: the priority of the data

Returns:

error: the error message

func (*Server) RequestRange

func (server *Server) RequestRange(id uint16, timeStart uint32, timeDiff uint16, dst uint8, priority uint8) error

RequestRange Service: Request the data from the database based on the simulink time stamp Compared with Request, RequestRange can request a range of data with a N * M matrix Args:

id: the data id
timeStart: the start time stamp
timeDiff: the time difference
dst: the destination of the data
priority: the priority of the data

Returns:

error: the error message

func (*Server) Send

func (server *Server) Send(id uint16, time uint32, physical_time uint32, rawData []float64) error

Send Service: Store the data info into the database Note that Send func is different from send. send is a private func to send the data to one remote client.

Args:

id: the data id
time: the simulink time stamp
physical_time: the physical time stamp
rawData: the data

Returns:

error: the error message

func (*Server) Subscribe

func (server *Server) Subscribe(id uint16, dst uint8, synt uint32, rate uint16) error

Subscribe Service: Subscribe the data from the database based to client Args:

id: the data id
dst: the destination of the data
synt: the simulink time stamp
rate: the rate of the data

Returns:

error: the error message

type ServicePacket

type ServicePacket struct {
	Packet
	Service     uint8  `json:"service"`
	Flag        uint8  `json:"flag"`
	Option1     uint8  `json:"option_1"`
	Option2     uint8  `json:"option_2"`
	SubframeNum uint16 `json:"subframe_num"`

	Subpackets []*SubPacket
}

ServicePacket struct Defined on top of the TSN Emulation Protocol by adding service, flag, option1, option2, subframe_num fields

func FromServiceBuf

func FromServiceBuf(buf []byte) ServicePacket

FromServiceBuf function converts a byte slice to a ServicePacket struct Args:

buf: the byte slice to be converted

Returns:

pkt: the converted ServicePacket struct

func (*ServicePacket) ToServiceBuf

func (pkt *ServicePacket) ToServiceBuf() []byte

ToServiceBuf function converts a ServicePacket struct to a byte slice Args:

pkt: the ServicePacket struct to be converted

Returns:

buf: the converted byte slice

type SubPacket

type SubPacket struct {
	DataID   uint16
	TimeDiff uint16
	Row      uint8
	Col      uint8
	Length   uint16
	Payload  []byte
}

SubPacket struct Note subpacket is the smallest unit of data in the service packet

type VisualData

type VisualData struct {
	Timestamp uint64  `json:"timestamp"`
	Value     float64 `json:"value"`
	ID        string  `json:"id"`
}

type WebServer

type WebServer struct {
	utils.JsonStandard
	utils.ServiceStandard

	LocalSystemID     uint8
	AllClientSystemID []uint8

	DBHandler *handler.Handler
	UDPServer *Server
	// contains filtered or unexported fields
}

func (*WebServer) CommandProcess

func (server *WebServer) CommandProcess(ctx *sgo.Context) error

MsgHandler handles the set-point command from the client Args:

  • ctx: context

Return:

  • err: error

func (*WebServer) HistoryProcess

func (server *WebServer) HistoryProcess(ctx *sgo.Context) error

Feed the history data to the Visualization as a list of VisualData Args:

  • ctx: context

Return:

  • err: error

func (*WebServer) Init

func (server *WebServer) Init(id uint8, udpServer *Server, port string) error

Init function initializes the web server Args:

src: the source of the web server
hmsServer: the pointer to the hms server

Returns:

err: the error message

func (*WebServer) RealtimeProcess

func (server *WebServer) RealtimeProcess(ctx *sgo.Context) error

The event handler for websocket connection Args:

  • ctx: context

Return:

  • err: error

func (*WebServer) RequestRange

func (server *WebServer) RequestRange(id uint16, timeStart uint32, timeEnd uint32) ([]uint32, []uint64, [][]float64, error)

Overwrite the function in ServiceStandard instead of using from server.go

Args:

  • id: data id
  • timeStart: start time of the data
  • timeEnd: end time of the data

Return:

  • timeSimuVec: simulation time vector
  • timePhyVec: physical time vector
  • dataMat: data matrix
  • err: error

func (*WebServer) Subscribe

func (server *WebServer) Subscribe(id uint16, closeSig *bool) error

Subscribe function reads data from database and send it to the visualization. Unlike the UDP-Server here subscribe is not to directly forward the data from clients to visualization but to read data from database

Args:

  • id: data id
  • closeSig: close signal

Return:

  • err: error

Jump to

Keyboard shortcuts

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