func Main(parsedDataCh <-chan []int64)
Main is the entry point for the websocketserver. Requires timestampdataCh, which expects parsed data from the analysis package.
func clientHandler(ws *websocket.Conn, everyMs int64, dataCh <-chan []int64)
clientHandler handles a websocket connection. It processes the timestampdata from the analysis module, and puts them into their respective 60 buckets. When everyMs has passed, it calls the sendAndResetBucket function
func sendAndResetBucket(bucket *[]int64, ws *websocket.Conn, timeNow *int64)
sendAndResetBucket sends the bucket array out on the websocket connection. After sending the bucket onto the websocket, it sets all the element in the buffer to zero, and sets the timeNow the last recorded time in analysis.
func serverMain(registerNewClientCh chan<- splitterRequest, deleteClientCh chan<- splitterRequest)
serverMain is the entry point for the websocket server. Takes as input a channel with timestamp data from the analysis module, two splitterRequest channels registering and deleting itself
func splitterMain(timestampdataCh <-chan []int64, registerNewClientCh <-chan splitterRequest, deleteClientCh <-chan splitterRequest)
splitterMain is a PUBSUB implementation, taking the data from timestampdataCh and broadcasting it to all subscribers. In order to register as a subscriber, you must register yourself by sending a request on the registerNewClientCh. When you do no longer wish to subscribe, you must delete yourself by sending a request on the deleteClientCh.
func stimulateServer(rw http.ResponseWriter, req *http.Request)
stimulateServer is the handler for HTTP POST requests to stimulate the MEA server. Verifies that the incoming POST request is valid, and the json payload is valid, before sending it to the MEA server.
Parts of this code is inspired by https://stackoverflow.com/questions/15672556/handling-json-post-request-in-go
splitterRequest defines a request to join the PUBSUB splitterMain. ID
type splitterRequest struct {
ID uuid.UUID // A unique ID which no other subscriber has yet acquired
DataCh chan []int64 // A channel you wish to receive the subscriber data.
}
stimulateRequest represents the JSON message in the stimulate POST request. See stimulateServer
type stimulateRequest struct {
Frequency int `json:"frequency""`
Duration int `json:"duration""`
Channel int `json:"channel""`
}