99 lines
2.3 KiB
Go
99 lines
2.3 KiB
Go
package control
|
|
|
|
import (
|
|
"jannex/robot-control-manager/modules/cache"
|
|
"jannex/robot-control-manager/modules/request"
|
|
"jannex/robot-control-manager/modules/structs"
|
|
|
|
"git.ex.umbach.dev/Alex/roese-utils/rsutils"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func ControlRex(c *fiber.Ctx) error {
|
|
// swagger:operation POST /control/1 control controlRex
|
|
// ---
|
|
// summary: Control Rex.
|
|
// description: |
|
|
// This is used to control Rex.
|
|
// consumes:
|
|
// - application/json
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - in: body
|
|
// name: body
|
|
// description: Control Rex body.
|
|
// required: true
|
|
// schema:
|
|
// "$ref": "#/definitions/ControlBody"
|
|
// responses:
|
|
// "200":
|
|
// description: Control Rex
|
|
// "400":
|
|
// description: Invalid request body
|
|
// "422":
|
|
// description: Robot not found
|
|
|
|
var body structs.ControlBody
|
|
|
|
if err := rsutils.BodyParserHelper(c, &body); err != nil {
|
|
return c.SendStatus(fiber.StatusBadRequest)
|
|
}
|
|
|
|
/*
|
|
if body.Task.Y == nil {
|
|
fmt.Println("y not sent")
|
|
} else {
|
|
fmt.Printf("y-value: %d\n", *body.Task.Y)
|
|
} */
|
|
|
|
robot := cache.GetRobotByName(body.RobotName)
|
|
|
|
if robot == nil {
|
|
return c.SendStatus(fiber.StatusUnprocessableEntity)
|
|
}
|
|
|
|
robot.ProcessJobTask(body.JobId)
|
|
|
|
if err := request.Request(fiber.MethodPost, robot.Address+":5000/api/v1/control", body.Task); err != nil {
|
|
return c.JSON(structs.StatusResponse{Status: "err"})
|
|
}
|
|
|
|
return c.JSON(structs.StatusResponse{Status: "ok"})
|
|
}
|
|
|
|
func FinishControlRex(c *fiber.Ctx) error {
|
|
// swagger:operation POST /control/1/finish control finishControlRex
|
|
// ---
|
|
// summary: Finish control Rex.
|
|
// description: |
|
|
// This is used to finish control Rex.
|
|
// consumes:
|
|
// - application/json
|
|
// produces:
|
|
// - application/json
|
|
// responses:
|
|
// "200":
|
|
// description: Finish control Rex
|
|
// "400":
|
|
// description: Invalid robot name
|
|
// "422":
|
|
// description: Robot not found
|
|
|
|
var body structs.RobotFinishBody
|
|
|
|
if err := rsutils.BodyParserHelper(c, &body); err != nil {
|
|
return c.SendStatus(fiber.StatusBadRequest)
|
|
}
|
|
|
|
robot := cache.GetRobotByName(body.RobotName)
|
|
|
|
if robot == nil || robot.CurrentJobId != body.JobId {
|
|
return c.SendStatus(fiber.StatusUnprocessableEntity)
|
|
}
|
|
|
|
robot.SetCurrentJobId("")
|
|
|
|
return c.SendStatus(fiber.StatusOK)
|
|
}
|