Beispiel #1
0
        static void Main(string[] args)
        {
            //todo:
            //
            //auto com port selector, xml serializer, cli input - output, argument commands (u-pload, d-ump), more cs files for the helper functions and the classes

            //init
            string      username, password;
            XmlDocument connCheckResponse = invokeService("checkConnection");

            SERVER_TIME = DateTime.Parse(extractTag(connCheckResponse, "ServerDate"));

            username = "";
            password = "";

            if (username == "" || password == "")
            {
                handleError("no username or password given");
            }

            XmlDocument loginResponse     = invokeService("login", "<username>" + username + "</username><password>" + password + "</password><client_IPAddress>" + getRetardedIpAddress() + "</client_IPAddress>");
            XmlDocument patientIdResponse = invokeService("getPatientId", "<userName>" + username + "</userName><password>" + password + "</password>");

            string loginString = extractTag(loginResponse, "returnValue");
            string patientId   = extractTag(patientIdResponse, "returnValue");

            //dump
            SerialPort    comPort  = new SerialPort();
            List <string> usbPorts = GetUsbPorts();

            GlucoResponse contents = dumpFromComPort(comPort, usbPorts[0]);

            //analyze
            float low;
            float high;
            int   fieldSize;
            int   softwareVersion = (int)getSoftVer((List <byte>)contents.returnValue);
            int   dataLength      = ((List <byte>)contents.returnValue).Count + 2; //wtf

            XmlDocument fieldSizeResponse = invokeService("getDcontFieldSize", "<deviceType>0</deviceType><softwareVersion>" + softwareVersion + "</softwareVersion><dataLength>" + dataLength + "</dataLength>");

            float[] fieldSizes = getFieldSizes(extractTag(fieldSizeResponse, "returnValue"));
            low       = fieldSizes[0];
            high      = fieldSizes[1];
            fieldSize = (int)fieldSizes[2];

            DbGlucoTransferRecord transferInfo = getTransferInfo(((List <byte>)contents.returnValue));
            GlucoResponse         measurements = analyze(fieldSize, softwareVersion, low, high, ((List <byte>)contents.returnValue));


            dumpToXmlFile((List <DbMeasurementRecord>)measurements.returnValue);
            measurements.returnValue = xmlFileToObject([MODDED XML PATH]); //i know, it will fail, a reminder to change the path
Beispiel #2
0
        static private GlucoResponse analyze(
            int fieldSize, int SoftwareVersion, float low, float high, List <byte> data)
        {
            GlucoResponse glucoResponse1 = new GlucoResponse();

            glucoResponse1.operationResult = GlucoOperationResultEnum.Failed;
            try
            {
                int num = (data.Count - 19) / fieldSize;
                if (num == 0)
                {
                    glucoResponse1.operationResult = GlucoOperationResultEnum.Success;
                    glucoResponse1.returnValue     = (object)null;
                    return(glucoResponse1);
                }
                List <DbMeasurementRecord> measurementRecordList = new List <DbMeasurementRecord>();

                int year   = SERVER_TIME.Year;
                int month1 = SERVER_TIME.Month;

                for (int index1 = 0; index1 < num; ++index1)
                {
                    DbMeasurementRecord measurementRecord = new DbMeasurementRecord();
                    int index2 = index1 * fieldSize + 10;
                    measurementRecord.Value = (float)(((double)data[index2] + (double)(((int)data[index2 + 1] & 1) << 8)) / 10.0);
                    if ((double)measurementRecord.Value <= (double)low && (double)measurementRecord.Value != 0.0)
                    {
                        measurementRecord.Value  = low;
                        measurementRecord.IsLoHi = 1;
                    }
                    if ((double)measurementRecord.Value >= (double)high)
                    {
                        measurementRecord.Value  = high;
                        measurementRecord.IsLoHi = 2;
                    }
                    int month2 = ((int)data[index2 + 1] >> 4) + 1;
                    int day    = ((int)data[index2 + 3] >> 3) + 1;
                    int hour   = (int)data[index2 + 2] >> 6 & 3 | ((int)data[index2 + 3] & 7) << 2;
                    int minute = (int)data[index2 + 2] & 63;
                    measurementRecord.Marker        = ((int)data[index2 + 1] & 2) == 2;
                    measurementRecord.IsBloodPlasma = ((int)data[index2 + 1] & 4) == 4;
                    if (SoftwareVersion >= 96U)
                    {
                        if (SoftwareVersion >= 100U)
                        {
                            measurementRecord.IsHypo = new bool?(((int)data[index2 + 1] & 12) >> 2 == 2);
                            switch (((int)data[index2 + 4] & 224) >> 5)
                            {
                            case 1:
                                measurementRecord.IsPremeal = new bool?(true);
                                break;

                            case 2:
                                measurementRecord.IsPostmeal = new bool?(true);
                                break;

                            case 3:
                                measurementRecord.IsSport = new bool?(true);
                                break;

                            case 4:
                                measurementRecord.IsFasting = new bool?(true);
                                break;

                            case 5:
                                measurementRecord.Marker = true;
                                break;
                            }
                        }
                        else
                        {
                            measurementRecord.IsHypo     = new bool?(((int)data[index2 + 1] & 8) == 8);
                            measurementRecord.IsSport    = new bool?((int)data[index2 + 4] >> 7 == 1);
                            measurementRecord.IsPostmeal = new bool?(((int)data[index2 + 4] >> 6 & 1) == 1);
                            measurementRecord.IsPremeal  = new bool?(((int)data[index2 + 4] >> 5 & 1) == 1);
                        }
                    }
                    if (fieldSize == 5)
                    {
                        year = 2008 + ((int)data[index2 + 4] & 31);
                    }
                    try
                    {
                        measurementRecord.Date      = new DateTime(year, month2, day, hour, minute, 0);
                        measurementRecord.DcontDate = fieldSize != 4 ? measurementRecord.Date : new DateTime(1980, month2, day, hour, minute, 0);
                    }
                    catch (Exception ex)
                    {
                        GlucoResponse glucoResponse2 = glucoResponse1;
                        glucoResponse2.error = glucoResponse2.error + ex.ToString() + "\n\n\n";
                        continue;
                    }
                    measurementRecord.IsVisible = true;
                    if ((double)measurementRecord.Value != 0.0)
                    {
                        measurementRecordList.Add(measurementRecord);
                    }
                }
                measurementRecordList.Reverse();
                glucoResponse1.returnValue = (object)measurementRecordList;
            }
            catch (Exception ex)
            {
                glucoResponse1.error = ex.ToString();
                return(glucoResponse1);
            }
            glucoResponse1.operationResult = GlucoOperationResultEnum.Success;
            return(glucoResponse1);
        }
Beispiel #3
0
        static GlucoResponse dumpFromComPort(SerialPort ComPort, string selectedPortName)
        {
            GlucoResponse glucoResponse = new GlucoResponse();

            glucoResponse.operationResult = GlucoOperationResultEnum.Failed;
            glucoResponse.error           = (string)null;
            bool        abortRead          = false;
            List <byte> lastRead           = new List <byte>();
            byte        num1               = 0;
            byte        num2               = 0;
            bool        needInicializePort = true;

            while (num2.ToString("X") != "AA" && num1.ToString("X") != "55" && !abortRead)
            {
                num2 = num1;
                try
                {
                    if (needInicializePort)
                    {
                        if (ComPort != null && ComPort.IsOpen)
                        {
                            ComPort.Close();
                        }
                        ComPort                = new SerialPort(selectedPortName);
                        ComPort.BaudRate       = 2400;
                        ComPort.DataBits       = 8;
                        ComPort.Parity         = Parity.Odd;
                        ComPort.StopBits       = StopBits.One;
                        ComPort.ReadTimeout    = 125;
                        ComPort.ReadBufferSize = 4096;
                        ComPort.ParityReplace  = (byte)0;
                        try
                        {
                            //  this.stopwatcher.Start();
                            ComPort.Open();
                            needInicializePort = false;
                            ComPort.DiscardInBuffer();

                            SendCurrentDateTime(ComPort);
                        }
                        catch (Exception e)
                        {
                            Console.Write(".");
                        }
                    }
                    if (ComPort.IsOpen)
                    {
                        num1 = (byte)ComPort.ReadByte();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception2:" + e);
                }
            }
            if (!abortRead)
            {
                //       this.OnPercentChange(0);
                //     this.OnAddStatusText("Az adatok számítógépre történő feltöltése folyamatban van, amely néhány percet is igénybe vehet.");
                Console.WriteLine("abortRead");
                ComPort.ReadTimeout = 5000;
            }
            int num3 = 21;
            int num4 = num3;
            int num5 = 2;

            while (!abortRead && num5 < num4)
            {
                if ((num5 & 15) == 0)
                {
                    int percentage = Math.Min(100, num5 * 100 / num4);
                    Console.WriteLine("%: " + percentage);
                }
                //  this.OnPercentChange();
                if (num5 == 8)
                {
                    num4 = 5 * (int)(short)((int)lastRead[4] + ((int)lastRead[5] << 8)) + num3;
                }
                try
                {
                    lastRead.Add((byte)ComPort.ReadByte()); ++num5;
                }
                catch (TimeoutException ex)
                {
                    Console.WriteLine("TimeoutException:" + ex);
                    break;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception3:" + ex);
                    break;
                }
            }
            if (ComPort.IsOpen)
            {
                ComPort.Close();
                ComPort.Dispose();
            }
            List <byte> byteList = new List <byte>();

            byteList.Add((byte)170);
            byteList.Add((byte)85);
            byteList.AddRange((IEnumerable <byte>)lastRead);
            if (abortRead)
            {
                Console.WriteLine("Felhasználó által megszakítva.");
                return(glucoResponse);
            }
            if (!ValidateCheckSum(byteList.ToArray()))
            {
                /*
                 * glucoResponse.operationResult = GlucoOperationResultEnum.Failed;
                 * glucoResponse.error = this.CHECKSUM_ERROR;
                 * this.OnAddStatusText(this.CHECKSUM_ERROR);
                 * glucoResponse.returnValue = (object)this.lastRead;
                 */
                Console.WriteLine("checksum error");
            }
            else if (glucoResponse.error == null)
            {
                glucoResponse.returnValue     = (object)lastRead;
                glucoResponse.operationResult = GlucoOperationResultEnum.Success;
            }

            Console.WriteLine("OK!");
            return(glucoResponse);
        }