Documentation
¶
Index ¶
- func Float64frombytes(bytes []byte) float64
- func PayloadBuf2Float(buf []byte) []float64
- func PayloadFloat2Buf(payload []float64) []byte
- type Packet
- type Server
- func (server *Server) Init(src uint8) error
- func (server *Server) Publish(id uint16, dst uint8, rows uint8, cols uint8, synt uint32, ...) error
- func (server *Server) Request(id uint16, synt uint32, dst uint8, priority uint8) error
- func (server *Server) RequestRange(id uint16, timeStart uint32, timeDiff uint16, dst uint8, priority uint8) error
- func (server *Server) Send(id uint16, time uint32, physical_time uint32, rawData []float64) error
- func (server *Server) Subscribe(id uint16, dst uint8, synt uint32, rate uint16) error
- type ServicePacket
- type SubPacket
- type VisualData
- type WebServer
- func (server *WebServer) CommandProcess(ctx *sgo.Context) error
- func (server *WebServer) HistoryProcess(ctx *sgo.Context) error
- func (server *WebServer) Init(id uint8, udpServer *Server, port string) error
- func (server *WebServer) RealtimeProcess(ctx *sgo.Context) error
- func (server *WebServer) RequestRange(id uint16, timeStart uint32, timeEnd uint32) ([]uint32, []uint64, [][]float64, error)
- func (server *WebServer) Subscribe(id uint16, closeSig *bool) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Float64frombytes ¶
Float64frombytes function converts a byte slice to a float64 Args:
bytes: the byte slice to be converted
Returns:
float: the converted float64
func PayloadBuf2Float ¶
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 ¶
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 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"` }
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 ¶
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 ¶
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 ¶
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
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 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 ¶
MsgHandler handles the set-point command from the client Args:
- ctx: context
Return:
- err: error
func (*WebServer) HistoryProcess ¶
Feed the history data to the Visualization as a list of VisualData Args:
- ctx: context
Return:
- err: error
func (*WebServer) Init ¶
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 ¶
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 ¶
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