Пример #1
0
        public static bool GetBluetoothState(UART uart)
        {
            ushort serviceCode = (ushort)TegamServiceCode_t.TEGAM_BLUETOOTH_GET_REQ;
            ushort valueSize   = 0;

            byte[] cmdbuf  = new byte[10];
            byte[] cobsbuf = new byte[12];

            cmdbuf[0] = CMD_MARK_START;
            cmdbuf[1] = CMD_MARK_HEADER & 0x00FF;
            cmdbuf[2] = (CMD_MARK_HEADER & 0xFF00) >> 8;
            cmdbuf[3] = CMD_VERSION_CODE & 0x00FF;
            cmdbuf[4] = (CMD_VERSION_CODE & 0xFF00) >> 8;
            cmdbuf[5] = (byte)(serviceCode & 0x00FF);
            cmdbuf[6] = (byte)((serviceCode & 0xFF00) >> 8);
            cmdbuf[7] = (byte)(valueSize & 0x00FF);
            cmdbuf[8] = (byte)((valueSize & 0xFF00) >> 8);
            cmdbuf[9] = CMD_MARK_END;

            COBS.Encode(cmdbuf, 10, ref cobsbuf);

            cobsbuf[11] = 0;

            if (WRITE)
            {
                uart.Write(cobsbuf, 12);
            }

            return(true);
        }
Пример #2
0
        public static bool SendSerialNumber(UART uart, byte[] value)
        {
            ushort serviceCode = (ushort)TegamServiceCode_t.TEGAM_SERIAL_NUMBER_SET_REQ;
            ushort valueSize   = 10;

            byte[] cmdbuf  = new byte[20];
            byte[] cobsbuf = new byte[22];

            cmdbuf[0]  = CMD_MARK_START;
            cmdbuf[1]  = CMD_MARK_HEADER & 0x00FF;
            cmdbuf[2]  = (CMD_MARK_HEADER & 0xFF00) >> 8;
            cmdbuf[3]  = CMD_VERSION_CODE & 0x00FF;
            cmdbuf[4]  = (CMD_VERSION_CODE & 0xFF00) >> 8;
            cmdbuf[5]  = (byte)(serviceCode & 0x00FF);
            cmdbuf[6]  = (byte)((serviceCode & 0xFF00) >> 8);
            cmdbuf[7]  = (byte)(valueSize & 0x00FF);
            cmdbuf[8]  = (byte)((valueSize & 0xFF00) >> 8);
            cmdbuf[9]  = value[0];
            cmdbuf[10] = value[1];
            cmdbuf[11] = value[2];
            cmdbuf[12] = value[3];
            cmdbuf[13] = value[4];
            cmdbuf[14] = value[5];
            cmdbuf[15] = value[6];
            cmdbuf[16] = value[7];
            cmdbuf[17] = value[8];
            cmdbuf[18] = value[9];
            cmdbuf[19] = CMD_MARK_END;

            COBS.Encode(cmdbuf, 20, ref cobsbuf);

            cobsbuf[21] = 0;

            if (WRITE)
            {
                uart.Write(cobsbuf, 22);
            }

            if (VERIFY)
            {
                System.Threading.Thread.Sleep(100);

                char[] readBuf    = uart.ReadBuffer();
                byte[] decodedBuf = new byte[11];

                // decoded what was read from UART
                COBS.Decode(Encoding.Default.GetBytes(readBuf), 11, ref decodedBuf);

                // reset the UART read buffer after obtaining read data
                uart.ResetReadBuffer();

                // ensure ACK command is valid
                return(ValidateACK(decodedBuf, TegamServiceCode_t.TEGAM_SERIAL_NUMBER_SET_ACK));
            }
            else
            {
                return(true);
            }
        }