private byte[] ControlOilBreak(int index) { CmdData cmdData = new CmdData(); ControlOilCircuit data = new ControlOilCircuit(); data.BreakOilCircuitTime = DateTime.Now; if (index == 1) { cmdData.Data.Cmd = ControlCmdType.BreakOilCircuitByForce; data.Data.operateMode = ControlOilMode.Force; data.Data.operateType = ContorlOilType.CutOil; } else if (index == 2) { cmdData.Data.Cmd = ControlCmdType.SupplyOilCircuit; data.Data.operateMode = ControlOilMode.Smart; data.Data.operateType = ContorlOilType.RestoreOil; } data.GPSCode = txtGpsCode.Text.Trim(); if (data.GPSCode.StartsWith("0019")) data.Data.GpsType = GPSType.YaXun; else if (data.GPSCode.StartsWith("0013")) data.Data.GpsType = GPSType.BoShiJie; else if (data.GPSCode.StartsWith("0023")) data.Data.GpsType = GPSType.KangKaiSi; else if (data.GPSCode.StartsWith("0033")) data.Data.GpsType = GPSType.LianHuaYingKe; data.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(data.GPSCode).Length; data.SerialNumber = Guid.NewGuid().ToString(); data.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(data.SerialNumber).Length; byte[] buffer = new byte[data.GetLength()]; data.WriteBuffer(0, buffer); ControlOilCircuit dest = new ControlOilCircuit(); dest.ReadBuffer(0, buffer); cmdData.DataBuffer = buffer; cmdData.Data.DataLen = (ushort)data.GetLength(); byte[] sendBuffer = new byte[cmdData.GetLenth()]; cmdData.WriteBuffer(0, sendBuffer); return sendBuffer; }
/// <summary> 发送应答信息给应用 /// 发送应答信息给应用 /// </summary> /// <param name="serialNumber">流水号</param> /// <param name="isGpsAckMsg">是否是GPS应答消息</param> /// <param name="gpscode"></param> /// <param name="cmdType">下发的命令类型</param> /// <param name="result">GPS终端对命令的执行结果:成功或失败</param> //private void SendAnswerToWeb(string serialNumber, bool isGpsAckMsg, string gpscode, ControlCmdType cmdType, bool result, params SimpleCmdType[] simplecmd) //{ // //获取WEB列表 // EndPoint adress = (EndPoint)WebTable[gpscode]; // if (adress != null) // { // byte[] answerBytes = SetAnswerByte(serialNumber, isGpsAckMsg, gpscode, cmdType, result, simplecmd); // CmdServer.SendTo((IPEndPoint)adress, answerBytes); // } //} /// <summary> 构造应答数据 /// 构造应答数据 /// </summary> /// <param name="serialNumber">流水号</param> /// <param name="isGpsAckMsg">是否是GPS应答信息</param> /// <param name="gpsCode">GPSG带前缀编码</param> /// <param name="cmd">下发的命令类型</param> /// <param name="result">GPS终端对命令的执行结果:成功或失败</param> /// <param name="simpleCmd">简单控制命令类型</param> /// <returns></returns> private byte[] SetAnswerByte(string serialNumber,bool isGpsAckMsg, string gpsCode, ControlCmdType cmd, bool result, params SimpleCmdType[] simpleCmd) { try { byte[] sendBuffer = null; byte[] dataBuffer = null; CmdData cmddata = new CmdData(); cmddata.Data.Cmd = cmd; byte gpsCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length; byte serialLen = (byte)Encoding.Default.GetBytes(serialNumber).Length; switch (cmd) { case ControlCmdType.DeviceCircuitresAndOil://控制油路应答 ControlOilCircuit structOil = new ControlOilCircuit(); structOil.Data.IsGpsAckMsg = isGpsAckMsg; structOil.GPSCode = gpsCode; structOil.Data.Result = result; structOil.Data.GPSCodeLen = gpsCodeLen; structOil.SerialNumber = serialNumber; structOil.Data.SerialNumberLen = serialLen; byte[] bytsOil = new byte[structOil.GetLength()]; structOil.WriteBuffer(0, bytsOil); cmddata.DataBuffer = bytsOil; cmddata.Data.DataLen = (ushort)bytsOil.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; //解除报警应答 case ControlCmdType.DischargeAlarm: DischangeAlarmControl structAlarm = new DischangeAlarmControl(); structAlarm.GPSCode = gpsCode; structAlarm.Data.Result = result; structAlarm.Data.GPSCodeLen = gpsCodeLen; structAlarm.SerialNumber = serialNumber; structAlarm.Data.SerialNumberLen = serialLen; byte[] bytsAlarm = new byte[structAlarm.GetLength()]; structAlarm.WriteBuffer(0, bytsAlarm); cmddata.DataBuffer = bytsAlarm; cmddata.Data.DataLen = (ushort)bytsAlarm.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; //调度控制(下发文本) case ControlCmdType.DispatchControl: DispatchControl structDispatch = new DispatchControl(); structDispatch.Data.IsGpsAckMsg = isGpsAckMsg; structDispatch.GPSCode = gpsCode; structDispatch.Data.Result = result; structDispatch.Data.GPSCodeLen = gpsCodeLen; structDispatch.SerialNumber = serialNumber; byte[] bytsDispatch = new byte[structDispatch.GetLength()]; structDispatch.WriteBuffer(0, bytsDispatch); cmddata.DataBuffer = bytsDispatch; cmddata.Data.DataLen = (ushort)bytsDispatch.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; //监听喊话 case ControlCmdType.ListenCall: ListenCallControl structListenCall = new ListenCallControl(); structListenCall.Data.IsGpsAckMsg = isGpsAckMsg; structListenCall.GPSCode = gpsCode; structListenCall.Data.GPSCodeLen = gpsCodeLen; structListenCall.Data.Result = result; structListenCall.Data.SerialNumberLen = serialLen; structListenCall.SerialNumber = serialNumber; byte[] bytsListenCall = new byte[structListenCall.GetLength()]; structListenCall.WriteBuffer(0, bytsListenCall); cmddata.DataBuffer = bytsListenCall; cmddata.Data.DataLen = (ushort)bytsListenCall.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; case ControlCmdType.BJSZLedControl://透传数据应答(BJSZ LED) BJSZLEDContentControl structBJSZLED = new BJSZLEDContentControl(); structBJSZLED.Data.IsGpsAckMsg = isGpsAckMsg; structBJSZLED.GPSCode = gpsCode; structBJSZLED.Data.Result = result; structBJSZLED.Data.SerialNumberLen = serialLen; structBJSZLED.SerialNumber = serialNumber; structBJSZLED.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length; byte[] bytsBJSZLED = new byte[structBJSZLED.GetLength()]; structBJSZLED.WriteBuffer(0, bytsBJSZLED); cmddata.DataBuffer = bytsBJSZLED; cmddata.Data.DataLen = (ushort)bytsBJSZLED.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; case ControlCmdType.LongHanAnswered://龙汗数据应答 break; case ControlCmdType.SimpleInstruction://简单控制命令 SimpleInstructionControl structSimple = new SimpleInstructionControl(); structSimple.Data.InstructionType = simpleCmd[0]; structSimple.Data.IsGpsAckMsg = isGpsAckMsg; structSimple.GPSCode = gpsCode; structSimple.Data.Result = result; structSimple.Data.SerialNumberLen = serialLen; structSimple.SerialNumber = serialNumber; structSimple.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length; byte[] bytsSimple = new byte[structSimple.GetLength()]; structSimple.WriteBuffer(0, bytsSimple); cmddata.DataBuffer = bytsSimple; cmddata.Data.DataLen = (ushort)bytsSimple.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; case ControlCmdType.SendTakePicture://拍照应答 TakePictureControl structPicture = new TakePictureControl(); structPicture.Data.IsGpsAckMsg = isGpsAckMsg; structPicture.GPSCode = gpsCode; structPicture.Data.Result = result; structPicture.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length; structPicture.SerialNumber = serialNumber; structPicture.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(serialNumber).Length; byte[] bytsPicture = new byte[structPicture.GetLength()]; structPicture.WriteBuffer(0, bytsPicture); cmddata.DataBuffer = bytsPicture; cmddata.Data.DataLen = (ushort)bytsPicture.Length; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; //对下发广告的回复 case ControlCmdType.SendAdvertisement: LEDControl ledControl = new LEDControl(); ledControl.GPSCode = gpsCode; ledControl.SerialNumber = serialNumber; ledControl.Data.SerialNumberLen = serialLen; ledControl.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(gpsCode).Length; ledControl.Data.IsGpsAckMsg = false; ledControl.Data.Result = result; dataBuffer = new byte[ledControl.GetLength()]; ledControl.WriteBuffer(0, dataBuffer); cmddata.DataBuffer = dataBuffer; cmddata.Data.DataLen = (ushort)dataBuffer.Length; cmddata.Data.Cmd = ControlCmdType.SendAdvertisement; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; //超速报警 case ControlCmdType.OverSpeedAlarm: OverSpeedAlarmControl overSpeedCrl = new OverSpeedAlarmControl(); overSpeedCrl.GPSCode = gpsCode; overSpeedCrl.Data.GPSCodeLen = gpsCodeLen; overSpeedCrl.SerialNumber = serialNumber; overSpeedCrl.Data.SerialNumberLen = serialLen; overSpeedCrl.Data.IsGpsAckMsg = isGpsAckMsg; overSpeedCrl.Data.Result = result; dataBuffer = new byte[overSpeedCrl.GetLength()]; overSpeedCrl.WriteBuffer(0, dataBuffer); cmddata.DataBuffer = dataBuffer; cmddata.Data.DataLen = (ushort)dataBuffer.Length; cmddata.Data.Cmd = ControlCmdType.OverSpeedAlarm; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; } return sendBuffer; } catch (Exception ex) { Logger.Error(ex, null); return new byte[0]; } }