Пример #1
0
        private void Decode_patientData(List<string> IDinDataBase,Patient patient)
        {
            if (!CheckSum(DataStrAry))
            {
                Initiation();
                MessageBox.Show("Data Error!");
            }
            else
            {
                //--- 確認ID
                #region ID
                string ID = GetIDFromDevice(DataStrAry);
                dataID = ID;
                #endregion

                if (dataNo == 0)
                {
                    Initiation();
                    MessageBox.Show("No data in BPA!");
                }
                else
                {
                    for (int i = 0; i < dataNo; i++)
                    {
                        #region decode

                        #region year Month Day Hour Minute MAM? Arr
                        int year2BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 1], 16);
                        int year1BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 2], 16);
                        int month2BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 3], 16);
                        int month1BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 4], 16);
                        int day2BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 5], 16);
                        int day1BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 6], 16);
                        int hour2BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 7], 16);
                        int hour1BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 8], 16);
                        int minute2BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 9], 16);
                        int minute1BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 10], 16);

                        // Arr and MAM
                        if (DataStrAry[32 * (i + 1) + 11] == "02" || DataStrAry[32 * (i + 1) + 11] == "01" || DataStrAry[32 * (i + 1) + 11] == "00")
                            arr = versionArr;
                        else
                            arr = "";
                        if (DataStrAry[32 * (i + 1) + 11] == "02" || DataStrAry[32 * (i + 1) + 11] == "32")
                            mAM = "\u25CF";     // Lighted
                        else if (DataStrAry[32 * (i + 1) + 11] == "01" || DataStrAry[32 * (i + 1) + 11] == "31")
                            mAM = "\u25CF";     // Weighted
                        else
                            mAM = "";
                        string year2B = Char.ConvertFromUtf32(year2BTemp);
                        string year1B = Char.ConvertFromUtf32(year1BTemp);
                        string month2B = Char.ConvertFromUtf32(month2BTemp);
                        string month1B = Char.ConvertFromUtf32(month1BTemp);
                        string day2B = Char.ConvertFromUtf32(day2BTemp);
                        string day1B = Char.ConvertFromUtf32(day1BTemp);
                        string hour2B = Char.ConvertFromUtf32(hour2BTemp);
                        string hour1B = Char.ConvertFromUtf32(hour1BTemp);
                        string minute2B = Char.ConvertFromUtf32(minute2BTemp);
                        string minute1B = Char.ConvertFromUtf32(minute1BTemp);

                        dataYear = "20" + year2B + year1B;
                        dataMonth = month2B + month1B;
                        dataDay = day2B + day1B;
                        dataHour = hour2B + hour1B;
                        dataMin = minute2B + minute1B;
                        dataDateTime = String.Format("{0} {1}/{2} {3}:{4}", dataYear, dataMonth, dataDay, dataHour, dataMin);

                        // confirm data whether setting date time
                        if (dataDateTime == "2013 00/00 00:00")
                            dataDateTime = "n/a";

                        #endregion

                        #region Pulse
                        int pulse2BTemp1 = Convert.ToInt32(DataStrAry[32 * (i + 1) + 18], 16);
                        int pulse1BTemp1 = Convert.ToInt32(DataStrAry[32 * (i + 1) + 19], 16);
                        string pulse2BChar = Char.ConvertFromUtf32(pulse2BTemp1);
                        string pulse1BChar = Char.ConvertFromUtf32(pulse1BTemp1);
                        string pulseChar = pulse2BChar + pulse1BChar;
                        int pulse = Convert.ToInt32(pulseChar, 16);
                        this.pulse = pulse.ToString();
                        #endregion

                        #region Diastole
                        int diastole3BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 20], 16);
                        int diastole2BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 21], 16);
                        int diastole1BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 22], 16);
                        string diastole3BChar = Char.ConvertFromUtf32(diastole3BTemp);
                        string diastole2BChar = Char.ConvertFromUtf32(diastole2BTemp);
                        string diastole1BChar = Char.ConvertFromUtf32(diastole1BTemp);
                        int diastole3B = Convert.ToInt32(diastole3BChar, 16);
                        int diastole2B = Convert.ToInt32(diastole2BChar, 16);
                        int diastole1B = Convert.ToInt32(diastole1BChar, 16);
                        int diastole = diastole3B * 64 + diastole2B * 4 + diastole1B / 4;
                        this.diastole = diastole.ToString();
                        #endregion

                        #region Systole
                        int systole2BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 23], 16);
                        int systole1BTemp = Convert.ToInt32(DataStrAry[32 * (i + 1) + 24], 16);
                        string systole2BChar = Char.ConvertFromUtf32(systole2BTemp);
                        string systole1BChar = Char.ConvertFromUtf32(systole1BTemp);
                        string systoleChar = systole2BChar + systole1BChar;
                        int systole = Convert.ToInt32(systoleChar, 16);
                        this.systole = systole.ToString();
                        #endregion

                        // 存在string[] 方便之後存入 dataBase
                        patient.patientData[(int)PatientDataIndex.arr] = arr;
                        patient.patientData[(int)PatientDataIndex.dateTime] = dataDateTime;
                        patient.patientData[(int)PatientDataIndex.dia] = this.diastole;
                        patient.patientData[(int)PatientDataIndex.ID] = dataID;
                        patient.patientData[(int)PatientDataIndex.mam] = mAM;
                        patient.patientData[(int)PatientDataIndex.pulse] = this.pulse;
                        patient.patientData[(int)PatientDataIndex.sys] = this.systole;
                        #endregion

                        #region save to database
                        // if there is same ID in dataBase -> save to dataBase
                        foreach (var item in IDinDataBase)
                        {
                            if (dataID == item)
                            {
                                IDisInDataBase = true;
                                break;
                            }
                            else
                                IDisInDataBase = false;
                        }
                        if (IDisInDataBase)
                        {
                            // if user didn't set the time -> save to another table (_IDNoDateTime)
                            if (patient.patientData[(int)PatientDataIndex.dateTime] != "n/a")
                                patient.SavePatientDataToDataBase(dataID);
                            else
                                patient.SavePatientDataToDataBase(dataID+"NoDateTime");
                        }
                            
                        #endregion
                    }
                    dataNo = 0;
                    Initiation();
                }
            }
            
        }
