Пример #1
0
        private void ReceiveGain(byte[] b)
        {
            ChecksumClass cs = new ChecksumClass();

            if (cs.VerifyChecksumFromReceivedMessage(b))
            {
                Console.WriteLine("CHECKSUM MATCH");
            }
            else
            {
                Console.WriteLine("CHECKSUM DONT MATCH");
                return;
            }

            var newArr = UARTHelperClass.RemoveChecksumFromMessage(b);

            ByteArrayDecoderClass dec = new ByteArrayDecoderClass(newArr);

            //int size = dec.Get2BytesAsInt() / 2;
            dec.Get2BytesAsInt(); // Just remove 2 bytes i know length for this message

            float temp = dec.Get4BytesAsFloat();

            this.Invoke(new Action(() =>
            {
                textBoxGain.Text = temp.ToString();
            }));
        }
Пример #2
0
        private void DebugRead(byte[] b)
        {
            uartReceiver.Reset();
            // Check checksum and remove from message
            ChecksumClass cs = new ChecksumClass();

            if (cs.VerifyChecksumFromReceivedMessage(b))
            {
                Console.WriteLine("CHECKSUM MATCH");
            }
            else
            {
                Console.WriteLine("CHECKSUM DONT MATCH");
                return;
            }

            var newArr = UARTHelperClass.RemoveChecksumFromMessage(b);

            Console.WriteLine("in debug, read bytes: " + b.Length);
            this.Invoke(new Action(() =>
            {
                //FormDataPresenter fdp = new FormDataPresenter(newArr);
                FormDataPresenter2 fdp = new FormDataPresenter2(newArr);
                fdp.Show();
            }));
        }
Пример #3
0
        private void FetchHeaders(byte[] b)
        {
            // Check checksum and remove from message
            ChecksumClass cs = new ChecksumClass();

            if (cs.VerifyChecksumFromReceivedMessage(b))
            {
                Console.WriteLine("CHECKSUM MATCH");
            }
            else
            {
                Console.WriteLine("CHECKSUM DONT MATCH");
                return;
            }

            var newArr = UARTHelperClass.RemoveChecksumFromMessage(b);


            ByteArrayDecoderClass decoder = new ByteArrayDecoderClass(newArr);

            decoder.Get2BytesAsInt(); // Remove first 2 values (number of data transmited)

            int[] timestamp     = decoder.Get6BytesAsTimestamp();
            int   prescaler     = decoder.Get4BytesAsInt();
            int   numOfPoints   = decoder.Get2BytesAsInt();
            int   operatingMode = decoder.Get1ByteAsInt();
            int   channelMode   = decoder.Get1ByteAsInt();

            // Fill header with remaining data
            headers[currentHeader].timestamp     = timestamp;
            headers[currentHeader].prescaler     = prescaler;
            headers[currentHeader].numOfPoints   = numOfPoints;
            headers[currentHeader].operatingMode = operatingMode;
            headers[currentHeader].channel       = channelMode;
            headers[currentHeader].ready         = true;
            // Fill labels
            FillLabelGroup(currentHeader, headers[currentHeader].headerAddress, timestamp, prescaler, numOfPoints, operatingMode, channelMode);

            uartReceiver.Reset();

            currentHeader++;
            if (currentHeader == headers.Count) // Last time in here, reset everything
            {
                processFunction = Dummy;
                return;
            }
#warning Update to use CommandFormerClass
            // Send command to get measurement header
            List <byte> sb = new List <byte>();

            sb.Add(startSeq);
            sb.Add(deviceAddr);
            // Append message length and include checksum
            sb.Add(0);
            sb.Add(9);
            // Append command
            sb.Add(commandRead);

            // Get and append address
            byte[] bAddress = CustomConvertorClass.ConvertIntTo4Bytes(headers[currentHeader].headerAddress);
            sb.AddRange(bAddress);
            // Get and append length
            byte[] bLen = CustomConvertorClass.ConvertIntTo2Bytes(HEADER_LENGTH);
            sb.AddRange(bLen);
            Thread.Sleep(50);
            //Console.WriteLine("FetchHeaders -- sending " + sb.Count);

            // Now calculate and append checksum
            UInt16 csum  = ChecksumClass.CalculateChecksum(sb.ToArray());
            byte[] bcsum = CustomConvertorClass.ConvertIntTo2BytesBE(csum);
            sb.AddRange(bcsum); // 2B

            serial.Write(sb.ToArray(), 0, sb.Count);
        }
Пример #4
0
        /// <summary>
        /// Measurement info is received, decode data and send requests to read measurement headers
        /// </summary>
        /// <param name="b"></param>
        private void ProcessGetMeasurementInfo(byte[] b)
        {
            // Check checksum and remove from message
            ChecksumClass cs = new ChecksumClass();

            if (cs.VerifyChecksumFromReceivedMessage(b))
            {
                Console.WriteLine("CHECKSUM MATCH");
            }
            else
            {
                Console.WriteLine("CHECKSUM DONT MATCH");
                return;
            }

            var newArr = UARTHelperClass.RemoveChecksumFromMessage(b);


            ByteArrayDecoderClass decoder = new ByteArrayDecoderClass(newArr);

            decoder.Get2BytesAsInt(); // Remove first 2 values (number of data transmited)
            EraseLabels();
            // Get number of measurements and their header starting addresses
            int numOfMeasurements = decoder.Get2BytesAsInt();

            Console.WriteLine("Number of measurements: " + numOfMeasurements);
            if (numOfMeasurements == 0)
            {
                // if no measurements leave it as it is
                processFunction = Dummy;
                return;
            }
            headers = new List <MeasurementHeaderClass>(); // Reset headers list
            for (int i = 0; i < numOfMeasurements; i++)
            {
                headers.Add(new MeasurementHeaderClass(decoder.Get4BytesAsInt()));
            }

            // Reset UART receiver and set new method for data processing
            uartReceiver.Reset();
            processFunction = FetchHeaders;
            currentHeader   = 0; // Reset header index


            // Bootstrap
#warning Update to use CommandFormerClass
            // Send command to get measurement header
            List <byte> sb = new List <byte>();

            sb.Add(startSeq);
            sb.Add(deviceAddr);
            // Append message length
            sb.Add(0);
            sb.Add(9);
            // Append command
            sb.Add(commandRead);

            // Get and append address
            byte[] bAddress = CustomConvertorClass.ConvertIntTo4Bytes(headers[0].headerAddress);
            sb.AddRange(bAddress);
            // Get and append length
            byte[] bLen = CustomConvertorClass.ConvertIntTo2Bytes(HEADER_LENGTH);
            sb.AddRange(bLen);
            //Thread.Sleep(200);
            //Console.WriteLine("ProcessGetMeasurementInfo --sending " + sb.Count);

            // Now calculate and append checksum
            UInt16 csum  = ChecksumClass.CalculateChecksum(sb.ToArray());
            byte[] bcsum = CustomConvertorClass.ConvertIntTo2BytesBE(csum);
            sb.AddRange(bcsum); // 2B

            serial.Write(sb.ToArray(), 0, sb.Count);
        }