Ejemplo n.º 1
0
        public bool GetFastLogData(ref byte logSession, out uint logSeqNo, out byte[] log)
        {
            logSeqNo = 0;
            log      = null;

            byte[] data = new byte[] { logSession };

            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetFastLogData, data);
            VivoPacket retPacket = SendCommand(cmdPacket);

            if (retPacket.Data == null || retPacket.Data.Length < 5)
            {
                return(false);
            }

            int logLength;

            logSession = retPacket.Data[0];
            logSeqNo   = BitConverter.ToUInt16(retPacket.Data, 1);
            logLength  = BitConverter.ToUInt16(retPacket.Data, 3);

            if (logLength == retPacket.Data.Length - 5)
            {
                log = new byte[logLength];

                Array.Copy(retPacket.Data, 5, log, 0, logLength);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public string GetVersion()
        {
            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetModel, null);
            VivoPacket retPacket = SendCommand(cmdPacket);

            if (retPacket.Data == null)
            {
                return(string.Empty);
            }

            return(ConvertByteArrayToString(retPacket.Data));
        }
Ejemplo n.º 3
0
        public bool SetMeasurePointValue(ushort index, int value)
        {
            byte[] data = new byte[6];

            BitConverter.GetBytes(index + 1).CopyTo(data, 0); // point 0 is hidden from user
            BitConverter.GetBytes(value).CopyTo(data, 2);

            VivoPacket cmdPacket = new VivoPacket(VivoCommand.SetMeasure, data);
            VivoPacket retPacket = SendCommand(cmdPacket);

            return(retPacket.Command != VivoCommand.Error && retPacket.Command != VivoCommand.NACK);
        }
Ejemplo n.º 4
0
        public byte[] GetFastGenericLogData(byte logId, int logVersion, int startOffset, int logLength)
        {
            byte[] data = new byte[13];

            data[0] = logId;
            BitConverter.GetBytes(logVersion).CopyTo(data, 1);
            BitConverter.GetBytes(startOffset).CopyTo(data, 5);
            BitConverter.GetBytes(logLength).CopyTo(data, 9);

            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetFastGenericLogData, data);
            VivoPacket retPacket = SendCommand(cmdPacket);

            return(retPacket.Data);
        }
Ejemplo n.º 5
0
        public string GetStringValue(ushort index)
        {
            byte[] data = BitConverter.GetBytes(index);

            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetString, data);
            VivoPacket retPacket = SendCommand(cmdPacket);

            if (retPacket.Data == null)
            {
                return(string.Empty);
            }

            return(ConvertByteArrayToString(retPacket.Data));
        }
Ejemplo n.º 6
0
        public ushort GetNumStringPoints()
        {
            ushort count = 0;
            //int shift = getshift();
            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetStringCount, null);
            VivoPacket retPacket = SendCommand(cmdPacket);

            //retPacket.decode(shift);
            if (retPacket.Data != null && retPacket.Data.Length == 1)
            {
                count = retPacket.Data[0];
            }

            return(count);
        }
Ejemplo n.º 7
0
        public string GetStringPointInfo(ushort index)
        {
            string name = string.Empty;

            byte[] data = BitConverter.GetBytes(index);

            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetStringInfo, data);
            VivoPacket retPacket = SendCommand(cmdPacket);

            if (retPacket.Data != null)
            {
                name = ConvertByteArrayToString(retPacket.Data);
            }

            return(name);
        }
Ejemplo n.º 8
0
        public ushort GetNumMeasurePoints()
        {
            ushort pointCount = 0;
            //int shift = getshift();
            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetMeasureInfo, new byte[2]);
            VivoPacket retPacket = SendCommand(cmdPacket);

            //retPacket.decode(shift);
            if (retPacket.Data != null && retPacket.Data.Length == MaxPacketDataSize)
            {
                pointCount = BitConverter.ToUInt16(retPacket.Data, 28);
                pointCount--; // Point 0 is hidden from user
            }

            return(pointCount);
        }
Ejemplo n.º 9
0
        public void GetFastGenericLogInfo(byte logId, out int version, out int size)
        {
            version = 0;
            size    = 0;

            byte[] data = new byte[] { logId };

            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetFastGenericLogInfo, data);
            VivoPacket retPacket = SendCommand(cmdPacket);

            if (retPacket.Data == null || retPacket.Data.Length < 8)
            {
                return;
            }

            version = BitConverter.ToInt32(retPacket.Data, 0);
            size    = BitConverter.ToInt32(retPacket.Data, 4);
        }
Ejemplo n.º 10
0
 private VivoPacket SendCommand(VivoPacket packet)
 {
     lock (cmdLock)
     {
         int    shift;
         byte[] receivedData = communication.SendMessage(packet.ToArray());
         if (packet.Command == VivoCommand.GetString)
         {
             shift = 0;
         }
         else
         {
             shift = getshift();
         }
         VivoPacket result = new VivoPacket(receivedData);
         //result.decode(shift);
         return(result);
     }
 }
