/// <summary> /// 电机控制器1 反馈第1帧 使能及控制信息等反馈 /// ID:0x0C4203D5 /// 波特率:250Kbps /// 数据长度:8bytes /// 周期:50ms /// </summary> ElecOilPump_Scm_MCU1_Frame1 ElecOilPump_ByteToScmMcu1Frame1(CanStandardData scmCanByte1) { ElecOilPump_Scm_MCU1_Frame1 scmMcu1Frame1 = new ElecOilPump_Scm_MCU1_Frame1(); //byte0 //bit0,1 scmMcu1Frame1.actual_running_enable = (byte)(scmCanByte1.datas[0] & 0x03); //电机实际使能状况,bit0,bit1,偏移量0,00未使能,01使能 //bit2,3 scmMcu1Frame1.actual_control_mode = (byte)(scmCanByte1.datas[0] >> 2 & 0x03); //工作模式,00-无控制,01-扭矩,10-转速控制 //byte1,转矩,范围0-32,默认值0,分辨率0.125 scmMcu1Frame1.actual_torque = (byte)(scmCanByte1.datas[1] / 8); //byte2,3,速度,范围0-5000,默认值0,分辨率1 scmMcu1Frame1.actual_speed = (ushort)(scmCanByte1.datas[3] * 256 + scmCanByte1.datas[2]); //byte6,故障等级 scmMcu1Frame1.error_level = scmCanByte1.datas[6]; //byte7,故障代码 scmMcu1Frame1.error_code = scmCanByte1.datas[7]; return(scmMcu1Frame1); }
/// <summary> /// 接收数据并处理 /// </summary> public List <ElecOilPump_Scm_MCU1_Frame1> TransformEcuReceiveData(AbstractMotorControl.CanStandardData canRecDatas) { if (canRecDatas.canId != ElecOilPump_Scm_MCU1_Frame1.canId) { return(null); } List <ElecOilPump_Scm_MCU1_Frame1> recMcus = new List <ElecOilPump_Scm_MCU1_Frame1>(); ElecOilPump_Scm_MCU1_Frame1 recMcu1 = ElecOilPump_ByteToScmMcu1Frame1(canRecDatas.datas); recMcus.Add(recMcu1); return(recMcus); }
/// <summary> /// 电机控制器反馈帧1 /// ID:0x0C7103D5 /// 波特率:250Kbps /// 数据长度:8bytes /// 周期:按需发送 /// </summary> public ElecOilPump_Scm_MCU1_Frame1 ElecOilPump_ByteToScmMcu1Frame1(byte[] scmCanByte1) { ElecOilPump_Scm_MCU1_Frame1 scmMcu1Frame1 = new ElecOilPump_Scm_MCU1_Frame1(); //byte0,N scmMcu1Frame1.N = (byte)(scmCanByte1[0]); //byte1,2,Config[N] scmMcu1Frame1.ConfigRegN = (ushort)(scmCanByte1[2] * 256 + scmCanByte1[1]); //byte3,4,Config[29] scmMcu1Frame1.ConfigReg29 = (ushort)(scmCanByte1[4] * 256 + scmCanByte1[3]); return(scmMcu1Frame1); }
/// <summary> /// 接收数据并处理 /// </summary> /// <param name="canRecDatas"></param> public override ScmCanReceiveMsg TransformEcuReceiveData(CanStandardData canRecDatas) { uint rec = CanDataFilterById(canRecDatas); ScmCanReceiveMsg recMsg = new ScmCanReceiveMsg(); //若是ID被筛选,则推送筛选ID if (rec != 0xffffffff) //筛选id { return(null); } //ID未被筛选 recMsg.canId = canRecDatas.canId; recMsg.baudrate = canRecDatas.baudrate; recMsg.datas = canRecDatas.datas; switch (canRecDatas.canId) { case ElecOilPump_Scm_MCU1_Frame1.canId: //反馈第一帧,使能,方向,扭矩,转速 { ElecOilPump_Scm_MCU1_Frame1 scmMcu1 = ElecOilPump_ByteToScmMcu1Frame1(canRecDatas); //工作模式 recMsg.containFeedBkMtclMode = true; switch (scmMcu1.actual_control_mode) { case 0: recMsg.FeedBkMtclMode = Ecm_WorkMode.None; break; //初始化 case 1: recMsg.FeedBkMtclMode = Ecm_WorkMode.TorqueMode; break; //转矩环 case 2: recMsg.FeedBkMtclMode = Ecm_WorkMode.SpeedMode; break; //转速环 default: recMsg.FeedBkMtclMode = Ecm_WorkMode.None; break; } //转速 recMsg.containFeedBkMotorSpeed = true; recMsg.FeedBkMotorSpeed = (short)scmMcu1.actual_speed; //转矩 recMsg.containFeedBkMotorTorque = true; recMsg.FeedBkMotorTorque = (short)scmMcu1.actual_torque; //故障等级 recMsg.containFeedBkErrorLevel = true; recMsg.FeedBkErrorLevel = scmMcu1.error_level; //故障码 recMsg.containFeedBkErrorCode = true; recMsg.FeedBkErrorCode = new byte[1] { scmMcu1.error_code }; //故障名称 recMsg.containFeedBkErrorStr = true; recMsg.FeedBkErrorStr = ReceiveErrorTransform(scmMcu1.error_code); break; } case ElecOilPump_Scm_MCU1_Frame2.canId: //电流电压 { ElecOilPump_Scm_MCU1_Frame2 scmMcu2 = ElecOilPump_ByteToScmMcu1Frame2(canRecDatas); //实际电流 recMsg.containFeedBkDcCurrent = true; recMsg.FeedBkDcCurrent = scmMcu2.dc_current; //相电压 recMsg.containFeedBkDcVoltage = true; recMsg.FeedBkDcVoltage = scmMcu2.dc_voltage; //实际电流 recMsg.containFeedBkAcCurrent = true; recMsg.FeedBkAcCurrent = scmMcu2.ac_current; //相电压 recMsg.containFeedBkAcVoltage = true; recMsg.FeedBkAcVoltage = scmMcu2.ac_voltage; //MCU电压 recMsg.containFeedBkMcuVoltage = true; recMsg.FeedBkMcuVoltage = scmMcu2.mcu_voltage; break; } case ElecOilPump_Scm_MCU1_Frame3.canId: //功率、温度 { ElecOilPump_Scm_MCU1_Frame3 scmMcu3 = ElecOilPump_ByteToScmMcu1Frame3(canRecDatas); recMsg.containFeedBkActPower = true; recMsg.FeedBkActPower = scmMcu3.actual_power; recMsg.containFeedBkMtclInvTemp = true; recMsg.FeedBkMtclInvTemp = scmMcu3.inverter_temperature; recMsg.containFeedBkMotorWindingTemp = true; recMsg.FeedBkMotorWindingTemp = scmMcu3.wind_temperature; recMsg.containFeedBkMtclChipTemp = true; recMsg.FeedBkMtclChipTemp = scmMcu3.mtclChip_temperature; break; } case ElecOilPump_Scm_MCU1_Frame4.canId: //软件版本 { ElecOilPump_Scm_MCU1_Frame4 scmMcu4 = ElecOilPump_ByteToScmMcu1Frame4(canRecDatas); recMsg.containFeekBkMtclVersion = true; recMsg.FeekBkMtclVersion = scmMcu4.year.ToString("X2") + "." + scmMcu4.month.ToString("X2") + "." + scmMcu4.day.ToString("X2") + "." + scmMcu4.hour.ToString("X2") + "." + scmMcu4.minute.ToString("X2"); break; } default: //continue; //其他ID的数据一律不接收 break; } return(recMsg); //推送数据 }