Пример #2
0
        public void DecodingData(byte[] rawDataByteAry,List<string> IDinDataBase,Patient patient,UsbLibrary.UsbHidPort usb)
        {
            if (String.Format("{0:X2}",rawDataByteAry[2],16) == "06")
            {
                GetByteNeedReceive(rawDataByteAry);
                // command is27
                #region command is27(set date and time to BPA)
                if (FlagSetTime)
                {
                    FlagSetTime = false;
                    SendSetTimeCommand(usb);
                }
                #endregion

                #region command is25(change user number)
                if (FlagChangeUser)
                {
                    FlagChangeUser = false;
                    SendChangeUserNumberCommand(usb);
                }
                #endregion

                #region command is23 (set ID)
                if (FlagSendID)
                {
                    FlagSendID = false;
                    FlagSetIDFinish = true;
                    byte[] DataNeedToSend = new byte[34];
                    byte[] command = new byte[9];
                    command[0] = 0x00;
                    command[1] = 0x07;
                    if (FlagClearID)
                        DataNeedToSend = BPACommand.ClearDataAndSetID;
                    else
                        DataNeedToSend = BPACommand.NotClearDataAndSetID;

                    for (int i = 0; i < 4; i++)
                    {
                        for (int j = 2; j < 9; j++)
                        {
                            command[j] = DataNeedToSend[i * 7 + j - 2];
                        }
                        usb.SpecifiedDevice.SendData(command);
                    }
                    command[1] = 0x06; command[8] = 0x00;
                    for (int i = 2, j = 28; i < 8; i++, j++)
                    {
                        command[i] = DataNeedToSend[j];
                    }
                    Initiation();

                    usb.SpecifiedDevice.SendData(command);
                    Thread.Sleep(100);
                }
                #endregion
            }
            else if (DataStrAry[0] == "06")
            {
               
                GetByteNeedReceive(rawDataByteAry);
                int dataSize = 0;
                if (DataStrAry[1] == "30" && DataStrAry[2] == "30")  // command22(Read Cycle data from bpa) feature
                {
                    dataNo = GetDataNumber();
                    dataSize = dataNo * 32 + 34;
                    goto isData;
                }

                #region command is24(ID)

                if (dataCount == 33)
                {
                    if (CheckCommand() == "is24")
                    {
                        FlagCheckID = true;
                        Decode_ID();
                    }
                }
                #endregion

                #region command is28(userNumber)
                if (dataCount == 9)
                {
                    if (CheckCommand() == "is28")
                    {
                        FlagReadUserNumber = true;
                        Decode_UserNumber();
                    }
                            
                }
                #endregion

                #region command is3E(version)
                if (dataCount == 13)
                {
                    if (CheckCommand() == "is3E")
                    {
                        FlagCheckVer = true;
                        Decode_Ver();
                    } 
                }
                #endregion

                #region command is26(DataTime)
                if (dataCount == 87)
                {
                    PcNowTime = System.DateTime.Now;  // 取得PC端的時間
                    if (CheckCommand() == "is26")
                    {
                        FlagCheckDateTime = true;
                        Decode_DateTime();
                    }
                }
                #endregion

                #region command is22(Data)
                isData:
                if (dataCount == dataSize + 1)
                {
                    FlagCommandisData = true;
                    Decode_patientData(IDinDataBase, patient);
                }
                        
                #endregion


            }
        }