From 7272901f33e1b58ea79aa0f7a9ce9451dcc6bf56 Mon Sep 17 00:00:00 2001 From: Zhanpeng Yang Date: Fri, 11 Oct 2024 13:24:56 +0800 Subject: [PATCH] =?UTF-8?q?[Feature]=E6=96=B0=E5=A2=9E=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=EF=BC=8C=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=87=8D=E5=90=AF=E9=94=99=E8=AF=AF=E7=BD=91=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 67 +++++++++++++++++++++++ main.ps1 => SEMS-system-guardian.ps1 | 82 +++++++++++++++++++++++++++- 2 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 .env rename main.ps1 => SEMS-system-guardian.ps1 (81%) diff --git a/.env b/.env new file mode 100644 index 0000000..37d3e4b --- /dev/null +++ b/.env @@ -0,0 +1,67 @@ +################################# +# 数据收集相关配置 +################################ +#光谱相机设备型号索引 +SPECTRUM_deviceTypeIndex=1 +#光谱相机帧率 +SPECTRUM_FrameRate=4.0 +#光谱相机曝光时间 +SPECTRUM_ExposureTime=10.0 +#光谱相机空间像素组合,设置为0,空间维度为1024,1为512,2为256,3为128 +SPECTRUM_BinningSpatial=1 +#光谱相机光谱像素组合,设置为0,光谱维度为448,1为224,2为112,3为56 +SPECTRUM_BinningSpectral=1 +#是否开启像素组合,1为开启,0为不开启 +SPECTRUM_BinningAverage=1 +#循环缓存区大小 +SPECTRUM_RingBufferSize=2 + +#原始光谱数据保存路径 +RAWDATA_Folder=C:/tmp/ + +# 每个原始光谱数据bin文件最大多少Byte, 10737418240 是10G( 10*1024*1024*1024),10485760是10M +RAWDATA_MaxSize=10737418240 + +################################# +# 后台服务相关配置 +################################ + +#设备ID +NEXT_PUBLIC_DEVICE_ID=DOJHBG +#设备名字备注 +NEXT_PUBLIC_DEVICE_NAME=办公室测试设备 +#设备ID +ON_DEVICE_SERVER_PORT=22110 +#推理服务的API +MODEL_INFERENCE_API=http://sems-model-inference:22111/post +#将炉次数据回传的API +# FURNACE_UPLOAD_API=https://3.u1227383.nyat.app:25889/api/upload +FURNACE_UPLOAD_API=http://10.8.8.8:22114/api/upload + + + + + + + + +# VIDEO_ + + +# spectral_camera_configs: +# deviceTypeIndex: 1 +# FrameRate: 4.0 +# ExposureTime: 10.0 +# BinningSpatial: 1 +# BinningSpectral: 1 +# BinningAverage: true +# RingBufferSize: 2 + + +# visible_light_camera_configs: +# enable: false +# video_capture_index: 0 + +# save_configs: +# save_dir: C:/tmp/ +# max_file_size: 10737418240 # 1073741824 # 10*1024*1024*1024 = 10GB 10737418240 10485760(10M) \ No newline at end of file diff --git a/main.ps1 b/SEMS-system-guardian.ps1 similarity index 81% rename from main.ps1 rename to SEMS-system-guardian.ps1 index d2b4994..48609cc 100644 --- a/main.ps1 +++ b/SEMS-system-guardian.ps1 @@ -3,7 +3,48 @@ $UPDATE_SOURCE = "https://1.u1227383.nyat.app:23587/api/v1/repos/zhanpeng" $TOCKEN = "e9aaae4b5f7756d0a2977764dbcbdfeb68bb2e13" $PRODUCTION_FOLDER = "C:\SEMS-production" -$RAWDATA_FOLDER = "C:\tmp" +# $RAWDATA_FOLDER = "C:\tmp" + +# try{ +# $errorNetAdapter = Get-PnpDevice -Status ERROR -Class ‘Net’ +# $errorNetAdapter | Disable-PnpDevice -Confirm:$false +# $errorNetAdapter | Enable-PnpDevice -Confirm:$false +# }catch{ + + +# } + + +try { + $errorDevices = Get-CimInstance -Query "SELECT * FROM Win32_PnPEntity WHERE PNPClass = 'Net' AND Status = 'Error'" + + if ( $null -eq $errorDevices -or $errorDevices.Count -eq 0) { + Write-Host "没有找到状态为ERROR的网络设备。" + } + else { + Write-Host "以下网络设备状态为ERROR, 正在重启:" + $errorDevices | ForEach-Object { + Write-Host $_.DeviceID + } + $errorNetAdapter | Disable-PnpDevice -Confirm:$false + $errorNetAdapter | Enable-PnpDevice -Confirm:$false + } +} +catch [Microsoft.Management.Infrastructure.CimException] { + if ($_.Exception.Message -like '*No matching Win32_PnPEntity objects found*') { + Write-Host "没有找到状态为ERROR的网络设备。" + } + else { + Write-Host "执行命令时发生错误: $_" + } +} +catch { + Write-Host "执行命令时发生未知错误: $_" +} + + + + if (Test-Path -Path $PRODUCTION_FOLDER -PathType Container) { @@ -205,6 +246,41 @@ else { + +function Set-PermanentEnvFromDotEnv { + param ( + [string]$envFilePath = ".env", + [System.EnvironmentVariableTarget]$scope = [System.EnvironmentVariableTarget]::User + ) + + + + if (-Not (Test-Path $envFilePath)) { + Write-Error "File '$envFilePath' not found." + return + } + + Get-Content $envFilePath | ForEach-Object { + $line = $_.Trim() + if ($line -and -not $line.StartsWith("#")) { + $parts = $line -split "=", 2 + if ($parts.Length -eq 2) { + $key = $parts[0].Trim() + $value = $parts[1].Trim() + [System.Environment]::SetEnvironmentVariable($key, $value, $scope) + # ${ENV}:$key = $value + Set-Item -Path "ENV:$key" -Value $value + } + } + } +} + +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +Write-Output "[初始化]环境变量 $scriptDir\.env" +Set-PermanentEnvFromDotEnv -envFilePath "$scriptDir\.env" -scope User + + + $folders = Get-ChildItem -Path $PRODUCTION_FOLDER -Directory $folderDataCollection = $folders | Where-Object { $_.Name -like "*SEMS-data-collection*" } @@ -251,10 +327,12 @@ else { } +Write-Output "[状态]数据集路径 $env:RAWDATA_Folder" + if ($container -eq "true") { Write-Output "[状态]容器 'sems-on-device-server' 正在运行" } else { Write-Output "[状态]容器 'sems-on-device-server' 不在运行,正在运行" - docker run --rm -d -p "22110:22110" -v "$($folderOnDeviceServer.FullName):/app" -v "${RAWDATA_FOLDER}:/data" --env-file "C:\SEMS-production\configs\.env" --name sems-on-device-server --link sems-model-inference sems-on-device-server:latest + docker run --rm -d -p "22110:22110" -v "$($folderOnDeviceServer.FullName):/app" -v "$ENV:RAWDATA_Folder:/data" --env-file "C:\SEMS-production\configs\.env" --name sems-on-device-server --link sems-model-inference sems-on-device-server:latest }