Ejemplo n.º 1
0
        private byte[] EncodeConfigureInfo()
        {
            byte[] result = default(byte[]);            //this.ShowData(System.Text.Encoding.Default.GetBytes("TJSP-A-0002"));
            if (this._ActionMode.Equals(ActionMode.BlueTooth))
            {
                List <byte> buffer = new List <byte>(11);
                buffer.AddRange(new byte[] { 0x7F, 0x7F });
                buffer.AddRange(new byte[] { 0x84, 0x00, 0x10 });
                buffer.AddRange(GeneralMethods.StringToBytes(this.BlueToothConfigurationInfo1, 4));
                buffer.Add(0x2D);
                buffer.Add(GeneralMethods.StringToBytes(this.BlueToothConfigurationInfo2, 1)[0]);
                buffer.Add(0x2D);
                buffer.AddRange(GeneralMethods.StringToBytes(this.BlueToothConfigurationInfo3, 4));
                buffer.AddRange(GeneralMethods.GetCrcResult(buffer.ToArray()));
                buffer.AddRange(new byte[] { 0x0D, 0x0A });
                result = buffer.ToArray();
            }
            else
            {
                byte   highByte = 0, lowByte = 0;
                byte[] head  = default(byte[]);
                byte[] bytes = default(byte[]);
                switch (this._ActionMode)
                {
                case ActionMode.ConfigurChannel:
                {
                    head  = new byte[] { 0x83, 0x00, 0x00 };
                    bytes = new byte[] { 0x00, this.ChannelConfigurationInfo };
                    break;
                }

                case ActionMode.ConfigurPanID:
                {
                    head  = new byte[] { 0x82, 0x00, 0x00 };
                    bytes = this.PanIDConfigurationInfo;
                    break;
                }

                case ActionMode.ConfigurLocalID:
                {
                    head  = new byte[] { 0x80, 0x00, 0x00 };
                    bytes = this.LocalIDConfigurationInfo;
                    break;
                }

                case ActionMode.ConfigurTargetID:
                {
                    head  = new byte[] { 0x81, 0x00, 0x00 };
                    bytes = this.TargetIDConfigurationInfo;
                    break;
                }

                case ActionMode.Finish:
                {
                    head  = new byte[] { 0x95, 0x00, 0x00 };
                    bytes = new byte[] { 0x00, 0x00, 0x00, 0x00 };
                    break;
                }

                //case ActionMode.LockOn:
                //{
                //	head = new byte[] { 0x00, 0x00, 0x05 };
                //	bytes = new byte[] { 0x00, 0x00, 0x02, 0x00 };
                //	break;
                //}
                //case ActionMode.LockOff:
                //{
                //	head = new byte[] { 0x00, 0x00, 0x05 };
                //	bytes = new byte[] { 0x00, 0x00, 0x01, 0x00 };
                //	break;
                //}
                default: break;
                }
                highByte = bytes[0];
                lowByte  = bytes[1];
                List <byte> buffer = new List <byte>(11);
                buffer.AddRange(new byte[] { 0x7F, 0x7F });
                buffer.AddRange(head);
                buffer.Add(highByte);
                buffer.Add(lowByte);
                buffer.AddRange(GeneralMethods.GetCrcResult(buffer.ToArray()));
                buffer.AddRange(new byte[] { 0x0D, 0x0A });
                result = buffer.ToArray();
            }
            this._ActionMode = ActionMode.None;
            return(result);
        }
Ejemplo n.º 2
0
        public static string UshortToHexString(byte high, byte low)
        {
            string result = $"{GeneralMethods.HEX_STRING_PREFIX}{GeneralMethods.ByteToHexString(high)}{GeneralMethods.ByteToHexString(low)}";

            return(result);
        }
Ejemplo n.º 3
0
        private byte[] EncodeModifyInfo(byte[] buffer)
        {
            var localAddressHigh = buffer[GeneralMethods.LOCAL_LocalID_HIGH_INDEX];
            var localAddressLow  = buffer[GeneralMethods.LOCAL_LocalID_LOW_INDEX];

            if (this._ActionMode == ActionMode.ModifyChannel)
            {
                buffer[GeneralMethods.CHANNEL_INDEX] = this.ChannelModificationInfo;
            }
            else if (this._ActionMode == ActionMode.ResetChannel)
            {
                buffer[GeneralMethods.CHANNEL_INDEX] = 11;
            }
            else
            {
                byte[] bytes = default(byte[]);
                int    highIndex = 0, lowIndex = 0;
                switch (this._ActionMode)
                {
                case ActionMode.ModifyPanID:
                {
                    bytes     = this.PanIDModificationInfo;
                    highIndex = GeneralMethods.PANID_HIGH_INDEX;
                    lowIndex  = GeneralMethods.PANID_LOW_INDEX;
                    break;
                }

                case ActionMode.ResetPanID:
                {
                    bytes     = new byte[] { 0x88, 0x88 };
                    highIndex = GeneralMethods.PANID_HIGH_INDEX;
                    lowIndex  = GeneralMethods.PANID_LOW_INDEX;
                    break;
                }

                case ActionMode.ModifyLocalID:
                {
                    bytes     = this.LocalIDModificationInfo;
                    highIndex = GeneralMethods.LOCAL_LocalID_HIGH_INDEX;
                    lowIndex  = GeneralMethods.LOCAL_LocalID_LOW_INDEX;
                    break;
                }

                case ActionMode.ResetLocalID:
                {
                    bytes     = new byte[] { 0x77, 0x77 };
                    highIndex = GeneralMethods.LOCAL_LocalID_HIGH_INDEX;
                    lowIndex  = GeneralMethods.LOCAL_LocalID_LOW_INDEX;
                    break;
                }

                case ActionMode.ModifyTargetID:
                {
                    bytes     = this.TargetIDModificationInfo;
                    highIndex = GeneralMethods.TARGET_ADDRESS_HIGH_INDEX;
                    lowIndex  = GeneralMethods.TARGET_ADDRESS_LOW_INDEX;
                    break;
                }

                case ActionMode.ResetTargetID:
                {
                    bytes     = new byte[] { 0x66, 0x66 };
                    highIndex = GeneralMethods.TARGET_ADDRESS_HIGH_INDEX;
                    lowIndex  = GeneralMethods.TARGET_ADDRESS_LOW_INDEX;
                    break;
                }
                }
                buffer[highIndex] = bytes[0];
                buffer[lowIndex]  = bytes[1];
            }

            var         deviceInfo    = buffer.Skip(4).Take(65).ToArray();
            List <byte> sendingBuffer = new List <byte>();

            sendingBuffer.AddRange(GeneralMethods._ModifyInfoHeader);
            sendingBuffer.Add(localAddressHigh);
            sendingBuffer.Add(localAddressLow);
            sendingBuffer.AddRange(deviceInfo);
            sendingBuffer.Add(GeneralMethods.SumVerification(sendingBuffer.ToArray()));
            this._ActionMode = ActionMode.None;
            return(sendingBuffer.ToArray());
        }