예제 #1
0
        private void onACK(uMCPInoPacket packet)
        {
            ACKReceived++;

            if (state == uMCPInoState.ASTART)
            {
                #region state == ASTART

                if (packet.RCNT == 0)
                {
                    IsTimeoutTimerRunning = false;
                    STATE = uMCPInoState.RUNNING;
                }

                #endregion
            }
            else if (state == uMCPInoState.RUNNING)
            {
                #region state == RUNNING

                SREP = false;
                IsTimeoutTimerRunning = false;
                if ((packet.RCNT == N) || (IsByteInRangeExclusive(A, N, packet.RCNT)))
                {
                    AcknowledgeSentItems(packet.RCNT);
                }

                #endregion
            }

            SELECT = true;
        }
예제 #2
0
        private void onSTR(uMCPInoPacket packet)
        {
            SELECT = true;
            if ((state == uMCPInoState.HALTED) || (state == uMCPInoState.ISTART))
            {
                #region state == HALTED || ISTART

                STATE = uMCPInoState.ASTART;
                IsTimeoutTimerRunning = false;
                SendPacket(new uMCPInoCTRLPacket(uMCPInoPacketType.STA, 0, 0), true);

                #endregion
            }
            else if (state == uMCPInoState.ASTART)
            {
                #region state == ASTART

                STATE = uMCPInoState.RUNNING;
                IsTimeoutTimerRunning = false;
                SendPacket(new uMCPInoCTRLPacket(uMCPInoPacketType.ACK, 0, 0), false);

                #endregion
            }
            else
            {
                STATE = uMCPInoState.HALTED;
            }
        }
예제 #3
0
        private void SendPacket(uMCPInoPacket packet, bool isStartTimer)
        {
            OnActionInfoEventHandler.Rise(this, new uMCPInoActionInfoEventArgs(string.Format("Sending: {0}", packet.ToString())));

            var serializedPacket = packet.Serialize();

            OnOutcomingEventHandler.Rise(this, new uMCPInoDataEventArgs(serializedPacket));
            sentPacket = packet;
            isTimerStartPendingOnTxFinish = isStartTimer;
            txFinishedInterval            = Convert.ToUInt32(1000 * (fixedTxDelayS + serializedPacket.Length * 8 / baudRateBps));
            IsTxFinishedTimerRunning      = true;

            SELECT = (packet.PTYPE == uMCPInoPacketType.DTA);

            if (packet.PTYPE == uMCPInoPacketType.ACK)
            {
                ACKSent++;
            }
            else if ((packet.PTYPE == uMCPInoPacketType.DTA) || (packet.PTYPE == uMCPInoPacketType.DTE))
            {
                DTADTESent++;
            }
            else if (packet.PTYPE == uMCPInoPacketType.REP)
            {
                REPSent++;
            }
        }
예제 #4
0
        private void onSTA(uMCPInoPacket packet)
        {
            SELECT = true;

            if ((state == uMCPInoState.ISTART) || (state == uMCPInoState.ASTART) || (state == uMCPInoState.RUNNING))
            {
                STATE = uMCPInoState.RUNNING;
                IsTimeoutTimerRunning = false;
                SendPacket(new uMCPInoCTRLPacket(uMCPInoPacketType.ACK, 0, 0), false);
            }
        }
예제 #5
0
        private void onREP(uMCPInoPacket packet)
        {
            REPReceived++;

            if (state == uMCPInoState.RUNNING)
            {
                IsTimeoutTimerRunning = false;
                SACK   = true;
                SREP   = false;
                SELECT = true;
            }
        }
예제 #6
0
        private void onDTADTE(uMCPInoPacket packet)
        {
            DTADTEReceived++;

            if (state == uMCPInoState.RUNNING)
            {
                uMCPInoDATAPacket dPacket = (packet as uMCPInoDATAPacket);

                if (dPacket.TCNT <= R + 1)
                {
                    if (dPacket.TCNT == Convert.ToByte((R + 1) % MaxMessages))
                    {
                        R = Convert.ToByte((R + 1) % MaxMessages);
                        OnDataBlockReceivedEventHandler.Rise(this, new uMCPInoDataEventArgs(dPacket.DATA));
                        BytesReceived += Convert.ToUInt32(dPacket.DATA.Length);
                    }

                    SACK = true;
                }

                SREP = false;
                IsTimeoutTimerRunning = false;

                if ((dPacket.RCNT == N) || (IsByteInRangeExclusive(A, N, dPacket.RCNT)))
                {
                    AcknowledgeSentItems(dPacket.RCNT);
                }

                if (dPacket.PTYPE == uMCPInoPacketType.DTA)
                {
                    IsTimeoutTimerRunning = true;
                }

                SELECT = (dPacket.PTYPE == uMCPInoPacketType.DTE);
            }
        }