/// <summary> /// 电机控制器1 状态反馈第3帧 电压电流 /// ID:0x1864D0D1 /// 波特率:250Kbps /// 数据长度:8bytes /// 周期:10ms /// </summary> Scm_MCU1_Frame3 ByteToScmMcu1Frame3(CanStandardData scmCanByte3) { Scm_MCU1_Frame3 scmMcu1Frame3 = new Scm_MCU1_Frame3(); //byte0,1,母线电压,0-1000,分辨率1 scmMcu1Frame3.isg_dc_u = (ushort)(scmCanByte3.datas[1] * 256 + scmCanByte3.datas[0]); //byte2,3,母线电流,-500-500,偏移量-500,分辨率1 scmMcu1Frame3.isg_dc_i = (short)(scmCanByte3.datas[3] * 256 + scmCanByte3.datas[2] - 500); //byte4,5,相电压,0-1000,分辨率1 scmMcu1Frame3.isg_ac_u = (ushort)(scmCanByte3.datas[5] * 256 + scmCanByte3.datas[4]); //byte6,7,线电流,-500-500,偏移量-500,分辨率1 scmMcu1Frame3.isg_ac_i = (short)(scmCanByte3.datas[7] * 256 + scmCanByte3.datas[6] - 500); return(scmMcu1Frame3); }
/// <summary> /// 电机控制器1 状态反馈第3帧 功率及温度 /// 电机1 ID:0x1864D0D1 /// 电机1 ID:0x1854D0D2 /// 波特率:250Kbps /// 数据长度:8bytes /// 周期:50ms /// </summary> /// <param name="scmCanByte3"></param> /// <returns></returns> Scm_MCU1_Frame3 ByteToScmMcu1Frame3(CanStandardData scmCanByte3) { Scm_MCU1_Frame3 scmMcu1Frame3 = new Scm_MCU1_Frame3(); //byte0,1,实际电功率,KW,范围-300-300,分辨率,0.01 scmMcu1Frame3.dualsource_pwr_acu = (short)((scmCanByte3.datas[1] * 256 + scmCanByte3.datas[0]) * 0.01 - 300); //byte2,3,实际电能消耗KWh,范围-300-300,分辨率,0.01 scmMcu1Frame3.dualsource_totegy_act = (short)((scmCanByte3.datas[3] * 256 + scmCanByte3.datas[2]) * 0.01 - 300); //byte4,绕组温度,范围-40-210,分辨率1,默认-40 scmMcu1Frame3.dualsource_wind_t = (short)(scmCanByte3.datas[4] - 40); //byte5,逆变器温度,范围-40-210,分辨率1,默认-40 scmMcu1Frame3.dualsource_inv_t = (short)(scmCanByte3.datas[5] - 40); //byte6,逆变器温度,范围-40-210,分辨率1,默认-40 scmMcu1Frame3.dualsource_bear_t = (short)(scmCanByte3.datas[6] - 40); //byte7 保留 return(scmMcu1Frame3); }
/// <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 Scm_MCU1_Frame1.canId: // 0x0C62D0D1: //反馈第一帧,使能,方向,扭矩,转速 { Scm_MCU1_Frame1 scmMcu1 = ByteToScmMcu1Frame1(canRecDatas); //电机使能 recMsg.containFeedBkMcuEnable = true; recMsg.FeedBkMcuEnable = scmMcu1.isg_ena_act == 1 ? false : true; //工作模式 recMsg.containFeedBkMtclMode = true; switch (scmMcu1.isg_ctrl_mod_act) { case 0: recMsg.FeedBkMtclMode = Ecm_WorkMode.None; break; //初始化 case 1: recMsg.FeedBkMtclMode = Ecm_WorkMode.None; break; //低压上电正常 case 2: recMsg.FeedBkMtclMode = Ecm_WorkMode.None; break; //保留 case 3: recMsg.FeedBkMtclMode = Ecm_WorkMode.None; break; //电机允许运行 case 4: recMsg.FeedBkMtclMode = Ecm_WorkMode.SpeedMode; break; //转速环 case 5: recMsg.FeedBkMtclMode = Ecm_WorkMode.TorqueMode; break; //转矩环 case 6: recMsg.FeedBkMtclMode = Ecm_WorkMode.None; break; //下强电 case 7: recMsg.FeedBkMtclMode = Ecm_WorkMode.None; break; //下弱电 case 8: recMsg.FeedBkMtclMode = Ecm_WorkMode.ErrorProtected; break; //故障 default: break; } recMsg.containFeedBkGear = true; switch (scmMcu1.isg_run_dir_act) { case 0: recMsg.FeedBkGear = Ecm_Gear.NeutralGear; break; //空档 case 1: recMsg.FeedBkGear = Ecm_Gear.DriveGear; break; //前进 case 2: recMsg.FeedBkGear = Ecm_Gear.ReverseGear; break; //后退 default: recMsg.FeedBkGear = Ecm_Gear.ErrorGear; break; } //扭矩 recMsg.containFeedBkMotorTorque = true; recMsg.FeedBkMotorTorque = scmMcu1.isg_tq_acu; //转速 recMsg.containFeedBkMotorSpeed = true; recMsg.FeedBkMotorSpeed = scmMcu1.isg_spd_acu; //最大转矩 recMsg.containFeedBkMotorMaxTorque = true; recMsg.FeedbkMotorMaxTorque = scmMcu1.isg_tq_acu_max; break; } case Scm_MCU1_Frame2.canId: // 0x0C63D0D1: //反馈第二帧,故障等级及故障码 { Scm_MCU1_Frame2 scmMcu2 = ByteToScmMcu1Frame2(canRecDatas); //故障等级 recMsg.containFeedBkErrorLevel = true; recMsg.FeedBkErrorLevel = scmMcu2.isg_err_lvl; //故障码 recMsg.containFeedBkErrorCode = true; recMsg.FeedBkErrorCode = new byte[1] { scmMcu2.isg_err_cod }; //故障位 recMsg.containFeedBkErrorBits = true; recMsg.FeedBkErrorBits = new byte[6] { scmMcu2.isg_err_bit1, scmMcu2.isg_err_bit2, (byte)(scmMcu2.isg_err_bit3 & 0xff), (byte)((scmMcu2.isg_err_bit3 >> 8) & 0xff), (byte)((scmMcu2.isg_err_bit3 >> 16) & 0xff), scmMcu2.isg_err_bit4 }; //故障名称 recMsg.containFeedBkErrorStr = true; recMsg.FeedBkErrorStr = ReceiveErrorTransform(recMsg.FeedBkErrorLevel, scmMcu2.isg_err_cod, scmMcu2.isg_err_bit1, scmMcu2.isg_err_bit2, scmMcu2.isg_err_bit3, scmMcu2.isg_err_bit4); break; } case Scm_MCU1_Frame3.canId: // 0x1864D0D1: //反馈第三帧,电流电压 { Scm_MCU1_Frame3 scmMcu3 = ByteToScmMcu1Frame3(canRecDatas); //直流电压 recMsg.containFeedBkDcVoltage = true; recMsg.FeedBkDcVoltage = scmMcu3.isg_dc_u; //直流电流 recMsg.containFeedBkDcCurrent = true; recMsg.FeedBkDcCurrent = scmMcu3.isg_dc_i; //交流电压 recMsg.containFeedBkAcVoltage = true; recMsg.FeedBkAcVoltage = scmMcu3.isg_ac_u; //交流电流 recMsg.containFeedBkAcCurrent = true; recMsg.FeedBkAcCurrent = scmMcu3.isg_ac_i; break; } case Scm_MCU1_Frame4.canId: // 0x1865D0D1: //反馈第四帧,功率、温度 { Scm_MCU1_Frame4 scmMcu4 = ByteToScmMcu1Frame4(canRecDatas); //功率 recMsg.containFeedBkActPower = true; recMsg.FeedBkActPower = scmMcu4.isg_pwr_acu; recMsg.containFeedBkMotorWindingTemp = true; recMsg.FeedBkMotorWindingTemp = scmMcu4.isg_wind_t; recMsg.containFeedBkMtclInvTemp = true; recMsg.FeedBkMtclInvTemp = scmMcu4.isg_inv_t; //isg_bear_t; //isg_life_cyc; break; } case Scm_MCU1_Frame5.canId: //版本 { Scm_MCU1_Frame5 scmMcu5 = ByteToScmMcu1Frame5(canRecDatas); recMsg.containFeekBkMtclVersion = true; recMsg.FeekBkMtclVersion = scmMcu5.sys_type_isg.ToString("X2") + "." + scmMcu5.mcu_type_isg.ToString("X2") + "." + scmMcu5.soft_rev_isg.ToString("X2") + "." + scmMcu5.cmc_pro_ver_isg.ToString("X2") + "." + scmMcu5.rating_data_isg[0].ToString("X2") + scmMcu5.rating_data_isg[1].ToString("X2"); break; } default: //continue; //其他ID的数据一律不接收 break; } return(recMsg); //推送数据 }
/// <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 { //if(m_receiveAbanCallback!=null) // m_receiveAbanCallback(rec); //推送筛选掉的ID return(null); } //ID未被筛选 recMsg.canId = canRecDatas.canId; recMsg.baudrate = canRecDatas.baudrate; recMsg.datas = canRecDatas.datas; switch (canRecDatas.canId) { #region 电机1 case Scm_MCU1_Frame1.motor1CanId: //反馈第一帧,使能,方向,扭矩,转速,故障 { Scm_MCU1_Frame1 scmMcu1 = ByteToScmMcu1Frame1(canRecDatas); //工作模式 recMsg.containFeedBkMtclMode = true; //转速转矩与其他协议的不一样,反的 switch (scmMcu1.dualsource_ctrl_mod_act) { case 1: recMsg.FeedBkMtclMode = Ecm_WorkMode.TorqueMode; break; //转矩环 case 2: recMsg.FeedBkMtclMode = Ecm_WorkMode.SpeedMode; break; //转速环 default: recMsg.FeedBkMtclMode = Ecm_WorkMode.None; break; } recMsg.containFeedBkGear = true; switch (scmMcu1.dualsource_run_dir_act) { case 0: recMsg.FeedBkGear = Ecm_Gear.NeutralGear; break; //空档 case 1: recMsg.FeedBkGear = Ecm_Gear.DriveGear; break; //前进 case 2: recMsg.FeedBkGear = Ecm_Gear.ReverseGear; break; //后退 default: recMsg.FeedBkGear = Ecm_Gear.ErrorGear; break; } //扭矩 recMsg.containFeedBkMotorTorque = true; recMsg.FeedBkMotorTorque = scmMcu1.dualsource_tq_acu; //转速 recMsg.containFeedBkMotorSpeed = true; recMsg.FeedBkMotorSpeed = scmMcu1.dualsource_spd_acu; //最大转矩 recMsg.containFeedBkMotorMaxTorque = true; recMsg.FeedbkMotorMaxTorque = scmMcu1.dualsource_tq_acu_max; //故障等级 recMsg.containFeedBkErrorLevel = true; recMsg.FeedBkErrorLevel = scmMcu1.dualsource_errorlevel; //故障码 recMsg.containFeedBkErrorCode = true; recMsg.FeedBkErrorCode = new byte[1] { scmMcu1.dualsource_error_code }; ReceiveErrorTransform(recMsg.FeedBkErrorCode[0]); recMsg.motorIndex = 0; //电机1 } break; case Scm_MCU1_Frame2.motor1CanId: //反馈第二帧,电流电压 { Scm_MCU1_Frame2 scmMcu2 = ByteToScmMcu1Frame2(canRecDatas); //直流电压 recMsg.containFeedBkDcVoltage = true; recMsg.FeedBkDcVoltage = scmMcu2.dualsource_dc_u; //直流电流 recMsg.containFeedBkDcCurrent = true; recMsg.FeedBkDcCurrent = scmMcu2.dualsource_dc_i; //交流电压 recMsg.containFeedBkAcVoltage = true; recMsg.FeedBkAcVoltage = scmMcu2.dualsource_ac_u; //交流电流 recMsg.containFeedBkAcCurrent = true; recMsg.FeedBkAcCurrent = scmMcu2.dualsource_ac_i; recMsg.motorIndex = 0; //电机1 } break; case Scm_MCU1_Frame3.motor1CanId: //反馈第三帧,功率及温度 { Scm_MCU1_Frame3 scmMcu3 = ByteToScmMcu1Frame3(canRecDatas); //功率 recMsg.containFeedBkActPower = true; recMsg.FeedBkActPower = scmMcu3.dualsource_pwr_acu; recMsg.containFeedBkMotorWindingTemp = true; recMsg.FeedBkMotorWindingTemp = scmMcu3.dualsource_wind_t; recMsg.containFeedBkMtclInvTemp = true; recMsg.FeedBkMtclInvTemp = scmMcu3.dualsource_inv_t; //dualsource_bear_t; //dualsource_life_cyc; recMsg.motorIndex = 0; //电机1 } break; #endregion #region 电机2 //反馈第一帧,使能,方向,扭矩,转速,故障 case Scm_MCU1_Frame1.motor2CanId: { Scm_MCU1_Frame1 scmMcu1 = ByteToScmMcu1Frame1(canRecDatas); //工作模式 recMsg.containFeedBkMtclMode = true; //转速转矩与其他协议的不一样,反的 switch (scmMcu1.dualsource_ctrl_mod_act) { case 1: recMsg.FeedBkMtclMode = Ecm_WorkMode.TorqueMode; break; //转矩环 case 2: recMsg.FeedBkMtclMode = Ecm_WorkMode.SpeedMode; break; //转速环 default: recMsg.FeedBkMtclMode = Ecm_WorkMode.None; break; } recMsg.containFeedBkGear = true; switch (scmMcu1.dualsource_run_dir_act) { case 0: recMsg.FeedBkGear = Ecm_Gear.NeutralGear; break; //空档 case 1: recMsg.FeedBkGear = Ecm_Gear.DriveGear; break; //前进 case 2: recMsg.FeedBkGear = Ecm_Gear.ReverseGear; break; //后退 default: recMsg.FeedBkGear = Ecm_Gear.ErrorGear; break; } //扭矩 recMsg.containFeedBkMotorTorque = true; recMsg.FeedBkMotorTorque = scmMcu1.dualsource_tq_acu; //转速 recMsg.containFeedBkMotorSpeed = true; recMsg.FeedBkMotorSpeed = scmMcu1.dualsource_spd_acu; //最大转矩 recMsg.containFeedBkMotorMaxTorque = true; recMsg.FeedbkMotorMaxTorque = scmMcu1.dualsource_tq_acu_max; //故障等级 recMsg.containFeedBkErrorLevel = true; recMsg.FeedBkErrorLevel = scmMcu1.dualsource_errorlevel; //故障码 recMsg.containFeedBkErrorCode = true; recMsg.FeedBkErrorCode = new byte[1] { scmMcu1.dualsource_error_code }; ReceiveErrorTransform(recMsg.FeedBkErrorCode[0]); recMsg.motorIndex = 1; //电机2 } break; //反馈第二帧,电流电压 case Scm_MCU1_Frame2.motor2CanId: { Scm_MCU1_Frame2 scmMcu2 = ByteToScmMcu1Frame2(canRecDatas); //直流电压 recMsg.containFeedBkDcVoltage = true; recMsg.FeedBkDcVoltage = scmMcu2.dualsource_dc_u; //直流电流 recMsg.containFeedBkDcCurrent = true; recMsg.FeedBkDcCurrent = scmMcu2.dualsource_dc_i; //交流电压 recMsg.containFeedBkAcVoltage = true; recMsg.FeedBkAcVoltage = scmMcu2.dualsource_ac_u; //交流电流 recMsg.containFeedBkAcCurrent = true; recMsg.FeedBkAcCurrent = scmMcu2.dualsource_ac_i; recMsg.motorIndex = 1; //电机2 } break; //反馈第三帧,功率及温度 case Scm_MCU1_Frame3.motor2CanId: { Scm_MCU1_Frame3 scmMcu3 = ByteToScmMcu1Frame3(canRecDatas); //功率 recMsg.containFeedBkActPower = true; recMsg.FeedBkActPower = scmMcu3.dualsource_pwr_acu; recMsg.containFeedBkMotorWindingTemp = true; recMsg.FeedBkMotorWindingTemp = scmMcu3.dualsource_wind_t; recMsg.containFeedBkMtclInvTemp = true; recMsg.FeedBkMtclInvTemp = scmMcu3.dualsource_inv_t; //dualsource_bear_t; //dualsource_life_cyc; recMsg.motorIndex = 1; //电机2 } break; #endregion default: //continue; //其他ID的数据一律不接收 break; } return(recMsg); //推送数据 }