Compare commits

..

No commits in common. "f710a66c69c1afa5fda756bfdfd941058dca2794" and "8221f8e1335ae5d0518600396f7f6efdbb1fa72c" have entirely different histories.

5 changed files with 3419 additions and 3532 deletions

View File

@ -11,7 +11,6 @@ static class CameraAddr
public const UInt32 STORE_NUM = BASE + 0x13; public const UInt32 STORE_NUM = BASE + 0x13;
public const UInt32 EXPECTED_VH = BASE + 0x14; public const UInt32 EXPECTED_VH = BASE + 0x14;
public const UInt32 CAPTURE_ON = BASE + 0x15; public const UInt32 CAPTURE_ON = BASE + 0x15;
public const UInt32 CAMERA_POWER = BASE + 0x16; //[0]: rstn, 0 is reset. [8]: power down, 1 is down.
} }
class Camera class Camera
@ -27,7 +26,7 @@ class Camera
const uint CAM_I2C_ADDR = 0x3C; const uint CAM_I2C_ADDR = 0x3C;
const Peripherals.I2cClient.I2cProtocol CAM_PROTO = Peripherals.I2cClient.I2cProtocol.SCCB; const Peripherals.I2cClient.I2cProtocol CAM_PROTO = Peripherals.I2cClient.I2cProtocol.SCCB;
const byte PLL_MUX = 60; const byte PLL_MUX = 10;
const UInt32 FrameAddr = 0x00; const UInt32 FrameAddr = 0x00;
// 动态分辨率参数 // 动态分辨率参数
@ -162,56 +161,6 @@ class Camera
return true; return true;
} }
public async ValueTask<Result<bool>> EnableCameraHardware(bool isEnable)
{
{
var ret = await UDPClientPool.WriteAddr(this.ep, this.taskID, CameraAddr.CAMERA_POWER, (isEnable ? 0x00000001u : 0x00000000u));
if (!ret.IsSuccessful)
{
logger.Error($"Failed to write STORE_ADDR: {ret.Error}");
return new(ret.Error);
}
if (!ret.Value)
{
logger.Error("STORE_ADDR write returned false");
return new(new Exception("STORE_ADDR write returned false"));
}
}
return true;
}
public async ValueTask<Result<bool>> SleepCameraHardware(bool isEnable)
{
{
var ret = await UDPClientPool.WriteAddr(this.ep, this.taskID, CameraAddr.CAMERA_POWER, (isEnable ? 0x00000101u : 0x00000001u));
if (!ret.IsSuccessful)
{
logger.Error($"Failed to write STORE_ADDR: {ret.Error}");
return new(ret.Error);
}
if (!ret.Value)
{
logger.Error("STORE_ADDR write returned false");
return new(new Exception("STORE_ADDR write returned false"));
}
}
await Task.Delay(5);
{
var ret = await UDPClientPool.WriteAddr(this.ep, this.taskID, CameraAddr.CAMERA_POWER, 0x00000101);
if (!ret.IsSuccessful)
{
logger.Error($"Failed to write STORE_ADDR: {ret.Error}");
return new(ret.Error);
}
if (!ret.Value)
{
logger.Error("STORE_ADDR write returned false");
return new(new Exception("STORE_ADDR write returned false"));
}
}
return true;
}
/// <summary> /// <summary>
/// 读取一帧图像数据 /// 读取一帧图像数据
/// </summary> /// </summary>
@ -228,7 +177,7 @@ class Camera
this.ep, this.ep,
this.taskID, // taskID this.taskID, // taskID
FrameAddr, FrameAddr,
(int)_currentFrameLength, // 使用当前分辨率的动态大小 (int)(_currentWidth * _currentHeight * 2), // 使用当前分辨率的动态大小
this.timeout); this.timeout);
if (!result.IsSuccessful) if (!result.IsSuccessful)
@ -301,6 +250,7 @@ class Camera
} }
} }
} }
return true; return true;
} }

View File

