Ejemplo n.º 1
0
        public void Parse(LogicChannel channelData, int offset, ReceivedData result)
        {
            var protokol = (MLEPduType)TetraUtils.BitsToInt32(channelData.Ptr, offset, 3);

            offset += 3;
            result.Add(GlobalNames.MLE_PDU_Type, (int)protokol);

            //Debug.Write(" " + protokol.ToString());

            switch (protokol)
            {
            case MLEPduType.CMCE:
                ParseCMCEPDU(channelData, offset, result);
                break;

            case MLEPduType.MLE:
                ParseMLEPDU(channelData, offset, result);
                break;

            default:
                //Debug.Write(" Unknow_PDU_Type");
                result.Add(GlobalNames.UnknowData, 1);
                break;
            }
        }
Ejemplo n.º 2
0
        public void AccessAsignPDU(LogicChannel channelData)
        {
            var offset = 0;

            var length = _aachLength[AccessAssign.Header];
            var header = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;

            length = _aachLength[AccessAssign.Field1];
            var field1 = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;

            length = _aachLength[AccessAssign.Field2];
            var field2 = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            Field1 = field1;
            Field2 = field2;

            if (channelData.Frame == 18)
            {
                DownLinkChannelType = ChannelType.Common;
                return;
            }

            switch (header)
            {
            case 0:
                DownLinkChannelType = ChannelType.Common;
                break;

            case 1:
            case 2:
            case 3:
                switch (field1)
                {
                case 0:
                    DownLinkChannelType = ChannelType.Unalloc;
                    break;

                case 1:
                    DownLinkChannelType = ChannelType.Assigned;
                    break;

                case 2:
                    DownLinkChannelType = ChannelType.Common;
                    break;

                case 3:
                    DownLinkChannelType = ChannelType.Reserved;
                    break;

                default:
                    DownLinkChannelType = ChannelType.Traffic;
                    break;
                }
                break;
            }
        }
Ejemplo n.º 3
0
        public void MacFraqPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var startOffset = offset - 3;

            //Debug.Write(" | Frag_PDU");

            if (FraqmentsBufferIsEmpty(channelData.TimeSlot))
            {
                Debug.Write(" Buffer_is_empty!!!");
                return;
            }

            var fill = (TetraUtils.BitsToInt32(channelData.Ptr, offset, 1) != 0);

            offset++;

            var realLength = channelData.Length - offset;

            if (fill)
            {
                realLength = CalcRealLength(channelData.Ptr, offset, realLength);
            }

            if (realLength < 0)
            {
                result.Add(GlobalNames.UnknowData, 1);
                Debug.Write(" frag_length_err");
                return;
            }

            AddFraqmentsToBuffer(channelData, offset, realLength);
        }
Ejemplo n.º 4
0
        public int ParseTLService(LogicChannel channelData, int offset, ReceivedData result)
        {
            var length      = 4;
            var messageType = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;
            result.Add(GlobalNames.SDS_TL_MesaggeType, messageType);
            switch (messageType)
            {
            case 0:    //Forward
                offset = Global.ParseParams(channelData, offset, _d_Sds_TL_ForwardRules, result);
                break;

            case 1:    //Report
                offset = Global.ParseParams(channelData, offset, _d_Sds_TL_ReportRules, result);
                break;

            case 2:
            case 3:
                //
                break;
            }

            return(offset);
        }
Ejemplo n.º 5
0
        public void ParseSDS(LogicChannel channelData, int offset, ReceivedData result)
        {
            var length = 8;
            var type   = (SdsProtocolIdent)TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;
            result.Add(GlobalNames.Protocol_identifier, (int)type);

            Debug.Write(" " + type.ToString());

            if ((int)type > 127)
            {
                offset = ParseTLService(channelData, offset, result);
            }

            switch (type)
            {
            case SdsProtocolIdent.Simple_immediate_text:
            case SdsProtocolIdent.Simple_text_msg:

                offset = Global.ParseParams(channelData, offset, _sds_SimpleTextRules, result);
                ParseTextMessage(channelData, offset, result);
                break;

            case SdsProtocolIdent.Immediate_text_messaging_TL:
            case SdsProtocolIdent.Text_Messaging_TL:
                offset = Global.ParseParams(channelData, offset, _sds_SimpleTextRules, result);
                ParseTextMessage(channelData, offset, result);
                break;

            case SdsProtocolIdent.Location_System_TL:
            case SdsProtocolIdent.Simple_location_system:
                length = 8;
                var locationCodingSheme = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);
                offset += length;
                result.Add(GlobalNames.Location_System_Coding, locationCodingSheme);
                if (locationCodingSheme == 0)
                {
                    result.Add(GlobalNames.Text_coding_scheme, 1);
                    ParseTextMessage(channelData, offset, result);
                }
                else
                {
                    result.Add(GlobalNames.UnknowData, 1);
                }
                break;

            case SdsProtocolIdent.Location_information_protokol:
                ParseLocationInformationProtokol(channelData, offset, result);
                break;

            default:
                offset = Global.ParseParams(channelData, offset, _sds_SimpleTextRules, result);
                ParseTextMessage(channelData, offset, result);
                result.Add(GlobalNames.UnknowData, 1);
                break;
            }
        }
