diff --git a/ds-cv-inference/Dockerfile b/ds-cv-inference/Dockerfile index cc05ca5..eeefd07 100644 --- a/ds-cv-inference/Dockerfile +++ b/ds-cv-inference/Dockerfile @@ -1,4 +1,4 @@ -# Copyright © 2022 Intel Corporation. All rights reserved. +# Copyright © 2023 Intel Corporation. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause ARG OPENVINO_BASE=ubuntu20_dev @@ -24,10 +24,8 @@ RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" RUN apt-get update && apt-get install libgtk2.0-dev libgtk-3-dev libjpeg62 -y WORKDIR /go/src/ds-cv-inference -COPY go.* /go/src/ds-cv-inference/ -RUN go mod download - COPY . /go/src/ds-cv-inference +RUN go mod tidy RUN /bin/bash -c "source /opt/intel/openvino/setupvars.sh && echo building ds-cv-inference... && go build -o ds-cv-inference" && \ chmod +x entrypoint.sh diff --git a/ds-cv-inference/LICENSE b/ds-cv-inference/LICENSE index 7c1aef1..df5d5be 100644 --- a/ds-cv-inference/LICENSE +++ b/ds-cv-inference/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright © 2020-2022, Intel Corporation +Copyright © 2020-2023, Intel Corporation All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/ds-cv-inference/Makefile b/ds-cv-inference/Makefile index 58e9d19..ee0bbc9 100644 --- a/ds-cv-inference/Makefile +++ b/ds-cv-inference/Makefile @@ -1,9 +1,9 @@ -# Copyright © 2020 Intel Corporation. All rights reserved. +# Copyright © 2023 Intel Corporation. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause .PHONY: build run down -MICROSERVICE=automated-checkout/ds-cv-inference +MICROSERVICE=automated-vending/ds-cv-inference tidy: go mod tidy diff --git a/ds-cv-inference/docker-compose.yml b/ds-cv-inference/docker-compose.yml index 0fb84ca..eb91173 100644 --- a/ds-cv-inference/docker-compose.yml +++ b/ds-cv-inference/docker-compose.yml @@ -1,6 +1,6 @@ --- -# Copyright © 2020 Intel Corporation. All rights reserved. +# Copyright © 2023 Intel Corporation. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause version: '3.4' @@ -8,7 +8,7 @@ version: '3.4' services: ds-cv-inference: - image: automated-checkout/ds-cv-inference:dev + image: automated-vending/ds-cv-inference:dev command: ["/go/src/ds-cv-inference/images","127.0.0.1:1883","0.85","/go/src/ds-cv-inference/skumapping.json"] ports: - "127.0.0.1:9005:9005" diff --git a/ds-cv-inference/go.mod b/ds-cv-inference/go.mod index 8b115a3..aa5d8de 100644 --- a/ds-cv-inference/go.mod +++ b/ds-cv-inference/go.mod @@ -1,9 +1,9 @@ -// Copyright © 2022 Intel Corporation. All rights reserved. +// Copyright © 2023 Intel Corporation. All rights reserved. // SPDX-License-Identifier: BSD-3-Clause module ds-cv-inference -go 1.18 +go 1.20 require ( github.com/eclipse/paho.mqtt.golang v1.2.0 diff --git a/ds-cv-inference/main.go b/ds-cv-inference/main.go index 6bf8d2d..88844c4 100644 --- a/ds-cv-inference/main.go +++ b/ds-cv-inference/main.go @@ -1,4 +1,4 @@ -// Copyright © 2022 Intel Corporation. All rights reserved. +// Copyright © 2023 Intel Corporation. All rights reserved. // SPDX-License-Identifier: BSD-3-Clause package main @@ -10,7 +10,7 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -38,12 +38,12 @@ func main() { } defer skuMappingJSONFile.Close() - skuMappingJSONByte, _ := ioutil.ReadAll(skuMappingJSONFile) + skuMappingJSONByte, _ := io.ReadAll(skuMappingJSONFile) inferenceInit(*directory, *model, *configFile, *confidence, skuMappingJSONByte) mqttConnection := mqtt.NewMqttConnection(*mqttAddress) - mqttConnection.SubscribeToAutomatedCheckout() + mqttConnection.SubscribeToAutomatedVending() defer mqttConnection.Disconnect() inference.Stream = mjpeg.NewStream() diff --git a/ds-cv-inference/mqtt/mqtt.go b/ds-cv-inference/mqtt/mqtt.go index 3ba6bcc..891bb0c 100644 --- a/ds-cv-inference/mqtt/mqtt.go +++ b/ds-cv-inference/mqtt/mqtt.go @@ -1,4 +1,4 @@ -// Copyright © 2020 Intel Corporation. All rights reserved. +// Copyright © 2023 Intel Corporation. All rights reserved. // SPDX-License-Identifier: BSD-3-Clause package mqtt @@ -9,6 +9,7 @@ import ( "fmt" "net/http" "os" + "strings" "sync" "time" @@ -56,7 +57,7 @@ func NewMqttConnection(connectionString string) Connection { return mc } -//define a function for the default message handler +// define a function for the default message handler var commandTopicFunction MQTT.MessageHandler = func(client MQTT.Client, msg MQTT.Message) { var edgeXMessage map[string]string @@ -67,7 +68,16 @@ var commandTopicFunction MQTT.MessageHandler = func(client MQTT.Client, msg MQTT fmt.Printf("received message: %v+", edgeXMessage) - switch edgeXMessage["cmd"] { + words := strings.Split(msg.Topic(), "/") + if len(words) != 5 { + fmt.Println(http.StatusBadRequest, fmt.Sprintf("mqtt command topic not formatted for EdgeX 3.0: %s", msg.Topic())) + return + } + cmd := words[2] + uuid := words[4] + publishTopic := fmt.Sprintf("%s/%s", responseTopic, uuid) + + switch cmd { case "inferenceHeartbeat": { pingMessage := edgeXMessage @@ -77,7 +87,7 @@ var commandTopicFunction MQTT.MessageHandler = func(client MQTT.Client, msg MQTT if err != nil { fmt.Println("Failed to marshal mqtt message") } - token := client.Publish(responseTopic, 0, false, pongMessage) + token := client.Publish(publishTopic, 0, false, pongMessage) token.Wait() } case "inferenceDoorStatus": @@ -90,7 +100,7 @@ var commandTopicFunction MQTT.MessageHandler = func(client MQTT.Client, msg MQTT if err != nil { fmt.Println("Failed to marshal mqtt message") } - token := client.Publish(responseTopic, 0, false, pongMessage) + token := client.Publish(publishTopic, 0, false, pongMessage) token.Wait() checkDoorStatus(isDoorClosed, client) } @@ -141,16 +151,14 @@ func checkDoorStatus(isDoorClosed string, client MQTT.Client) { func SendDeltaData(client MQTT.Client, delta []byte) { cmdSKUDelta := "inferenceSkuDelta" - + publishTopic := fmt.Sprintf("%s/%s/%s", dataTopic, "Inference-device", cmdSKUDelta) edgeXMessage := make(map[string]string) - edgeXMessage["name"] = "Inference-device" - edgeXMessage["cmd"] = cmdSKUDelta edgeXMessage["method"] = "get" edgeXMessage[cmdSKUDelta] = string(delta) deltaMessage, _ := json.Marshal(edgeXMessage) fmt.Println("Final deltaMessage is ", string(deltaMessage)) - token := client.Publish(dataTopic, 0, false, deltaMessage) + token := client.Publish(publishTopic, 0, false, deltaMessage) token.Wait() } @@ -173,7 +181,7 @@ func (mqttCon *Connection) Connect(connectionString string) { } } -func (mqttCon *Connection) SubscribeToAutomatedCheckout() { +func (mqttCon *Connection) SubscribeToAutomatedVending() { //subscribe to the topic inference/CommandTopic and handle messages in the commandTopicFunction attempts := 0 for attempts < retryCount {