Exemple #1
0
func MakeShiver(t *Trigger) *activa.Motion {

	var m activa.Motion
	m.TaskState = activa.TASK_STATE_new

	return &m
}
Exemple #2
0
func HandleNewMotion(motion *activa.Motion) (err error) {
	err = cross.WriteMotion(motion)
	if err == nil {
		motion.TaskState = activa.TASK_STATE_inprogress
	} else {
		motion.TaskState = activa.TASK_STATE_failed
		return err
	}
	return err
}
Exemple #3
0
func Handle(messages chan CompNotes) {
	motions := make(chan *activa.Motion, 100)
	go activa.Handle(motions)
	var websocket_connection = wsclient.WsConn
	for {
		select {
		case message := <-messages:
			fmt.Printf("\n<<Evebridge: message has been recieved>>\n")
			var ws_message_data = wsclient.DataUpdate{SourcePath: message.Path, SourceType: message.SourceType}
			message_data_raw, err := ws_message_data.GetRaw()
			if err == nil {
				var ws_message = &wsclient.Message{DataType: "data_update", Data: message_data_raw}
				fmt.Printf("\nStart writing\n")
				websocket_connection.Write(ws_message)
				fmt.Printf("\nFinish writing\n")
				fmt.Printf("Message: %v HaveToParse: %v\n", message, message.FieldExists("HashSum"))
			}
		case message := <-websocket_connection.OutChannel:
			if message.DataType == "server_response" {
				var response wsclient.Response
				data := message.Data
				err_unmarshal := json.Unmarshal(data, &response)
				if err_unmarshal == nil {
					fmt.Printf("\nMessage from server: %v\n", response)
				}
			} else if message.DataType == "motion" {
				var motion activa.Motion
				data := message.Data
				err_unmarshal := json.Unmarshal(data, &motion)
				if err_unmarshal == nil {
					//fmt.Printf("\nNew motion %v\n", motion)
					motion.TaskState = activa.TASK_STATE_inprogress
					cross.WriteMotion(&motion)
					//
					if motion.Type == activa.MOTION_TYPE_BLACKOUT {

					} else if motion.Type == activa.MOTION_TYPE_BLACKTOP {

					}

					//
					motions <- &motion
				}

			}
		default:
			time.Sleep(LOG_CHANNEL_TIMEOUT_MS * time.Millisecond)
			//fmt.Println("No messages")
		}
	}
}