using BZFAStandardLib; using Newtonsoft.Json; using System; namespace MainForm.ClassFile.XiaomiAPI { /// /// 小米 MqttClient类 - API拓展方法 /// 故障⽇志 /// 故障发⽣时,必须要上报对应的故障⽇志;设备状态数据同步也需要上报Fault,同时确保故障数据和上报的设备状态数据中fault_tm和fault_code⼀致。 /// 故障编码规则需要依据⼩⽶标准,区分等级(A,B,C,D,E)。在录⼊数据字典时,也需按照此标准定义故障编码。如:B60028 /// public partial class XiaomiMqttClient_Extend : XiaomiMqttClient { /// /// 故障⽇志- 事件Id /// private static string FaultLogId { get; set; } = "fault_log/electric_control/alarm/work_module/{0}"; /// /// 故障⽇志- 事件方法 /// /// 事件数据;Json /// 自定义事件Id;如:guid /// public static (int, string) Write_FaultLog(FaultLogRequest request, string dataId = "") { int result = 0; string resultStr = ""; string msg = JsonConvert.SerializeObject(request); byte[] bytes = ToUTF8(msg); string faultLogId = string.Format(FaultLogId, request.fault_code); // 发送 if (string.IsNullOrEmpty(dataId)) result = Write(faultLogId, bytes); else result = WriteWithDataId(faultLogId, bytes, dataId); var try1 = Enum.TryParse(result.ToString(), out XiaomiMqttResponse_ErrCode errCode); if (try1) resultStr = errCode.ToString(); else resultStr = XiaomiMqttResponse_ErrCode.ERR_UNKOWN.ToString(); string logPath = GlobalContext.MqttAlarmLogDir + "AlarmType" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; FileOperate.NewTxtFile(logPath, "MQTT【故障日志】提交:" + msg + "\r\n==>提交结果:" + resultStr + ""); return (result, resultStr); } /// /// 故障⽇志- 参数 /// ◦ function_name是对test_item进⾏分类聚合,同⼀类的test_item对应同⼀个function_name名称。 /// ◦ test_item可以是装备作业过程中的检测项、算法参数、⼯艺参数等 /// ◦ result_val可以是检测值/算法的输出值/⼯艺参数值 /// ◦ description填写对应test_item的中⽂描述,⽤于描述这条数据的含义 /// public class FaultLogRequest { /// /// ⼯位 /// string[1,64] /// • 当上报⼯位信息时,表⽰当前上报的是⼯位状态 /// • 当上报的⼯位信息为空时,表⽰状态状态 /// public string station { get; set; } = string.Empty; /// /// 故障名称 /// string[1,128] /// 故障事件名称,同数据字典中的事件名称。 /// public string fault_name { get; set; } = string.Empty; /// /// 故障编码 /// string[1,32] /// 故障编码规则需要依据⼩⽶标准,区分等级(A,B,C,D,E)。在录⼊数据字典时,也需按照此标准定义故障编码。如:B60028 /// public string fault_code { get; set; } = string.Empty; /// /// 故障部件 /// string[1,64] /// public string fault_cmpnt { get; set; } = string.Empty; /// /// 故障描述 /// string[1,64] /// public string fault_desc { get; set; } = string.Empty; /// /// 故障发⽣时间 /// string[1,32] /// 事件发⽣时间(时间戳,毫秒),如:2022-06-01 14:27:57.283 /// public string fault_tm { get; set; } = string.Empty; } } }