1 /******************************************************************************\
2  * Technische Universitaet Darmstadt, Institut fuer Nachrichtentechnik
3  * Copyright (c) 2001-2007
4  *
5  * Author(s):
6  *	Volker Fischer, Andrew Murphy, Andrea Russo
7  *
8  * Adapted for ham sstv use Ties Bos - PA0MBO
9  *
10  * Description:
11  *	See Parameter.cpp
12  *
13  * 10/01/2007 Andrew Murphy, BBC Research & Development, 2005
14  *	- Additions to include additional RSCI related fields
15  *
16  * 11/21/2005 Andrew Murphy, BBC Research & Development, 2005
17  *	- Additions to include AMSS demodulation (Added class
18  *    CAltFreqOtherServicesSign)
19  *
20  * 11/28/2005 Andrea Russo
21  *	- Added classes for store alternative frequencies schedules and regions
22  *
23  *******************************************************************************
24  *
25  * This program is free software; you can redistribute it and/or modify it under
26  * the terms of the GNU General Public License as published by the Free Software
27  * Foundation; either version 2 of the License, or (at your option) any later
28  * version.
29  *
30  * This program is distributed in the hope that it will be useful, but WITHOUT
31  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
32  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
33  * details.
34  *
35  * You should have received a copy of the GNU General Public License along with
36  * this program; if not, write to the Free Software Foundation, Inc.,
37  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38  *
39 \******************************************************************************/
40 
41 #if !defined(PARAMETER_H__3B0BA660_CA63_4344_BB2B_23E7A0D31912__INCLUDED_)
42 #define PARAMETER_H__3B0BA660_CA63_4344_BB2B_23E7A0D31912__INCLUDED_
43 
44 #include "GlobalDefinitions.h"
45 #include "ofdmcellmapping/CellMappingTable.h"
46 #include "matlib/Matlib.h"
47 #include <time.h>
48 //#include "GPSData.h"
49 //#include "ServiceInformation.h"
50 #include <set>
51 #include <map>
52 #include <iostream>
53 
54 class CDRMReceiver;
55 
56 	/* CS: Coding Scheme */
57 	enum ECodScheme { CS_1_SM, CS_2_SM, CS_3_SM, CS_3_HMSYM, CS_3_HMMIX };
58 
59 	/* CT: Channel Type */
60 	enum EChanType { CT_MSC, CT_SDC, CT_FAC };
61 
62 enum ETypeIntFreq
63 { FLINEAR, FDFTFILTER, FWIENER };
64 enum ETypeIntTime
65 { TLINEAR, TWIENER };
66 enum ETypeSNREst
67 { SNR_FAC, SNR_PIL };
68 enum ETypeRxStatus
69 { NOT_PRESENT, CRC_ERROR, DATA_ERROR, RX_OK };
70 	/* RM: Receiver mode (analog or digital demodulation) */
71 
72 enum ERecMode
73 { RM_DRM, RM_AM, RM_NONE };
74 
75 	/* Acquisition state of receiver */
76 enum EAcqStat {AS_NO_SIGNAL, AS_WITH_SIGNAL};
77 
78 	/* Receiver state */
79 enum ERecState {RS_TRACKING, RS_ACQUISITION};
80 
81 /* Classes ********************************************************************/
82 
83 	class CAudioParam
84 	{
85 	  public:
86 
87 		/* AC: Audio Coding */
88 		enum EAudCod { AC_AAC, AC_CELP, AC_HVXC };
89 
90 		/* SB: SBR */
91 		enum ESBRFlag { SB_NOT_USED, SB_USED };
92 
93 		/* AM: Audio Mode */
94 		enum EAudMode { AM_MONO, AM_P_STEREO, AM_STEREO };
95 
96 		/* HR: HVXC Rate */
97 		enum EHVXCRate { HR_2_KBIT, HR_4_KBIT };
98 
99 		/* AS: Audio Sampling rate */
100 		enum EAudSamRat { AS_8_KHZ, AS_12KHZ, AS_16KHZ, AS_24KHZ };
101 
CAudioParam()102 		CAudioParam(): strTextMessage(), iStreamID(STREAM_ID_NOT_USED),
103 			eAudioCoding(AC_AAC), eSBRFlag(SB_NOT_USED), eAudioSamplRate(AS_24KHZ),
104 			bTextflag(false), bEnhanceFlag(false), eAudioMode(AM_MONO),
105 			iCELPIndex(0), bCELPCRC(false), eHVXCRate(HR_2_KBIT), bHVXCCRC(false)
106 		{
107 		}
CAudioParam(const CAudioParam & ap)108 		CAudioParam(const CAudioParam& ap):
109 			strTextMessage(ap.strTextMessage),
110 			iStreamID(ap.iStreamID),
111 			eAudioCoding(ap.eAudioCoding),
112 			eSBRFlag(ap.eSBRFlag),
113 			eAudioSamplRate(ap.eAudioSamplRate),
114 			bTextflag(ap.bTextflag),
115 			bEnhanceFlag(ap.bEnhanceFlag),
116 			eAudioMode(ap.eAudioMode),
117 			iCELPIndex(ap.iCELPIndex),
118 			bCELPCRC(ap.bCELPCRC),
119 			eHVXCRate(ap.eHVXCRate),
120 			bHVXCCRC(ap.bHVXCCRC)
121 		{
122 		}
123 		CAudioParam& operator=(const CAudioParam& ap)
124 		{
125 			strTextMessage = ap.strTextMessage;
126 			iStreamID = ap.iStreamID;
127 			eAudioCoding = ap.eAudioCoding;
128 			eSBRFlag = ap.eSBRFlag;
129 			eAudioSamplRate = ap.eAudioSamplRate;
130 			bTextflag =	ap.bTextflag;
131 			bEnhanceFlag = ap.bEnhanceFlag;
132 			eAudioMode = ap.eAudioMode;
133 			iCELPIndex = ap.iCELPIndex;
134 			bCELPCRC = ap.bCELPCRC;
135 			eHVXCRate = ap.eHVXCRate;
136 			bHVXCCRC = ap.bHVXCCRC;
137 			return *this;
138 		}
139 
140 		/* Text-message */
141 		string strTextMessage;	/* Max length is (8 * 16 Bytes) */
142 
143 		int iStreamID;			/* Stream Id of the stream which carries the audio service */
144 
145 		EAudCod eAudioCoding;	/* This field indicated the source coding system */
146 		ESBRFlag eSBRFlag;		/* SBR flag */
147 		EAudSamRat eAudioSamplRate;	/* Audio sampling rate */
148 		_BOOLEAN bTextflag;		/* Indicates whether a text message is present or not */
149 		_BOOLEAN bEnhanceFlag;	/* Enhancement flag */
150 
151 		/* For AAC: Mono, LC Stereo, Stereo --------------------------------- */
152 		EAudMode eAudioMode;	/* Audio mode */
153 
154 		/* For CELP --------------------------------------------------------- */
155 		int iCELPIndex;			/* This field indicates the CELP bit rate index */
156 		_BOOLEAN bCELPCRC;		/* This field indicates whether the CRC is used or not */
157 
158 		/* For HVXC --------------------------------------------------------- */
159 		EHVXCRate eHVXCRate;	/* This field indicates the rate of the HVXC */
160 		_BOOLEAN bHVXCCRC;		/* This field indicates whether the CRC is used or not */
161 
162 
163 		/* This function is needed for detection changes in the class */
164 		_BOOLEAN operator!=(const CAudioParam AudioParam)
165 		{
166 			if (iStreamID != AudioParam.iStreamID)
167         return true;
168 			if (eAudioCoding != AudioParam.eAudioCoding)
169         return true;
170 			if (eSBRFlag != AudioParam.eSBRFlag)
171         return true;
172 			if (eAudioSamplRate != AudioParam.eAudioSamplRate)
173         return true;
174 			if (bTextflag != AudioParam.bTextflag)
175         return true;
176 			if (bEnhanceFlag != AudioParam.bEnhanceFlag)
177         return true;
178 
179 			switch (AudioParam.eAudioCoding)
180 			{
181 			case AC_AAC:
182 				if (eAudioMode != AudioParam.eAudioMode)
183           return true;
184 				break;
185 
186 			case AC_CELP:
187 				if (bCELPCRC != AudioParam.bCELPCRC)
188           return true;
189 				if (iCELPIndex != AudioParam.iCELPIndex)
190           return true;
191 				break;
192 
193 			case AC_HVXC:
194 				if (eHVXCRate != AudioParam.eHVXCRate)
195           return true;
196 				if (bHVXCCRC != AudioParam.bHVXCCRC)
197           return true;
198 				break;
199 			}
200 			return false;
201 		}
202 	};
203 
204 	class CDataParam
205 	{
206 	  public:
207 
208 		/* PM: Packet Mode */
209 		enum EPackMod { PM_SYNCHRON_STR_MODE, PM_PACKET_MODE };
210 
211 		/* DU: Data Unit */
212 		enum EDatUnit { DU_SINGLE_PACKETS, DU_DATA_UNITS };
213 
214 		/* AD: Application Domain */
215 		enum EApplDomain { AD_DRM_SPEC_APP, AD_DAB_SPEC_APP, AD_OTHER_SPEC_APP };
216 
217 		int iStreamID;			/* Stream Id of the stream which carries the data service */
218 
219 		EPackMod ePacketModInd;	/* Packet mode indicator */
220 
221 		/* In case of packet mode ------------------------------------------- */
222 		EDatUnit eDataUnitInd;	/* Data unit indicator */
223 		int iPacketID;			/* Packet Id (2 bits) */
224 		int iPacketLen;			/* Packet length */
225 
226 		// "DAB specified application" not yet implemented!!!
227 		EApplDomain eAppDomain;	/* Application domain */
228 		int iUserAppIdent;		/* User application identifier, only DAB */
229 
CDataParam()230 		CDataParam():
231 			iStreamID(STREAM_ID_NOT_USED),
232 			ePacketModInd(PM_PACKET_MODE),
233 			eDataUnitInd(DU_DATA_UNITS),
234 			iPacketID(0),
235 			iPacketLen(0),
236 			eAppDomain(AD_DAB_SPEC_APP),
237 			iUserAppIdent(2)        // was 0 ipc 2 (AT_MOTSLISHOW) pa0mbo Nov 7th 2011
238 		{
239 		}
CDataParam(const CDataParam & DataParam)240 		CDataParam(const CDataParam& DataParam):
241 			iStreamID(DataParam.iStreamID),
242 			ePacketModInd(DataParam.ePacketModInd),
243 			eDataUnitInd(DataParam.eDataUnitInd),
244 			iPacketID(DataParam.iPacketID),
245 			iPacketLen(DataParam.iPacketLen),
246 			eAppDomain(DataParam.eAppDomain),
247 			iUserAppIdent(DataParam.iUserAppIdent)
248 		{
249 		}
250 		CDataParam& operator=(const CDataParam& DataParam)
251 		{
252 			iStreamID = DataParam.iStreamID;
253 			ePacketModInd = DataParam.ePacketModInd;
254 			eDataUnitInd = DataParam.eDataUnitInd;
255 			iPacketID = DataParam.iPacketID;
256 			iPacketLen = DataParam.iPacketLen;
257 			eAppDomain = DataParam.eAppDomain;
258 			iUserAppIdent = DataParam.iUserAppIdent;
259 			return *this;
260 		}
261 
262 		/* This function is needed for detection changes in the class */
263 		_BOOLEAN operator!=(const CDataParam DataParam)
264 		{
265 			if (iStreamID != DataParam.iStreamID)
266         return true;
267 			if (ePacketModInd != DataParam.ePacketModInd)
268         return true;
269 			if (DataParam.ePacketModInd == PM_PACKET_MODE)
270 			{
271 				if (eDataUnitInd != DataParam.eDataUnitInd)
272           return true;
273 				if (iPacketID != DataParam.iPacketID)
274           return true;
275 				if (iPacketLen != DataParam.iPacketLen)
276           return true;
277 				if (eAppDomain != DataParam.eAppDomain)
278           return true;
279 				if (DataParam.eAppDomain == AD_DAB_SPEC_APP)
280 					if (iUserAppIdent != DataParam.iUserAppIdent)
281             return true;
282 			}
283 			return false;
284 		}
285 	};
286 
287 	class CService
288 	{
289 	  public:
290 
291 		/* CA: CA system */
292 		enum ECACond { CA_USED, CA_NOT_USED };
293 
294 		/* SF: Service Flag */
295 		enum ETyOServ { SF_AUDIO, SF_DATA };
296 
CService()297 		CService():
298 			iServiceID(SERV_ID_NOT_USED), eCAIndication(CA_NOT_USED),
299 			iLanguage(0), eAudDataFlag(SF_AUDIO), iServiceDescr(0),
300 			strCountryCode(), strLanguageCode(), strLabel(),
301 			AudioParam(), DataParam()
302 		{
303 		}
CService(const CService & s)304 		CService(const CService& s):
305 			iServiceID(s.iServiceID), eCAIndication(s.eCAIndication),
306 			iLanguage(s.iLanguage), eAudDataFlag(s.eAudDataFlag),
307 			iServiceDescr(s.iServiceDescr), strCountryCode(s.strCountryCode),
308 			strLanguageCode(s.strLanguageCode), strLabel(s.strLabel),
309 			AudioParam(s.AudioParam), DataParam(s.DataParam)
310 		{
311 		}
312 		CService& operator=(const CService& s)
313 		{
314 			iServiceID = s.iServiceID;
315 			eCAIndication = s.eCAIndication;
316 			iLanguage = s.iLanguage;
317 			eAudDataFlag = s.eAudDataFlag;
318 			iServiceDescr = s.iServiceDescr;
319 			strCountryCode = s.strCountryCode;
320 			strLanguageCode = s.strLanguageCode;
321 			strLabel = s.strLabel;
322 			AudioParam = s.AudioParam;
323 			DataParam = s.DataParam;
324 			return *this;
325 		}
326 
IsActive()327 		_BOOLEAN IsActive() const
328 		{
329 			return iServiceID != SERV_ID_NOT_USED;
330 		}
331 
332 		uint32_t iServiceID;
333 		ECACond eCAIndication;
334 		int iLanguage;
335 		ETyOServ eAudDataFlag;
336 		int iServiceDescr;
337 		string strCountryCode;
338 		string strLanguageCode;
339 
340 		/* Label of the service */
341 		string strLabel;
342 
343 		/* Audio parameters */
344 		CAudioParam AudioParam;
345 
346 		/* Data parameters */
347 		CDataParam DataParam;
348 	};
349 
350 	class CStream
351 	{
352 	  public:
353 
CStream()354 		CStream():iLenPartA(0), iLenPartB(0)
355 		{
356 		}
CStream(const CStream & s)357 		CStream(const CStream& s):iLenPartA(s.iLenPartA), iLenPartB(s.iLenPartB)
358 		{
359 		}
360 		CStream& operator=(const CStream& Stream)
361 		{
362 			iLenPartA=Stream.iLenPartA; iLenPartB=Stream.iLenPartB;
363 			return *this;
364 		}
365 
366 		bool operator==(const CStream Stream)
367 		{
368 			if (iLenPartA != Stream.iLenPartA)
369 				return false;
370 			if (iLenPartB != Stream.iLenPartB)
371 				return false;
372 			return true;
373 		}
374 
375 		int iLenPartA;			/* Data length for part A */
376 		int iLenPartB;			/* Data length for part B */
377 	};
378 
379 	class CMSCProtLev
380 	{
381 	  public:
382 
CMSCProtLev()383     CMSCProtLev(){init();}
init()384     void init() { iPartA=iPartB=iHierarch=0; };
CMSCProtLev(const CMSCProtLev & p)385 		CMSCProtLev(const CMSCProtLev& p):iPartA(p.iPartA),iPartB(p.iPartB),iHierarch(p.iHierarch) {}
386 		CMSCProtLev& operator=(const CMSCProtLev& NewMSCProtLev)
387 		{
388 			iPartA = NewMSCProtLev.iPartA;
389 			iPartB = NewMSCProtLev.iPartB;
390 			iHierarch = NewMSCProtLev.iHierarch;
391 			return *this;
392 		}
393 
394 		int iPartA;				/* MSC protection level for part A */
395 		int iPartB;				/* MSC protection level for part B */
396 		int iHierarch;			/* MSC protection level for hierachical frame */
397 	};
398 
399 	/* Alternative Frequency Signalling ************************************** */
400 	/* Alternative frequency signalling Schedules informations class */
401 	class CAltFreqSched
402 	{
403 	  public:
CAltFreqSched()404 		CAltFreqSched():iDayCode(0),iStartTime(0),iDuration(0)
405 		{
406 		}
CAltFreqSched(const CAltFreqSched & nAFS)407 		CAltFreqSched(const CAltFreqSched& nAFS):
408 			iDayCode(nAFS.iDayCode), iStartTime(nAFS.iStartTime),
409 			iDuration(nAFS.iDuration)
410 		{
411 		}
412 
413 		CAltFreqSched& operator=(const CAltFreqSched& nAFS)
414 		{
415 			iDayCode = nAFS.iDayCode;
416 			iStartTime = nAFS.iStartTime;
417 			iDuration = nAFS.iDuration;
418 
419 			return *this;
420 		}
421 
422 		_BOOLEAN operator==(const CAltFreqSched& nAFS)
423 		{
424 			if (iDayCode != nAFS.iDayCode)
425 				return false;
426 			if (iStartTime != nAFS.iStartTime)
427 				return false;
428 			if (iDuration != nAFS.iDuration)
429 				return false;
430 
431       return true;
432 		}
433 
434 		_BOOLEAN IsActive(const time_t ltime);
435 
436 		int iDayCode;
437 		int iStartTime;
438 		int iDuration;
439 	};
440 
441 	/* Alternative frequency signalling Regions informations class */
442 	class CAltFreqRegion
443 	{
444 	  public:
CAltFreqRegion()445 		CAltFreqRegion():veciCIRAFZones(),
446 			iLatitude(0), iLongitude(0),
447 			iLatitudeEx(0), iLongitudeEx(0)
448 		{
449 		}
CAltFreqRegion(const CAltFreqRegion & nAFR)450 		CAltFreqRegion(const CAltFreqRegion& nAFR):
451 			veciCIRAFZones(nAFR.veciCIRAFZones),
452 			iLatitude(nAFR.iLatitude),
453 			iLongitude(nAFR.iLongitude),
454 			iLatitudeEx(nAFR.iLatitudeEx), iLongitudeEx(nAFR.iLongitudeEx)
455 		{
456 		}
457 
458 		CAltFreqRegion& operator=(const CAltFreqRegion& nAFR)
459 		{
460 			iLatitude = nAFR.iLatitude;
461 			iLongitude = nAFR.iLongitude;
462 			iLatitudeEx = nAFR.iLatitudeEx;
463 			iLongitudeEx = nAFR.iLongitudeEx;
464 
465 			veciCIRAFZones = nAFR.veciCIRAFZones;
466 
467 			return *this;
468 		}
469 
470 		_BOOLEAN operator==(const CAltFreqRegion& nAFR)
471 		{
472 			if (iLatitude != nAFR.iLatitude)
473 				return false;
474 			if (iLongitude != nAFR.iLongitude)
475 				return false;
476 			if (iLatitudeEx != nAFR.iLatitudeEx)
477 				return false;
478 			if (iLongitudeEx != nAFR.iLongitudeEx)
479 				return false;
480 
481 			/* Vector sizes */
482 			if (veciCIRAFZones.size() != nAFR.veciCIRAFZones.size())
483 				return false;
484 
485 			/* Vector contents */
486 			for (size_t i = 0; i < veciCIRAFZones.size(); i++)
487 				if (veciCIRAFZones[i] != nAFR.veciCIRAFZones[i])
488 					return false;
489 
490       return true;
491 		}
492 
493 		vector<int> veciCIRAFZones;
494 		int iLatitude;
495 		int iLongitude;
496 		int iLatitudeEx;
497 		int iLongitudeEx;
498 	};
499 
500 	class CServiceDefinition
501 	{
502  	public:
CServiceDefinition()503 		CServiceDefinition():veciFrequencies(), iRegionID(0), iScheduleID(0),iSystemID(0)
504 		{
505 		}
506 
CServiceDefinition(const CServiceDefinition & nAF)507 		CServiceDefinition(const CServiceDefinition& nAF):
508 			veciFrequencies(nAF.veciFrequencies),
509 			iRegionID(nAF.iRegionID), iScheduleID(nAF.iScheduleID),
510 			iSystemID(nAF.iSystemID)
511 		{
512 		}
513 
514 		CServiceDefinition& operator=(const CServiceDefinition& nAF)
515 		{
516 			veciFrequencies = nAF.veciFrequencies;
517 			iRegionID = nAF.iRegionID;
518 			iScheduleID = nAF.iScheduleID;
519 			iSystemID = nAF.iSystemID;
520 			return *this;
521 		}
522 
523 		bool operator==(const CServiceDefinition& sd) const
524 		{
525 			size_t i;
526 
527 			/* Vector sizes */
528 			if (veciFrequencies.size() != sd.veciFrequencies.size())
529 				return false;
530 
531 			/* Vector contents */
532 			for (i = 0; i < veciFrequencies.size(); i++)
533 				if (veciFrequencies[i] != sd.veciFrequencies[i])
534 					return false;
535 
536 			if (iRegionID != sd.iRegionID)
537 				return false;
538 
539 			if (iScheduleID != sd.iScheduleID)
540 				return false;
541 
542 			if (iSystemID != sd.iSystemID)
543 				return false;
544 
545       return true;
546 		}
547 		bool operator!=(const CServiceDefinition& sd) const { return !(*this==sd); }
548 
549 		string Frequency(size_t) const;
550 		string FrequencyUnits() const;
551 		string System() const;
552 
553 		vector<int> veciFrequencies;
554 		int iRegionID;
555 		int iScheduleID;
556 		int iSystemID;
557 	};
558 
559 	class CMultiplexDefinition: public CServiceDefinition
560 	{
561  	public:
CMultiplexDefinition()562 		CMultiplexDefinition():CServiceDefinition(), veciServRestrict(4), bIsSyncMultplx(false)
563 		{
564 		}
565 
CMultiplexDefinition(const CMultiplexDefinition & nAF)566 		CMultiplexDefinition(const CMultiplexDefinition& nAF):CServiceDefinition(nAF),
567 			veciServRestrict(nAF.veciServRestrict),
568 			bIsSyncMultplx(nAF.bIsSyncMultplx)
569 		{
570 		}
571 
572 		CMultiplexDefinition& operator=(const CMultiplexDefinition& nAF)
573 		{
574 			CServiceDefinition(*this) = nAF;
575 			veciServRestrict = nAF.veciServRestrict;
576 			bIsSyncMultplx = nAF.bIsSyncMultplx;
577 			return *this;
578 		}
579 
580 		bool operator==(const CMultiplexDefinition& md) const
581 		{
582 			if (CServiceDefinition(*this) != md)
583 				return false;
584 
585 			/* Vector sizes */
586 			if (veciServRestrict.size() != md.veciServRestrict.size())
587 				return false;
588 
589 			/* Vector contents */
590 			for (size_t i = 0; i < veciServRestrict.size(); i++)
591 				if (veciServRestrict[i] != md.veciServRestrict[i])
592 					return false;
593 
594 			if (bIsSyncMultplx != md.bIsSyncMultplx)
595 				return false;
596 
597       return true;
598 		}
599 
600 		vector<int> veciServRestrict;
601 		_BOOLEAN bIsSyncMultplx;
602 	};
603 
604 	class COtherService: public CServiceDefinition
605 	{
606 	public:
COtherService()607     COtherService(): CServiceDefinition(), bSameService(true),
608 			iShortID(0), iServiceID(SERV_ID_NOT_USED)
609 		{
610 		}
611 
COtherService(const COtherService & nAF)612 		COtherService(const COtherService& nAF):
613 			CServiceDefinition(nAF), bSameService(nAF.bSameService),
614 			iShortID(nAF.iShortID), iServiceID(nAF.iServiceID)
615 		{
616 		}
617 
618 		COtherService& operator=(const COtherService& nAF)
619 		{
620 			CServiceDefinition(*this) = nAF;
621 
622 			bSameService = nAF.bSameService;
623 			iShortID = nAF.iShortID;
624 			iServiceID = nAF.iServiceID;
625 
626 			return *this;
627 		}
628 
629 		bool operator==(const COtherService& nAF)
630 		{
631 			if (CServiceDefinition(*this) != nAF)
632 				return false;
633 
634 			if (bSameService != nAF.bSameService)
635 				return false;
636 
637 			if (iShortID != nAF.iShortID)
638 				return false;
639 
640 			if (iServiceID != nAF.iServiceID)
641 				return false;
642 
643       return true;
644 		}
645 
646 		string ServiceID() const;
647 
648 		_BOOLEAN bSameService;
649 		int iShortID;
650 		uint32_t iServiceID;
651 	};
652 
653 	/* Alternative frequency signalling class */
654 	class CAltFreqSign
655 	{
656 	  public:
657 
CAltFreqSign()658 		CAltFreqSign():vecRegions(16),vecSchedules(16),vecMultiplexes(),vecOtherServices(),
659 			bRegionVersionFlag(false),bScheduleVersionFlag(false),
660 			bMultiplexVersionFlag(false),bOtherServicesVersionFlag(false)
661 		{
662 		}
663 
CAltFreqSign(const CAltFreqSign & a)664 		CAltFreqSign(const CAltFreqSign& a):vecRegions(a.vecRegions),
665 			vecSchedules(a.vecSchedules), vecMultiplexes(a.vecMultiplexes),
666 			bRegionVersionFlag(a.bRegionVersionFlag),
667 			bScheduleVersionFlag(a.bScheduleVersionFlag),
668 			bMultiplexVersionFlag(a.bMultiplexVersionFlag),
669 			bOtherServicesVersionFlag(a.bOtherServicesVersionFlag)
670 		{
671 		}
672 
673 		CAltFreqSign& operator=(const CAltFreqSign& a)
674 		{
675 			vecRegions = a.vecRegions;
676 			vecSchedules = a.vecSchedules;
677 			vecMultiplexes = a.vecMultiplexes;
678 			bRegionVersionFlag = a.bRegionVersionFlag;
679 			bScheduleVersionFlag = a.bScheduleVersionFlag;
680 			bMultiplexVersionFlag = a.bMultiplexVersionFlag;
681 			bOtherServicesVersionFlag = a.bOtherServicesVersionFlag;
682 			return *this;
683 		}
684 
ResetRegions(_BOOLEAN b)685 		void ResetRegions(_BOOLEAN b)
686 		{
687 			vecRegions.clear();
688 			vecRegions.resize(16);
689 			bRegionVersionFlag=b;
690 		}
691 
ResetSchedules(_BOOLEAN b)692 		void ResetSchedules(_BOOLEAN b)
693 		{
694 			vecSchedules.clear();
695 			vecSchedules.resize(16);
696 			bScheduleVersionFlag=b;
697 		}
698 
ResetMultiplexes(_BOOLEAN b)699 		void ResetMultiplexes(_BOOLEAN b)
700 		{
701 			vecMultiplexes.clear();
702 			bMultiplexVersionFlag=b;
703 		}
704 
ResetOtherServices(_BOOLEAN b)705 		void ResetOtherServices(_BOOLEAN b)
706 		{
707 			vecOtherServices.clear();
708 			bOtherServicesVersionFlag=b;
709 		}
710 
Reset()711 		void Reset()
712 		{
713 			ResetRegions(false);
714 			ResetSchedules(false);
715 			ResetMultiplexes(false);
716 			ResetOtherServices(false);
717 		}
718 
719 		vector < vector<CAltFreqRegion> > vecRegions; // outer vector indexed by regionID
720 		vector < vector<CAltFreqSched> > vecSchedules; // outer vector indexed by scheduleID
721 		vector < CMultiplexDefinition > vecMultiplexes;
722 		vector < COtherService > vecOtherServices;
723 		_BOOLEAN bRegionVersionFlag;
724 		_BOOLEAN bScheduleVersionFlag;
725 		_BOOLEAN bMultiplexVersionFlag;
726 		_BOOLEAN bOtherServicesVersionFlag;
727 	};
728 
729 	/* Class to store information about the last service selected ------------- */
730 
731 	class CLastService
732 	{
733 	  public:
CLastService()734 		CLastService():iService(0), iServiceID(SERV_ID_NOT_USED)
735 		{
736 		}
CLastService(const CLastService & l)737 		CLastService(const CLastService& l):iService(l.iService), iServiceID(l.iServiceID)
738 		{
739 		}
740 		CLastService& operator=(const CLastService& l)
741 		{
742 			iService = l.iService;
743 			iServiceID = l.iServiceID;
744 			return *this;
745 		}
746 
Reset()747 		void Reset()
748 		{
749 			iService = 0;
750 			iServiceID = SERV_ID_NOT_USED;
751 		};
752 
Save(const int iCurSel,const int iCurServiceID)753 		void Save(const int iCurSel, const int iCurServiceID)
754 		{
755 			if (iCurServiceID != SERV_ID_NOT_USED)
756 			{
757 				iService = iCurSel;
758 				iServiceID = iCurServiceID;
759 			}
760 		};
761 
762 		/* store only fac parameters */
763 		int iService;
764 		uint32_t iServiceID;
765 	};
766 
767 	/* Classes to keep track of status flags for RSCI rsta tag and log file */
768 	class CRxStatus
769 	{
770 	public:
CRxStatus()771 		CRxStatus():status(NOT_PRESENT),iNum(0),iNumOK(0) {}
CRxStatus(const CRxStatus & s)772 		CRxStatus(const CRxStatus& s):status(s.status),iNum(s.iNum),iNumOK(s.iNumOK) {}
773 		CRxStatus& operator=(const CRxStatus& s)
774 			{ status = s.status; iNum = s.iNum; iNumOK = s.iNumOK; return *this;}
775 		void SetStatus(const ETypeRxStatus);
GetStatus()776 		ETypeRxStatus GetStatus() { return status; }
GetCount()777 		int GetCount() { return iNum; }
GetOKCount()778 		int GetOKCount() { return iNumOK; }
ResetCounts()779 		void ResetCounts() { iNum=0; iNumOK = 0; }
780 	private:
781 		ETypeRxStatus status;
782 		int iNum, iNumOK;
783 	};
784 
785 	class CReceiveStatus
786 	{
787 	  public:
CReceiveStatus()788 		CReceiveStatus():FSync(),TSync(),Interface(),
789 		FAC(),SDC(),Audio(),LLAudio(),MOT()
790 		{
791 		}
CReceiveStatus(const CReceiveStatus & s)792 		CReceiveStatus(const CReceiveStatus& s):FSync(s.FSync), TSync(s.TSync),
793 			Interface(s.Interface), FAC(s.FAC), SDC(s.SDC),
794 			Audio(s.Audio),LLAudio(s.LLAudio),MOT(s.MOT)
795 		{
796 		}
797 		CReceiveStatus& operator=(const CReceiveStatus& s)
798 		{
799 			FSync = s.FSync;
800 			TSync = s.TSync;
801 			Interface = s.Interface;
802 			FAC = s.FAC;
803 			SDC = s.SDC;
804 			Audio = s.Audio;
805 			LLAudio = s.LLAudio;
806 			MOT = s.MOT;
807 			return *this;
808 		}
809 
810 		CRxStatus FSync;
811 		CRxStatus TSync;
812 		CRxStatus Interface;
813 		CRxStatus FAC;
814 		CRxStatus SDC;
815 		CRxStatus Audio;
816 		CRxStatus LLAudio;
817 		CRxStatus MOT;
818 	};
819 
820 
821 	/* Simulation raw-data management. We have to implement a shift register
822 	   with varying size. We do that by adding a variable for storing the
823 	   current write position. */
824 	class CRawSimData
825 	{
826 		/* We have to implement a shift register with varying size. We do that
827 		   by adding a variable for storing the current write position. We use
828 		   always the first value of the array for reading and do a shift of the
829 		   other data by adding a arbitrary value (0) at the end of the whole
830 		   shift register */
831 	  public:
832 		/* Here, the maximal size of the shift register is set */
CRawSimData()833 		CRawSimData():ciMaxDelBlocks(50), iCurWritePos(0)
834 		{
835 			veciShRegSt.Init(ciMaxDelBlocks);
836 		}
837 
838 		void Add(uint32_t iNewSRS);
839 		uint32_t Get();
840 
Reset()841 		void Reset()
842 		{
843 			iCurWritePos = 0;
844 		}
845 
846 	  protected:
847 		/* Max number of delayed blocks */
848 		int ciMaxDelBlocks;
849 		CShiftRegister < uint32_t > veciShRegSt;
850 		int iCurWritePos;
851 	};
852 
853 	class CFrontEndParameters
854 	{
855 	public:
856 		enum ESMeterCorrectionType {S_METER_CORRECTION_TYPE_CAL_FACTOR_ONLY, S_METER_CORRECTION_TYPE_AGC_ONLY, S_METER_CORRECTION_TYPE_AGC_RSSI};
857 
858 		// Constructor
CFrontEndParameters()859 		CFrontEndParameters():
860 			eSMeterCorrectionType(S_METER_CORRECTION_TYPE_CAL_FACTOR_ONLY), rSMeterBandwidth(10000.0),
861         rDefaultMeasurementBandwidth(10000.0), bAutoMeasurementBandwidth(true), rCalFactorAM(0.0),
862 				rCalFactorDRM(0.0), rIFCentreFreq(12000.0)
863 			{}
CFrontEndParameters(const CFrontEndParameters & p)864 		CFrontEndParameters(const CFrontEndParameters& p):
865 			eSMeterCorrectionType(p.eSMeterCorrectionType), rSMeterBandwidth(p.rSMeterBandwidth),
866 			rDefaultMeasurementBandwidth(p.rDefaultMeasurementBandwidth),
867 			bAutoMeasurementBandwidth(p.bAutoMeasurementBandwidth),
868 			rCalFactorAM(p.rCalFactorAM), rCalFactorDRM(p.rCalFactorDRM),
869 			rIFCentreFreq(p.rIFCentreFreq)
870 			{}
871 		CFrontEndParameters& operator=(const CFrontEndParameters& p)
872 		{
873 			eSMeterCorrectionType = p.eSMeterCorrectionType;
874 			rSMeterBandwidth = p.rSMeterBandwidth;
875 			rDefaultMeasurementBandwidth = p.rDefaultMeasurementBandwidth;
876 			bAutoMeasurementBandwidth = p.bAutoMeasurementBandwidth;
877 			rCalFactorAM = p.rCalFactorAM;
878 			rCalFactorDRM = p.rCalFactorDRM;
879 			rIFCentreFreq = p.rIFCentreFreq;
880 			return *this;
881 		}
882 
883 		ESMeterCorrectionType eSMeterCorrectionType;
884 		_REAL rSMeterBandwidth; // The bandwidth the S-meter uses to do the measurement
885 
886 		_REAL rDefaultMeasurementBandwidth; // Bandwidth to do measurement if not synchronised
887     _BOOLEAN bAutoMeasurementBandwidth; // true: use the current FAC bandwidth if locked, false: use default bandwidth always
888 		_REAL rCalFactorAM;
889 		_REAL rCalFactorDRM;
890 		_REAL rIFCentreFreq;
891 
892 	};
893 
894 
895 class CMinMaxMean
896 {
897 public:
898 	CMinMaxMean();
899 
900 	void addSample(_REAL);
901 	_REAL getCurrent();
902 	_REAL getMean();
903 	void getMinMax(_REAL&, _REAL&);
904 protected:
905 	_REAL rSum, rCur, rMin, rMax;
906 	int iNum;
907 };
908 
909 class CParameter
910 {
911   public:
912   CParameter();
913   void init();
914   CParameter(const CParameter& p);
915 	//CParameter(CDRMReceiver *pRx, CParameter *pParameter); // OPH - just copy some of the members
916 	virtual ~CParameter();
917 	CParameter& operator=(const CParameter&);
918 
919 	/* Enumerations --------------------------------------------------------- */
920 	/* AS: AFS in SDC is valid or not */
921 	enum EAFSVali { AS_VALID, AS_NOT_VALID };
922 
923 
924 	/* SI: Symbol Interleaver */
925 	enum ESymIntMod { SI_LONG, SI_SHORT };
926 
927 	/* ST: Simulation Type */
928 	enum ESimType
929 	{ ST_NONE, ST_BITERROR, ST_MSECHANEST, ST_BER_IDEALCHAN,
930 		ST_SYNC_PARAM, ST_SINR
931 	};
932 
933 	/* Misc. Functions ------------------------------------------------------ */
934 	void GenerateRandomSerialNumber();
935 //	void GenerateReceiverID();
936 	void ResetServicesStreams();
937 	void GetActiveServices(set<int>& actServ);
938 	void GetActiveStreams(set<int>& actStr);
939 	void InitCellMapTable(const ERobMode eNewWaveMode,
940 						  const ESpecOcc eNewSpecOcc);
941 
942 	void SetNumDecodedBitsMSC(const int iNewNumDecodedBitsMSC);
943 	void SetNumDecodedBitsSDC(const int iNewNumDecodedBitsSDC);
944 	void SetNumBitsHieraFrTot(const int iNewNumBitsHieraFrTot);
945 	void SetNumAudioDecoderBits(const int iNewNumAudioDecoderBits);
946 	void SetNumDataDecoderBits(const int iNewNumDataDecoderBits);
947 
948 	_BOOLEAN SetWaveMode(const ERobMode eNewWaveMode);
GetWaveMode()949 	ERobMode GetWaveMode() const { return eRobustnessMode; }
950 
SetFrequency(int iNewFrequency)951 	void SetFrequency(int iNewFrequency) { iFrequency = iNewFrequency; }
GetFrequency()952 	int GetFrequency() { return iFrequency; }
953 
954 	void SetServiceParameters(int iShortID, const CService& newService);
955 
956 	void SetCurSelAudioService(const int iNewService);
GetCurSelAudioService()957 	int GetCurSelAudioService() const { return iCurSelAudioService; }
958 	void SetCurSelDataService(const int iNewService);
GetCurSelDataService()959 	int GetCurSelDataService() const { return iCurSelDataService; }
960 
ResetCurSelAudDatServ()961 	void ResetCurSelAudDatServ()
962 	{
963 		iCurSelAudioService = 0;
964 		iCurSelDataService = 0;
965 	}
966 
967 	void EnableMultimedia(const _BOOLEAN bFlag);
GetEnableMultimedia()968 	_BOOLEAN GetEnableMultimedia() const { return bUsingMultimedia; }
969 
GetDCFrequency()970 	_REAL GetDCFrequency() const
971 	{
972 		return SOUNDCRD_SAMPLE_RATE * (rFreqOffsetAcqui + rFreqOffsetTrack);
973 	}
974 
975 	_REAL GetBitRateKbps(const int iShortID, const _BOOLEAN bAudData);
976 	_REAL PartABLenRatio(const int iShortID);
977 
978 	/* Parameters controlled by FAC ----------------------------------------- */
979 	void SetInterleaverDepth(const ESymIntMod eNewDepth);
GetInterleaverDepth()980 	ESymIntMod GetInterleaverDepth()
981 	{
982 		return eSymbolInterlMode;
983 	}
984 
985 	void SetMSCCodingScheme(const ECodScheme eNewScheme);
986 	void SetSDCCodingScheme(const ECodScheme eNewScheme);
987 
988 	void SetSpectrumOccup(ESpecOcc eNewSpecOcc);
GetSpectrumOccup()989 	ESpecOcc GetSpectrumOccup() const
990 	{
991 		return eSpectOccup;
992 	}
993 
994 	void SetNumOfServices(const size_t iNNumAuSe, const size_t iNNumDaSe);
GetTotNumServices()995 	size_t GetTotNumServices()
996 	{
997 		return iNumAudioService + iNumDataService;
998 	}
999 
1000 	void SetAudDataFlag(const int iShortID, const CService::ETyOServ iNewADaFl);
1001 	void SetServiceID(const int iShortID, const uint32_t iNewServiceID);
1002 
1003 //	CDRMReceiver* pDRMRec; joma removed rx
1004 
1005 	/* Symbol interleaver mode (long or short interleaving) */
1006 	ESymIntMod eSymbolInterlMode;
1007 
1008 	ECodScheme eMSCCodingScheme;	/* MSC coding scheme */
1009 	ECodScheme eSDCCodingScheme;	/* SDC coding scheme */
1010 
1011 	size_t iNumAudioService;
1012 	size_t iNumDataService;
1013 
1014 	/* AMSS */
1015 	int iAMSSCarrierMode;
1016 
1017 	/* Serial number and received ID */
1018 	string sReceiverID;
1019 	string sSerialNumber;
1020 	string sDataFilesDirectory;
1021 
1022 	/* Parameters controlled by SDC ----------------------------------------- */
1023 	void SetAudioParam(const int iShortID, const CAudioParam& NewAudParam);
1024 	CAudioParam GetAudioParam(const int iShortID);
1025 	CDataParam GetDataParam(const int iShortID);
1026 	void SetDataParam(const int iShortID, const CDataParam& NewDataParam);
1027 
1028 	void SetMSCProtLev(const CMSCProtLev NewMSCPrLe, const _BOOLEAN bWithHierarch);
1029 	void SetStreamLen(const int iStreamID, const int iNewLenPartA, const int iNewLenPartB);
1030 	void GetStreamLen(const int iStreamID, int& iLenPartA, int& iLenPartB);
1031 	int GetStreamLen(const int iStreamID);
1032 
1033 	/* Protection levels for MSC */
1034 	CMSCProtLev MSCPrLe;
1035 
1036 	vector<CStream> Stream;
1037 	vector<CService> Service;
1038 
1039 	/* information about services gathered from SDC, EPG and web schedules */
1040 //	map<uint32_t,CServiceInformation> ServiceInformation;
1041 
1042 	/* These values are used to set input and output block sizes of some modules */
1043 	int iNumBitsHierarchFrameTotal;
1044 	int iNumDecodedBitsMSC;
1045 	int iNumSDCBitsPerSFrame;	/* Number of SDC bits per super-frame */
1046 	int iNumAudioDecoderBits;	/* Number of input bits for audio module */
1047 	int iNumDataDecoderBits;	/* Number of input bits for data decoder module */
1048 
1049 	/* Date */
1050 	int iYear;
1051 	int iMonth;
1052 	int iDay;
1053 
1054 	/* UTC (hours and minutes) */
1055 	int iUTCHour;
1056 	int iUTCMin;
1057 
1058 	/* Identifies the current frame. This parameter is set by FAC */
1059 	int iFrameIDTransm;
1060 	int iFrameIDReceiv;
1061 
1062 	/* Synchronization ------------------------------------------------------ */
1063 	_REAL rFreqOffsetAcqui;
1064 	_REAL rFreqOffsetTrack;
1065 
1066 	_REAL rResampleOffset;
1067 
1068 	int iTimingOffsTrack;
1069 
GetReceiverMode()1070 	ERecMode GetReceiverMode() { return eReceiverMode; }
1071 	ERecMode eReceiverMode;
GetAcquiState()1072 	EAcqStat GetAcquiState() { return eAcquiState; }
1073 	EAcqStat eAcquiState;
1074 	int iNumAudioFrames;
1075 
1076 	CVector <_BINARY> vecbiAudioFrameStatus;
1077 	_BOOLEAN bMeasurePSD;
1078 
1079 	/* vector to hold the PSD valued for the rpsd tag. */
1080 	CVector <_REAL> vecrPSD;
1081 
1082 	CMatrix <_COMPLEX> matcReceivedPilotValues;
1083 
1084 	/* Simulation ----------------------------------------------------------- */
1085 	CRawSimData RawSimDa;
1086 	ESimType eSimType;
1087 
1088 	int iDRMChannelNum;
1089 	int iSpecChDoppler;
1090 	_REAL rBitErrRate;
1091 	_REAL rSyncTestParam;		/* For any other simulations, used
1092 								   with "ST_SYNC_PARAM" type */
1093 	_REAL rSINR;
1094 	int iNumBitErrors;
1095 	int iChanEstDelay;
1096 
1097 	int iNumTaps;
1098 	vector<int> iPathDelay;
1099 	_REAL rGainCorr;
1100 	int iOffUsfExtr;
1101 
1102 	void SetSNR(const _REAL);
1103 	_REAL GetSNR();
1104 	void SetNominalSNRdB(const _REAL rSNRdBNominal);
1105 	_REAL GetNominalSNRdB();
SetSystemSNRdB(const _REAL rSNRdBSystem)1106 	void SetSystemSNRdB(const _REAL rSNRdBSystem)
1107 	{
1108 		rSysSimSNRdB = rSNRdBSystem;
1109 	}
GetSystemSNRdB()1110 	_REAL GetSystemSNRdB() const
1111 	{
1112 		return rSysSimSNRdB;
1113 	}
1114 	_REAL GetSysSNRdBPilPos() const;
1115 
1116 	CReceiveStatus ReceiveStatus;
1117 	CFrontEndParameters FrontEndParameters;
1118 	CAltFreqSign AltFreqSign;
1119 
Lock()1120 	void Lock()
1121 	{
1122 		Mutex.Lock();
1123 	}
Unlock()1124 	void Unlock()
1125 	{
1126 		Mutex.Unlock();
1127 	}
1128 	/* Channel Estimation */
1129 	_REAL rMER;
1130 	_REAL rWMERMSC;
1131 	_REAL rWMERFAC;
1132 	_REAL rSigmaEstimate;
1133 	_REAL rMinDelay;
1134 	_REAL rMaxDelay;
1135 
1136 	_BOOLEAN bMeasureDelay;
1137 	CRealVector vecrRdel;
1138 	CRealVector vecrRdelThresholds;
1139 	CRealVector vecrRdelIntervals;
1140 	_BOOLEAN bMeasureDoppler;
1141 	_REAL rRdop;
1142 	/* interference (constellation-based measurement rnic)*/
1143 	_BOOLEAN bMeasureInterference;
1144 	_REAL rIntFreq, rINR, rICR;
1145 
1146 	/* peak of PSD - for PSD-based interference measurement rnip */
1147 	_REAL rMaxPSDwrtSig;
1148 	_REAL rMaxPSDFreq;
1149 
1150 	/* the signal level as measured at IF by dream */
1151 	void SetIFSignalLevel(_REAL);
1152 	_REAL GetIFSignalLevel();
1153 	_REAL rSigStrengthCorrection;
1154 
1155 	/* General -------------------------------------------------------------- */
1156 	_REAL GetNominalBandwidth();
1157 	_REAL GetSysToNomBWCorrFact();
1158 	_BOOLEAN bRunThread;
1159 	_BOOLEAN bUsingMultimedia;
1160 
1161 	CCellMappingTable CellMappingTable;
1162 
1163 //	CGPSData GPSData;
1164 	CMinMaxMean SNRstat, SigStrstat;
1165 
1166 protected:
1167 
1168 	_REAL rSysSimSNRdB;
1169 
1170 	int iFrequency;
1171 	_BOOLEAN bValidSignalStrength;
1172 	_REAL rSigStr;
1173 	_REAL rIFSigStr;
1174 
1175 	/* Current selected audio service for processing */
1176 	int iCurSelAudioService;
1177 	int iCurSelDataService;
1178 
1179 	ERobMode eRobustnessMode;	/* E.g.: Mode A, B, C or D */
1180 	ESpecOcc eSpectOccup;
1181 
1182 	/* For resync to last service------------------------------------------- */
1183 	CLastService LastAudioService;
1184 	CLastService LastDataService;
1185 
1186 	CMutex Mutex;
1187 };
1188 
1189 #endif // !defined(PARAMETER_H__3B0BA660_CA63_4344_BB2B_23E7A0D31912__INCLUDED_)
1190