Exemplo n.º 1
0
        private void onACK(uMCPPacket packet)
        {
            ACKReceived++;

            uMCPACKPacket aPacket = (packet as uMCPACKPacket);

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

                if (aPacket.RCNT == 0)
                {
                    IsTimeoutTimerRunning = false;
                    STATE = uMCPState.RUNNING;
                }

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

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

                #endregion
            }

            SELECT = true;
        }
Exemplo n.º 2
0
        private void onSTR(uMCPPacket packet)
        {
            SELECT = true;
            if ((state == uMCPState.HALTED) || (state == uMCPState.ISTART))
            {
                #region state == HALTED || ISTART

                STATE = uMCPState.ASTART;
                IsTimeoutTimerRunning = false;
                SendPacket(new uMCPSTPacket(uMCPPacketType.STA, ID, TID), true);

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

                STATE = uMCPState.RUNNING;
                IsTimeoutTimerRunning = false;
                SendPacket(new uMCPACKPacket(ID, TID, 0, 0), false);

                #endregion
            }
            else
            {
                STATE = uMCPState.HALTED;
            }
        }
Exemplo n.º 3
0
        private void SendPacket(uMCPPacket packet, bool isStartTimer)
        {
            OnActionInfoEventHandler.Rise(this, new uMCPActionInfoEventArgs(string.Format("Sending: {0}", packet.ToString())));

            var serializedPacket = packet.Serialize();

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

            SELECT = (packet.PTYPE == uMCPPacketType.DTA);
            //  if (packet.PTYPE != uMCPPacketType.DTA) // sending SELECT flag
            //     SELECT = false;

            if (packet.PTYPE == uMCPPacketType.ACK)
            {
                ACKSent++;
            }
            else if ((packet.PTYPE == uMCPPacketType.DTA) || (packet.PTYPE == uMCPPacketType.DTE))
            {
                DTADTESent++;
            }
            else if (packet.PTYPE == uMCPPacketType.REP)
            {
                REPSent++;
            }
        }
Exemplo n.º 4
0
        private void onSTA(uMCPPacket packet)
        {
            SELECT = true;

            if ((state == uMCPState.ISTART) || (state == uMCPState.ASTART) || (state == uMCPState.RUNNING))
            {
                STATE = uMCPState.RUNNING;
                IsTimeoutTimerRunning = false;
                SendPacket(new uMCPACKPacket(ID, TID, 0, 0), false);
            }
        }
Exemplo n.º 5
0
        private void onREP(uMCPPacket packet)
        {
            REPReceived++;

            if (state == uMCPState.RUNNING)
            {
                IsTimeoutTimerRunning = false;
                SACK   = true;
                SREP   = false;
                SELECT = true;
            }
        }
Exemplo n.º 6
0
        private void onDTADTE(uMCPPacket packet)
        {
            DTADTEReceived++;

            if (state == uMCPState.RUNNING)
            {
                uMCPDATAPacket dPacket = (packet as uMCPDATAPacket);

                if (dPacket.TCNT <= R + 1)
                {
                    if (dPacket.TCNT == Convert.ToByte((R + 1) % 256))
                    {
                        R++;
                        OnDataBlockReceivedEventHandler.Rise(this, new uMCPDataEventArgs(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 == uMCPPacketType.DTA)
                {
                    IsTimeoutTimerRunning = true;
                }

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