Esempio n. 1
0
        public void GlucometerResult(GlucoResult res, int datatype, bool updateResult)
        {
            switch (datatype)
            {
            case 0:
                tmpResult       = new GlucoResult();
                tmpResult.Year  = res.Year;
                tmpResult.Month = res.Month;
                tmpResult.Day   = res.Day;
                tmpResult.Hour  = res.Hour;
                tmpResult.Min   = res.Min;
                //  GlucometerDataReceiveCallback?.Invoke(tmpResult);
                break;

            case 1:
                tmpResult.TestResult = res.TestResult;
                tmpResult.Unit       = res.Unit;
                tmpResult.TestType   = res.TestType;
                tmpResult.Mode       = res.Mode;
                //"GLUCMDRES>V:{0}>U:{1}>T:{2}>M:{3}>D:{4}>T:{5}";
                string strres = string.Format(CommunicationCommands.GLUCORESULTRES, res.TestResult, res.Unit, res.TestType,
                                              res.Mode, tmpResult.Month + "/" + tmpResult.Day + "/" + tmpResult.Year, tmpResult.Hour + ":" + tmpResult.Min);
                MainPage.mainPage.commChannel.SendMessageToMCC(strres);
                GlucometerDataReceiveCallback?.Invoke(tmpResult);
                break;

            case 2:
                tmpResult             = new GlucoResult();
                tmpResult.RecordCount = res.RecordCount;
                GlucometerDataReceiveCallback?.Invoke(tmpResult);
                break;
            }
        }
Esempio n. 2
0
 private async void GlucometerResultEvent(GlucoResult glucoResult)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         if (!string.IsNullOrEmpty(glucoResult.TestResult))
         {
             TxtDate.Text   = glucoResult.TestDay + " " + glucoResult.TestTime;
             TxtResult.Text = glucoResult.TestValue;
             Txttype.Text   = glucoResult.TestType;
             TxtMode.Text   = glucoResult.Mode;
         }
         else
         {
             TxtTestDataByIndex.Text = glucoResult.RecordCount.ToString();
         }
     });
 }
