00001
00002 #include "stdio.h"
00003 #include "stdlib.h"
00004 #include "asx.h"
00005 #include "asxstring.h"
00006
00007 int CheckError(ASX_HANDLE hObj, const int nLine, const int nExitOnError);
00008 void PrintControlName(ASX_HANDLE hControl);
00009 ASX_HANDLE hSystem;
00010
00011 int main(int argc, char* argv[])
00012 {
00013
00014 char *pszName;
00015 ASX_HANDLE hAdapter;
00016 ASX_HANDLE hMixer;
00017 ASX_HANDLE hTuner;
00018 ASX_HANDLE hPAD;
00019 ASX_ERROR asxError;
00020 int nAdapterToUse=0;
00021 int i,nLen;
00022 unsigned long lFreq;
00023 float fMin,fMax,fStep,fGain;
00024 float fLevel;
00025 enum asxTUNERBAND eBand;
00026 int nCount;
00027 char szString[64];
00028 int nRequiredStringSize;
00029 unsigned int nStatusBits,nStatusMask;
00030
00031
00032 ASX_System_Create(ASX_SYSTEM_TYPE_HPI,&hSystem);
00033 CheckError(hSystem, __LINE__,1);
00034
00035
00036 asxError = ASX_System_GetAdapter(hSystem,nAdapterToUse,&hAdapter);
00037 CheckError(hSystem, __LINE__,1);
00038
00039 ASX_Adapter_GetName(hAdapter,0,0,&nLen);
00040 CheckError(hAdapter, __LINE__,1);
00041 pszName = (char *)malloc(nLen);
00042 ASX_Adapter_GetName(hAdapter,pszName,nLen,&nLen);
00043 CheckError(hAdapter, __LINE__,1);
00044 printf("Adapter [%d] is %s \n", nAdapterToUse,pszName);
00045
00046
00047 asxError = ASX_Adapter_GetMixer( hAdapter, &hMixer );
00048 CheckError(hAdapter, __LINE__,1);
00049
00050
00051 asxError = ASX_Mixer_GetControlByNodeTypeAndIndex(
00052 hMixer,
00053 asxNODE_TUNER_IN,0,
00054 0,0,
00055 asxCONTROL_TUNER,
00056 &hTuner);
00057 CheckError(hMixer, __LINE__,1);
00058
00059 PrintControlName(hTuner);
00060
00061
00062 asxError=ASX_Tuner_GetBand( hTuner, &eBand );
00063 CheckError(hTuner, __LINE__,1);
00064 if(!asxError)
00065 {
00066 ASXSTRING_EnumToString(eBand, szString, 64, &nRequiredStringSize);
00067 printf("Tuner band is currently %s\n",szString);
00068 }
00069
00070
00071
00072 asxError=ASX_Tuner_EnumerateBand( hTuner, 0, &eBand, &nCount);
00073
00074 printf("Total tuner bands available is %d\n",nCount);
00075 for(i=0;i<nCount;i++)
00076 {
00077 asxError=ASX_Tuner_EnumerateBand( hTuner, i, &eBand, &nCount);
00078 CheckError(hTuner, __LINE__,1);
00079
00080 if(!asxError)
00081 {
00082 ASXSTRING_EnumToString(eBand, szString, 64, &nRequiredStringSize);
00083 printf("Tuner band [%d] is %s\n",i,szString);
00084 }
00085 }
00086
00087
00088 asxError=ASX_Tuner_SetBand( hTuner, asxTUNERBAND_FM );
00089 CheckError(hTuner, __LINE__,1);
00090
00091 asxError = ASX_Tuner_GetFrequency( hTuner, &lFreq);
00092 CheckError(hTuner, __LINE__,1);
00093 asxError = ASX_Tuner_SetFrequency( hTuner, lFreq);
00094 CheckError(hTuner, __LINE__,1);
00095
00096
00097 asxError = ASX_Tuner_GetGainRange( hTuner, &fMin,&fMax,&fStep);
00098 CheckError(hTuner, __LINE__,1);
00099 if(!asxError)
00100 {
00101 printf("Gain range, min=%f dB, Max = %f dB, Step size is %f dB\n",
00102 fMin,
00103 fMax,
00104 fStep);
00105
00106 asxError = ASX_Tuner_GetGain( hTuner, &fGain);
00107 CheckError(hTuner, __LINE__, 0);
00108 asxError = ASX_Tuner_SetGain( hTuner, fGain);
00109 CheckError(hTuner, __LINE__, 0);
00110 }
00111
00112
00113 asxError = ASX_Tuner_GetRFLevel( hTuner, &fLevel);
00114 CheckError(hTuner, __LINE__, 0);
00115 printf("RF level is %f \n",fGain);
00116
00117
00118 asxError = ASX_Tuner_GetStatus( hTuner, &nStatusMask, &nStatusBits);
00119 CheckError(hTuner, __LINE__, 0);
00120 if(!asxError)
00121 printf("Tuner status mask 0x%08X, vale 0x%08X\n",nStatusMask,nStatusBits);
00122
00123
00124
00125
00126
00127 asxError = ASX_Mixer_GetControlByNodeTypeAndIndex(
00128 hMixer,
00129 asxNODE_TUNER_IN,0,
00130 0,0,
00131 asxCONTROL_PAD,
00132 &hPAD);
00133 CheckError(hMixer, __LINE__,0);
00134 if(!asxError)
00135 {
00136 char szBuffer[ASX_LONGLONG_STRING];
00137 int n;
00138
00139
00140 PrintControlName(hPAD);
00141
00142
00143 asxError = ASX_PAD_GetChannelName(hPAD,szBuffer,sizeof(szBuffer));
00144 CheckError(hMixer, __LINE__,0);
00145 if(asxError==asxERROR_NO_ERROR)
00146 printf("PAD (ChannelName) : %s\n",szBuffer);
00147
00148
00149 asxError = ASX_PAD_GetRdsPI(hPAD,&n);
00150 CheckError(hMixer, __LINE__,0);
00151 if(asxError==asxERROR_NO_ERROR)
00152 printf("PAD (RDS PI) : %d\n",n);
00153
00154
00155 asxError = ASX_PAD_GetProgramType(hPAD,&n);
00156 CheckError(hMixer, __LINE__,0);
00157 if(asxError==asxERROR_NO_ERROR)
00158 {
00159 asxError=ASX_PAD_GetProgramTypeString(
00160 hPAD,
00161 asxTUNER_RDS_TYPE_RDS,
00162 n,
00163 szBuffer,
00164 sizeof(szBuffer));
00165
00166 printf("PAD (Program Type) : [%d] %s\n",n,szBuffer);
00167 }
00168
00169
00170 asxError = ASX_PAD_GetArtist(hPAD,szBuffer,sizeof(szBuffer));
00171 CheckError(hMixer, __LINE__,0);
00172 if(asxError==asxERROR_NO_ERROR)
00173 printf("PAD (Artist) : %s\n",szBuffer);
00174
00175
00176 asxError = ASX_PAD_GetTitle(hPAD,szBuffer,sizeof(szBuffer));
00177 CheckError(hMixer, __LINE__,0);
00178 if(asxError==asxERROR_NO_ERROR)
00179 printf("PAD (Title) : %s\n",szBuffer);
00180
00181
00182 asxError = ASX_PAD_GetComment(hPAD,szBuffer,sizeof(szBuffer));
00183 CheckError(hMixer, __LINE__,0);
00184 if(asxError==asxERROR_NO_ERROR)
00185 printf("PAD (Comment) : %s\n",szBuffer);
00186
00187 }
00188
00189
00190 printf("DONE.\n");
00191 printf("Press ENTER to exit\n");
00192 getchar();
00193 ASX_System_Delete(hSystem);
00194 return 0;
00195 }
00196
00197 void PrintControlName(ASX_HANDLE hControl)
00198 {
00199 char *pszName;
00200 int nLen;
00201 enum asxCONTROL eControl;
00202
00203 ASX_Control_GetType(hControl, &eControl);
00204 ASXSTRING_EnumToString(eControl,0,0,&nLen);
00205 pszName=(char *)malloc(nLen);
00206 ASXSTRING_EnumToString(eControl,pszName,nLen,&nLen);
00207 printf("Control : %s\n",pszName);
00208
00209 free(pszName);
00210 }
00211
00212
00213 int CheckError(ASX_HANDLE hObj, const int nLine, const int nExitOnError)
00214 {
00215 int nError;
00216 int asxSubSystemErrorCode=0;
00217 char *pszAsxErrorString;
00218 char *pszAsxSubSystemErrorString;
00219 int nLen1,nLen2;
00220
00221 ASX_Error_GetLast( hObj, &nError, &asxSubSystemErrorCode);
00222 if(!nError)
00223 return 0;
00224 ASX_Error_GetLastString( hObj, 0,0,&nLen1,0,0,&nLen2);
00225 pszAsxErrorString = (char *)malloc(nLen1);
00226 pszAsxSubSystemErrorString = (char *)malloc(nLen2);
00227 ASX_Error_GetLastString( hObj, pszAsxErrorString,nLen1,&nLen1,pszAsxSubSystemErrorString,nLen2,&nLen2);
00228 printf("Error: #%d, %s - Subsystem Error: #%ld, %s \n",
00229 nError,
00230 pszAsxErrorString,
00231 asxSubSystemErrorCode,
00232 pszAsxSubSystemErrorString );
00233 printf("When called from source %s line %d\n",__FILE__,nLine);
00234 if(nExitOnError)
00235 {
00236 printf("Press ENTER to exit\n");
00237 getchar();
00238 free(pszAsxErrorString);
00239 free(pszAsxSubSystemErrorString);
00240 ASX_System_Delete(hSystem);
00241 exit(1);
00242 }
00243 return 1;
00244 }