Ejemplo n.º 6
0
        public void UsignalPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            HalfSlotStolen = (TetraUtils.BitsToInt32(channelData.Ptr, offset, 1) != 0);
            offset++;

            //Debug.Write(" Usig_PDU");

            //Possible pdu encrypted
            //_llc.Parse(channelData, offset, result);
        }
Ejemplo n.º 7
0
        // This code is Reed Mahler's decoder for RM (30,14)
        // The code is not universal, optimized for tetra
        // Recovers 3 bits out of 30 transmitted.
        public unsafe void Test()
        {
            var rnd = new Random();

            var inTestBuffer    = UnsafeBuffer.Create(32, sizeof(byte));
            var inTestBufferPtr = (byte *)inTestBuffer;

            var outTestBuffer    = UnsafeBuffer.Create(14, sizeof(byte));
            var outTestBufferPtr = (byte *)outTestBuffer;

            var result   = (uint)0;
            var checkBit = (uint)0;

            var error = 0;

            // All possible options, 16K x 30 bits
            for (int j = 1; j < 16384; j++)
            {
                result = 0;

                for (int column = 0; column < 30; column++)
                {
                    checkBit = 0;

                    for (int row = 0; row < 14; row++)
                    {
                        checkBit ^= (uint)((j >> (13 - row)) & 1) & gMatrix[row, column];
                    }

                    result <<= 1;
                    result  |= (uint)checkBit;
                }

                var data = result;

                for (int n = 0; n < 3; n++)
                {
                    var bitNum = rnd.Next(0, 29);
                    data ^= (1u << bitNum);
                }

                TetraUtils.UIntToBits(data, inTestBufferPtr, 2);

                Process(inTestBufferPtr, outTestBufferPtr);

                data = TetraUtils.BitsToUInt32(outTestBufferPtr, 0, 14);

                if ((result >> 16) != data)
                {
                    error++;
                }
            }
        }
Ejemplo n.º 8
0
        private void ParseMLEPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var length = 3;
            var type   = (MlePrimitivesType)TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;
            result.Add(GlobalNames.MLE_Primitives_Type, (int)type);

            //Debug.Write(" " + type.ToString());

            switch (type)
            {
            case MlePrimitivesType.D_NWRK_BROADCAST:
                offset = Global.ParseParams(channelData, offset, _d_Nwrk_BroadcastRules, result);

                var count = 0;

                if (result.TryGetValue(GlobalNames.Number_of_Neighbour_cells_element, ref count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var neighbourData = new ReceivedData();
                        offset = Global.ParseParams(channelData, offset, _neighbour_Cell_InfoRules, neighbourData);

                        var cellID = 0;
                        if (neighbourData.TryGetValue(GlobalNames.Cell_identifier, ref cellID))
                        {
                            //////Debug.WriteLine("Neighbour " + Thread.CurrentThread.ManagedThreadId.ToString());

                            if (Global.NeighbourList.Count < 32)
                            {
                                Global.NeighbourList.Add(neighbourData);
                            }
                        }
                    }
                }

                break;

            case MlePrimitivesType.D_NEW_CELL:
            case MlePrimitivesType.D_PREPARE:
            case MlePrimitivesType.D_RESTORE_ACK:
            case MlePrimitivesType.D_RESTORE_FAIL:

            default:
                //Debug.Write(" Unknow_MLE_SDU");
                result.Add(GlobalNames.UnknowData, 1);
                break;
            }
        }
Ejemplo n.º 9
0
        public void DmacFraqPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var fill = (TetraUtils.BitsToInt32(channelData.Ptr, offset, 1) != 0);

            offset++;

            var realLength = channelData.Length - offset;

            if (fill)
            {
                realLength = CalcRealLength(channelData.Ptr, offset, realLength);
            }

            AddFraqmentsToBuffer(channelData, offset, realLength);

            Debug.Write("Fragment_PDU");
        }
Ejemplo n.º 10
0
        public void DmoParseMacPDU(LogicChannel channelData, List <ReceivedData> result)
        {
            var offset = 0;
            var pdu    = new ReceivedData();

            pdu.Add(GlobalNames.CurrTimeSlot, channelData.TimeSlot);

            var pduType = (MAC_PDU_Type)TetraUtils.BitsToInt32(channelData.Ptr, offset, 2);

            offset += 2;
            pdu.Add(GlobalNames.MAC_PDU_Type, (int)pduType);

            switch (pduType)
            {
            case MAC_PDU_Type.MAC_resource:    //DMAC-DATA
                DmacDataPDU(channelData, offset, pdu);
                break;

            case MAC_PDU_Type.MAC_frag:

                var isTheEnd = TetraUtils.BitsToInt32(channelData.Ptr, offset, 1);
                offset++;

                if (isTheEnd == 0)
                {
                    Debug.Write(" DMAC-Frag_PDU");
                    DmacFraqPDU(channelData, offset, pdu);
                }
                else
                {
                    Debug.Write(" DMAC-End_PDU");
                    DmacEndPDU(channelData, offset, pdu);
                }
                break;

            case MAC_PDU_Type.MAC_U_Signal:
                Debug.Write(" U-signal_DMO_PDU");
                //UsignalPDU(channelData, offset, pdu);
                break;

            case MAC_PDU_Type.Broadcast:    //Not used for dmo
                Debug.Write(" Reserved_DMO_PDU");
                break;
            }
            result.Add(pdu);
        }