Ejemplo n.º 11
0
        public MeasurePointDefinition GetMeasurePointInformation(ushort nativeId)
        {
            string name             = string.Empty;
            float  correctionFactor = 0;
            int    type             = 0;

            byte[] data = BitConverter.GetBytes(nativeId + 1); // point 0 is hidden from user

            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetMeasureInfo, data);
            VivoPacket retPacket = SendCommand(cmdPacket);

            if (retPacket.Data != null && retPacket.Data.Length == MaxPacketDataSize)
            {
                name             = ConvertByteArrayToString(retPacket.Data, 0, 24);
                correctionFactor = BitConverter.ToSingle(retPacket.Data, 24);
                type             = retPacket.Data[28];
            }

            return(new MeasurePointDefinitionStringKey(name, correctionFactor, (ushort)type, nativeId));
        }
Ejemplo n.º 12
0
        public bool SetStringValue(ushort index, string value)
        {
            byte[] stringBytes = new byte[30];
            int    i           = 0;

            for (; i < value.Length; i++)
            {
                int v = value[i];
                stringBytes[i] = (byte)(v & 0x7F);
            }
            stringBytes[i] = 0;
            byte[] data = new byte[Math.Min(stringBytes.Length, MaxPacketDataSize)];

            data[0] = (byte)index;
            Array.Copy(stringBytes, 0, data, 1, data.Length - 1);

            VivoPacket cmdPacket = new VivoPacket(VivoCommand.SetString, data);
            VivoPacket retPacket = SendCommand(cmdPacket);

            return(retPacket.Command != VivoCommand.Error && retPacket.Command != VivoCommand.NACK);
        }
Ejemplo n.º 13
0
        public int GetMeasurePointValue(ushort index)
        {
            byte[] data = BitConverter.GetBytes(index + 1); // point 0 is hidden from user
            //Decode


            //int shift = getshift();
            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetMeasure, data);
            VivoPacket retPacket = SendCommand(cmdPacket);

            //retPacket.decode(shift);

            //for (int i = 0; i < retPacket.Data.Length; i++)
            //{
            //    retPacket.Data[i] = Rotate(retPacket.Data[i], shift);
            //}


            //Decode End
            if (retPacket.Data == null)
            {
                return(-1);
            }

            if (retPacket.Data.Length == 2)
            {
                return(BitConverter.ToInt16(retPacket.Data, 0));
            }
            else if (retPacket.Data.Length == 4)
            {
                return(BitConverter.ToInt32(retPacket.Data, 0));
            }
            else
            {
                return(-1);
            }
        }
Ejemplo n.º 14
0
        private bool GetMultipleMeasurePointValues(int[] ids, int[] sizes, out int[] results)
        {
            results = null;

            if (ids.Length != sizes.Length)
            {
                return(false);
            }

            byte[] data      = new byte[ids.Length * 2];
            int    totalSize = 0;

            // pack the points and ids into 16-bit points, with 14 bits for the id and 2 bits for the size
            for (int i = 0; i < ids.Length; i++)
            {
                // 16382 because id zero is hidden
                if (ids[i] < 0 || ids[i] >= 16382)
                {
                    return(false);
                }

                if (sizes[i] < 1 || sizes[i] > 4)
                {
                    return(false);
                }

                totalSize += sizes[i];
                if (totalSize > MaxMultipacketDataLength)
                {
                    return(false);
                }

                // size 4 is encoded as zero
                ushort packedPoint = (ushort)((ushort)ids[i] | ((sizes[i] == 4 ? 0 : (ushort)sizes[i]) << 14));

                BitConverter.GetBytes(packedPoint).CopyTo(data, i * 2);
            }

            VivoPacket cmdPacket = new VivoPacket(VivoCommand.GetMultipleMeasure, data);
            VivoPacket retPacket = SendCommand(cmdPacket);

            if (retPacket.Data == null)
            {
                return(false);
            }

            results = new int[sizes.Length];
            int bp = 0;

            for (int i = 0; i < sizes.Length && bp <= retPacket.Data.Length; i++)
            {
                switch (sizes[i])
                {
                case 1:
                    results[i] = retPacket.Data[bp];
                    bp        += 1;
                    break;

                case 2:
                    results[i] = BitConverter.ToUInt16(retPacket.Data, bp);
                    bp        += 2;
                    break;

                case 3:
                    results[i]  = (int)retPacket.Data[bp] << 16;
                    bp         += 1;
                    results[i] += BitConverter.ToUInt16(retPacket.Data, bp);
                    bp         += 2;
                    break;

                case 4:
                    results[i] = BitConverter.ToInt32(retPacket.Data, bp);
                    bp        += 4;
                    break;
                }
            }

            return(true);
        }