Loading core/jni/android_hardware_fm_wl1271.cpp +49 −6 Original line number Diff line number Diff line Loading @@ -153,15 +153,49 @@ static jint android_hardware_fmradio_FmReceiverJNI_setControlNative return FM_JNI_SUCCESS; } static int HexStr2Int(const char* szHexStr) { unsigned long Result; sscanf(szHexStr, "%lx", &Result); return Result; } /* native interface */ static jint android_hardware_fmradio_FmReceiverJNI_getFreqNative (JNIEnv * env, jobject thiz, jint fd) { //TODO it actually never read the frequency, but this is not implemented correctly nevertheless int retval = system("hcitool cmd 0x3f 0x133 0x0a 0x02 0x00"); LOGD("getFreqNative() %d", retval); FILE *pRunPipe=NULL; char sAux[200]; char sLow[3]; char sHigh[3]; char sNoValid[3]; char sResult[5]; // Create a pipe and wait for tool answere pRunPipe = popen("hcitool cmd 0x3F 0x133 0x0A 0x02 0x00", "r"); if (pRunPipe) { // Wait until pipe finish while (!feof(pRunPipe)) fgets(sAux, 200, pRunPipe); pclose(pRunPipe); // Check if we get a valid answere if ( strstr(sAux, " 01 33 FD 00 ") ) { // Convert result data into HEX to get the freq. sscanf(sAux," 01 33 FD 00 %s %s%s",sLow,sHigh,sNoValid); sprintf(sResult,"%s%s",sLow,sHigh); // Return FM actual freq. return (HexStr2Int( sResult ) * 50 + 87500); } else return FM_JNI_FAILURE; } else return FM_JNI_FAILURE; return retval; } /*native interface */ Loading Loading @@ -196,7 +230,14 @@ static jint android_hardware_fmradio_FmReceiverJNI_getControlNative static jint android_hardware_fmradio_FmReceiverJNI_startSearchNative (JNIEnv * env, jobject thiz, jint fd, jint dir) { LOGD("startSearchNative() %d", dir); int retval = system("hcitool cmd 0x3f 0x135 0x0f 0x02 0x00 0x00 0x10"); if (dir == 0) retval = system("hcitool cmd 0x3f 0x135 0x1b 0x02 0x00 0x00 0x01"); else retval = system("hcitool cmd 0x3f 0x135 0x1b 0x02 0x00 0x00 0x00"); retval = system("hcitool cmd 0x3f 0x135 0x2d 0x02 0x00 0x00 0x02"); LOGD("startSearchNative() %d", retval); return FM_JNI_SUCCESS; } Loading @@ -204,7 +245,9 @@ static jint android_hardware_fmradio_FmReceiverJNI_startSearchNative static jint android_hardware_fmradio_FmReceiverJNI_cancelSearchNative (JNIEnv * env, jobject thiz, jint fd) { LOGD("cancelSearchNative()"); int retval = system("hcitool cmd 0x3f 0x135 0x2d 0x02 0x00 0x00 0x00"); LOGD("cancelSearchNative() %d", retval); return FM_JNI_SUCCESS; } Loading Loading
core/jni/android_hardware_fm_wl1271.cpp +49 −6 Original line number Diff line number Diff line Loading @@ -153,15 +153,49 @@ static jint android_hardware_fmradio_FmReceiverJNI_setControlNative return FM_JNI_SUCCESS; } static int HexStr2Int(const char* szHexStr) { unsigned long Result; sscanf(szHexStr, "%lx", &Result); return Result; } /* native interface */ static jint android_hardware_fmradio_FmReceiverJNI_getFreqNative (JNIEnv * env, jobject thiz, jint fd) { //TODO it actually never read the frequency, but this is not implemented correctly nevertheless int retval = system("hcitool cmd 0x3f 0x133 0x0a 0x02 0x00"); LOGD("getFreqNative() %d", retval); FILE *pRunPipe=NULL; char sAux[200]; char sLow[3]; char sHigh[3]; char sNoValid[3]; char sResult[5]; // Create a pipe and wait for tool answere pRunPipe = popen("hcitool cmd 0x3F 0x133 0x0A 0x02 0x00", "r"); if (pRunPipe) { // Wait until pipe finish while (!feof(pRunPipe)) fgets(sAux, 200, pRunPipe); pclose(pRunPipe); // Check if we get a valid answere if ( strstr(sAux, " 01 33 FD 00 ") ) { // Convert result data into HEX to get the freq. sscanf(sAux," 01 33 FD 00 %s %s%s",sLow,sHigh,sNoValid); sprintf(sResult,"%s%s",sLow,sHigh); // Return FM actual freq. return (HexStr2Int( sResult ) * 50 + 87500); } else return FM_JNI_FAILURE; } else return FM_JNI_FAILURE; return retval; } /*native interface */ Loading Loading @@ -196,7 +230,14 @@ static jint android_hardware_fmradio_FmReceiverJNI_getControlNative static jint android_hardware_fmradio_FmReceiverJNI_startSearchNative (JNIEnv * env, jobject thiz, jint fd, jint dir) { LOGD("startSearchNative() %d", dir); int retval = system("hcitool cmd 0x3f 0x135 0x0f 0x02 0x00 0x00 0x10"); if (dir == 0) retval = system("hcitool cmd 0x3f 0x135 0x1b 0x02 0x00 0x00 0x01"); else retval = system("hcitool cmd 0x3f 0x135 0x1b 0x02 0x00 0x00 0x00"); retval = system("hcitool cmd 0x3f 0x135 0x2d 0x02 0x00 0x00 0x02"); LOGD("startSearchNative() %d", retval); return FM_JNI_SUCCESS; } Loading @@ -204,7 +245,9 @@ static jint android_hardware_fmradio_FmReceiverJNI_startSearchNative static jint android_hardware_fmradio_FmReceiverJNI_cancelSearchNative (JNIEnv * env, jobject thiz, jint fd) { LOGD("cancelSearchNative()"); int retval = system("hcitool cmd 0x3f 0x135 0x2d 0x02 0x00 0x00 0x00"); LOGD("cancelSearchNative() %d", retval); return FM_JNI_SUCCESS; } Loading