static int ChannelLock() { Dword dwFrequency = 0; Word wBandwidth = 0; Dword dwStatus = 0; Bool boolIsLock = 0; int res; printf("\n=> Please Input Frequency (KHz): "); res = scanf("%lu", &dwFrequency); gFreq = dwFrequency; printf("\n=> Please Choose Bandwidth (0:8MHz 1:7MHz 2:6MHz): "); res = scanf("%d",&gChoseBand); if (gChoseBand == 0) wBandwidth = 8; else if (gChoseBand == 1) wBandwidth = 7; else wBandwidth = 6; printf("\n\n**************** Lock Status ****************"); printf("\nFrequency = %lu KHz\n", dwFrequency); printf("Bandwidth = %i MHz\n\n", wBandwidth); dwStatus = DTV_AcquireChannel(dwFrequency, wBandwidth); if (dwStatus) printf("DTV_AcquireChannel() return error!\n"); dwStatus = DTV_DisablePIDTbl(); if (dwStatus) printf("DTV_DisablePIDTbl() return error!\n"); dwStatus = DTV_IsLocked((Bool *)&boolIsLock); if (dwStatus) printf("DTV_IsLocked() return error!\n"); if (boolIsLock) printf("*** Channel Locked ***\n"); else printf("*** Channel Unlocked ***\n"); return 0; }
//================================================================================================== static int ChannelLock(options_t *options) { Dword dwFrequency = 0; Word wBandwidth = 0; Dword dwStatus = 0; Bool boolIsLock = 0; int res; dwFrequency = options->frequency; gFreq = options->frequency; gChoseBand = options->bandwidth; fprintf(stderr, "\n"); if(gChoseBand>=2000 && gChoseBand<3000) wBandwidth = 2; else if(gChoseBand>=3000 && gChoseBand<4000) wBandwidth = 3; else if(gChoseBand>=4000 && gChoseBand<5000) wBandwidth = 4; else if(gChoseBand>=5000 && gChoseBand<6000) wBandwidth = 5; else if(gChoseBand>=6000 && gChoseBand<7000) wBandwidth = 6; else if(gChoseBand>=7000 && gChoseBand<8000) wBandwidth = 7; else if(gChoseBand>=8000 && gChoseBand<9000) wBandwidth = 8; else { fprintf(stderr, "No Supported Bandwidth!\n"); return ERR_INVALID_BW; } fprintf(stderr, "Trying to lock:\n"); fprintf(stderr, "Frequency ...: %lu KHz\n", dwFrequency); fprintf(stderr, "Bandwidth ...: %i MHz\n\n", wBandwidth); dwStatus = DTV_AcquireChannel(dwFrequency, wBandwidth); if (dwStatus) { fprintf(stderr, "DTV_AcquireChannel() returned error %s (%lx)\n", DTV_Error(dwStatus), dwStatus); } dwStatus = DTV_DisablePIDTbl(); if (dwStatus) { fprintf(stderr, "DTV_DisablePIDTbl() returned error %s (%lx)\n", DTV_Error(dwStatus), dwStatus); } dwStatus = DTV_IsLocked((Bool *)&boolIsLock); if (dwStatus) { fprintf(stderr, "DTV_IsLocked() returned error %s (%lx)\n", DTV_Error(dwStatus), dwStatus); } if (boolIsLock) { fprintf(stderr, "*** Channel Locked ***\n"); } else { fprintf(stderr, "*** Channel Unlocked ***\n"); } return 0; }
//================================================================================================== static int MultiChannelTest() { Dword dwFrequency = 0; Word wBandwidth = 0; Dword dwStatus = 0; Bool boolIsLock = 0; Dword dwpPostErrCnt; // ErrorBitCount Dword dwpPostBitCnt; // TotalBitCount Word wpAbortCnt; // number of abort RSD packet Word wpQuality; // signal quality (0 - 100) Word wpStrength; // signal strength (0 - 100) DTVStatistic StatisicEx; int startFreq, stopFreq; int channels = 0, res; FILE* pFile = NULL; pFile = fopen("scanlog.txt", "w"); printf("\n=> Please Input Start Frequency (KHz): "); res = scanf("%d", &startFreq); printf("\n=> Please Input Stop Frequency (KHz): "); res = scanf("%d", &stopFreq); printf("\n=> Please Choose Bandwidth (0:8MHz 1:7MHz 2:6MHz): "); res = scanf("%d",&gChoseBand); if (gChoseBand == 0) wBandwidth = 8; else if (gChoseBand == 1) wBandwidth = 7; else wBandwidth = 6; gFreq = startFreq; while (gFreq <= stopFreq) { dwFrequency = gFreq; dwStatus = DTV_AcquireChannel(dwFrequency, wBandwidth); if (dwStatus) printf("DTV_AcquireChannel() return error!\n"); usleep(2500000); dwStatus = DTV_GetStatistic(10000, (Dword *)&dwpPostErrCnt, (Dword *)&dwpPostBitCnt, (Word *)&wpAbortCnt, (Word *)&wpQuality, (Word *)&wpStrength); if (dwStatus) printf("DTV_GetStatistic() return error!\n"); dwStatus = DTV_GetStatisticEx(&StatisicEx); if (dwStatus) printf("DTV_GetStatisticEx() return error!\n"); dwStatus = DTV_IsLocked((Bool *)&boolIsLock); if (dwStatus) printf("DTV_IsLocked() return error!\n"); if (boolIsLock) { channels ++; printf("\n====== Statistics ======\n"); printf("Frequency = %i KHz\n", gFreq); printf("Demod locked: %d\n", StatisicEx.signalLocked); printf("TPS locked :%d\n", StatisicEx.signalPresented); printf("Quality: %d\n", wpQuality); printf("Strength: %d\n", wpStrength); if (dwpPostBitCnt != 0) printf("BER: %3.3e\n", ((float)dwpPostErrCnt)/dwpPostBitCnt); else printf("BER: %3.3e\n", (double) dwpPostBitCnt); printf("Abort Count: %d\n", wpAbortCnt); printf("===============================\n"); if (pFile) { fprintf(pFile, "\n====== Statistics ======\n"); fprintf(pFile, "Frequency = %i KHz\n", gFreq); fprintf(pFile, "Demod locked: %d\n", StatisicEx.signalLocked); fprintf(pFile, "TPS locked :%d\n", StatisicEx.signalPresented); fprintf(pFile, "Quality: %d\n", wpQuality); fprintf(pFile, "Strength: %d\n", wpStrength); if (dwpPostBitCnt != 0) fprintf(pFile, "BER: %3.3e\n", ((float)dwpPostErrCnt)/dwpPostBitCnt); else fprintf(pFile, "BER: %3.3e\n", (double) dwpPostBitCnt); fprintf(pFile, "Abort Count: %d\n", wpAbortCnt); fprintf(pFile, "===============================\n"); } } if (gChoseBand == 0) gFreq = gFreq + 8000; else if (gChoseBand == 1) gFreq = gFreq + 7000; else gFreq = gFreq + 6000; } printf("\n============ Analysis ============"); printf("\n Frequency %d(KHz) ~ %d(KHz)", startFreq, stopFreq); printf("\n Scan Channel : %d channels Locked \n", channels); if (pFile) { fprintf(pFile, "\n============ Analysis ============"); fprintf(pFile, "\n Frequency %d(KHz) ~ %d(KHz)", startFreq, stopFreq); fprintf(pFile, "\n Scan Channel : %d channels Locked \n", channels); fclose(pFile); printf("\n Save log to file scanlog.txt\n\n"); } return 0; }