Update chức năng thay thế URL, api authen fix cứng 5000,5003

This commit is contained in:
HaiMD 2020-07-07 15:01:28 +07:00
parent 6262d16aa5
commit 5c9a8aa0cc
5 changed files with 54 additions and 34 deletions

Binary file not shown.

View File

@ -1,7 +1,7 @@
package main
import (
"beetai_local/file"
"beetai_server_local/file"
"fmt"
"io"
@ -26,7 +26,7 @@ var Path_base_engine string = path_base + "/engine/" + name_dir_engine //"count_
var Path_log_engine string = path_base + "/log/log_engine"
var Path_log_luncher string = path_base + "/log/log_launcher"
var Path_engine_config string = path_base + "/setup/engine.json" // dia chi duoi file Config.txt
var Path_config string = Path_base_engine + "/data/Config.txt"
var Path_config string = Path_base_engine + "/data/config.json"
// var path = "/root/monitor/log/log_engine.txt"
@ -454,7 +454,7 @@ func RunEngine(name string) {
// FaceRecognition/FaceRecognition ../data/Config.txt > /dev/null 2>&1 &
//var cmd = "cd " + path_base + "/engine/" + name + "/build/ && " + "screen -dm -S Engine " + name + "/" + name + " ../data/Config.txt > /dev/null 2>&1 &"
//var cmd = "export DISPLAY=:0&&export OPENBLAS_NUM_THREADS=1&&cd " + path_base + "/engine/" + name + "/build/ " + "&& " + name + "/" + name + " " + name + "/data/Config.txt > /dev/null 2>&1 &"
var cmd = "export DISPLAY=:0&&export OPENBLAS_NUM_THREADS=1&&cd " + path_base + "/engine/" + name + "/build/ " + "&& " + name + "/" + name + " ../data/Config.txt > /dev/null 2>&1 &"
var cmd = "export DISPLAY=:0&&export OPENBLAS_NUM_THREADS=1&&cd " + path_base + "/engine/" + name + "/build/ " + "&& " + name + "/" + name + " ../data/config.json > /dev/null 2>&1 &"
if Debug == 1 {
fmt.Println("cmd run engine", cmd)
}

Binary file not shown.

View File

@ -1,9 +1,9 @@
package main
import (
_ "beetai_local/action_engine"
"beetai_local/box"
"beetai_local/file"
_ "beetai_server_local/action_engine"
"beetai_server_local/box"
"beetai_server_local/file"
"bytes"
"encoding/json"
"fmt"

View File

@ -1,7 +1,7 @@
package box
import (
"beetai_local/file"
"beetai_server_local/file"
"bufio"
"bytes"
"encoding/json"
@ -80,7 +80,7 @@ var Path_base_engine = path_base + "/engine/" + name_dir_engine //"count_people_
var Path_log_engine = path_base + "/log/log_engine"
var Path_log_luncher = path_base + "/log/log_launcher"
var Path_engine_config = path_base + "/setup/engine.json" // dia chi duoi file Config.txt
var Path_config = Path_base_engine + "/data/Config.txt"
var Path_config = Path_base_engine + "/data/config.json"
var Path_backup = path_base + "/backup"
var Path_upgrade = path_base + "/upgrade"
var Path_engine_update = Path_upgrade + "/engine_update.json"
@ -120,14 +120,16 @@ type Datas struct {
}
type Engine struct {
IsConfig string `json:"isConfig,omitempty"`
Active int `json:"active"`
Engine_id int `json:"engine_id"`
Id int `json:"id"`
Link string `json:"link"`
Name string `json:"name"`
Path string `json:"path"`
Version string `json:"version"`
IsConfig string `json:"isConfig,omitempty"`
Active int `json:"active"`
Engine_id int `json:"engine_id"`
Threshold float32 `json:"threshold"` //"threshold"
Id int `json:"id"`
Url string `json:"url"`
Link string `json:"link"`
Name string `json:"name"`
Path string `json:"path"`
Version string `json:"version"`
//PortStream int `json:"portstream,omitempty"`
Time_run string `json:"time_run,omitempty"`
}
@ -313,10 +315,11 @@ func DowloadEngineUpdate(name string, link string, version string, id int) {
file.Println(message.Data.Engines[index].Name)
file.Println(message.Data.Engines[index].Path)
var id_val = strconv.Itoa(message.Data.Engines[index].Id)
var path_val = message.Data.Engines[index].Path + "/data/Config.txt"
var path_val = message.Data.Engines[index].Path + "/data/config.json"
fmt.Println("ID new: ", id_val)
fmt.Println("Path config:", path_val)
Replace_id(path_val, id_val) // Cap nhap ID BOX cho file config.txt trong engine
threshold := fmt.Sprintf("%.2f", message.Data.Engines[index].Threshold)
Replace_id(path_val, id_val, threshold, message.Data.Engines[index].Url) // Cap nhap ID BOX cho file config.txt trong engine
// Do cap nhat chua biet port dang nao la bao nhieu len ko set dc
//ChangePort(path_val, port) // Change portstream local cho cac engine thanh khac nhau
file.Println("---------------------------------------------------")
@ -384,10 +387,11 @@ func Dowload_engine() {
file.Println(message.Data.Engines[i].Name)
file.Println(message.Data.Engines[i].Path)
var id_val = strconv.Itoa(message.Data.Engines[i].Id)
var path_val = message.Data.Engines[i].Path + "/data/Config.txt"
var path_val = message.Data.Engines[i].Path + "/data/config.json"
fmt.Println("ID new: ", id_val)
fmt.Println("Path config:", path_val)
Replace_id(path_val, id_val) // Cap nhap ID BOX cho file config.txt trong engine
threshold := fmt.Sprintf("%.2f", message.Data.Engines[i].Threshold)
Replace_id(path_val, id_val, threshold, message.Data.Engines[i].Url) // Cap nhap ID BOX cho file config.txt trong engine
// message.Data.Engines[i].PortStream = ChangePort(path_val, i)
fmt.Println(ChangePort(path_val, i))
// Change portstream local cho cac engine thanh khac nhau
@ -454,7 +458,7 @@ func RequestUpdate(Url string) {
if message.Data.Engines[j].Name == messageUpdate.Data.Engines[i].Name+"_"+strconv.Itoa(messageUpdate.Data.Engines[i].Id) {
if message.Data.Engines[j].Version != messageUpdate.Data.Engines[i].Version {
// Backup file config.txt vao thu muc backup
file.CoppyFile(message.Data.Engines[j].Path+"/data/Config.txt", message.Data.Engines[j].Id)
file.CoppyFile(message.Data.Engines[j].Path+"/data/config.json", message.Data.Engines[j].Id)
// Delete foder engine old
file.DeleteForder(message.Data.Engines[j].Path)
message.Data.Engines[j] = messageUpdate.Data.Engines[i]
@ -795,10 +799,10 @@ func ChangePort(path string, k int) int {
}
//Replace_id () : Thay the id engine vào file config
func Replace_id(path string, id_box string) {
file.Println("Function Replace_id")
file.Println("Path : " + path)
file.Println("Id_box: " + id_box)
func Replace_id(path string, id_box string, th string, api_url string) { // Chỉ danh cho bản server local có trường Url lỗi :"url":"http://192.168.0.42:5003;http://192.168.0.42:5005",
fmt.Println("Function Replace_id")
fmt.Println("Path : " + path)
fmt.Println("Id_box: " + id_box)
var msg string = ""
var file_r, err = os.OpenFile(path, os.O_RDWR, 0644)
if err != nil {
@ -829,32 +833,48 @@ func Replace_id(path string, id_box string) {
}
}
msg = string(text)
//fmt.Printf("msg=\n%s", msg)
}
defer file_r.Close()
i := strings.Index(msg, "cam_id:")
//file.Println("Index: ", i)
i := strings.Index(msg, `"cam_id":`)
fmt.Println("Index: ", i)
if i > -1 {
index := msg[i+7:]
//fmt.Println()
//fmt.Println(msg[i+7:])
index := msg[i+10:]
// fmt.Println()
// fmt.Println(msg[i+10:])
list := strings.Split(index, "\n")
// list = strings.Split(index, "\n")
file.Println(list[0])
//fmt.Println(list[0])
//fmt.Println()
fmt.Println(list[0])
fmt.Println()
var id = list[0]
if Debug == 1 {
fmt.Println("id_cam old: ", id)
}
// fmt.Println("++++++++++++++++++++++")
// fmt.Println(`"cam_id": ` + id)
// fmt.Println(`"cam_id": ` + id_box + ",")
// fmt.Println("++++++++++++++++++++++")
// Replace
newConfig := strings.Replace(msg, "cam_id:"+id, "cam_id:"+id_box, -1)
newConfig := strings.Replace(msg, `"cam_id": `+id, `"cam_id": `+id_box+",", -1)
//Replace trường accuracy_face_recognition
file.Write_log(" --- > Replace accuracy_face_recognition < ---", Path_log_luncher)
newConfig = strings.Replace(newConfig, "[threshold]", th, -1)
//Replace trường API
newConfig = strings.Replace(newConfig, "[api_url]", api_url, -1)
// Replace trường Server authen http://api.cloudv2.beetai.com
api_authen := strings.Replace(api_url, "5003", "5000", -1)
newConfig = strings.Replace(newConfig, "http://api.cloudv2.beetai.com", api_authen, -1)
err = ioutil.WriteFile(path, []byte(newConfig), 0)
if err != nil {
//panic(err)
}
} else {
file.Write_log("cam_id not found", Path_log_luncher)
//file.Println("cam_id not found")
fmt.Println("cam_id not found")
}
fmt.Println("------------------------------------------------------")
}
// List function