Esempio n. 3
0
        private void Characteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
        {
            byte[]  data;
            IBuffer buffer = args.CharacteristicValue;

            try
            {
                GlucoResult Result = new GlucoResult();
                CryptographicBuffer.CopyToByteArray(buffer, out data);
                int    cmd     = data[0];
                int    data0   = data[2];
                int    data1   = data[3];
                int    data2   = data[4];
                int    data3   = data[5];
                int    stopbit = data[6];
                string rawdata = string.Format("{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}", cmd, data[1],
                                               data0, data1, data2, data3, stopbit, data[7]);
                MainPage.TestresultModel.LogMessage(rawdata);
                if (data[0] == 81)
                {
                    switch (data[1])
                    {
                    case 37:     //date time
                        string strdata0 = Convert.ToString(data0, 2).PadLeft(8, '0');

                        string strdata1 = Convert.ToString(data1, 2).PadLeft(8, '0');
                        strdata1 = strdata1 + strdata0;
                        // 7bit 4bit 5bit
                        //15 14 13 12 11 10 9 8 7 6  5  4  3  2  1    0
                        //1  2  3  4  5  6 , 7 8 9 10 ,11 12   13   14   15
                        //0010100,0111,00101
                        string day   = strdata1.Substring(11, 5);
                        string Month = strdata1.Substring(7, 4);
                        string year  = strdata1.Substring(0, 7);


                        year  = Convert.ToInt32(year, 2).ToString();
                        Month = Convert.ToInt32(Month, 2).ToString();
                        day   = Convert.ToInt32(day, 2).ToString();
                        //000,01001
                        string strdata3 = Convert.ToString(data3, 2).PadLeft(8, '0');
                        string strdata2 = Convert.ToString(data2, 2).PadLeft(8, '0');
                        string hour     = Convert.ToInt32(strdata3.Substring(3, 5), 2).ToString();
                        //00,010000
                        string min = Convert.ToInt32(strdata2.Substring(2, 6), 2).ToString();
                        Result.Year  = year;
                        Result.Month = Month;
                        Result.Day   = day;
                        Result.Hour  = hour;
                        Result.Min   = min;
                        MainPage.TestresultModel.GlucometerResult(Result, 0, false);
                        break;

                    case 38:     //reading
                                 //  100 ,01000
                                 //   3210 43210
                                 //D3 10000001
                                 //D2 01000110
                                 //D3D2
                                 //10000001 01000110
                                 //GTYPE 10
                                 //10, 0110,0101000110

                        //D3 01000001
                        //D2 1000110
                        //01000001 1000110
                        strdata0 = Convert.ToString(data0, 2).PadLeft(8, '0');
                        strdata1 = Convert.ToString(data1, 2).PadLeft(8, '0');
                        strdata1 = strdata1 + strdata0;

                        strdata2 = Convert.ToString(data2, 2).PadLeft(8, '0');
                        strdata3 = Convert.ToString(data3, 2).PadLeft(8, '0');
                        strdata3 = strdata3 + strdata2;
                        string Type1 = strdata3.Substring(0, 2);
                        string Type2 = strdata3.Substring(2, 4);
                        string code  = strdata3.Substring(6);

                        //string strmode = Convert.ToString(data3, 2).PadLeft(8, '0');
                        switch (Convert.ToInt32(Type1.Substring(0, 2), 2))
                        {
                        case 0:
                            Result.Mode = "Gen(Any time)";
                            break;

                        case 1:
                            Result.Mode = "AC(Before meal)";
                            break;

                        case 2:
                            Result.Mode = "PC(After meal)";
                            break;
                        }
                        switch (Convert.ToInt32(Type2, 2))
                        {
                        case 0:
                            Result.TestResult = Convert.ToInt32(strdata1, 2).ToString();      //data0.ToString();
                            Result.Unit       = "mg/dL";
                            Result.TestType   = "GLU";

                            break;

                        case 7:
                        {
                            decimal  ketone      = ((decimal)(Convert.ToInt32(strdata1, 2)) / 30);
                            string[] decimalpart = ketone.ToString().Split('.');
                            Result.TestResult = string.Format("{0}.{1}", decimalpart[0], decimalpart.Length > 1 ? decimalpart[1].Substring(0, 1) : "0");
                            Result.Unit       = "mmol/L";
                            Result.TestType   = "Ketone";
                            //  Result.Mode = "Gen";
                        }
                        break;

                        case 6:         //Hematocrit.
                        {
                            decimal  ketone      = ((decimal)(Convert.ToInt32(strdata1, 2)) / 10);
                            string[] decimalpart = ketone.ToString().Split('.');
                            Result.TestResult = string.Format("{0}.{1}", decimalpart[0], decimalpart.Length > 1 ? decimalpart[1].Substring(0, 1) : "0");
                            Result.Unit       = "g/dL";
                            Result.TestType   = "KB";
                            // Result.Mode = "Gen";
                        }
                        break;

                        case 9:         // Cholesterol value.
                        {
                            decimal  ketone      = ((decimal)(Convert.ToInt32(strdata1, 2)) / (decimal)38.665);
                            string[] decimalpart = ketone.ToString().Split('.');
                            Result.TestResult = string.Format("{0}.{1}", decimalpart[0], decimalpart.Length > 1 ? decimalpart[1].Substring(0, 1) : "0");
                            Result.Unit       = "mmol/L";
                            Result.TestType   = "Cholesterol";
                            //  Result.Mode = "Gen";
                        }
                        break;

                        case 8:         //Uric acid value.
                        {
                            decimal  ketone      = ((decimal)(Convert.ToInt32(strdata1, 2)) / 10);
                            string[] decimalpart = ketone.ToString().Split('.');
                            Result.TestResult = string.Format("{0}.{1}", decimalpart[0], decimalpart.Length > 1 ? decimalpart[1].Substring(0, 1) : "0");
                            Result.Unit       = " mg/dL";
                            Result.TestType   = "Uric acid";
                            Result.Mode       = "Gen";
                        }
                        break;

                        case 11:
                        {
                            decimal  ketone      = ((decimal)(Convert.ToInt32(strdata1, 2)) / 10);
                            string[] decimalpart = ketone.ToString().Split('.');
                            Result.TestResult = string.Format("{0}.{1}", decimalpart[0], decimalpart.Length > 1 ? decimalpart[1].Substring(0, 1) : "0");
                            Result.Unit       = " mg/dL";
                            Result.TestType   = "Uric acid";
                            Result.Mode       = "Gen";
                        }
                        break;

                        case 12:
                        {
                            decimal  ketone      = ((decimal)(Convert.ToInt32(strdata1, 2)) / 10);
                            string[] decimalpart = ketone.ToString().Split('.');
                            Result.TestResult = string.Format("{0}.{1}", decimalpart[0], decimalpart.Length > 1 ? decimalpart[1].Substring(0, 1) : "0");
                            Result.Unit       = " mg/dL";
                            Result.TestType   = "Uric acid";
                            Result.Mode       = "Gen";
                        }
                        break;

                        default:
                        {
                            decimal ketone = ((decimal)(Convert.ToInt32(strdata1, 2)));
                            Result.TestResult = ketone.ToString().Substring(0, 3);
                            Result.Unit       = " ";
                            Result.TestType   = " ";
                            Result.Mode       = " ";
                        }
                        break;
                        }
                        MainPage.TestresultModel.GlucometerResult(Result, 1, true);
                        break;

                    case 43:     //count 2b

                        int    sum       = data0 + data1;
                        string strdataq0 = sum.ToString("x");
                        Result.RecordCount = Convert.ToInt32(strdataq0) - 1;
                        MainPage.TestresultModel.GlucometerResult(Result, 2, true);

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
        }