Exemple #1
0
        /// <summary>
        /// 初步处理更新服药时间
        /// </summary>
        /// <param name="recvMsg"></param>
        private void UpdateTakeTimeStatus(RecvMsg recvMsg)
        {
            string time   = recvMsg.Data.Substring(0, 2);
            string status = recvMsg.Data.Substring(2);
            int    id     = MedicineLogic.QueryPatientIdByDeviceNo(recvMsg.DeviceNo);

            switch (time)
            {
            case "31":     // 早
                UpdateTakeTimeStatus(id, "MorningStatus", status);
                break;

            case "32":     //中
                UpdateTakeTimeStatus(id, "NoonStatus", status);
                break;

            case "33":     //晚
                UpdateTakeTimeStatus(id, "EveningStatus", status);
                break;

            case "34":     //附加
                break;

            default:
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// 处理接收的数据
        /// </summary>
        /// <param name="obj"></param>
        private void HandleRecvDate(object obj)
        {
            IPEndPoint client = new IPEndPoint(IPAddress.Any, 0);
            EndPoint   remote = (EndPoint)client;

            byte[] data = new byte[128];
            while (true)
            {
                try
                {
                    var recv = sokListen.ReceiveFrom(data, ref remote);
                    LogService.WriteLog($"收到数据:{Common.ByteToHexStr(data, recv)}");
                    if (Common.IsDataComplete(data, recv))
                    {
                        string  strData = Common.GetData(Common.ByteToHexStr(data, recv));
                        RecvMsg recvMsg = new RecvMsg
                        {
                            DeviceNo = Convert.ToInt32(strData.Substring(0, 4), 16),
                            FuncNo   = strData.Substring(4, 2),
                            Data     = strData.Substring(6, strData.Length - 12),
                            Flg      = Common.HexStringToByte(strData.Substring(strData.Length - 6, 4)),
                        };
                        switch (recvMsg.FuncNo)
                        {
                        case "04":     //开机
                            SendTime(recvMsg.DeviceNo, remote);
                            if (MedicineLogic.IsDeviceExistbyDeviceNo(recvMsg.DeviceNo))
                            {
                                Device device = MedicineLogic.QueryDeviceByDeviceNo(recvMsg.DeviceNo);
                                MedicineLogic.UpdateDeviceIp(device.Id, remote.ToString());
                            }
                            else
                            {
                                MedicineLogic.AddDevice(new Device
                                {
                                    DeviceNo = recvMsg.DeviceNo,
                                    DeviceIP = remote.ToString()
                                });
                            }
                            break;

                        case "06":     //服药情况
                        {
                            UpdateTakeTimeStatus(recvMsg);
                            int id = MedicineLogic.QueryPatientIdByDeviceNo(recvMsg.DeviceNo);
                            UpdateUi(id);
                        }
                        break;

                        case "07":     //开药仓反馈
                        {
                            int id       = MedicineLogic.QueryPatientIdByDeviceNo(recvMsg.DeviceNo);
                            int dispenId = Convert.ToInt32(Common.ByteToHexStr(recvMsg.Flg, 2), 16);
                            MedicineLogic.UpdateIsTake(dispenId);
                            //SetIsTakeOnUi(dispenId);
                            UpdateUi(id);
                            SendDispensing(id);
                        }
                        break;

                        default:     //命令响应
                            lock (msgList)
                            {
                                int index = msgList.FindIndex(n => ByteEquals(n.Flg, recvMsg.Flg));
                                if (index >= 0)
                                {
                                    msgList.RemoveAt(index);
                                }
                            }
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogService.WriteLog(ex, "数据处理异常");
                }
            }
        }