291 lines
8.0 KiB
C++

#ifndef IVRCONFIG_H
#define IVRCONFIG_H
#include <cstdint>
#include <string>
#include <vector>
#include <QMetaType>
#include <QString>
#include "ILedDisplayDevice.h"
#include "IRsLidarDevice.h"
#include "IVisionApplicationStatus.h"
#include "VrCommonConfig.h"
struct VrParkingSpaceGuideParam
{
double minGuideDistance = 200.0;
double maxGuideDistance = 8000.0;
double targetStopOffset = 500.0;
double lateralTolerance = 100.0;
double angleTolerance = 5.0;
double confidenceThreshold = 0.60;
};
struct VrGuideLineCalibration
{
bool calibrated = false;
double startX = 0.0;
double startY = 0.0;
double endX = 0.0;
double endY = 0.0;
std::string calibrationTime;
};
struct VrParkingSpaceCalibrationParam
{
VrGuideLineCalibration centerLine;
VrGuideLineCalibration stopLine;
double countdownStartDistance = 15000.0;
double modelVerifyDistance = 12000.0;
};
struct VrAlgorithmParams
{
VrParkingSpaceGuideParam guideParam;
VrParkingSpaceCalibrationParam calibrationParam;
VrAlgorithmParams() = default;
VrAlgorithmParams(const VrAlgorithmParams&) = default;
VrAlgorithmParams& operator=(const VrAlgorithmParams&) = default;
};
struct UdpBroadcastConfig
{
bool enabled = false;
std::string address = "239.255.0.1";
int port = 8800;
std::string targetId = "T001";
std::string parkId = "P01";
};
struct MvsCameraConfig
{
bool enabled = true;
std::string serialNumber;
int deviceIndex = 0;
};
struct HttpServerConfig
{
bool enabled = true;
std::string address = "0.0.0.0";
int port = 8801;
int maxQueued = 16;
int maxThreads = 4;
};
struct ConfigResult
{
std::vector<DeviceInfo> cameraList;
MvsCameraConfig mvsCamera;
RsLidarConfig lidarConfig;
LedDisplayConfig ledDisplayConfig;
UdpBroadcastConfig udpBroadcastConfig;
HttpServerConfig httpServerConfig;
VrAlgorithmParams algorithmParams;
VrDebugParam debugParam;
ConfigResult() = default;
ConfigResult(const ConfigResult&) = default;
ConfigResult& operator=(const ConfigResult&) = default;
void Normalize()
{
cameraList.clear();
DeviceInfo camera;
camera.index = 1;
camera.name = "平面相机";
camera.ip = mvsCamera.serialNumber;
camera.baseDistance = 0.0;
cameraList.push_back(camera);
if (mvsCamera.deviceIndex < 0) {
mvsCamera.deviceIndex = 0;
}
if (algorithmParams.calibrationParam.countdownStartDistance < 0.0) {
algorithmParams.calibrationParam.countdownStartDistance = 15000.0;
}
if (algorithmParams.calibrationParam.modelVerifyDistance < 0.0) {
algorithmParams.calibrationParam.modelVerifyDistance = 12000.0;
}
if (udpBroadcastConfig.address.empty()) {
udpBroadcastConfig.address = "239.255.0.1";
}
if (udpBroadcastConfig.port <= 0 || udpBroadcastConfig.port > 65535) {
udpBroadcastConfig.port = 8800;
}
if (udpBroadcastConfig.targetId.empty()) {
udpBroadcastConfig.targetId = "T001";
}
if (udpBroadcastConfig.parkId.empty()) {
udpBroadcastConfig.parkId = "P01";
}
if (httpServerConfig.address.empty()) {
httpServerConfig.address = "0.0.0.0";
}
if (httpServerConfig.port <= 0 || httpServerConfig.port > 65535) {
httpServerConfig.port = 8801;
}
if (httpServerConfig.maxQueued <= 0) {
httpServerConfig.maxQueued = 16;
}
if (httpServerConfig.maxThreads <= 0) {
httpServerConfig.maxThreads = 4;
}
if (ledDisplayConfig.ip.empty()) {
ledDisplayConfig.ip = "192.168.1.100";
}
if (ledDisplayConfig.port <= 0 || ledDisplayConfig.port > 65535) {
ledDisplayConfig.port = 5005;
}
if (ledDisplayConfig.slaveId < 0 || ledDisplayConfig.slaveId > 65535) {
ledDisplayConfig.slaveId = 0xFFFE;
}
if (ledDisplayConfig.startAddress < 0 || ledDisplayConfig.startAddress > 31) {
ledDisplayConfig.startAddress = 0;
}
if (ledDisplayConfig.timeoutMs < 100) {
ledDisplayConfig.timeoutMs = 1000;
}
if (ledDisplayConfig.controllerType < 0 || ledDisplayConfig.controllerType > 255) {
ledDisplayConfig.controllerType = 0xFE;
}
if (ledDisplayConfig.areaX < 0) {
ledDisplayConfig.areaX = 0;
}
if (ledDisplayConfig.areaY < 0) {
ledDisplayConfig.areaY = 0;
}
if (ledDisplayConfig.areaWidth <= 0) {
ledDisplayConfig.areaWidth = 64;
}
if (ledDisplayConfig.areaHeight <= 0) {
ledDisplayConfig.areaHeight = 32;
}
if (ledDisplayConfig.dynamicTimeoutSec < 0 || ledDisplayConfig.dynamicTimeoutSec > 65535) {
ledDisplayConfig.dynamicTimeoutSec = 10;
}
if (ledDisplayConfig.displayMode < 1 || ledDisplayConfig.displayMode > 7) {
ledDisplayConfig.displayMode = 1;
}
if (ledDisplayConfig.speed < 0 || ledDisplayConfig.speed > 24) {
ledDisplayConfig.speed = 2;
}
if (ledDisplayConfig.stayTime < 0 || ledDisplayConfig.stayTime > 255) {
ledDisplayConfig.stayTime = 10;
}
}
};
enum LoadConfigErrorCode
{
LOAD_CONFIG_SUCCESS = 0,
LOAD_CONFIG_FILE_NOT_FOUND = -1,
LOAD_CONFIG_PARSE_ERROR = -2,
LOAD_CONFIG_INVALID_FORMAT = -3,
LOAD_CONFIG_UNKNOWN_ERROR = -99
};
class IVrConfig
{
public:
virtual ~IVrConfig() {}
static bool CreateInstance(IVrConfig** ppVrConfig);
virtual int LoadConfig(const std::string& filePath, ConfigResult& configResult) = 0;
virtual bool SaveConfig(const std::string& filePath, ConfigResult& configResult) = 0;
virtual void SetConfigChangeNotify(IVrConfigChangeNotify* notify) = 0;
};
struct ParkingSpaceGuidePosition : public PositionData<double>
{
ParkingSpaceGuidePosition() : PositionData<double>() {}
ParkingSpaceGuidePosition(double x, double y, double z,
double roll, double pitch, double yaw)
: PositionData<double>(x, y, z, roll, pitch, yaw)
{
}
};
enum class ParkingGuideState : int
{
Unknown = 0,
DockingStarted = 1,
Capturing = 2,
Tracking = 3,
ApproachRate = 4,
CenterLineAligned = 5,
Slow = 6,
AzimuthGuidance = 7,
StopPositionReached = 8,
DockingCompleted = 9,
Overshot = 10,
StoppedShort = 11,
Waiting = 12,
SlowBadWeather = 13,
SlowAircraftLost = 14,
AircraftVerificationFailed = 15,
GateBlocked = 16,
ViewBlocked = 17,
SbuStop = 18,
TooFast = 19,
EmergencyStop = 20,
ChocksOn = 21,
SystemError = 22,
SystemFailure = 23,
PowerFailure = 24
};
inline ParkingGuideState ParkingGuideStateFromCode(int guideStateCode)
{
if (guideStateCode < static_cast<int>(ParkingGuideState::Unknown) ||
guideStateCode > static_cast<int>(ParkingGuideState::PowerFailure)) {
return ParkingGuideState::Unknown;
}
return static_cast<ParkingGuideState>(guideStateCode);
}
struct ParkingSpaceGuideInfo
{
QString targetId;
QString parkId;
QString modelType;
bool hasException = false;
double distance = 0.0;
double lateralOffset = 0.0;
double angle = 0.0;
double aircraftSpeed = 0.0;
double confidence = 0.0;
int guideStateCode = 0;
QString guideText;
};
struct DetectionResult : public DetectionResultData<ParkingSpaceGuidePosition>
{
std::vector<ParkingSpaceGuideInfo> parkingSpaceInfoList;
QString message;
};
struct ParkingSpaceGuideDetectOutput
{
bool success = true;
int errorCode = 0;
QString message;
int cameraIndex = 1;
qint64 timestamp = 0;
std::vector<ParkingSpaceGuideInfo> guideOutputs;
};
Q_DECLARE_METATYPE(ParkingSpaceGuidePosition)
Q_DECLARE_METATYPE(ParkingSpaceGuideInfo)
Q_DECLARE_METATYPE(DetectionResult)
#endif // IVRCONFIG_H