Exemplo n.º 1
0
        //
        // Constructor
        //
        public DataLinkProvider(String callSign, TNCChannel channel)
        {
            _localTncChannel     = channel;
            _localStationAddress = new StationAddress(callSign);

            timerSegmenterHandler = new ElapsedEventHandler(timerSegmenter_Elapsed);
            timerSegmenter        = new Timer(timerSegmenterHandler, "UI Segmenter - " + _localStationAddress.stationIDString);

            timerSegmenter.SetTime(1000 * 60 * 10);     // 10 munite segmenter timeout

            timerTestCommandTimeoutHandler = new ElapsedEventHandler(timerTestCommandTimeout_Elapsed);
            timerTestCommandTimeout        = new Timer(timerTestCommandTimeoutHandler, "TestCommandTimeout - " + _localStationAddress.stationIDString);

            timerBeaconHandler = new ElapsedEventHandler(timerBeacon_Elapsed);
            timerBeacon        = new Timer(timerBeaconHandler, "Beacon for - " + _localStationAddress.stationIDString);
            //
            // Start processing
            //
            DataLinkThread      = new Thread(ProcessDLPackets);
            DataLinkThread.Name = "DataLinkProvider Packet Processing Thread for Station: " + _localStationAddress.stationIDString;
            DataLinkThread.Start();
        }
Exemplo n.º 2
0
            //
            // Decode the received frame
            //
            Boolean Decode(out String packetFrame)
            {
                Int32         ptr    = 0;
                Boolean       retVal = false;
                StringBuilder s      = new StringBuilder("|", 4096);

                try
                {
                    //
                    //  Catch any exceptions during decode
                    //
                    ptr = staLink.destinationStation.Decode(inBuf, ptr);
                    ptr = staLink.sourceStation.Decode(inBuf, ptr);

                    s.Append("|" + staLink.sourceStation.stationIDString + "|ch=" + staLink.sourceStation.chBit.ToString());
                    s.Append("|" + staLink.destinationStation.stationIDString + "|ch=" + staLink.destinationStation.chBit.ToString());

                    if (staLink.sourceStation.extBit == 0)
                    {
                        ptr = staLink.relayStation1.Decode(inBuf, ptr);
                        s.Append("|" + staLink.relayStation1.stationIDString + "|ch=" + staLink.relayStation1.chBit.ToString());
                        if (staLink.relayStation1.extBit == 0)
                        {
                            ptr = staLink.relayStation2.Decode(inBuf, ptr);
                            s.Append("|" + staLink.relayStation2.stationIDString + "|ch=" + staLink.relayStation2.chBit.ToString());
                            if (staLink.relayStation2.extBit == 0)
                            {
                                StationAddress tmpR = new StationAddress();
                                s.Append("|r??:(");

                                do
                                {
                                    ptr = tmpR.Decode(inBuf, ptr);
                                    s.Append("\\" + tmpR.stationIDString + ":ch=" + tmpR.chBit.ToString());
                                } while (tmpR.extBit == 0);
                                s.Append(")");
                                //throw new Exception("Too many relay addresses");
                            }
                            else
                            {
                                s.Append("|");
                            }
                        }
                        else
                        {
                            s.Append("||");
                        }
                    }
                    else
                    {
                        s.Append("|||");
                    }
                    cmdOctetPtr = ptr;

                    if ((staLink.destinationStation.chBit == staLink.sourceStation.chBit))
                    {
                        //
                        // Old protocol version
                        //
                        version = ProtocolVersion.V20;
                    }
                    else
                    {
                        //
                        // New protocol version
                        //
                        version = ProtocolVersion.V22;
                    }

                    if (staLink.destinationStation.chBit == 0)
                    {
                        //
                        // Response type
                        //
                        cmdResp = PacketType.Response;
                    }
                    else
                    {
                        //
                        // Command type
                        //
                        cmdResp = PacketType.Command;
                    }

                    //
                    // Get frame type.  I and S frame must be decoded later after we know whether we
                    // are using mod8 or mod128 sequence numbers.
                    //
                    Byte   tmp = inBuf[ptr];
                    String t   = "";

                    pfBit = (tmp >> 4) & 0x01;      //ToDo  change needed to support SABME

                    seqNumMode = SequenceNumberMode.Mod8;

                    //Frame.InformationFrame.Decode(this, rawBuf, ptr, out t);

                    if ((tmp & 0x01) == I)
                    {
                        //
                        // I frame
                        //
                        frameClass = FrameClasses.IClass;
                        frameType  = FrameTypes.IType;
                        ptr        = InformationFrame.Decode(this, inBuf, ptr, out t);
                    }

                    if ((tmp & 0x03) == S)
                    {
                        //
                        // S frame
                        //
                        frameClass = FrameClasses.SClass;
                        frameType  = (FrameTypes)(tmp & 0x0f);
                        ptr        = SupervisoryFrame.Decode(this, inBuf, ptr, out t);
                    }

                    if ((tmp & 0x03) == U)
                    {
                        //
                        // U frame.  We can decode uFrames right away
                        //
                        frameClass = FrameClasses.UClass;
                        frameType  = (FrameTypes)(tmp & 0xef);
                        ptr        = UnnumberedFrame.Decode(this, inBuf, ptr, out t);
                    }
                    s.Append("|" + version.ToString() + "|" + frameType.ToString() + "|" + cmdResp.ToString() + "|pf=" + pfBit.ToString());

                    if (t.Length > 0)
                    {
                        s.Append(t);
                    }
                    s.Append(Support.DumpRawFrame(rawBuf));

                    retVal = true;
                }
                catch (Exception ex)
                {
                    s.Append(ex.Message + CRLF);
                    Support.DbgPrint("Exception during frame decode:" + ex.Message + CRLF);
                    retVal = false;
                }
                finally
                {
                    s.Append("]");
                    packetFrame = s.ToString();
                }

                return(retVal);
            }