public bool SetFriendNumber(string gpsCode, string SMSStr, int type) { SettingEMOpenGPSInfo(gpsCode, type); KKSSimpleControl control = new KKSSimpleControl(); control.GPSCode = gpsCode; control.SendContent = SMSStr; control.Data.GpsType = GPSType.KangKaiSi; control.SerialNumber = Guid.NewGuid().ToString(); control.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(control.GPSCode).Length; control.Data.ContentLen = (byte)Encoding.Default.GetBytes(control.SendContent).Length; control.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(control.SerialNumber).Length; control.Data.IsGpsAckMsg = true; control.Data.SimpleControlType = KKSSimpleControlType.SetFriendNumber; byte[] dataBuffer = new byte[control.GetLength()]; control.WriteBuffer(0, dataBuffer); CmdData cmdData = new CmdData(); cmdData.Data.Cmd = ControlCmdType.SetFriendNumber; cmdData.DataBuffer = dataBuffer; cmdData.Data.DataLen = (ushort)dataBuffer.Length; byte[] destBuffer = new byte[cmdData.GetLenth()]; cmdData.WriteBuffer(0, destBuffer); IPEndPoint endPoint = GetEndPoint(gpsCode); return SendData(destBuffer, endPoint); }
private byte[] SetFriendNumber() { KKSSimpleControl control = new KKSSimpleControl(); control.GPSCode = txtGpsCode.Text.Trim(); control.SendContent = txtParam1.Text.Trim(); control.Data.GpsType = GPSType.KangKaiSi; control.SerialNumber = Guid.NewGuid().ToString(); control.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(control.GPSCode).Length; control.Data.ContentLen = (byte)Encoding.Default.GetBytes(control.SendContent).Length; control.Data.SerialNumberLen = (byte)Encoding.Default.GetBytes(control.SerialNumber).Length; control.Data.IsGpsAckMsg = true; control.Data.SimpleControlType = KKSSimpleControlType.SetFriendNumber; byte[] dataBuffer = new byte[control.GetLength()]; control.WriteBuffer(0, dataBuffer); CmdData cmdData = new CmdData(); cmdData.Data.Cmd = ControlCmdType.SetFriendNumber; cmdData.DataBuffer = dataBuffer; cmdData.Data.DataLen = (ushort)dataBuffer.Length; byte[] destBuffer = new byte[cmdData.GetLenth()]; cmdData.WriteBuffer(0, destBuffer); return destBuffer; }
/// <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://控制油路应答 case ControlCmdType.BreakOilCircuitBySmart: case ControlCmdType.BreakOilCircuitByForce: case ControlCmdType.SupplyOilCircuit: ControlOilCircuit structOil = new ControlOilCircuit(); structOil.BreakOilCircuitTime = DateTime.Now; 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.Data.SerialNumberLen = serialLen; 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; //更新总里程 case ControlCmdType.updatemileage: UpdateMileage UpMileage = new UpdateMileage(); UpMileage.GPSCode = gpsCode; UpMileage.Data.GPSCodeLen = gpsCodeLen; UpMileage.SerialNumber = serialNumber; UpMileage.Data.SerialNumberLen = serialLen; UpMileage.Data.IsGpsAckMsg = isGpsAckMsg; UpMileage.Data.Result = result; dataBuffer = new byte[UpMileage.GetLength()]; UpMileage.WriteBuffer(0, dataBuffer); cmddata.DataBuffer = dataBuffer; cmddata.Data.DataLen = (ushort)dataBuffer.Length; cmddata.Data.Cmd = ControlCmdType.updatemileage; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; case ControlCmdType.SetFriendNumber: KKSSimpleControl control1 = new KKSSimpleControl(); control1.GPSCode = gpsCode; control1.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(control1.GPSCode).Length; control1.Data.GpsType = GPSType.KangKaiSi; control1.SendContent = serialNumber; control1.Data.ContentLen = (byte)Encoding.Default.GetBytes(serialNumber).Length; control1.Data.IsGpsAckMsg = isGpsAckMsg; dataBuffer = new byte[control1.GetLength()]; control1.WriteBuffer(0, dataBuffer); cmddata.DataBuffer = dataBuffer; cmddata.Data.DataLen = (ushort)dataBuffer.Length; cmddata.Data.Cmd = ControlCmdType.SetFriendNumber; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; case ControlCmdType.GetFriendNumber: KKSSimpleControl control2 = new KKSSimpleControl(); control2.GPSCode = gpsCode; control2.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(control2.GPSCode).Length; control2.Data.GpsType = GPSType.KangKaiSi; control2.SendContent = serialNumber; control2.Data.ContentLen = (byte)Encoding.Default.GetBytes(serialNumber).Length; control2.Data.IsGpsAckMsg = isGpsAckMsg; dataBuffer = new byte[control2.GetLength()]; control2.WriteBuffer(0, dataBuffer); cmddata.DataBuffer = dataBuffer; cmddata.Data.DataLen = (ushort)dataBuffer.Length; cmddata.Data.Cmd = ControlCmdType.GetFriendNumber; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; case ControlCmdType.OpenGPS: KKSSimpleControl control = new KKSSimpleControl(); control.GPSCode = gpsCode; control.Data.GPSCodeLen = (byte)Encoding.Default.GetBytes(control.GPSCode).Length; control.Data.GpsType = GPSType.KangKaiSi; control.SendContent = serialNumber; control.Data.ContentLen = (byte)Encoding.Default.GetBytes(serialNumber).Length; control.Data.IsGpsAckMsg = isGpsAckMsg; dataBuffer = new byte[control.GetLength()]; control.WriteBuffer(0, dataBuffer); cmddata.DataBuffer = dataBuffer; cmddata.Data.DataLen = (ushort)dataBuffer.Length; cmddata.Data.Cmd = ControlCmdType.OpenGPS; sendBuffer = new byte[cmddata.GetLenth()]; cmddata.WriteBuffer(0, sendBuffer); break; } return sendBuffer; } catch (Exception ex) { Logger.Error(ex, null); return new byte[0]; } }