Ejemplo n.º 11
0
        public void SyncPDU(LogicChannel channelData, ReceivedData result)
        {
            var length     = 4;
            var offset     = 0;
            var systemCode = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;

            result.SetValue(GlobalNames.SystemCode, systemCode);

            switch (systemCode)
            {
            case 12:
            case 13:
                length = 2;
                var pduType = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);
                offset += length;
                result.SetValue(GlobalNames.SYNC_PDU_type, pduType);

                switch (pduType)
                {
                case 0:
                    //Dmac-Sync
                    Debug.Write(" DMAC-Sync");
                    offset = Global.ParseParams(channelData, offset, _dmacSyncInfoRulesDMO, result);
                    break;

                case 1:
                    //DPRES-SYNC
                    Debug.Write(" Dpres-Sync");
                    offset = Global.ParseParams(channelData, offset, _dpresSyncInfoRules, result);
                    break;

                default:
                    //Reserved;
                    Debug.Write(" Unknow_DMO_SyncPdu_type");
                    result.SetValue(GlobalNames.UnknowData, 1);
                    break;
                }
                break;

            default:
                Global.ParseParams(channelData, offset, _syncInfoRulesTMO, result);
                break;
            }
        }
Ejemplo n.º 12
0
        private void ParseLocationInformationProtokol(LogicChannel channelData, int offset, ReceivedData result)
        {
            var length  = 2;
            var pduType = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;
            result.Add(GlobalNames.Location_PDU_type, pduType);

            switch (pduType)
            {
            case 0:    //Short
                Global.ParseParams(channelData, offset, _sds_LocationShortRules, result);
                break;

            case 1:    //Long
                length = 4;
                var pduSubType = (LocationTypeExtension)TetraUtils.BitsToInt32(channelData.Ptr, offset, length);
                offset += length;
                result.Add(GlobalNames.Location_PDU_type_extension, (int)pduSubType);
                switch (pduSubType)
                {
                case LocationTypeExtension.Immediate_location_report:
                    Global.ParseParams(channelData, offset, _sds_ImmediateLocRepRules, result);
                    break;

                case LocationTypeExtension.Long_location_report:
                case LocationTypeExtension.Remove_trigger:
                case LocationTypeExtension.Location_report_acknowledgement:
                case LocationTypeExtension.Add_modify_trigger:
                case LocationTypeExtension.Backlog:
                case LocationTypeExtension.Basic_location_parameters:
                case LocationTypeExtension.Location_reporting_enable_disable:
                case LocationTypeExtension.Location_reporting_temporary_control:
                case LocationTypeExtension.Report_basic_location_parameters:
                case LocationTypeExtension.Report_trigger:
                default:
                    result.Add(GlobalNames.UnknowData, 1);
                    break;
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 13
0
        public unsafe bool Process(byte *inBuffer, byte *outBuffer)
        {
            uint alphaValue = 0;
            int  counter    = 0;

            //Принятое кодовое слово
            var vector = TetraUtils.BitsToUInt32(inBuffer, 0, n);

            int syndromeI = 0;

            for (int i = 0; i < nk; i++)
            {
                alphaValue = vector & _hMatrixUintPtr[i];

                counter = _onesCounterPtr[alphaValue & 0xff]
                          + _onesCounterPtr[(alphaValue >> 8) & 0xff]
                          + _onesCounterPtr[(alphaValue >> 16) & 0xff]
                          + _onesCounterPtr[(alphaValue >> 24) & 0xff];

                syndromeI <<= 1;
                syndromeI  |= (counter & 1);
            }

            var noErrors = (syndromeI == 0);

            if (!noErrors)
            {
                var bitMask = _syndromesDecoderPtr[syndromeI];
                vector  ^= bitMask;
                noErrors = bitMask != 0;
            }

            for (int i = 0; i < k; i++)
            {
                outBuffer[i] = (byte)((vector & msb) == 0 ? 0 : 1);
                vector     <<= 1;
            }

            return(noErrors);
        }
Ejemplo n.º 14
0
        public int SysInfoPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var subType = TetraUtils.BitsToByte(channelData.Ptr, offset, 2);

            result.SetValue(GlobalNames.MAC_Broadcast_Type, subType);
            offset += 2;

            switch (subType)
            {
            case 1:
                //Debug.Write(" AcсessDef_PDU");
                offset = Global.ParseParams(channelData, offset, _accessDefineRules, result);
                break;

            case 0:
                //Debug.Write(" Broadcast_PDU");
                offset = Global.ParseParams(channelData, offset, _sysInfoRules, result);
                break;
            }

            return(offset);
        }
Ejemplo n.º 15
0
        private unsafe void ParseTextMessage(LogicChannel channelData, int offset, ReceivedData result)
        {
            if (result.Contains(GlobalNames.OutOfBuffer))
            {
                return;
            }

            var codingSheme = result.Value(GlobalNames.Text_coding_scheme);

            Encoding encTable   = Encoding.GetEncoding("iso-8859-1");
            int      symbLength = 8;

            switch (codingSheme)
            {
            case 1:
                encTable = Encoding.GetEncoding("iso-8859-1");
                break;

            case 2:
                encTable = Encoding.GetEncoding("iso-8859-2");
                break;

            case 3:
                encTable = Encoding.GetEncoding("iso-8859-3");
                break;

            case 4:
                encTable = Encoding.GetEncoding("iso-8859-4");
                break;

            case 5:
                encTable = Encoding.GetEncoding("iso-8859-5");
                break;

            case 6:
                encTable = Encoding.GetEncoding("iso-8859-6");
                break;

            case 7:
                encTable = Encoding.GetEncoding("iso-8859-7");
                break;

            case 8:
                encTable = Encoding.GetEncoding("iso-8859-8");
                break;

            case 9:
                encTable = Encoding.GetEncoding("iso-8859-9");
                break;

            case 10:
                encTable = Encoding.GetEncoding("iso-8859-10");
                break;

            case 11:
                encTable = Encoding.GetEncoding("iso-8859-13");
                break;

            case 12:
                encTable = Encoding.GetEncoding("iso-8859-14");
                break;

            case 13:
                encTable = Encoding.GetEncoding("iso-8859-15");
                break;

            case 14:
                encTable = Encoding.GetEncoding(437);
                break;

            case 15:
                encTable = Encoding.GetEncoding(737);
                break;

            case 16:
                encTable = Encoding.GetEncoding(850);
                break;

            case 17:
                encTable = Encoding.GetEncoding(852);
                break;

            case 18:
                encTable = Encoding.GetEncoding(855);
                break;

            case 19:
                encTable = Encoding.GetEncoding(857);
                break;

            case 20:
                encTable = Encoding.GetEncoding(860);
                break;

            case 21:
                encTable = Encoding.GetEncoding(861);
                break;

            case 22:
                encTable = Encoding.GetEncoding(863);
                break;

            case 23:
                encTable = Encoding.GetEncoding(865);
                break;

            case 24:
                encTable = Encoding.GetEncoding(866);
                break;

            case 25:
                encTable = Encoding.GetEncoding(869);
                break;

            default:
                break;
                result.Add(GlobalNames.UnknowData, 1);
                return;
            }

            Decoder dec           = encTable.GetDecoder();
            var     messageLength = (channelData.Length - offset) / symbLength;

            if (messageLength < 0)
            {
                return;
            }

            string message;

            byte[] symbolsArray = new byte[messageLength];
            int    index        = 0;

            while (messageLength > 0)
            {
                symbolsArray[index++] = TetraUtils.BitsToByte(channelData.Ptr, offset, symbLength);
                offset += symbLength;
                messageLength--;
            }

            message = encTable.GetString(symbolsArray);

            Debug.WriteLine(" data:" + message);
        }
Ejemplo n.º 16
0
        private void ParseCMCEPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var length = 5;
            var type   = (CmcePrimitivesType)TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;
            result.Add(GlobalNames.CMCE_Primitives_Type, (int)type);

            //Debug.Write(" " + type.ToString());

            switch (type)
            {
            case CmcePrimitivesType.D_Connect:
                Global.ParseParams(channelData, offset, _d_connectRules, result);
                break;

            case CmcePrimitivesType.D_Setup:
                Global.ParseParams(channelData, offset, _d_setupRules, result);
                break;

            case CmcePrimitivesType.D_TX_Granted:
                Global.ParseParams(channelData, offset, _d_TX_GrantedRules, result);
                break;

            case CmcePrimitivesType.D_TX_Ceased:
                Global.ParseParams(channelData, offset, _d_TX_CeasedRules, result);
                break;

            case CmcePrimitivesType.D_Release:
                Global.ParseParams(channelData, offset, _d_ReleaseRules, result);
                break;

            case CmcePrimitivesType.D_Disconnect:

                break;

            case CmcePrimitivesType.D_Connect_Acknowledgea:

                break;

            case CmcePrimitivesType.D_Info:
                Global.ParseParams(channelData, offset, _d_infoRules, result);
                break;

            case CmcePrimitivesType.D_SDS_Data:
                offset = Global.ParseParams(channelData, offset, _d_SdsDataRules, result);

                if (result.Contains(GlobalNames.User_Defined_Data4_Length))
                {
                    var sdsData = new LogicChannel
                    {
                        Ptr    = channelData.Ptr + offset,
                        Length = result.Value(GlobalNames.User_Defined_Data4_Length),
                    };

                    _sds.ParseSDS(sdsData, 0, result);
                }
                break;

            case CmcePrimitivesType.D_Alert:
            case CmcePrimitivesType.D_Call_Proceeding:
            case CmcePrimitivesType.D_Status:
            case CmcePrimitivesType.D_TX_Continue:
            case CmcePrimitivesType.D_TX_Wait:
            case CmcePrimitivesType.D_TX_Interrupt:
            case CmcePrimitivesType.D_Call_Restore:
            case CmcePrimitivesType.D_Facility:
            case CmcePrimitivesType.Reserved17:
            case CmcePrimitivesType.Reserved18:
            case CmcePrimitivesType.Reserved19:
            case CmcePrimitivesType.Reserved20:
            case CmcePrimitivesType.Reserved21:
            case CmcePrimitivesType.Reserved22:
            case CmcePrimitivesType.Reserved23:
            case CmcePrimitivesType.Reserved24:
            case CmcePrimitivesType.Reserved25:
            case CmcePrimitivesType.Reserved26:
            case CmcePrimitivesType.Reserved27:
            case CmcePrimitivesType.Reserved28:
            case CmcePrimitivesType.Reserved29:
            case CmcePrimitivesType.Reserved30:
            case CmcePrimitivesType.CMCE_Function_Not_Supported:

                //Debug.Write(" Unknow_CMCE_SDU");
                result.Add(GlobalNames.UnknowData, 1);

                break;
            }
        }
Ejemplo n.º 17
0
        public void TmoParseMacPDU(LogicChannel channelData, List <ReceivedData> result)
        {
            var nullPduLength = 16; // only for receive pi/4 modulation ;
            var blockOffset   = 0;
            var nullPdu       = false;
            var pduEnd        = false;

            for (int i = 0; i < 5; i++)
            {
                var offset = blockOffset;
                var pdu    = new ReceivedData();

                pdu.Add(GlobalNames.CurrTimeSlot, channelData.TimeSlot);

                var resourceType = (MAC_PDU_Type)TetraUtils.BitsToInt32(channelData.Ptr, offset, 2);
                offset += 2;
                pdu.Add(GlobalNames.MAC_PDU_Type, (int)resourceType);

                switch (resourceType)
                {
                case MAC_PDU_Type.Broadcast:
                    blockOffset = SysInfoPDU(channelData, offset, pdu);
                    break;

                case MAC_PDU_Type.MAC_resource:
                    ResourcePDU(channelData, offset, pdu);
                    blockOffset += (pdu.Value(GlobalNames.Length_indication) * 8);
                    break;

                case MAC_PDU_Type.MAC_U_Signal:
                    if (channelData.Length == 124)
                    {
                        UsignalPDU(channelData, offset, pdu);
                        pduEnd = true;
                    }
                    else
                    {
                        Debug.Write(" MAC-D-BLCK_PDU");
                        pduEnd = true;
                    }
                    break;

                case MAC_PDU_Type.MAC_frag:

                    var isTheEnd = TetraUtils.BitsToInt32(channelData.Ptr, offset, 1);
                    offset++;

                    if (isTheEnd == 0)
                    {
                        MacFraqPDU(channelData, offset, pdu);
                        pduEnd = true;
                    }
                    else
                    {
                        MacEndPDU(channelData, offset, pdu);
                        blockOffset += (pdu.Value(GlobalNames.Length_indication) * 8);
                    }
                    break;
                }

                nullPdu = pdu.Contains(GlobalNames.Null_pdu) || pdu.Contains(GlobalNames.OutOfBuffer);

                if (nullPdu)
                {
                    pduEnd = true;
                }

                //if (pdu.ContainsKey(GlobalNames.UnknowData)) nullPdu = true;

                if (!nullPdu)
                {
                    result.Add(pdu);
                }

                if ((blockOffset >= (channelData.Length - nullPduLength)) || pduEnd)
                {
                    break;
                }
            }
        }
Ejemplo n.º 18
0
        public int Process(Burst burst, float *audioOut)
        {
            var trafficChannel = 0;

            BurstReceived = (burst.Type != BurstType.None);

            _timeCounter++;
            Ber = _averageBer;
            if (_timeCounter > 100)
            {
                Mer = (_badBurstCounter / _timeCounter) * 100.0f;

                _timeCounter     = 0;
                _badBurstCounter = 0;
            }

            _networkTime.AddTimeSlot();

            if (burst.Type == BurstType.None)
            {
                _haveErrors = true;
                if (TetraMode == Mode.TMO)
                {
                    _badBurstCounter++;
                    //Debug.WriteLine("burst err");
                    //Debug.Write(string.Format("ts:{0:0} fr:{1:00} Burst_Err", _networkTime.TimeSlot, _networkTime.Frame));
                }
                return(trafficChannel);
            }

            _haveErrors = false;

            //Debug.WriteLine("");
            //Debug.Write(string.Format("ts:{0:0} fr:{1:00}", _networkTime.TimeSlot, _networkTime.Frame));
            //Debug.Write(" " + burst.Type.ToString());

            _parse.ResetAACH();

            _data.Clear();
            _syncInfo.Clear();

            #region Sync burst

            if (burst.Type == BurstType.SYNC)
            {
                _phyLevel.ExtractSBChannels(burst, _sb1BufferPtr);

                _logicChannel     = _lowerMac.ExtractLogicChannelFromSB(_sb1BufferPtr, _sb1Buffer.Length);
                _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.5f;
                _haveErrors      |= !_logicChannel.CrcIsOk;
                _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                //Debug.Write(" slot 1:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                if (_logicChannel.CrcIsOk)
                {
                    _parse.SyncPDU(_logicChannel, _syncInfo);

                    if (_syncInfo.Value(GlobalNames.SystemCode) < 8)
                    {
                        TetraMode = Mode.TMO;
                        _lowerMac.ScramblerCode = TetraUtils.CreateScramblerCode(_syncInfo.Value(GlobalNames.MCC), _syncInfo.Value(GlobalNames.MNC), _syncInfo.Value(GlobalNames.ColorCode));
                        _networkTime.Synchronize(_syncInfo.Value(GlobalNames.TimeSlot), _syncInfo.Value(GlobalNames.Frame), _syncInfo.Value(GlobalNames.MultiFrame));
                    }
                    else
                    {
                        TetraMode = Mode.DMO;

                        if (_syncInfo.Value(GlobalNames.SYNC_PDU_type) == 0)
                        {
                            //Debug.Write(_syncInfo.Value(GlobalNames.Master_slave_link_flag) == 1 ? " Master" : " Slave");

                            if (_syncInfo.Value(GlobalNames.Master_slave_link_flag) == 1 || _syncInfo.Value(GlobalNames.Communication_type) == 0)
                            {
                                _networkTime.SynchronizeMaster(_syncInfo.Value(GlobalNames.TimeSlot), _syncInfo.Value(GlobalNames.Frame));
                            }
                            else
                            {
                                _networkTime.SynchronizeSlave(_syncInfo.Value(GlobalNames.TimeSlot), _syncInfo.Value(GlobalNames.Frame));
                            }
                        }
                    }
                }
                else
                {
                    //Debug.WriteLine("Sync SB crc error");
                }

                _phyLevel.ExtractPhyChannels(TetraMode, burst, _bbBufferPtr, _bkn1BufferPtr, _bkn2BufferPtr);

                if (TetraMode == Mode.TMO)
                {
                    _logicChannel          = _lowerMac.ExtractLogicChannelFromBKN(_bkn2BufferPtr, _bkn2Buffer.Length);
                    _logicChannel.TimeSlot = _networkTime.TimeSlot;
                    _logicChannel.Frame    = _networkTime.Frame;

                    _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.5f;
                    _haveErrors      |= !_logicChannel.CrcIsOk;
                    _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                    //Debug.Write(" slot 2:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                    if (_logicChannel.CrcIsOk)
                    {
                        _parse.TmoParseMacPDU(_logicChannel, _data);
                    }
                    else
                    {
                        //Debug.WriteLine("Sync BKN2 crc error");
                    }
                }
                else
                {
                    _logicChannel          = _lowerMac.ExtractLogicChannelFromBKN2(_bkn2BufferPtr, _bkn2Buffer.Length);
                    _logicChannel.TimeSlot = _networkTime.TimeSlot;
                    _logicChannel.Frame    = _networkTime.Frame;

                    _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.5f;
                    _haveErrors      |= !_logicChannel.CrcIsOk;
                    _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                    //Debug.Write(" slot 2:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                    if (_logicChannel.CrcIsOk)
                    {
                        _parse.SyncPDUHalfSlot(_logicChannel, _syncInfo);

                        if (_syncInfo.Value(GlobalNames.Communication_type) == 0)
                        {
                            if (_syncInfo.Contains(GlobalNames.MNC) && _syncInfo.Contains(GlobalNames.Source_address))
                            {
                                _lowerMac.ScramblerCode = TetraUtils.CreateScramblerCode(_syncInfo.Value(GlobalNames.MNC), _syncInfo.Value(GlobalNames.Source_address));
                            }
                        }
                        else if (_syncInfo.Value(GlobalNames.Communication_type) == 1)
                        {
                            if (_syncInfo.Contains(GlobalNames.Repeater_address) && _syncInfo.Contains(GlobalNames.Source_address))
                            {
                                _lowerMac.ScramblerCode = TetraUtils.CreateScramblerCode(_syncInfo.Value(GlobalNames.Repeater_address), _syncInfo.Value(GlobalNames.Source_address));
                            }
                        }
                    }
                }

                UpdateSyncInfo(_syncInfo);
            }
            #endregion

            UpdatePublicProp();

            #region Other burst

            if (burst.Type != BurstType.SYNC)
            {
                _phyLevel.ExtractPhyChannels(TetraMode, burst, _bbBufferPtr, _bkn1BufferPtr, _bkn2BufferPtr);

                if (TetraMode == Mode.TMO)
                {
                    _logicChannel          = _lowerMac.ExtractLogicChannelFromBB(_bbBufferPtr, _bbBuffer.Length);
                    _logicChannel.TimeSlot = _networkTime.TimeSlot;
                    _logicChannel.Frame    = _networkTime.Frame;

                    _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.2f;
                    _haveErrors      |= !_logicChannel.CrcIsOk;
                    //Debug.Write(_logicChannel.CrcIsOk ? " BB OK" : " BB Err");
                    if (_logicChannel.CrcIsOk)
                    {
                        _parse.AccessAsignPDU(_logicChannel);
                    }
                    else
                    {
                        //Debug.WriteLine("BB crc error");
                    }
                }

                switch (burst.Type)
                {
                case BurstType.NDB1:

                    if (((TetraMode == Mode.TMO) && (_parse.DownLinkChannelType == ChannelType.Traffic)) ||
                        ((TetraMode == Mode.DMO) && (!_networkTime.Frame18) && (_networkTime.TimeSlot == 1)) ||
                        ((TetraMode == Mode.DMO) && (!_networkTime.Frame18Slave) && (_networkTime.TimeSlotSlave == 1)))
                    {
                        //Debug.Write(" slot 12:voice");

                        _logicChannel = _lowerMac.ExtractVoiceDataFromBKN1BKN2(_bkn1BufferPtr, _bkn2BufferPtr, _bkn1Buffer.Length);
                        var itsAudio = DecodeAudio(audioOut, _logicChannel.Ptr, _logicChannel.Length, false, _networkTime.TimeSlot);
                        trafficChannel = itsAudio ? _networkTime.TimeSlot : 0;
                        break;
                    }
                    else
                    {
                        _logicChannel          = _lowerMac.ExtractLogicChannelFromBKN1BKN2(_bkn1BufferPtr, _bkn2BufferPtr, _bkn1Buffer.Length);
                        _logicChannel.TimeSlot = _networkTime.TimeSlot;
                        _logicChannel.Frame    = _networkTime.Frame;

                        _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.8f;
                        _haveErrors      |= !_logicChannel.CrcIsOk;
                        _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                        //Debug.Write(" slot 12:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                        if (_logicChannel.CrcIsOk)
                        {
                            if (TetraMode == Mode.TMO)
                            {
                                _parse.TmoParseMacPDU(_logicChannel, _data);
                            }
                            else
                            {
                                _parse.DmoParseMacPDU(_logicChannel, _data);
                            }
                        }
                        else
                        {
                            //Debug.WriteLine("BKN1 BKN2 crc error");
                        }
                    }
                    break;

                case BurstType.NDB2:

                    _logicChannel          = _lowerMac.ExtractLogicChannelFromBKN(_bkn1BufferPtr, _bkn1Buffer.Length);
                    _logicChannel.TimeSlot = _networkTime.TimeSlot;
                    _logicChannel.Frame    = _networkTime.Frame;

                    _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.4f;
                    _haveErrors      |= !_logicChannel.CrcIsOk;
                    _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                    //Debug.Write(" slot 1:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                    if (_logicChannel.CrcIsOk)
                    {
                        if (TetraMode == Mode.TMO)
                        {
                            _parse.TmoParseMacPDU(_logicChannel, _data);
                        }
                        else
                        {
                            _parse.DmoParseMacPDU(_logicChannel, _data);
                        }
                    }
                    else
                    {
                        //Debug.WriteLine("BKN1 crc error");
                    }

                    if ((_parse.DownLinkChannelType == ChannelType.Traffic && !_parse.HalfSlotStolen) ||
                        ((TetraMode == Mode.DMO) && (!_networkTime.Frame18) && (_networkTime.TimeSlot == 1) && (!_parse.HalfSlotStolen)) ||
                        ((TetraMode == Mode.DMO) && (!_networkTime.Frame18Slave) && (_networkTime.TimeSlotSlave == 1) && (!_parse.HalfSlotStolen)))
                    {
                        //Debug.Write(" slot 2:voice");
                        _logicChannel = _lowerMac.ExtractVoiceDataFromBKN2(_bkn2BufferPtr, _bkn2Buffer.Length);
                        var itsAudio = DecodeAudio(audioOut, _logicChannel.Ptr, _logicChannel.Length, true, _networkTime.TimeSlot);
                        trafficChannel = itsAudio ? _networkTime.TimeSlot : 0;
                        break;
                    }
                    else
                    {
                        _logicChannel          = _lowerMac.ExtractLogicChannelFromBKN(_bkn2BufferPtr, _bkn2Buffer.Length);
                        _logicChannel.TimeSlot = _networkTime.TimeSlot;
                        _logicChannel.Frame    = _networkTime.Frame;

                        _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.4f;
                        _haveErrors      |= !_logicChannel.CrcIsOk;
                        _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                        //Debug.Write(" slot 2:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                        if (_logicChannel.CrcIsOk)
                        {
                            if (TetraMode == Mode.TMO)
                            {
                                _parse.TmoParseMacPDU(_logicChannel, _data);
                            }
                            else
                            {
                                _parse.DmoParseMacPDU(_logicChannel, _data);
                            }
                        }
                        else
                        {
                            //Debug.WriteLine("BKN2 crc error");
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            if (_data.Count > 0)
            {
                UpdateData(_data);
            }

            #endregion

            return(trafficChannel);
        }
Ejemplo n.º 19
0
        public void Parse(LogicChannel channelData, int offset, ReceivedData result)
        {
            var llcType = (LLCPduType)TetraUtils.BitsToInt32(channelData.Ptr, offset, 4);

            offset += 4;
            result.Add(GlobalNames.LLC_Pdu_Type, (int)llcType);

            //Debug.WriteLine(" " + llcType.ToString());

            var fcsIsGood = true;

            switch (llcType)
            {
            case LLCPduType.BL_ADATA:
                offset += 1;     //N(R)
                offset += 1;     //N(S)
                break;

            case LLCPduType.BL_ADATA_FCS:
                offset   += 1;   //N(R)
                offset   += 1;   //N(S)
                fcsIsGood = CalculateFCS(channelData, offset);
                break;

            case LLCPduType.BL_DATA:
                offset += 1;     //N(S)
                break;

            case LLCPduType.BL_DATA_FCS:
                offset   += 1;   //N(S)
                fcsIsGood = CalculateFCS(channelData, offset);
                break;

            case LLCPduType.BL_UDATA:
                //No bits here
                break;

            case LLCPduType.BL_UDATA_FCS:
                //No bits here
                fcsIsGood = CalculateFCS(channelData, offset);
                break;

            case LLCPduType.BL_ACK:
                offset += 1;    //N(R)
                break;

            case LLCPduType.BL_ACK_FCS:
                offset   += 1;  //N(R)
                fcsIsGood = CalculateFCS(channelData, offset);
                break;

            case LLCPduType.AL_SETUP:
            case LLCPduType.AL_DATA_AR_FINAL:
            case LLCPduType.AL_UDATA_UFINAL:
            case LLCPduType.AL_ACK_RNR:
            case LLCPduType.AL_RECONNECT:
            case LLCPduType.Reserved1:
            case LLCPduType.Reserved2:
            case LLCPduType.AL_DISC:
            default:
                Debug.WriteLine(" Unknow_LLC_PDU " + llcType);
                result.Add(GlobalNames.UnknowData, 1);
                return;
            }

            if (fcsIsGood)
            {
                _mle.Parse(channelData, offset, result);
            }
            else
            {
                result.Add(GlobalNames.UnknowData, 1);
            }
        }
Ejemplo n.º 20
0
        public static int ParseParams(LogicChannel channelData, int offset, Rules[] rules, ReceivedData result)
        {
            var skipRules = 0;

            for (int i = 0; i < rules.Length; i++)
            {
                if (offset >= channelData.Length)
                {
                    if (!result.Contains(GlobalNames.OutOfBuffer))
                    {
                        result.SetValue(GlobalNames.OutOfBuffer, 1);
                    }
                    return(offset);
                }

                if (skipRules > 0)
                {
                    skipRules--;
                    continue;
                }

                var param = rules[i];
                var value = TetraUtils.BitsToInt32(channelData.Ptr, offset, param.Length);

                switch (param.Type)
                {
                case RulesType.Direct:
                    if (param.GlobalName != GlobalNames.Reserved)
                    {
                        result.SetValue(param.GlobalName, value);
                    }
                    offset += param.Length;
                    continue;

                case RulesType.Options_bit:
                    offset += param.Length;
                    if (value == 0)
                    {
                        return(offset);
                    }
                    break;

                case RulesType.Presence_bit:
                    if (value == 0)
                    {
                        skipRules = param.Ext1;
                    }
                    offset += param.Length;
                    break;

                case RulesType.More_bit:
                    offset += param.Length;
                    return(offset);

                case RulesType.Switch:
                    if (result.Value((GlobalNames)rules[i].Ext1) == rules[i].Ext2)
                    {
                        if (param.GlobalName != GlobalNames.Reserved)
                        {
                            result.SetValue(param.GlobalName, value);
                        }
                        offset += param.Length;
                    }
                    break;

                case RulesType.SwitchNot:
                    if (result.Value((GlobalNames)rules[i].Ext1) != rules[i].Ext2)
                    {
                        if (param.GlobalName != GlobalNames.Reserved)
                        {
                            result.SetValue(param.GlobalName, value);
                        }
                        offset += param.Length;
                    }
                    break;

                case RulesType.Jamp:
                    if (result.Value((GlobalNames)rules[i].Ext1) == rules[i].Ext2)
                    {
                        skipRules = param.Ext3;
                    }
                    break;

                case RulesType.JampNot:
                    if (result.Value((GlobalNames)rules[i].Ext1) != rules[i].Ext2)
                    {
                        skipRules = param.Ext3;
                    }
                    break;

                case RulesType.Reserved:
                {
                    offset += param.Length;
                }
                break;
                }
            }

            return(offset);
        }