Example #1
0
        /// <summary>
        /// 终端心跳
        /// </summary>
        private void SendClientPump()
        {
            HeadPack head = new HeadPack()
            {
                SeqNO = GetNextSeqNum(), MessageId = (ushort)MessageIds.ClientPump, BodyProp = (ushort)0
            };

            head.SetDeviceId(this.txtDeviceId.Text.Trim());
            //ClientPumpPack pack = new ClientPumpPack();
            //byte[] bytesSend = RawFormatter.Instance.Struct2Bytes(pack);
            //BodyPropertyHelper.SetMessageLength(ref head.BodyProp, (ushort)bytesSend.Length);
            BodyPropertyHelper.SetMessageLength(ref head.BodyProp, (ushort)0);

            byte[] headBytes = RawFormatter.Instance.Struct2Bytes(head);
            byte[] fullBytes = headBytes;// headBytes.Concat(bytesSend).ToArray();
            byte   checkByte = PackHelper.CalcCheckByte(fullBytes, 0, fullBytes.Length);

            byte[] bytesSend = (new byte[] { 0x7e }
                                .Concat(PackHelper.EncodeBytes(fullBytes.Concat(new byte[] { checkByte })))
                                .Concat(new byte[] { 0x7e })).ToArray();
            //////////////////////////////////////////////////////////////////////////
            //string e1 = Enum.GetName(typeof(MessageIds), Convert.ToInt32(head.MessageId));
            string e2 = ExtensionMethods.GetDescriptionByName <MessageIds>((MessageIds)Convert.ToInt32(head.MessageId));

            /////////////////////////////////////////////////////////////////////////////
            this.dataGridView1.Rows.Add("↑", head.GetDeviceId(), DateTime.Now, head.SeqNO, "0x" + Convert.ToString(head.MessageId, 16).PadLeft(4, '0') + "(" + e2 + ")", 0, bytesSend.ToHexString());

            this.dataGridView1.FirstDisplayedScrollingRowIndex = this.dataGridView1.Rows.Count - 1;
            //this.dataGridView1.Rows[this.dataGridView1.Rows.Count - 1].Selected = true;
            //this.dataGridView1.CurrentCell = this.dataGridView1[0, this.dataGridView1.Rows.Count - 1];

            SendMessage(bytesSend);;
        }
Example #2
0
        public static byte[] ToBytes(string deviceId, MessageIds messageId, ushort seqNO, byte[] bodyBytesReturn)
        {
            HeadPack head = new HeadPack()
            {
                BodyProp  = 0,
                MessageId = (ushort)messageId,
                SeqNO     = seqNO
            };

            head.SetDeviceId(deviceId);
            //BodyPropertyHelper.SetMessageLength(ref head.BodyProp,(ushort)bodyBytesReturn.Length);
            BodyPropertyHelper.SetMessageLength(ref head.BodyProp, (ushort)bodyBytesReturn.Length);
            return(RawFormatter.Instance.Struct2Bytes(head).Concat(bodyBytesReturn).ToArray());
        }
Example #3
0
        /// <summary>
        /// 终端注册
        /// </summary>
        private void SendClientRegist()
        {
            HeadPack head = new HeadPack()
            {
                SeqNO = GetNextSeqNum(), MessageId = (ushort)MessageIds.ClientRegist, BodyProp = (ushort)0
            };

            head.SetDeviceId(this.txtDeviceId.Text.Trim());
            ClientRegistPack pack = new ClientRegistPack()
            {
                Province     = Convert.ToUInt16("32"),
                City         = Convert.ToUInt16("1100"),
                Manufacturer = new byte[5],
                DeviceModel  = new byte[20],
                DeviceId     = new byte[7],
                CarColor     = 2
                               //CarNumber = System.Text.Encoding.GetEncoding("GBK").GetBytes(txtCarNumber.Text.Trim())
            };

            //车牌号
            byte[] carNumber = System.Text.Encoding.GetEncoding("GBK").GetBytes(txtCarNumber.Text.Trim());

            byte[] bytesSend = RawFormatter.Instance.Struct2Bytes(pack);
            //加上车牌
            bytesSend = bytesSend.Concat(carNumber).ToArray();

            BodyPropertyHelper.SetMessageLength(ref head.BodyProp, (ushort)bytesSend.Length);

            byte[] headBytes = RawFormatter.Instance.Struct2Bytes(head);
            byte[] fullBytes = headBytes.Concat(bytesSend).ToArray();
            byte   checkByte = PackHelper.CalcCheckByte(fullBytes, 0, fullBytes.Length);

            bytesSend = (new byte[] { 0x7e }
                         .Concat(PackHelper.EncodeBytes(fullBytes.Concat(new byte[] { checkByte })))
                         .Concat(new byte[] { 0x7e })).ToArray();
            //////////////////////////////////////////////////////////////////////////
            //string e1 = Enum.GetName(typeof(MessageIds), Convert.ToInt32(head.MessageId));
            string e2 = ExtensionMethods.GetDescriptionByName <MessageIds>((MessageIds)Convert.ToInt32(head.MessageId));

            /////////////////////////////////////////////////////////////////////////////
            this.dataGridView1.Rows.Add("↑", head.GetDeviceId(), DateTime.Now, head.SeqNO, "0x" + Convert.ToString(head.MessageId, 16).PadLeft(4, '0') + "(" + e2 + ")", 0, bytesSend.ToHexString());

            this.dataGridView1.FirstDisplayedScrollingRowIndex = this.dataGridView1.Rows.Count - 1;
            //this.dataGridView1.Rows[this.dataGridView1.Rows.Count - 1].Selected = true;
            //this.dataGridView1.CurrentCell = this.dataGridView1[0, this.dataGridView1.Rows.Count - 1];

            SendMessage(bytesSend);
        }
Example #4
0
        /// <summary>
        /// 位置和报警
        /// </summary>
        private void SendPosition()
        {
            HeadPack head = new HeadPack()
            {
                SeqNO = GetNextSeqNum(), MessageId = (ushort)MessageIds.PositionReport, BodyProp = (ushort)0
            };

            head.SetDeviceId(this.txtDeviceId.Text.Trim());

            double lat;
            double lon;
            int    speed = Convert.ToInt32(domainUpDown1.Text) + r.Next(10);// 10 + r.Next(90);

            latlonBuilder.GetNextLatlon(speed, out lat, out lon);
            //lat = Convert.ToDouble(txtLat.Text);
            //lon = Convert.ToDouble(txtLon.Text);


            #region 报警位设置
            BitValueAlerm bitAlerm = new BitValueAlerm(0);
            bitAlerm.Urgent      = checkBox0.Checked;
            bitAlerm.Speeding    = checkBox1.Checked;
            bitAlerm.Fatigue     = checkBox2.Checked;
            bitAlerm.Forewarning = checkBox3.Checked;
            #endregion

            #region 状态位设置
            BitValueState bitState = new BitValueState(0);
            bitState.ACC                  = checkBox40.Checked;
            bitState.Position             = checkBox41.Checked;
            bitState.IsSouth              = checkBox42.Checked;
            bitState.IsWest               = checkBox43.Checked;
            bitState.OperationStoped      = checkBox44.Checked;
            bitState.CarOilchannelBreaked = checkBox45.Checked;
            bitState.CarCircuitBreaked    = checkBox46.Checked;
            bitState.CarDoorLocked        = checkBox47.Checked;
            bitState.CarDrive             = checkBox48.Checked;//新国标新增的
            #endregion

            # region 附加信息