@Pigmon
2021-06-04T13:23:58.000000Z
字数 1979
阅读 580
遥控
错误代码在遥控驾驶系统最基本的车辆上行报文中,具体字段如下图所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestCSharp
{
class Program
{
static ushort ERRDET_GPS_LOSS = 0x0004;
static ushort ERRDET_IMU_LOSS = 0x0008;
static ushort ERRDET_LIDAR_LOSS = 0x0010;
static ushort ERRDET_POSTYPE = 0X0080;
static ushort ERRDET_OUTOFPATH = 0X0100;
static void Main(string[] args)
{
ushort err_msg = (ushort)(ERRDET_GPS_LOSS | ERRDET_LIDAR_LOSS | ERRDET_OUTOFPATH);
string msg1 = ErrorToString(err_msg);
string msg2 = ErrorToString_Single(err_msg);
Console.WriteLine("多个错误一起显示的方式:" + msg1);
Console.WriteLine("只显示一个错误的方式:" + msg2);
}
/// <summary>
/// 如果有多个错误,全部显示的函数;
/// </summary>
/// <param name="_err_msg">车辆上行报文中m_ctrl_info 的数值</param>
/// <returns>代表错误的字符串</returns>
static string ErrorToString(ushort _err_msg)
{
string ret = "";
bool location_error = (_err_msg & ERRDET_GPS_LOSS) == ERRDET_GPS_LOSS ||
(_err_msg & ERRDET_IMU_LOSS) == ERRDET_IMU_LOSS ||
(_err_msg & ERRDET_POSTYPE) == ERRDET_POSTYPE;
bool lidar_error = (_err_msg & ERRDET_LIDAR_LOSS) == ERRDET_LIDAR_LOSS;
bool path_error = (_err_msg & ERRDET_OUTOFPATH) == ERRDET_OUTOFPATH;
bool is_error = location_error || lidar_error || path_error;
if (is_error)
{
if (location_error)
ret += "定位系统故障;";
if (lidar_error)
ret += "激光雷达故障;";
if (path_error)
ret += "行驶异常;";
}
else
ret += "正常";
return ret;
}
/// <summary>
/// 同时发生多个错误,但只显示其中一个错误的函数
/// </summary>
/// <param name="_err_msg">车辆上行报文中m_ctrl_info 的数值</param>
/// <returns>代表错误的字符串</returns>
static string ErrorToString_Single(ushort _err_msg)
{
string ret = "";
bool location_error = (_err_msg & ERRDET_GPS_LOSS) == ERRDET_GPS_LOSS ||
(_err_msg & ERRDET_IMU_LOSS) == ERRDET_IMU_LOSS ||
(_err_msg & ERRDET_POSTYPE) == ERRDET_POSTYPE;
bool lidar_error = (_err_msg & ERRDET_LIDAR_LOSS) == ERRDET_LIDAR_LOSS;
bool path_error = (_err_msg & ERRDET_OUTOFPATH) == ERRDET_OUTOFPATH;
bool is_error = location_error || lidar_error || path_error;
// 假设错误显示优先级从高到低依次为:
// 1. 定位问题;
// 2. 行驶异常;
// 3. 激光雷达故障;
if (location_error)
ret += "定位系统故障;";
else if (path_error)
ret += "行驶异常;";
else if (lidar_error)
ret += "激光雷达故障;";
else
ret += "正常";
return ret;
}
}
}