예제 #1
0
 private async Task CheckSegments(CancellationToken cancelToken)
 {
     if (cancelToken.IsCancellationRequested)
     {
         return;
     }
     if (Session.PumpDataHistory.CurrentMultiPacketHandler != null && Session.PumpDataHistory.CurrentMultiPacketHandler.CurrentSegment != null)
     {
         var segment = Session.PumpDataHistory.CurrentMultiPacketHandler.CurrentSegment;
         Logger.LogInformation($"MultiPacket - got {segment.Packets.Count} messages.");
         var list = segment.GetMissingSegments();
         if (list.Count > 0)
         {
             Logger.LogInformation($"MultiPacket - Missing {list.Count} message(s).");
             foreach (var item in list)
             {
                 Logger.LogInformation($"MultiPacket - Getting missing message number {item}.");
                 CommunicationBlock communicationBlock2 = new CommunicationBlock();
                 communicationBlock2.Request = Session.GetMissingSegments((ushort)item, 1);
                 communicationBlock2.ExpectedResponses.Add(new SendMessageResponsePattern());
                 communicationBlock2.ExpectedResponses.Add(new RecieveMessageResponsePattern());
                 await StartCommunication(communicationBlock2, cancelToken);
             }
             //check again
             await CheckSegments(cancelToken);
         }
     }
 }
예제 #2
0
        private async Task EndMultiPacketAsync(byte[] bytes, CancellationToken cancelToken)
        {
            Logger.LogInformation("End MultiPacket");

            CommunicationBlock communicationBlock = new CommunicationBlock();

            communicationBlock.Request = Session.GetMultiPacket(bytes);


            communicationBlock.ExpectedResponses.Add(new SendMessageResponsePattern());
            communicationBlock.ExpectedResponses.Add(new RecieveMessageResponsePattern());
            communicationBlock.ExpectedResponses.Add(new RecieveMessageResponsePattern());
            communicationBlock.ExpectedResponses.Add(new RecieveMessageResponsePattern());


            await StartCommunication(communicationBlock, cancelToken);
        }
예제 #3
0
        private async Task StartReadHistoryAsync(HistoryDataTypeEnum historytype, CancellationToken cancelToken)
        {
            Logger.LogInformation($"ReadHistory: {historytype.ToString()}");

            int expectedSize = this.Session.PumpDataHistory.GetSize(historytype);

            CommunicationBlock communicationBlock = new CommunicationBlock();

            communicationBlock.Request = Session.GetReadHistory(historytype, expectedSize);
            communicationBlock.ExpectedResponses.Add(new SendMessageResponsePattern());
            communicationBlock.ExpectedResponses.Add(new RecieveMessageResponsePattern());
            communicationBlock.ExpectedResponses.Add(new RecieveMessageResponsePattern());
            communicationBlock.ExpectedResponses.Add(new RecieveMessageResponsePattern());


            await StartCommunication(communicationBlock, cancelToken);
        }
예제 #4
0
        private async Task StartCollectDeviceInfoAsync(CancellationToken cancelToken)
        {
            //if in bad state.....
            //await CloseAsync(cancelToken);


            Logger.LogInformation("Getting CNL deviceInformation");
            CommunicationBlock block = new CommunicationBlock();

            block.TimeoutSeconds = Session.Settings.TimeoutSeconds;;
            block.Request        = new AstmStart("X");
            //block.Request = new AstmStart("W");
            //expected responses for the request
            block.ExpectedResponses.Add(new ReportPattern(new byte[] { 0x00, 0x41, 0x42, 0x43 }, 0));
            block.ExpectedResponses.Add(new EnqOREotkPattern());
            //Start Communication
            await this.StartCommunication(block, cancelToken);

            if (!cancelToken.IsCancellationRequested)
            {
                if (string.IsNullOrEmpty(this.Session.SessionDevice.Device.SerialNumber))
                {
                    //if in bad state.....
                    //await CloseAsync(cancelToken);
                    this.Session.SessionCommunicationParameters.NeedResetCommunication = true;
                    throw new Exception("Could not communicate with CNL. Please unplug CNL and plug it in again to reset CNL-communication. ");
                }
                else
                {
                    //Get previous saved parameters Or set this session if device do not exsist
                    _stateRepository.GetOrSetSessionAndSettings(Session);
                    //using (CgmUnitOfWork uow = new CgmUnitOfWork())
                    //{
                    //    uow.Device.GetOrSetSessionAndSettings(Session);
                    //}
                }
            }
        }
예제 #5
0
        private async Task StartMultiPacketAsync(byte[] bytes, CancellationToken cancelToken)
        {
            CommunicationBlock communicationBlock = new CommunicationBlock();

            communicationBlock.Request = Session.GetMultiPacket(bytes);
            communicationBlock.ExpectedResponses.Add(new SendMessageResponsePattern());

            if (Session.PumpDataHistory.CurrentMultiPacketHandler == null)
            {
                throw new Exception($"Error in getting InitiateMultiPacketTransferResponse. CurrentMultiPacketHandler is not set.");
            }

            if (Session.PumpDataHistory.CurrentMultiPacketHandler.CurrentSegment == null)
            {
                throw new Exception($"Error in getting InitiateMultiPacketTransferResponse. CurrentSegment is not set.");
            }

            int expectedMessages = Session.PumpDataHistory.CurrentMultiPacketHandler.CurrentSegment.Init.PacketsToFetch;

            for (int i = 0; i < expectedMessages; i++)
            {
                communicationBlock.ExpectedResponses.Add(new RecieveMessageResponsePattern());
            }

            communicationBlock.TimeoutSeconds = (int)Math.Ceiling((Decimal)(expectedMessages / 4));
            //communicationBlock.LogDataRecieved = false;
            if (communicationBlock.TimeoutSeconds < 5)
            {
                communicationBlock.TimeoutSeconds = 5;
            }

            Logger.LogInformation($"MultiPacket Start- expecting {expectedMessages} packets.");
            await StartCommunication(communicationBlock, cancelToken);

            //get  missing segments
            //await CheckSegments(cancelToken);
        }