@ -157,7 +157,6 @@ public class HttpVideoStreamService : BackgroundService
} }
_cameraEnable = isEnabled; _cameraEnable = isEnabled;
await _camera.EnableCamera(_cameraEnable); await _camera.EnableCamera(_cameraEnable);
await _camera.SleepCameraHardware(!_cameraEnable);
} }
/// <summary> /// <summary>

View File

@ -480,7 +480,6 @@ public class UDPClientPool
if (outstanding >= 512 - batchSize) if (outstanding >= 512 - batchSize)
continue; continue;
// Send next batch of address packages (up to 128) // Send next batch of address packages (up to 128)
int batchSend = Math.Min(batchSize, pkgList.Count - sentCount); int batchSend = Math.Min(batchSize, pkgList.Count - sentCount);
var batchPkgs = pkgList.Skip(sentCount).Take(batchSend); var batchPkgs = pkgList.Skip(sentCount).Take(batchSend);

View File

@ -314,18 +314,19 @@ export class VideoStreamClient {
/** /**
* *
* @param request * @param width
* @return * @param height
* @return
*/ */
setResolution(request: ResolutionConfigRequest): Promise<any> { setResolution(width: number, height: number): Promise<boolean> {
let url_ = this.baseUrl + "/api/VideoStream/Resolution"; let url_ = this.baseUrl + "/api/VideoStream/SetResolution";
url_ = url_.replace(/[?&]$/, ""); url_ = url_.replace(/[?&]$/, "");
const content_ = JSON.stringify(request); const content_ = JSON.stringify({ width: width, height: height });
let options_: RequestInit = { let options_: RequestInit = {
body: content_,
method: "POST", method: "POST",
body: content_,
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Accept": "application/json" "Accept": "application/json"
@ -337,7 +338,7 @@ export class VideoStreamClient {
}); });
} }
protected processSetResolution(response: Response): Promise<any> { protected processSetResolution(response: Response): Promise<boolean> {
const status = response.status; const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) { if (status === 200) {
@ -348,20 +349,11 @@ export class VideoStreamClient {
return result200; return result200;
}); });
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
let resultData400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result400 = resultData400 !== undefined ? resultData400 : <any>null;
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) { } else if (status === 500) {
return response.text().then((_responseText) => { return response.text().then((_responseText) => {
let result500: any = null; let result500: any = null;
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver); let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result500 = resultData500 !== undefined ? resultData500 : <any>null; result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500); return throwException("A server side error occurred.", status, _responseText, _headers, result500);
}); });
} else if (status !== 200 && status !== 204) { } else if (status !== 200 && status !== 204) {
@ -369,15 +361,15 @@ export class VideoStreamClient {
return throwException("An unexpected server error occurred.", status, _responseText, _headers); return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}); });
} }
return Promise.resolve<any>(null as any); return Promise.resolve<boolean>(null as any);
} }
/** /**
* *
* @return * @return
*/ */
getCurrentResolution(): Promise<any> { getCurrentResolution(): Promise<any> {
let url_ = this.baseUrl + "/api/VideoStream/Resolution"; let url_ = this.baseUrl + "/api/VideoStream/GetCurrentResolution";
url_ = url_.replace(/[?&]$/, ""); url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = { let options_: RequestInit = {
@ -407,8 +399,7 @@ export class VideoStreamClient {
return response.text().then((_responseText) => { return response.text().then((_responseText) => {
let result500: any = null; let result500: any = null;
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver); let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result500 = resultData500 !== undefined ? resultData500 : <any>null; result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500); return throwException("A server side error occurred.", status, _responseText, _headers, result500);
}); });
} else if (status !== 200 && status !== 204) { } else if (status !== 200 && status !== 204) {
@ -420,11 +411,11 @@ export class VideoStreamClient {
} }
/** /**
* *
* @return * @return
*/ */
getSupportedResolutions(): Promise<any> { getSupportedResolutions(): Promise<any[]> {
let url_ = this.baseUrl + "/api/VideoStream/SupportedResolutions"; let url_ = this.baseUrl + "/api/VideoStream/GetSupportedResolutions";
url_ = url_.replace(/[?&]$/, ""); url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = { let options_: RequestInit = {
@ -439,7 +430,7 @@ export class VideoStreamClient {
}); });
} }
protected processGetSupportedResolutions(response: Response): Promise<any> { protected processGetSupportedResolutions(response: Response): Promise<any[]> {
const status = response.status; const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) { if (status === 200) {
@ -454,8 +445,7 @@ export class VideoStreamClient {
return response.text().then((_responseText) => { return response.text().then((_responseText) => {
let result500: any = null; let result500: any = null;
let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver); let resultData500 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result500 = resultData500 !== undefined ? resultData500 : <any>null; result500 = Exception.fromJS(resultData500);
return throwException("A server side error occurred.", status, _responseText, _headers, result500); return throwException("A server side error occurred.", status, _responseText, _headers, result500);
}); });
} else if (status !== 200 && status !== 204) { } else if (status !== 200 && status !== 204) {
@ -463,7 +453,7 @@ export class VideoStreamClient {
return throwException("An unexpected server error occurred.", status, _responseText, _headers); return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}); });
} }
return Promise.resolve<any>(null as any); return Promise.resolve<any[]>(null as any);
} }
} }
@ -2941,52 +2931,6 @@ export interface ICameraConfigRequest {
port: number; port: number;
} }
/** 分辨率配置请求模型 */
export class ResolutionConfigRequest implements IResolutionConfigRequest {
/** 宽度 */
width!: number;
/** 高度 */
height!: number;
constructor(data?: IResolutionConfigRequest) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(_data?: any) {
if (_data) {
this.width = _data["width"];
this.height = _data["height"];
}
}
static fromJS(data: any): ResolutionConfigRequest {
data = typeof data === 'object' ? data : {};
let result = new ResolutionConfigRequest();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["width"] = this.width;
data["height"] = this.height;
return data;
}
}
/** 分辨率配置请求模型 */
export interface IResolutionConfigRequest {
/** 宽度 */
width: number;
/** 高度 */
height: number;
}
export class ProblemDetails implements IProblemDetails { export class ProblemDetails implements IProblemDetails {
type?: string | undefined; type?: string | undefined;
title?: string | undefined; title?: string | undefined;

View File

@ -340,7 +340,7 @@ import {
AlertTriangle, AlertTriangle,
MoreHorizontal, MoreHorizontal,
} from "lucide-vue-next"; } from "lucide-vue-next";
import { VideoStreamClient, CameraConfigRequest, ResolutionConfigRequest } from "@/APIClient"; import { VideoStreamClient, CameraConfigRequest } from "@/APIClient";
import { useEquipments } from "@/stores/equipments"; import { useEquipments } from "@/stores/equipments";
const eqps = useEquipments(); const eqps = useEquipments();
@ -597,8 +597,7 @@ const refreshResolutions = async () => {
try { try {
addLog("info", "正在获取支持的分辨率列表..."); addLog("info", "正在获取支持的分辨率列表...");
const resolutions = await videoClient.getSupportedResolutions(); const resolutions = await videoClient.getSupportedResolutions();
supportedResolutions.value = resolutions.resolutions; supportedResolutions.value = resolutions;
console.log("支持的分辨率列表:", supportedResolutions.value);
// //
const currentRes = await videoClient.getCurrentResolution(); const currentRes = await videoClient.getCurrentResolution();
@ -630,11 +629,7 @@ const changeResolution = async () => {
} }
// //
const resolutionRequest = new ResolutionConfigRequest({ const success = await videoClient.setResolution(selectedResolution.value.width, selectedResolution.value.height);
width: selectedResolution.value.width,
height: selectedResolution.value.height
});
const success = await videoClient.setResolution(resolutionRequest);
if (success) { if (success) {
// //