file_name
stringlengths 6
86
| file_path
stringlengths 45
249
| content
stringlengths 47
6.26M
| file_size
int64 47
6.26M
| language
stringclasses 1
value | extension
stringclasses 1
value | repo_name
stringclasses 767
values | repo_stars
int64 8
14.4k
| repo_forks
int64 0
1.17k
| repo_open_issues
int64 0
788
| repo_created_at
stringclasses 767
values | repo_pushed_at
stringclasses 767
values |
---|---|---|---|---|---|---|---|---|---|---|---|
DvbFrontendActivity.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/app/src/main/java/info/martinmarinov/dvbdriver/DvbFrontendActivity.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.dvbdriver;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.fragment.app.FragmentActivity;
import java.io.File;
import java.io.IOException;
import info.martinmarinov.drivers.DeliverySystem;
public class DvbFrontendActivity extends FragmentActivity {
private Button btnStartStop;
private Button btnDumpTs;
private Button btnTune;
private EditText editFreq;
private Spinner spinBandwidth;
private Spinner spinDeliverySystem;
private CheckedTextView chHardwareReady;
private CheckedTextView chHasSignal;
private CheckedTextView chHasCarrier;
private CheckedTextView chHasSync;
private CheckedTextView chHasLock;
private TextView txtSnr;
private TextView txtDroppedFps;
private TextView txtBitRate;
private TextView txtDeviceName;
private ProgressBar prgRfStrength;
private ProgressBar prgQuality;
private DeviceController deviceController;
private String lastDeviceDebugString = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dvb_frontend);
editFreq = (EditText) findViewById(R.id.editFreq);
spinBandwidth = (Spinner) findViewById(R.id.spinBandwidth);
spinDeliverySystem = (Spinner) findViewById(R.id.spinDeliverySystem);
btnStartStop = (Button) findViewById(R.id.btnStartStop);
btnDumpTs = (Button) findViewById(R.id.btnDump);
btnTune = (Button) findViewById(R.id.btnTune);
chHardwareReady = (CheckedTextView) findViewById(R.id.chHardwareReady);
chHasSignal = (CheckedTextView) findViewById(R.id.chHasSignal);
chHasCarrier = (CheckedTextView) findViewById(R.id.chHasCarrier);
chHasSync = (CheckedTextView) findViewById(R.id.chHasSync);
chHasLock = (CheckedTextView) findViewById(R.id.chHasLock);
txtSnr = (TextView) findViewById(R.id.txtSnr);
txtDroppedFps = (TextView) findViewById(R.id.txtDroppedFps);
txtBitRate = (TextView) findViewById(R.id.txtBitrate);
txtDeviceName = (TextView) findViewById(R.id.txtDeviceName);
prgRfStrength = (ProgressBar) findViewById(R.id.progRf);
prgQuality = (ProgressBar) findViewById(R.id.progQuality);
btnStartStop.setOnClickListener(v -> {
try {
long desiredFreq = getUserFreqHz();
long desiredBand = getUserBandwidthHz();
DeliverySystem desiredDeliverySystem = getDeliveryStstem();
v.setEnabled(false);
new ControlStarter(desiredFreq, desiredBand, desiredDeliverySystem).start();
} catch (NumberFormatException e) {
handleException(e);
}
});
btnTune.setOnClickListener(v -> {
try {
deviceController.tuneTo(getUserFreqHz(), getUserBandwidthHz(), getDeliveryStstem());
} catch (NumberFormatException e) {
handleException(e);
}
});
btnDumpTs.setOnClickListener(v -> {
DataHandler dataHandler = deviceController.getDataHandler();
try {
if (dataHandler.isRecording()) {
dataHandler.stopRecording();
} else {
dataHandler.startRecording();
}
} catch (IOException e) {
handleException(e);
}
btnDumpTs.setText(dataHandler.isRecording() ? R.string.dump_stop : R.string.dump);
});
}
@Override
protected void onDestroy() {
super.onDestroy();
if (deviceController != null && deviceController.isAlive()) deviceController.interrupt();
}
// GUI helpers
private long getUserFreqHz() {
return Math.round( Double.parseDouble(editFreq.getText().toString()) * 1_000_000L );
}
private long getUserBandwidthHz() {
return Integer.parseInt(spinBandwidth.getSelectedItem().toString()) * 1_000_000L;
}
private DeliverySystem getDeliveryStstem() {
return DeliverySystem.valueOf(spinDeliverySystem.getSelectedItem().toString());
}
// GUI helpers that could be called from a non-GUI thread
void handleException(final Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
ExceptionDialog.showOneInstanceOnly(getSupportFragmentManager(), e, lastDeviceDebugString);
}
});
}
void announceMeasurements(final int snr, final int qualityPercertage, final int droppedFps,
final int rfStrengthPercentage,
final boolean hasSignal, final boolean hasCarrier,
final boolean hasSync, final boolean hasLock) {
runOnUiThread(new Runnable() {
@Override
public void run() {
chHasSignal.setChecked(hasSignal);
chHasCarrier.setChecked(hasCarrier);
chHasSync.setChecked(hasSync);
chHasLock.setChecked(hasLock);
Resources resources = getResources();
txtSnr.setText(resources.getString(R.string.snr, snr));
txtDroppedFps.setText(resources.getString(R.string.dropped_fps, droppedFps));
prgRfStrength.setProgress(rfStrengthPercentage);
prgQuality.setProgress(qualityPercertage);
}
});
}
void announceBitRate(final double bytesPerSecond) {
runOnUiThread(new Runnable() {
@Override
public void run() {
txtBitRate.setText(getResources().getString(R.string.mux_speed, bytesPerSecond / 1_000_000.0));
}
});
}
void announceRecorded(final File file, final int recordedSize) {
runOnUiThread(new Runnable() {
@Override
public void run() {
txtBitRate.setText(getResources().getString(R.string.rec_size, file.getPath(), recordedSize / 1_000_000.0));
}
});
}
void announceOpen(final boolean open, final String deviceDebugName) {
runOnUiThread(new Runnable() {
@Override
public void run() {
chHardwareReady.setChecked(open);
chHasSignal.setChecked(false);
chHasCarrier.setChecked(false);
chHasSync.setChecked(false);
chHasLock.setChecked(false);
if (deviceDebugName != null) {
lastDeviceDebugString = deviceDebugName;
} else {
lastDeviceDebugString = getString(R.string.no_device_open);
}
txtDeviceName.setText(lastDeviceDebugString);
txtSnr.setText(R.string.more_info);
if (open) txtDroppedFps.setText(R.string.more_info);
if (open) txtBitRate.setText(R.string.more_info);
if (open) {
btnTune.setEnabled(true);
btnDumpTs.setEnabled(true);
btnStartStop.setEnabled(true);
btnStartStop.setText(R.string.stop);
} else {
btnTune.setEnabled(false);
btnDumpTs.setEnabled(false);
btnStartStop.setEnabled(true);
btnStartStop.setText(R.string.start);
}
prgRfStrength.setProgress(0);
prgQuality.setProgress(0);
}
});
}
// Controlling the device
private class ControlStarter extends Thread {
private final long desiredFreq;
private final long desiredBand;
private final DeliverySystem desiredDeliverySystem;
ControlStarter(long desiredFreq, long desiredBand, DeliverySystem desiredDeliverySystem) {
this.desiredFreq = desiredFreq;
this.desiredBand = desiredBand;
this.desiredDeliverySystem = desiredDeliverySystem;
}
@Override
public void run() {
if (deviceController != null && deviceController.isAlive()) {
// wait for device to close
deviceController.interrupt();
try {
deviceController.join();
} catch (InterruptedException e) {
handleException(e);
runOnUiThread(new Runnable() {
@Override
public void run() {
btnStartStop.setEnabled(true);
btnDumpTs.setEnabled(false);
btnTune.setEnabled(false);
}
});
}
} else {
deviceController = new DeviceController(DvbFrontendActivity.this, desiredFreq, desiredBand, desiredDeliverySystem);
deviceController.start();
}
}
}
}
| 10,241 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DataHandler.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/app/src/main/java/info/martinmarinov/dvbdriver/DataHandler.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.dvbdriver;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import info.martinmarinov.dvbservice.tools.TsDumpFileUtils;
class DataHandler extends Thread {
private final DvbFrontendActivity dvbFrontendActivity;
private final Object recordingLock = new Object();
private final InputStream is;
private boolean recording = false;
private File file;
private FileOutputStream fos;
private int recordedSize = 0;
private long readB = 0;
private long currFreq;
private long currBandwidth;
DataHandler(DvbFrontendActivity dvbFrontendActivity, InputStream is) {
this.dvbFrontendActivity = dvbFrontendActivity;
this.is = is;
}
void reset() {
readB = 0;
}
void setFreqAndBandwidth(long freq, long bandwidth) {
this.currFreq = freq;
this.currBandwidth = bandwidth;
}
@Override
public void interrupt() {
super.interrupt();
try {
is.close();
} catch (IOException ignored) {}
}
@Override
public void run() {
try {
long nextUpdate = System.currentTimeMillis() + 1_000;
byte[] b = new byte[1024];
while (!isInterrupted()) {
int read = is.read(b);
if (read > 0) {
synchronized (recordingLock) {
if (recording) {
fos.write(b, 0, read);
recordedSize += read;
}
}
readB += b.length;
} else {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
interrupt();
}
continue;
}
if (System.currentTimeMillis() > nextUpdate) {
nextUpdate = System.currentTimeMillis() + 1_000;
if (recording) {
dvbFrontendActivity.announceRecorded(file, recordedSize);
} else {
dvbFrontendActivity.announceBitRate(readB);
}
readB = 0;
}
}
} catch (IOException e) {
if (!isInterrupted()) {
throw new RuntimeException(e);
}
} finally {
try {
if (fos != null) fos.close();
} catch (IOException ignored) {
}
}
}
boolean isRecording() {
return recording;
}
void startRecording() throws FileNotFoundException {
synchronized (recordingLock) {
file = TsDumpFileUtils.getFor(dvbFrontendActivity.getApplicationContext(), currFreq, currBandwidth, new Date());
fos = new FileOutputStream(file, false);
recordedSize = 0;
recording = true;
}
}
void stopRecording() throws IOException {
synchronized (recordingLock) {
recording = false;
fos.close();
fos = null;
file = null;
}
}
}
| 4,182 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
GplLicenseActivity.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/app/src/main/java/info/martinmarinov/dvbdriver/GplLicenseActivity.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.dvbdriver;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.TextView;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
public class GplLicenseActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gpl_license);
findViewById(R.id.license_btnOk).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
((TextView) findViewById(R.id.license_Txt)).setText(readToText(getResources().openRawResource(R.raw.copying)));
}
private String readToText(InputStream inputStream) {
try {
Scanner s = new Scanner(inputStream, "UTF-8").useDelimiter("\\A");
return s.next();
} finally {
closeOrDie(inputStream);
}
}
private static void closeOrDie(Closeable c) {
try {
c.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
| 2,114 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
ExceptionDialog.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/app/src/main/java/info/martinmarinov/dvbdriver/ExceptionDialog.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.dvbdriver;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;
import android.widget.Toast;
import info.martinmarinov.dvbservice.dialogs.ShowOneInstanceFragmentDialog;
import info.martinmarinov.dvbservice.tools.StackTraceSerializer;
public class ExceptionDialog extends ShowOneInstanceFragmentDialog {
private static final String DIALOG_TAG = ExceptionDialog.class.getSimpleName();
private static final String ARGS_EXC = "argsExc";
private static final String ARGS_LAST_DEV = "argsLastDev";
public static void showOneInstanceOnly(FragmentManager fragmentManager, Exception e, String lastDeviceDebugString) {
ExceptionDialog dialog = new ExceptionDialog();
Bundle args = new Bundle();
args.putSerializable(ARGS_EXC, e);
args.putSerializable(ARGS_LAST_DEV, lastDeviceDebugString);
dialog.showOneInstanceOnly(fragmentManager, DIALOG_TAG, args);
}
private Exception e;
private String lastDeviceDebugString;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
e = (Exception) args.getSerializable(ARGS_EXC);
lastDeviceDebugString = args.getString(ARGS_LAST_DEV);
}
@Override
public @NonNull Dialog onCreateDialog(Bundle savedInstanceState) {
final String msg = getMessage(e);
return new AlertDialog.Builder(getActivity())
.setCancelable(true)
.setMessage(msg)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(android.R.string.dialog_alert_title)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
})
.setNeutralButton(R.string.send_email, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sendEmail(
new String[] { getString(R.string.email_feedback_address) },
getString(R.string.email_subject),
getString(R.string.email_body, msg, getConstants())
);
}
})
.create();
}
private String getConstants() {
StringBuilder res = new StringBuilder();
res.append("Last Device: ").append(lastDeviceDebugString).append('\n');
res.append("Build.MANUFACTURER: ").append(Build.MANUFACTURER).append('\n');
res.append("Build.MODEL: ").append(Build.MODEL).append('\n');
res.append("Build.PRODUCT: ").append(Build.PRODUCT).append('\n');
res.append("Build.VERSION.SDK_INT: ").append(Build.VERSION.SDK_INT).append('\n');
res.append("Build.VERSION.RELEASE: ").append(Build.VERSION.RELEASE).append('\n');
try {
PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
res.append("Driver versionName: ").append(packageInfo.versionName).append('\n');
res.append("Driver versionCode: ").append(packageInfo.versionCode).append('\n');
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return res.toString();
}
private static String getMessage(Exception e) {
return e.getLocalizedMessage() + "\n\n" + StackTraceSerializer.serialize(e);
}
private void sendEmail(String[] addresses, String subject, String message) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(intent);
} else {
Toast.makeText(getContext(), R.string.cannot_send_email, Toast.LENGTH_LONG).show();
}
}
}
| 5,441 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DeviceFilterMatcherTest.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/test/java/info/martinmarinov/drivers/DeviceFilterMatcherTest.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers;
import android.hardware.usb.UsbDevice;
import org.junit.Test;
import org.mockito.Mockito;
import info.martinmarinov.drivers.tools.DeviceFilterMatcher;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_PID_AVERMEDIA_A835;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_PID_HAUPPAUGE_MYTV_T;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_PID_REALTEK_RTL2831U;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_PID_REALTEK_RTL2832U;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_VID_AVERMEDIA;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_VID_HAUPPAUGE;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_VID_REALTEK;
import static info.martinmarinov.drivers.tools.SetUtils.setOf;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
public class DeviceFilterMatcherTest {
private final static DeviceFilterMatcher TEST_MATCHER = new DeviceFilterMatcher(setOf(
new DeviceFilter(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_MYTV_T, "HAUPPAUGE"),
new DeviceFilter(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U, "RTL2831U"),
new DeviceFilter(0xFFFF, 0xFFFF, "Edge case")
));
@Test
public void whenMatches() throws Exception {
assertThat(TEST_MATCHER.getFilter(mockUsbDevice(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_MYTV_T)).getName(), equalTo("HAUPPAUGE"));
assertThat(TEST_MATCHER.getFilter(mockUsbDevice(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U)).getName(), equalTo("RTL2831U"));
assertThat(TEST_MATCHER.getFilter(mockUsbDevice(0xFFFF, 0xFFFF)).getName(), equalTo("Edge case"));
}
@Test
public void whenDoesntMatch() throws Exception {
assertThat(TEST_MATCHER.getFilter(mockUsbDevice(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835)), nullValue());
assertThat(TEST_MATCHER.getFilter(mockUsbDevice(USB_VID_REALTEK, USB_PID_REALTEK_RTL2832U)), nullValue());
assertThat(TEST_MATCHER.getFilter(mockUsbDevice(0xFFFF, USB_PID_HAUPPAUGE_MYTV_T)), nullValue());
assertThat(TEST_MATCHER.getFilter(mockUsbDevice(USB_VID_HAUPPAUGE, 0xFFFF)), nullValue());
}
private static UsbDevice mockUsbDevice(int vendorId, int productId) {
UsbDevice mockUsbDevice = Mockito.mock(UsbDevice.class);
when(mockUsbDevice.getVendorId()).thenReturn(vendorId);
when(mockUsbDevice.getProductId()).thenReturn(productId);
return mockUsbDevice;
}
} | 3,464 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
FastIntFilterTest.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/test/java/info/martinmarinov/drivers/tools/FastIntFilterTest.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import org.junit.Before;
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class FastIntFilterTest {
private FastIntFilter f;
@Before
public void setUp() {
f = new FastIntFilter(20);
}
@Test
public void testSimpleCase() {
f.setFilter(0, 3, 8, 18, 19);
confirmOnlyFiltered(0, 3, 8, 18, 19);
}
@Test
public void testWithReset() {
f.setFilter(1, 7, 8, 17);
confirmOnlyFiltered(1, 7, 8, 17);
f.setFilter(0);
confirmOnlyFiltered(0);
f.setFilter(13, 19);
confirmOnlyFiltered(13, 19);
}
@Test
public void testSlightlyOverSize() {
f.setFilter(23); // Doesn't throw exception
}
@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testTrulyOverSize() {
f.setFilter(24);
}
private void confirmOnlyFiltered(int ... vals) {
Set<Integer> set = new HashSet<>();
for (int val : vals) set.add(val);
int filteredCount = 0;
for (int i = 0; i < 20; i++) {
boolean isActuallyFiltered = set.contains(i);
boolean isFiltered = f.isFiltered(i);
if (isFiltered) filteredCount++;
assertThat(isFiltered, is(isActuallyFiltered));
}
assertThat(filteredCount, is(vals.length));
}
} | 2,345 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbMathTest.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/test/java/info/martinmarinov/drivers/tools/DvbMathTest.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class DvbMathTest {
@Test
public void fls() throws Exception {
assertThat(DvbMath.fls(1), is(1));
assertThat(DvbMath.fls(0), is(0));
assertThat(DvbMath.fls(0x80000000), is(32));
}
@Test
public void intlog2() throws Exception {
assertThat(DvbMath.intlog2(8), is(3 << 24));
assertThat(DvbMath.intlog2(1024), is(10 << 24));
assertThat(DvbMath.intlog2(0x80000000), is(31 << 24));
}
@Test
public void intlog10() throws Exception {
//example: intlog10(1000) will give 3 << 24 = 3 * 2^24
// due to the implementation intlog10(1000) might be not exactly 3 * 2^24
assertThat(DvbMath.intlog10(1_000), is(50331675));
}
} | 1,742 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
ConvertCStringToJavaArrayTool.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/test/java/info/martinmarinov/drivers/tools/ConvertCStringToJavaArrayTool.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import org.junit.Test;
// This is an abuse of JUnit tests but it is handy so it is ok
public class ConvertCStringToJavaArrayTool {
@Test
public void doConvert() {
convert("\\xc0\\x00\\x0c\\x00\\x00\\x01\\x01\\x01\\x01\\x01\\x01\\x02\\x00\\x00\\x01");
}
private void convert(String s) {
System.out.println(s.replace("\\", ", (byte) 0"));
}
}
| 1,283 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
BitReverseTest.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/test/java/info/martinmarinov/drivers/tools/BitReverseTest.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
public class BitReverseTest {
@Test
public void bitRev8() throws Exception {
assertThat(BitReverse.bitRev8((byte) 0x00), is((byte) 0x00));
assertThat(BitReverse.bitRev8((byte) 0xFF), is((byte) 0xFF));
assertThat(BitReverse.bitRev8((byte) 0x40), is((byte) 0x02));
assertThat(BitReverse.bitRev8((byte) 0x02), is((byte) 0x40));
assertThat(BitReverse.bitRev8((byte) 0x80), is((byte) 0x01));
assertThat(BitReverse.bitRev8((byte) 0x01), is((byte) 0x80));
assertThat(BitReverse.bitRev8((byte) 0xA0), is((byte) 0x05));
assertThat(BitReverse.bitRev8((byte) 0x18), is((byte) 0x18));
assertThat(BitReverse.bitRev8((byte) 0x1C), is((byte) 0x38));
assertThat(BitReverse.bitRev8((byte) 0x38), is((byte) 0x1C));
}
@Test
public void bitRev16() throws Exception {
assertThat(BitReverse.bitRev16((short) 0x0001), is((short) 0x8000));
assertThat(BitReverse.bitRev16((short) 0x8000), is((short) 0x0001));
assertThat(BitReverse.bitRev16((short) 0xFF00), is((short) 0x00FF));
assertThat(BitReverse.bitRev16((short) 0xFFF0), is((short) 0x0FFF));
assertThat(BitReverse.bitRev16((short) 0x000F), is((short) 0xF000));
}
@Test
public void bitRev32() throws Exception {
assertThat(BitReverse.bitRev32(0x00000001), is(0x80000000));
assertThat(BitReverse.bitRev32(0x80000000), is(0x00000001));
assertThat(BitReverse.bitRev32(0x0F000000), is(0x000000F0));
assertThat(BitReverse.bitRev32(0x000000F0), is(0x0F000000));
assertThat(BitReverse.bitRev32(0xF0000000), is(0x0000000F));
assertThat(BitReverse.bitRev32(0x0000000F), is(0xF0000000));
assertThat(BitReverse.bitRev32(0xFF000000), is(0x000000FF));
assertThat(BitReverse.bitRev32(0x000000FF), is(0xFF000000));
assertThat(BitReverse.bitRev32(0xFFFFF0FF), is(0xFF0FFFFF));
assertThat(BitReverse.bitRev32(0xFF0FFFFF), is(0xFFFFF0FF));
assertThat(BitReverse.bitRev32(0xFFFFFFF0), is(0x0FFFFFFF));
assertThat(BitReverse.bitRev32(0x0FFFFFFF), is(0xFFFFFFF0));
}
} | 3,139 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
RegMapTest.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/test/java/info/martinmarinov/drivers/tools/RegMapTest.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
public class RegMapTest {
@Test
public void readValueTest64bit() {
long expected = 0x123456789ABCDEFFL;
long actual = RegMap.readValue(new byte[] {
(byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
(byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xFF
});
assertThat(actual, is(expected));
}
@Test
public void writeValueTest64bit() {
byte[] expected = new byte[] {
(byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
(byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0xFF
};
byte[] actual;
RegMap.writeValue(actual = new byte[8], 0x123456789ABCDEFFL);
assertThat(actual, is(expected));
}
@Test
public void readValueTest16bit() {
long expected = 0x1234L;
long actual = RegMap.readValue(new byte[] {
(byte) 0x12, (byte) 0x34
});
assertThat(actual, is(expected));
}
@Test
public void writeValueTest16bit() {
byte[] expected = new byte[] {
(byte) 0x12, (byte) 0x34
};
byte[] actual;
RegMap.writeValue(actual = new byte[2], 0x1234L);
assertThat(actual, is(expected));
}
} | 2,277 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbDevice.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/DvbDevice.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers;
import androidx.annotation.NonNull;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
import info.martinmarinov.usbxfer.ByteSource;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
public abstract class DvbDevice implements Closeable {
private final DvbDemux dvbDemux;
private DataPump dataPump;
protected DvbDevice(DvbDemux dvbDemux) {
this.dvbDemux = dvbDemux;
}
public abstract void open() throws DvbException;
public abstract DeviceFilter getDeviceFilter();
public abstract DvbCapabilities readCapabilities() throws DvbException;
public abstract int readSnr() throws DvbException;
public abstract int readRfStrengthPercentage() throws DvbException;
public abstract int readBitErrorRate() throws DvbException;
public abstract Set<DvbStatus> getStatus() throws DvbException;
// Debug string to identify device for debugging purposes
public abstract String getDebugString();
protected abstract void tuneTo(long freqHz, long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException;
public final void tune(long freqHz, long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException {
tuneTo(freqHz, bandwidthHz, deliverySystem);
if (dvbDemux != null) dvbDemux.reset();
}
public int readDroppedUsbFps() throws DvbException {
return dvbDemux.getDroppedUsbFps();
}
public void setPidFilter(int... pids) throws DvbException {
dvbDemux.setPidFilter(pids);
}
public void disablePidFilter()throws DvbException {
dvbDemux.disablePidFilter();
}
@Override
public void close() throws IOException {
while (dataPump != null && dataPump.isAlive()) {
dataPump.interrupt();
try {
dataPump.join();
} catch (InterruptedException ignored) {}
}
dvbDemux.close();
}
public InputStream getTransportStream(StreamCallback streamCallback) throws DvbException {
if (dataPump != null && dataPump.isAlive()) throw new DvbException(BAD_API_USAGE, "Data stream is still running. Please close the input stream first to start a new one");
dataPump = new DataPump(streamCallback);
dataPump.start();
return dvbDemux.getInputStream();
}
public interface StreamCallback {
void onStreamException(IOException exception);
void onStoppedStreaming();
}
protected abstract ByteSource createTsSource();
/** This thread reads from the USB device as quickly as possible and puts it into the circular buffer.
* This thread also does pid filtering. **/
private class DataPump extends Thread {
private final StreamCallback callback;
private DataPump(StreamCallback callback) {
this.callback = callback;
}
@Override
public void interrupt() {
super.interrupt();
try {
dvbDemux.close();
} catch (IOException e) {
e.printStackTrace();
// Close the pipes
}
}
@Override
public void run() {
setName(DataPump.class.getSimpleName());
setPriority(MAX_PRIORITY);
ByteSource tsSource = createTsSource();
try {
tsSource.open();
dvbDemux.reset();
while (!isInterrupted()) {
try {
tsSource.readNext(dvbDemux);
} catch (IOException e) {
// Pipe is closed from other end
interrupt();
}
}
} catch (InterruptedException ignored) {
// interrupted is ok
} catch (IOException e) {
callback.onStreamException(e);
} finally {
try {
tsSource.close();
} catch (IOException e) {
e.printStackTrace();
}
callback.onStoppedStreaming();
}
}
}
}
| 5,126 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbDemux.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/DvbDemux.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import info.martinmarinov.drivers.tools.FastIntFilter;
import info.martinmarinov.usbxfer.ByteSink;
import info.martinmarinov.drivers.tools.io.NativePipe;
public class DvbDemux implements ByteSink,Closeable {
private static final boolean DVB_DEMUX_FEED_ERR_PKTS = true;
private static final boolean CHECK_PACKET_INTEGRITY = true;
private final int pktSize;
private final byte[] tsBuf = new byte[204];
private final NativePipe pipe;
private final OutputStream out;
private final FastIntFilter filter = new FastIntFilter(0x1fff);
@SuppressWarnings("ConstantConditions")
private final byte[] cntStorage = CHECK_PACKET_INTEGRITY ? new byte[(0x1fff / 2) + 1] : null;
private int tsBufP = 0;
private int droppedUsbFps;
private long lastUpdated;
private boolean passFullTsStream = false;
public static DvbDemux DvbDmxSwfilter() {
return new DvbDemux(188);
}
private DvbDemux(int pktSize) {
this.pktSize = pktSize;
this.pipe = new NativePipe();
this.out = pipe.getOutputStream();
reset();
}
void setPidFilter(int ... pids) {
passFullTsStream = false;
filter.setFilter(pids);
}
void disablePidFilter() {
passFullTsStream = true;
}
@Override
public void consume(byte[] buf, int count) throws IOException {
int p = 0;
if (tsBufP != 0) { /* tsbuf[0] is now 0x47. */
int i = tsBufP;
int j = pktSize - i;
if (count < j) {
System.arraycopy(buf, 0, tsBuf, i, count);
tsBufP += count;
return;
}
System.arraycopy(buf, 0, tsBuf, i, j);
if ((tsBuf[0] & 0xFF) == 0x47) { /* double check */
swfilterPacket(tsBuf, 0);
}
tsBufP = 0;
p += j;
}
while (true) {
p = findNextPacket(buf, p, count);
if (p >= count) {
break;
}
if (count - p < pktSize) {
break;
}
if (pktSize == 204 && (buf[p] & 0xFF) == 0xB8) {
System.arraycopy(buf, p, tsBuf, 0, 188);
tsBuf[0] = (byte) 0x47;
swfilterPacket(tsBuf, 0);
} else {
swfilterPacket(buf, p);
}
p += pktSize;
}
int i = count - p;
if (i != 0) {
System.arraycopy(buf, p, tsBuf, 0, i);
tsBufP = i;
if (pktSize == 204 && (tsBuf[0] & 0xFF) == 0xB8) {
tsBuf[0] = (byte) 0x47;
}
}
}
int getDroppedUsbFps() {
long now = System.currentTimeMillis();
long elapsed = now - lastUpdated;
lastUpdated = now;
double fps = droppedUsbFps * 1000.0 / elapsed;
droppedUsbFps = 0;
return (int) Math.abs(fps);
}
private int findNextPacket(byte[] buf, int pos, int count) {
int start = pos, lost;
while (pos < count) {
if ((buf[pos] & 0xFF) == 0x47 ||
(pktSize == 204 && (buf[pos] & 0xFF) == 0xB8)) {
break;
}
pos++;
}
lost = pos - start;
if (lost != 0) {
/* This garbage is part of a valid packet? */
int backtrack = pos - pktSize;
if (backtrack >= 0 && ((buf[backtrack] & 0xFF) == 0x47 ||
(pktSize == 204 && (buf[backtrack] & 0xFF) == 0xB8))) {
return backtrack;
}
}
return pos;
}
private void swfilterPacket(byte[] buf, int offset) throws IOException {
int pid = tsPid(buf, offset);
if ((buf[offset+1] & 0x80) != 0) {
droppedUsbFps++; // count this as dropped frame
/* data in this packet cant be trusted - drop it unless
* constant DVB_DEMUX_FEED_ERR_PKTS is set */
if (!DVB_DEMUX_FEED_ERR_PKTS) return;
} else {
if (CHECK_PACKET_INTEGRITY) {
if (!checkSequenceIntegrity(pid, buf, offset)) droppedUsbFps++;
}
}
if (passFullTsStream || filter.isFiltered(pid)) out.write(buf, offset, 188);
}
private boolean checkSequenceIntegrity(int pid, byte[] buf, int offset) {
if (pid == 0x1FFF) return true; // This PID is garbage that should be ignored always
int pidLoc = pid >> 1;
if ((pid & 1) == 0) {
// even pids are stored on left
if ((buf[offset + 3] & 0x10) != 0) {
int val = ((cntStorage[pidLoc] & 0xF0) + 0x10) & 0xF0;
cntStorage[pidLoc] = (byte) ((cntStorage[pidLoc] & 0x0F) | val);
}
if ((buf[offset + 3] & 0x0F) != ((cntStorage[pidLoc] & 0xF0) >> 4)) {
int val = (buf[offset + 3] & 0x0F) << 4;
cntStorage[pidLoc] = (byte) ((cntStorage[pidLoc] & 0x0F) | val);
return false;
} else {
return true;
}
} else {
// odd pids are stored on right
if ((buf[offset + 3] & 0x10) != 0) {
int val = ((cntStorage[pidLoc] & 0x0F) + 0x01) & 0x0F;
cntStorage[pidLoc] = (byte) ((cntStorage[pidLoc] & 0xF0) | val);
}
if ((buf[offset + 3] & 0x0F) != (cntStorage[pidLoc] & 0x0F)) {
int val = buf[offset + 3] & 0x0F;
cntStorage[pidLoc] = (byte) ((cntStorage[pidLoc] & 0xF0) | val);
return false;
} else {
return true;
}
}
}
private static int tsPid(byte[] buf, int offset) {
return ((buf[offset+1] & 0x1F) << 8) + (buf[offset+2] & 0xFF);
}
void reset() {
droppedUsbFps = 0;
lastUpdated = System.currentTimeMillis();
if (!passFullTsStream) setPidFilter(0); // by default we let through only pid 0
}
@Override
public void close() throws IOException {
pipe.close();
}
InputStream getInputStream() {
return pipe.getInputStream();
}
}
| 7,169 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbException.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/DvbException.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers;
import java.io.IOException;
public class DvbException extends IOException {
public enum ErrorCode {
BAD_API_USAGE,
IO_EXCEPTION,
NO_DVB_DEVICES_FOUND,
UNSUPPORTED_PLATFORM,
USB_PERMISSION_DENIED,
CANNOT_OPEN_USB,
HARDWARE_EXCEPTION,
CANNOT_TUNE_TO_FREQ,
UNSUPPORTED_BANDWIDTH,
DVB_DEVICE_UNSUPPORTED
}
private final ErrorCode errorCode;
public DvbException(ErrorCode errorCode, String message) {
super(message);
this.errorCode = errorCode;
}
public DvbException(ErrorCode errorCode, String message, Exception e) {
super(message, e);
this.errorCode = errorCode;
}
public DvbException(ErrorCode errorCode, Exception e) {
super(e);
this.errorCode = errorCode;
}
public ErrorCode getErrorCode() {
return errorCode;
}
}
| 1,799 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbStatus.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/DvbStatus.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers;
public enum DvbStatus {
FE_HAS_SIGNAL,
FE_HAS_CARRIER,
FE_HAS_VITERBI,
FE_HAS_SYNC,
FE_HAS_LOCK,
FE_TIMEDOUT,
FE_REINIT
}
| 1,048 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbCapabilities.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/DvbCapabilities.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers;
import androidx.annotation.NonNull;
import java.util.Set;
public class DvbCapabilities {
private final long frequencyMin;
private final long frequencyMax;
private final long frequencyStepSize;
private final @NonNull Set<DeliverySystem> supportedDeliverySystems;
public DvbCapabilities(long frequencyMin, long frequencyMax, long frequencyStepSize, @NonNull Set<DeliverySystem> supportedDeliverySystems) {
this.frequencyMin = frequencyMin;
this.frequencyMax = frequencyMax;
this.frequencyStepSize = frequencyStepSize;
this.supportedDeliverySystems = supportedDeliverySystems;
}
public long getFrequencyMin() {
return frequencyMin;
}
public long getFrequencyMax() {
return frequencyMax;
}
public long getFrequencyStepSize() {
return frequencyStepSize;
}
public @NonNull Set<DeliverySystem> getSupportedDeliverySystems() {
return supportedDeliverySystems;
}
@Override
public String toString() {
return "DvbCapabilities{" +
"frequencyMin=" + frequencyMin +
", frequencyMax=" + frequencyMax +
", frequencyStepSize=" + frequencyStepSize +
", supportedDeliverySystems=" + supportedDeliverySystems +
'}';
}
}
| 2,227 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DeliverySystem.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/DeliverySystem.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers;
public enum DeliverySystem {
// Warning: Do not reorder!
// The order is used by the TCP clients so any reordering will cause API incompatibilities
DVBT, DVBT2, DVBC
}
| 1,078 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DeviceFilter.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/DeviceFilter.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers;
import android.hardware.usb.UsbDevice;
import androidx.annotation.NonNull;
import java.io.Serializable;
public class DeviceFilter implements Serializable {
private final int vendorId;
private final int productId;
private final String name;
public DeviceFilter(int vendorId, int productId, String name) {
this.vendorId = vendorId;
this.productId = productId;
this.name = name;
}
public boolean matches(@NonNull UsbDevice usbDevice) {
return usbDevice.getVendorId() == vendorId && usbDevice.getProductId() == productId;
}
public int getVendorId() {
return vendorId;
}
public int getProductId() {
return productId;
}
public String getName() {
return name;
}
@SuppressWarnings("SimplifiableIfStatement")
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DeviceFilter that = (DeviceFilter) o;
if (vendorId != that.vendorId) return false;
return productId == that.productId;
}
@Override
public int hashCode() {
int result = vendorId;
result = 31 * result + productId;
return result;
}
@Override
public String toString() {
return name;
}
}
| 2,245 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbFrontend.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/DvbFrontend.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb;
import androidx.annotation.NonNull;
import java.util.Set;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.DvbStatus;
public interface DvbFrontend {
// TODO these capabilities contain frequency min and max which is actually determined by tuner
DvbCapabilities getCapabilities();
void attach() throws DvbException;
void release(); // release should always succeed or fail catastrophically
// don't forget to call tuner.init() from here!
void init(DvbTuner tuner) throws DvbException;
void setParams(long frequency, long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException;
int readSnr() throws DvbException;
int readRfStrengthPercentage() throws DvbException;
int readBer() throws DvbException;
Set<DvbStatus> getStatus() throws DvbException;
void setPids(int ... pids) throws DvbException;
void disablePidFilter() throws DvbException;
}
| 1,952 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbUsbDevice.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/DvbUsbDevice.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.UNSUPPORTED_PLATFORM;
import static info.martinmarinov.drivers.DvbException.ErrorCode.USB_PERMISSION_DENIED;
import static info.martinmarinov.drivers.tools.Retry.retry;
import android.content.Context;
import android.content.res.Resources;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.util.Log;
import androidx.annotation.NonNull;
import java.io.IOException;
import java.util.Set;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.DvbDemux;
import info.martinmarinov.drivers.DvbDevice;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.DvbStatus;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.Check;
import info.martinmarinov.drivers.tools.ThrowingCallable;
import info.martinmarinov.drivers.tools.ThrowingRunnable;
import info.martinmarinov.drivers.tools.UsbPermissionObtainer;
import info.martinmarinov.usbxfer.AlternateUsbInterface;
import info.martinmarinov.usbxfer.ByteSource;
import info.martinmarinov.usbxfer.UsbBulkSource;
import info.martinmarinov.usbxfer.UsbHiSpeedBulk;
public abstract class DvbUsbDevice extends DvbDevice {
private final static int RETRIES = 4;
public interface Creator {
/**
* Try to instantiate a {@link DvbDevice} with the provided {@link UsbDevice} instance.
* @param usbDevice a usb device that is attached to the system
* @param context the application context, used for accessing usb system service and obtaining permissions
* @param filter
* @return a {@link DvbDevice} instance to control the device if the current creator supports it
* or null if the {@link UsbDevice} is not supported by the creator.
*/
DvbDevice create(UsbDevice usbDevice, Context context, DeviceFilter filter) throws DvbException;
Set<DeviceFilter> getSupportedDevices();
}
private final static String TAG = DvbUsbDevice.class.getSimpleName();
private final UsbDevice usbDevice;
protected final Resources resources;
private final Context context;
private final DeviceFilter deviceFilter;
protected DvbFrontend frontend;
protected DvbTuner tuner;
protected UsbDeviceConnection usbDeviceConnection;
private AlternateUsbInterface usbInterface;
private DvbCapabilities capabilities;
protected DvbUsbDevice(UsbDevice usbDevice, Context context, DeviceFilter deviceFilter, DvbDemux dvbDemux) throws DvbException {
super(dvbDemux);
this.usbDevice = usbDevice;
this.context = context;
this.resources = context.getResources();
this.deviceFilter = deviceFilter;
if (!UsbHiSpeedBulk.IS_PLATFORM_SUPPORTED) throw new DvbException(UNSUPPORTED_PLATFORM, resources.getString(R.string.unsuported_platform));
}
@Override
public final void open() throws DvbException {
try {
usbDeviceConnection = UsbPermissionObtainer.obtainFdFor(context, usbDevice).get();
if (usbDeviceConnection == null)
throw new DvbException(USB_PERMISSION_DENIED, resources.getString(R.string.cannot_open_usb_connection));
usbInterface = getUsbInterface();
retry(RETRIES, new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
powerControl(true);
readConfig();
frontend = frontendAttatch();
frontend.attach();
// capabilities should only be accessed after frontend is attached
capabilities = frontend.getCapabilities();
tuner = tunerAttatch();
tuner.attatch();
frontend.init(tuner);
init();
}
});
} catch (DvbException e) {
throw e;
} catch (Exception e) {
throw new DvbException(BAD_API_USAGE, e);
}
}
@Override
public final void close() throws IOException {
super.close();
if (usbDeviceConnection != null) {
if (frontend != null) frontend.release();
if (tuner != null) tuner.release();
try {
powerControl(false);
} catch (DvbException e) {
e.printStackTrace();
}
usbDeviceConnection.close();
}
Log.d(TAG, "closed");
}
@Override
public DeviceFilter getDeviceFilter() {
return deviceFilter;
}
@Override
public String toString() {
return deviceFilter.getName();
}
@Override
public void setPidFilter(int... pids) throws DvbException {
super.setPidFilter(pids);
frontend.setPids(pids);
}
@Override
public void disablePidFilter() throws DvbException {
super.disablePidFilter();
frontend.disablePidFilter();
}
@Override
public DvbCapabilities readCapabilities() throws DvbException {
Check.notNull(capabilities, "Frontend not initialized");
return capabilities;
}
@Override
protected void tuneTo(final long freqHz, final long bandwidthHz, @NonNull final DeliverySystem deliverySystem) throws DvbException {
Check.notNull(frontend, "Frontend not initialized");
retry(RETRIES, new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
frontend.setParams(freqHz, bandwidthHz, deliverySystem);
}
});
}
@Override
public int readSnr() throws DvbException {
Check.notNull(frontend, "Frontend not initialized");
return retry(RETRIES, new ThrowingCallable<Integer, DvbException>() {
@Override
public Integer call() throws DvbException {
return frontend.readSnr();
}
});
}
@Override
public int readRfStrengthPercentage() throws DvbException {
Check.notNull(frontend, "Frontend not initialized");
return retry(RETRIES, new ThrowingCallable<Integer, DvbException>() {
@Override
public Integer call() throws DvbException {
return frontend.readRfStrengthPercentage();
}
});
}
@Override
public int readBitErrorRate() throws DvbException {
Check.notNull(frontend, "Frontend not initialized");
return retry(RETRIES, new ThrowingCallable<Integer, DvbException>() {
@Override
public Integer call() throws DvbException {
return frontend.readBer();
}
});
}
@Override
public Set<DvbStatus> getStatus() throws DvbException {
Check.notNull(frontend, "Frontend not initialized");
return retry(RETRIES, new ThrowingCallable<Set<DvbStatus>, DvbException>() {
@Override
public Set<DvbStatus> call() throws DvbException {
return frontend.getStatus();
}
});
}
protected int getNumRequests() {
return 40;
}
protected int getNumPacketsPerRequest() {
return 10;
}
@Override
protected ByteSource createTsSource() {
return new UsbBulkSource(usbDeviceConnection, getUsbEndpoint(), usbInterface, getNumRequests(), getNumPacketsPerRequest());
}
/** API for drivers to implement **/
// Turn tuner on or off
protected abstract void powerControl(boolean turnOn) throws DvbException;
// Allows determining the tuner type so correct commands could be used later
protected abstract void readConfig() throws DvbException;
protected abstract DvbFrontend frontendAttatch() throws DvbException;
protected abstract DvbTuner tunerAttatch() throws DvbException;
protected abstract void init() throws DvbException;
protected abstract AlternateUsbInterface getUsbInterface();
protected abstract UsbEndpoint getUsbEndpoint();
}
| 9,264 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbTuner.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/DvbTuner.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbException;
public interface DvbTuner {
void attatch() throws DvbException;
void release(); // release should always succeed or fail catastrophically
void init() throws DvbException;
void setParams(long frequency, long bandwidthHz, DeliverySystem deliverySystem) throws DvbException;
long getIfFrequency() throws DvbException;
int readRfStrengthPercentage() throws DvbException;
}
| 1,394 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbUsbIds.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/DvbUsbIds.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb;
@SuppressWarnings({"unused", "SpellCheckingInspection"})
public class DvbUsbIds {
/* Vendor IDs */
public static final int USB_VID_ADSTECH = 0x06e1;
public static final int USB_VID_AFATECH = 0x15a4;
public static final int USB_VID_ALCOR_MICRO = 0x058f;
public static final int USB_VID_ALINK = 0x05e3;
public static final int USB_VID_AMT = 0x1c73;
public static final int USB_VID_ANCHOR = 0x0547;
public static final int USB_VID_ANSONIC = 0x10b9;
public static final int USB_VID_ANUBIS_ELECTRONIC = 0x10fd;
public static final int USB_VID_ASUS = 0x0b05;
public static final int USB_VID_AVERMEDIA = 0x07ca;
public static final int USB_VID_COMPRO = 0x185b;
public static final int USB_VID_COMPRO_UNK = 0x145f;
public static final int USB_VID_CONEXANT = 0x0572;
public static final int USB_VID_CYPRESS = 0x04b4;
public static final int USB_VID_DEXATEK = 0x1d19;
public static final int USB_VID_DIBCOM = 0x10b8;
public static final int USB_VID_DPOSH = 0x1498;
public static final int USB_VID_DVICO = 0x0fe9;
public static final int USB_VID_E3C = 0x18b4;
public static final int USB_VID_ELGATO = 0x0fd9;
public static final int USB_VID_EMPIA = 0xeb1a;
public static final int USB_VID_GENPIX = 0x09c0;
public static final int USB_VID_GRANDTEC = 0x5032;
public static final int USB_VID_GTEK = 0x1f4d;
public static final int USB_VID_HANFTEK = 0x15f4;
public static final int USB_VID_HAUPPAUGE = 0x2040;
public static final int USB_VID_HYPER_PALTEK = 0x1025;
public static final int USB_VID_INTEL = 0x8086;
public static final int USB_VID_ITETECH = 0x048d;
public static final int USB_VID_KWORLD = 0xeb2a;
public static final int USB_VID_KWORLD_2 = 0x1b80;
public static final int USB_VID_KYE = 0x0458;
public static final int USB_VID_LEADTEK = 0x0413;
public static final int USB_VID_LITEON = 0x04ca;
public static final int USB_VID_MEDION = 0x1660;
public static final int USB_VID_MIGLIA = 0x18f3;
public static final int USB_VID_MSI = 0x0db0;
public static final int USB_VID_MSI_2 = 0x1462;
public static final int USB_VID_OPERA1 = 0x695c;
public static final int USB_VID_PINNACLE = 0x2304;
public static final int USB_VID_PCTV = 0x2013;
public static final int USB_VID_PIXELVIEW = 0x1554;
public static final int USB_VID_REALTEK = 0x0bda;
public static final int USB_VID_TECHNOTREND = 0x0b48;
public static final int USB_VID_TERRATEC = 0x0ccd;
public static final int USB_VID_TELESTAR = 0x10b9;
public static final int USB_VID_VISIONPLUS = 0x13d3;
public static final int USB_VID_SONY = 0x1415;
public static final int USB_PID_TEVII_S421 = 0xd421;
public static final int USB_PID_TEVII_S480_1 = 0xd481;
public static final int USB_PID_TEVII_S480_2 = 0xd482;
public static final int USB_PID_TEVII_S630 = 0xd630;
public static final int USB_PID_TEVII_S632 = 0xd632;
public static final int USB_PID_TEVII_S650 = 0xd650;
public static final int USB_PID_TEVII_S660 = 0xd660;
public static final int USB_PID_TEVII_S662 = 0xd662;
public static final int USB_VID_TWINHAN = 0x1822;
public static final int USB_VID_ULTIMA_ELECTRONIC = 0x05d8;
public static final int USB_VID_UNIWILL = 0x1584;
public static final int USB_VID_WIDEVIEW = 0x14aa;
public static final int USB_VID_GIGABYTE = 0x1044;
public static final int USB_VID_YUAN = 0x1164;
public static final int USB_VID_XTENSIONS = 0x1ae7;
public static final int USB_VID_HUMAX_COEX = 0x10b9;
public static final int USB_VID_774 = 0x7a69;
public static final int USB_VID_EVOLUTEPC = 0x1e59;
public static final int USB_VID_AZUREWAVE = 0x13d3;
public static final int USB_VID_TECHNISAT = 0x14f7;
public static final int USB_VID_LEAGUERME = 0x3344;
/* Product IDs */
public static final int USB_PID_ADSTECH_USB2_COLD = 0xa333;
public static final int USB_PID_ADSTECH_USB2_WARM = 0xa334;
public static final int USB_PID_AFATECH_AF9005 = 0x9020;
public static final int USB_PID_AFATECH_AF9015_9015 = 0x9015;
public static final int USB_PID_AFATECH_AF9015_9016 = 0x9016;
public static final int USB_PID_AFATECH_AF9035_1000 = 0x1000;
public static final int USB_PID_AFATECH_AF9035_1001 = 0x1001;
public static final int USB_PID_AFATECH_AF9035_1002 = 0x1002;
public static final int USB_PID_AFATECH_AF9035_1003 = 0x1003;
public static final int USB_PID_AFATECH_AF9035_9035 = 0x9035;
public static final int USB_PID_TREKSTOR_DVBT = 0x901b;
public static final int USB_PID_TREKSTOR_TERRES_2_0 = 0xC803;
public static final int USB_VID_ALINK_DTU = 0xf170;
public static final int USB_PID_ANSONIC_DVBT_USB = 0x6000;
public static final int USB_PID_ANYSEE = 0x861f;
public static final int USB_PID_AZUREWAVE_AD_TU700 = 0x3237;
public static final int USB_PID_AZUREWAVE_6007 = 0x0ccd;
public static final int USB_PID_AVERMEDIA_DVBT_USB_COLD = 0x0001;
public static final int USB_PID_AVERMEDIA_DVBT_USB_WARM = 0x0002;
public static final int USB_PID_AVERMEDIA_DVBT_USB2_COLD = 0xa800;
public static final int USB_PID_AVERMEDIA_DVBT_USB2_WARM = 0xa801;
public static final int USB_PID_COMPRO_DVBU2000_COLD = 0xd000;
public static final int USB_PID_COMPRO_DVBU2000_WARM = 0xd001;
public static final int USB_PID_COMPRO_DVBU2000_UNK_COLD = 0x010c;
public static final int USB_PID_COMPRO_DVBU2000_UNK_WARM = 0x010d;
public static final int USB_PID_COMPRO_VIDEOMATE_U500 = 0x1e78;
public static final int USB_PID_COMPRO_VIDEOMATE_U500_PC = 0x1e80;
public static final int USB_PID_CONCEPTRONIC_CTVDIGRCU = 0xe397;
public static final int USB_PID_CONEXANT_D680_DMB = 0x86d6;
public static final int USB_PID_CREATIX_CTX1921 = 0x1921;
public static final int USB_PID_DELOCK_USB2_DVBT = 0xb803;
public static final int USB_PID_DIBCOM_HOOK_DEFAULT = 0x0064;
public static final int USB_PID_DIBCOM_HOOK_DEFAULT_REENUM = 0x0065;
public static final int USB_PID_DIBCOM_MOD3000_COLD = 0x0bb8;
public static final int USB_PID_DIBCOM_MOD3000_WARM = 0x0bb9;
public static final int USB_PID_DIBCOM_MOD3001_COLD = 0x0bc6;
public static final int USB_PID_DIBCOM_MOD3001_WARM = 0x0bc7;
public static final int USB_PID_DIBCOM_STK7700P = 0x1e14;
public static final int USB_PID_DIBCOM_STK7700P_PC = 0x1e78;
public static final int USB_PID_DIBCOM_STK7700D = 0x1ef0;
public static final int USB_PID_DIBCOM_STK7700_U7000 = 0x7001;
public static final int USB_PID_DIBCOM_STK7070P = 0x1ebc;
public static final int USB_PID_DIBCOM_STK7070PD = 0x1ebe;
public static final int USB_PID_DIBCOM_STK807XP = 0x1f90;
public static final int USB_PID_DIBCOM_STK807XPVR = 0x1f98;
public static final int USB_PID_DIBCOM_STK8096GP = 0x1fa0;
public static final int USB_PID_DIBCOM_STK8096PVR = 0x1faa;
public static final int USB_PID_DIBCOM_NIM8096MD = 0x1fa8;
public static final int USB_PID_DIBCOM_TFE8096P = 0x1f9C;
public static final int USB_PID_DIBCOM_ANCHOR_2135_COLD = 0x2131;
public static final int USB_PID_DIBCOM_STK7770P = 0x1e80;
public static final int USB_PID_DIBCOM_NIM7090 = 0x1bb2;
public static final int USB_PID_DIBCOM_TFE7090PVR = 0x1bb4;
public static final int USB_PID_DIBCOM_TFE7790P = 0x1e6e;
public static final int USB_PID_DIBCOM_NIM9090M = 0x2383;
public static final int USB_PID_DIBCOM_NIM9090MD = 0x2384;
public static final int USB_PID_DPOSH_M9206_COLD = 0x9206;
public static final int USB_PID_DPOSH_M9206_WARM = 0xa090;
public static final int USB_PID_E3C_EC168 = 0x1689;
public static final int USB_PID_E3C_EC168_2 = 0xfffa;
public static final int USB_PID_E3C_EC168_3 = 0xfffb;
public static final int USB_PID_E3C_EC168_4 = 0x1001;
public static final int USB_PID_E3C_EC168_5 = 0x1002;
public static final int USB_PID_FREECOM_DVBT = 0x0160;
public static final int USB_PID_FREECOM_DVBT_2 = 0x0161;
public static final int USB_PID_UNIWILL_STK7700P = 0x6003;
public static final int USB_PID_GENIUS_TVGO_DVB_T03 = 0x4012;
public static final int USB_PID_GRANDTEC_DVBT_USB_COLD = 0x0fa0;
public static final int USB_PID_GRANDTEC_DVBT_USB_WARM = 0x0fa1;
public static final int USB_PID_GOTVIEW_SAT_HD = 0x5456;
public static final int USB_PID_INTEL_CE9500 = 0x9500;
public static final int USB_PID_ITETECH_IT9135 = 0x9135;
public static final int USB_PID_ITETECH_IT9135_9005 = 0x9005;
public static final int USB_PID_ITETECH_IT9135_9006 = 0x9006;
public static final int USB_PID_ITETECH_IT9303 = 0x9306;
public static final int USB_PID_KWORLD_399U = 0xe399;
public static final int USB_PID_KWORLD_399U_2 = 0xe400;
public static final int USB_PID_KWORLD_395U = 0xe396;
public static final int USB_PID_KWORLD_395U_2 = 0xe39b;
public static final int USB_PID_KWORLD_395U_3 = 0xe395;
public static final int USB_PID_KWORLD_395U_4 = 0xe39a;
public static final int USB_PID_KWORLD_MC810 = 0xc810;
public static final int USB_PID_KWORLD_PC160_2T = 0xc160;
public static final int USB_PID_KWORLD_PC160_T = 0xc161;
public static final int USB_PID_KWORLD_UB383_T = 0xe383;
public static final int USB_PID_KWORLD_UB499_2T_T09 = 0xe409;
public static final int USB_PID_KWORLD_VSTREAM_COLD = 0x17de;
public static final int USB_PID_KWORLD_VSTREAM_WARM = 0x17df;
public static final int USB_PID_PROF_1100 = 0xb012;
public static final int USB_PID_TERRATEC_CINERGY_S = 0x0064;
public static final int USB_PID_TERRATEC_CINERGY_T_USB_XE = 0x0055;
public static final int USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2 = 0x0069;
public static final int USB_PID_TERRATEC_CINERGY_T_STICK = 0x0093;
public static final int USB_PID_TERRATEC_CINERGY_T_STICK_RC = 0x0097;
public static final int USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC = 0x0099;
public static final int USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1 = 0x00a9;
public static final int USB_PID_TWINHAN_VP7041_COLD = 0x3201;
public static final int USB_PID_TWINHAN_VP7041_WARM = 0x3202;
public static final int USB_PID_TWINHAN_VP7020_COLD = 0x3203;
public static final int USB_PID_TWINHAN_VP7020_WARM = 0x3204;
public static final int USB_PID_TWINHAN_VP7045_COLD = 0x3205;
public static final int USB_PID_TWINHAN_VP7045_WARM = 0x3206;
public static final int USB_PID_TWINHAN_VP7021_COLD = 0x3207;
public static final int USB_PID_TWINHAN_VP7021_WARM = 0x3208;
public static final int USB_PID_TWINHAN_VP7049 = 0x3219;
public static final int USB_PID_TINYTWIN = 0x3226;
public static final int USB_PID_TINYTWIN_2 = 0xe402;
public static final int USB_PID_TINYTWIN_3 = 0x9016;
public static final int USB_PID_DNTV_TINYUSB2_COLD = 0x3223;
public static final int USB_PID_DNTV_TINYUSB2_WARM = 0x3224;
public static final int USB_PID_ULTIMA_TVBOX_COLD = 0x8105;
public static final int USB_PID_ULTIMA_TVBOX_WARM = 0x8106;
public static final int USB_PID_ULTIMA_TVBOX_AN2235_COLD = 0x8107;
public static final int USB_PID_ULTIMA_TVBOX_AN2235_WARM = 0x8108;
public static final int USB_PID_ULTIMA_TVBOX_ANCHOR_COLD = 0x2235;
public static final int USB_PID_ULTIMA_TVBOX_USB2_COLD = 0x8109;
public static final int USB_PID_ULTIMA_TVBOX_USB2_WARM = 0x810a;
public static final int USB_PID_ARTEC_T14_COLD = 0x810b;
public static final int USB_PID_ARTEC_T14_WARM = 0x810c;
public static final int USB_PID_ARTEC_T14BR = 0x810f;
public static final int USB_PID_ULTIMA_TVBOX_USB2_FX_COLD = 0x8613;
public static final int USB_PID_ULTIMA_TVBOX_USB2_FX_WARM = 0x1002;
public static final int USB_PID_UNK_HYPER_PALTEK_COLD = 0x005e;
public static final int USB_PID_UNK_HYPER_PALTEK_WARM = 0x005f;
public static final int USB_PID_HANFTEK_UMT_010_COLD = 0x0001;
public static final int USB_PID_HANFTEK_UMT_010_WARM = 0x0015;
public static final int USB_PID_DTT200U_COLD = 0x0201;
public static final int USB_PID_DTT200U_WARM = 0x0301;
public static final int USB_PID_WT220U_ZAP250_COLD = 0x0220;
public static final int USB_PID_WT220U_COLD = 0x0222;
public static final int USB_PID_WT220U_WARM = 0x0221;
public static final int USB_PID_WT220U_FC_COLD = 0x0225;
public static final int USB_PID_WT220U_FC_WARM = 0x0226;
public static final int USB_PID_WT220U_ZL0353_COLD = 0x022a;
public static final int USB_PID_WT220U_ZL0353_WARM = 0x022b;
public static final int USB_PID_WINTV_NOVA_T_USB2_COLD = 0x9300;
public static final int USB_PID_WINTV_NOVA_T_USB2_WARM = 0x9301;
public static final int USB_PID_HAUPPAUGE_NOVA_T_500 = 0x9941;
public static final int USB_PID_HAUPPAUGE_NOVA_T_500_2 = 0x9950;
public static final int USB_PID_HAUPPAUGE_NOVA_T_500_3 = 0x8400;
public static final int USB_PID_HAUPPAUGE_NOVA_T_STICK = 0x7050;
public static final int USB_PID_HAUPPAUGE_NOVA_T_STICK_2 = 0x7060;
public static final int USB_PID_HAUPPAUGE_NOVA_T_STICK_3 = 0x7070;
public static final int USB_PID_HAUPPAUGE_MYTV_T = 0x7080;
public static final int USB_PID_HAUPPAUGE_NOVA_TD_STICK = 0x9580;
public static final int USB_PID_HAUPPAUGE_NOVA_TD_STICK_52009 = 0x5200;
public static final int USB_PID_HAUPPAUGE_TIGER_ATSC = 0xb200;
public static final int USB_PID_HAUPPAUGE_TIGER_ATSC_B210 = 0xb210;
public static final int USB_PID_AVERMEDIA_EXPRESS = 0xb568;
public static final int USB_PID_AVERMEDIA_VOLAR = 0xa807;
public static final int USB_PID_AVERMEDIA_VOLAR_2 = 0xb808;
public static final int USB_PID_AVERMEDIA_VOLAR_A868R = 0xa868;
public static final int USB_PID_AVERMEDIA_MCE_USB_M038 = 0x1228;
public static final int USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R = 0x0039;
public static final int USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R_ATSC = 0x1039;
public static final int USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R_DVBT = 0x2039;
public static final int USB_PID_AVERMEDIA_VOLAR_X = 0xa815;
public static final int USB_PID_AVERMEDIA_VOLAR_X_2 = 0x8150;
public static final int USB_PID_AVERMEDIA_A309 = 0xa309;
public static final int USB_PID_AVERMEDIA_A310 = 0xa310;
public static final int USB_PID_AVERMEDIA_A850 = 0x850a;
public static final int USB_PID_AVERMEDIA_A850T = 0x850b;
public static final int USB_PID_AVERMEDIA_A805 = 0xa805;
public static final int USB_PID_AVERMEDIA_A815M = 0x815a;
public static final int USB_PID_AVERMEDIA_A835 = 0xa835;
public static final int USB_PID_AVERMEDIA_B835 = 0xb835;
public static final int USB_PID_AVERMEDIA_A835B_1835 = 0x1835;
public static final int USB_PID_AVERMEDIA_A835B_2835 = 0x2835;
public static final int USB_PID_AVERMEDIA_A835B_3835 = 0x3835;
public static final int USB_PID_AVERMEDIA_A835B_4835 = 0x4835;
public static final int USB_PID_AVERMEDIA_1867 = 0x1867;
public static final int USB_PID_AVERMEDIA_A867 = 0xa867;
public static final int USB_PID_AVERMEDIA_H335 = 0x0335;
public static final int USB_PID_AVERMEDIA_TD110 = 0xa110;
public static final int USB_PID_AVERMEDIA_TWINSTAR = 0x0825;
public static final int USB_PID_TECHNOTREND_CONNECT_S2400 = 0x3006;
public static final int USB_PID_TECHNOTREND_CONNECT_S2400_8KEEPROM = 0x3009;
public static final int USB_PID_TECHNOTREND_CONNECT_CT3650 = 0x300d;
public static final int USB_PID_TECHNOTREND_CONNECT_S2_4600 = 0x3011;
public static final int USB_PID_TECHNOTREND_CONNECT_CT2_4650_CI = 0x3012;
public static final int USB_PID_TECHNOTREND_CONNECT_CT2_4650_CI_2 = 0x3015;
public static final int USB_PID_TECHNOTREND_TVSTICK_CT2_4400 = 0x3014;
public static final int USB_PID_TECHNOTREND_CONNECT_S2_4650_CI = 0x3017;
public static final int USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY = 0x005a;
public static final int USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2 = 0x0081;
public static final int USB_PID_TERRATEC_CINERGY_HT_USB_XE = 0x0058;
public static final int USB_PID_TERRATEC_CINERGY_HT_EXPRESS = 0x0060;
public static final int USB_PID_TERRATEC_CINERGY_T_EXPRESS = 0x0062;
public static final int USB_PID_TERRATEC_CINERGY_T_XXS = 0x0078;
public static final int USB_PID_TERRATEC_CINERGY_T_XXS_2 = 0x00ab;
public static final int USB_PID_TERRATEC_CINERGY_S2_R1 = 0x00a8;
public static final int USB_PID_TERRATEC_CINERGY_S2_R2 = 0x00b0;
public static final int USB_PID_TERRATEC_CINERGY_S2_R3 = 0x0102;
public static final int USB_PID_TERRATEC_CINERGY_S2_R4 = 0x0105;
public static final int USB_PID_TERRATEC_H7 = 0x10b4;
public static final int USB_PID_TERRATEC_H7_2 = 0x10a3;
public static final int USB_PID_TERRATEC_H7_3 = 0x10a5;
public static final int USB_PID_TERRATEC_T3 = 0x10a0;
public static final int USB_PID_TERRATEC_T5 = 0x10a1;
public static final int USB_PID_NOXON_DAB_STICK = 0x00b3;
public static final int USB_PID_NOXON_DAB_STICK_REV2 = 0x00e0;
public static final int USB_PID_NOXON_DAB_STICK_REV3 = 0x00b4;
public static final int USB_PID_PINNACLE_EXPRESSCARD_320CX = 0x022e;
public static final int USB_PID_PINNACLE_PCTV2000E = 0x022c;
public static final int USB_PID_PINNACLE_PCTV_DVB_T_FLASH = 0x0228;
public static final int USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T = 0x0229;
public static final int USB_PID_PINNACLE_PCTV71E = 0x022b;
public static final int USB_PID_PINNACLE_PCTV72E = 0x0236;
public static final int USB_PID_PINNACLE_PCTV73E = 0x0237;
public static final int USB_PID_PINNACLE_PCTV310E = 0x3211;
public static final int USB_PID_PINNACLE_PCTV801E = 0x023a;
public static final int USB_PID_PINNACLE_PCTV801E_SE = 0x023b;
public static final int USB_PID_PINNACLE_PCTV340E = 0x023d;
public static final int USB_PID_PINNACLE_PCTV340E_SE = 0x023e;
public static final int USB_PID_PINNACLE_PCTV73A = 0x0243;
public static final int USB_PID_PINNACLE_PCTV73ESE = 0x0245;
public static final int USB_PID_PINNACLE_PCTV74E = 0x0246;
public static final int USB_PID_PINNACLE_PCTV282E = 0x0248;
public static final int USB_PID_PIXELVIEW_SBTVD = 0x5010;
public static final int USB_PID_PCTV_200E = 0x020e;
public static final int USB_PID_PCTV_400E = 0x020f;
public static final int USB_PID_PCTV_450E = 0x0222;
public static final int USB_PID_PCTV_452E = 0x021f;
public static final int USB_PID_PCTV_78E = 0x025a;
public static final int USB_PID_PCTV_79E = 0x0262;
public static final int USB_PID_REALTEK_RTL2831U = 0x2831;
public static final int USB_PID_REALTEK_RTL2832U = 0x2832;
public static final int USB_PID_TECHNOTREND_CONNECT_S2_3600 = 0x3007;
public static final int USB_PID_TECHNOTREND_CONNECT_S2_3650_CI = 0x300a;
public static final int USB_PID_NEBULA_DIGITV = 0x0201;
public static final int USB_PID_DVICO_BLUEBIRD_LGDT = 0xd820;
public static final int USB_PID_DVICO_BLUEBIRD_LG064F_COLD = 0xd500;
public static final int USB_PID_DVICO_BLUEBIRD_LG064F_WARM = 0xd501;
public static final int USB_PID_DVICO_BLUEBIRD_LGZ201_COLD = 0xdb00;
public static final int USB_PID_DVICO_BLUEBIRD_LGZ201_WARM = 0xdb01;
public static final int USB_PID_DVICO_BLUEBIRD_TH7579_COLD = 0xdb10;
public static final int USB_PID_DVICO_BLUEBIRD_TH7579_WARM = 0xdb11;
public static final int USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD = 0xdb50;
public static final int USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM = 0xdb51;
public static final int USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD = 0xdb58;
public static final int USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM = 0xdb59;
public static final int USB_PID_DVICO_BLUEBIRD_DUAL_4 = 0xdb78;
public static final int USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2 = 0xdb98;
public static final int USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2 = 0xdb70;
public static final int USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM = 0xdb71;
public static final int USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD = 0xdb54;
public static final int USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM = 0xdb55;
public static final int USB_PID_MEDION_MD95700 = 0x0932;
public static final int USB_PID_MSI_MEGASKY580 = 0x5580;
public static final int USB_PID_MSI_MEGASKY580_55801 = 0x5581;
public static final int USB_PID_KYE_DVB_T_COLD = 0x701e;
public static final int USB_PID_KYE_DVB_T_WARM = 0x701f;
public static final int USB_PID_LITEON_DVB_T_COLD = 0xf000;
public static final int USB_PID_LITEON_DVB_T_WARM = 0xf001;
public static final int USB_PID_DIGIVOX_MINI_SL_COLD = 0xe360;
public static final int USB_PID_DIGIVOX_MINI_SL_WARM = 0xe361;
public static final int USB_PID_GRANDTEC_DVBT_USB2_COLD = 0x0bc6;
public static final int USB_PID_GRANDTEC_DVBT_USB2_WARM = 0x0bc7;
public static final int USB_PID_WINFAST_DTV2000DS = 0x6a04;
public static final int USB_PID_WINFAST_DTV2000DS_PLUS = 0x6f12;
public static final int USB_PID_WINFAST_DTV_DONGLE_COLD = 0x6025;
public static final int USB_PID_WINFAST_DTV_DONGLE_WARM = 0x6026;
public static final int USB_PID_WINFAST_DTV_DONGLE_STK7700P = 0x6f00;
public static final int USB_PID_WINFAST_DTV_DONGLE_H = 0x60f6;
public static final int USB_PID_WINFAST_DTV_DONGLE_STK7700P_2 = 0x6f01;
public static final int USB_PID_WINFAST_DTV_DONGLE_GOLD = 0x6029;
public static final int USB_PID_WINFAST_DTV_DONGLE_MINID = 0x6f0f;
public static final int USB_PID_GENPIX_8PSK_REV_1_COLD = 0x0200;
public static final int USB_PID_GENPIX_8PSK_REV_1_WARM = 0x0201;
public static final int USB_PID_GENPIX_8PSK_REV_2 = 0x0202;
public static final int USB_PID_GENPIX_SKYWALKER_1 = 0x0203;
public static final int USB_PID_GENPIX_SKYWALKER_CW3K = 0x0204;
public static final int USB_PID_GENPIX_SKYWALKER_2 = 0x0206;
public static final int USB_PID_SIGMATEK_DVB_110 = 0x6610;
public static final int USB_PID_MSI_DIGI_VOX_MINI_II = 0x1513;
public static final int USB_PID_MSI_DIGIVOX_DUO = 0x8801;
public static final int USB_PID_OPERA1_COLD = 0x2830;
public static final int USB_PID_OPERA1_WARM = 0x3829;
public static final int USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD = 0x0514;
public static final int USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM = 0x0513;
public static final int USB_PID_GIGABYTE_U7000 = 0x7001;
public static final int USB_PID_GIGABYTE_U8000 = 0x7002;
public static final int USB_PID_ASUS_U3000 = 0x171f;
public static final int USB_PID_ASUS_U3000H = 0x1736;
public static final int USB_PID_ASUS_U3100 = 0x173f;
public static final int USB_PID_ASUS_U3100MINI_PLUS = 0x1779;
public static final int USB_PID_YUAN_EC372S = 0x1edc;
public static final int USB_PID_YUAN_STK7700PH = 0x1f08;
public static final int USB_PID_YUAN_PD378S = 0x2edc;
public static final int USB_PID_YUAN_MC770 = 0x0871;
public static final int USB_PID_YUAN_STK7700D = 0x1efc;
public static final int USB_PID_YUAN_STK7700D_2 = 0x1e8c;
public static final int USB_PID_DW2102 = 0x2102;
public static final int USB_PID_DW2104 = 0x2104;
public static final int USB_PID_DW3101 = 0x3101;
public static final int USB_PID_XTENSIONS_XD_380 = 0x0381;
public static final int USB_PID_TELESTAR_STARSTICK_2 = 0x8000;
public static final int USB_PID_MSI_DIGI_VOX_MINI_III = 0x8807;
public static final int USB_PID_SONY_PLAYTV = 0x0003;
public static final int USB_PID_MYGICA_D689 = 0xd811;
public static final int USB_PID_MYGICA_T230 = 0xc688;
public static final int USB_PID_GENIATECH_T230C = 0xc689;
public static final int USB_PID_ELGATO_EYETV_DIVERSITY = 0x0011;
public static final int USB_PID_ELGATO_EYETV_DTT = 0x0021;
public static final int USB_PID_ELGATO_EYETV_DTT_2 = 0x003f;
public static final int USB_PID_ELGATO_EYETV_DTT_Dlx = 0x0020;
public static final int USB_PID_ELGATO_EYETV_SAT = 0x002a;
public static final int USB_PID_ELGATO_EYETV_SAT_V2 = 0x0025;
public static final int USB_PID_ELGATO_EYETV_SAT_V3 = 0x0036;
public static final int USB_PID_DVB_T_USB_STICK_HIGH_SPEED_COLD = 0x5000;
public static final int USB_PID_DVB_T_USB_STICK_HIGH_SPEED_WARM = 0x5001;
public static final int USB_PID_FRIIO_WHITE = 0x0001;
public static final int USB_PID_TVWAY_PLUS = 0x0002;
public static final int USB_PID_SVEON_STV20 = 0xe39d;
public static final int USB_PID_SVEON_STV20_RTL2832U = 0xd39d;
public static final int USB_PID_SVEON_STV21 = 0xd3b0;
public static final int USB_PID_SVEON_STV22 = 0xe401;
public static final int USB_PID_SVEON_STV22_IT9137 = 0xe411;
public static final int USB_PID_AZUREWAVE_AZ6027 = 0x3275;
public static final int USB_PID_TERRATEC_DVBS2CI_V1 = 0x10a4;
public static final int USB_PID_TERRATEC_DVBS2CI_V2 = 0x10ac;
public static final int USB_PID_TECHNISAT_USB2_HDCI_V1 = 0x0001;
public static final int USB_PID_TECHNISAT_USB2_HDCI_V2 = 0x0002;
public static final int USB_PID_TECHNISAT_USB2_CABLESTAR_HDCI = 0x0003;
public static final int USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2 = 0x0004;
public static final int USB_PID_TECHNISAT_USB2_DVB_S2 = 0x0500;
public static final int USB_PID_CPYTO_REDI_PC50A = 0xa803;
public static final int USB_PID_CTVDIGDUAL_V2 = 0xe410;
public static final int USB_PID_PCTV_2002E = 0x025c;
public static final int USB_PID_PCTV_2002E_SE = 0x025d;
public static final int USB_PID_SVEON_STV27 = 0xd3af;
public static final int USB_PID_TURBOX_DTT_2000 = 0xd3a4;
public static final int USB_PID_WINTV_SOLOHD = 0x0264;
public static final int USB_PID_EVOLVEO_XTRATV_STICK = 0xa115;
public static final int USB_PID_SINHON_TDH601 = 0x24a0;
}
| 26,750 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbUsbDeviceRegistry.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/DvbUsbDeviceRegistry.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbDevice;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.tools.DeviceFilterMatcher;
import info.martinmarinov.drivers.usb.af9035.Af9035DvbDeviceCreator;
import info.martinmarinov.drivers.usb.cxusb.CxUsbDvbDeviceCreator;
import info.martinmarinov.drivers.usb.rtl28xx.Rtl2xx2DvbDeviceCreator;
public class DvbUsbDeviceRegistry {
public static DvbUsbDevice.Creator[] AVAILABLE_DRIVERS = new DvbUsbDevice.Creator[] {
new Rtl2xx2DvbDeviceCreator(),
new CxUsbDvbDeviceCreator(),
new Af9035DvbDeviceCreator()
};
/**
* Checks if the {@link UsbDevice} could be handled by the available drivers and returns a
* {@link DvbDevice} if the device is supported.
* @param usbDevice a {@link UsbDevice} device that is attached to the system
* @param context the application context, used for accessing usb system service and obtaining permissions
* @return a valid {@link DvbDevice} to control the {@link UsbDevice} as a DVB frontend or
* a null if none of the available drivers can handle the provided {@link UsbDevice}
*/
private static DvbDevice getDvbUsbDeviceFor(UsbDevice usbDevice, Context context) throws DvbException {
for (DvbUsbDevice.Creator c : AVAILABLE_DRIVERS) {
DeviceFilterMatcher deviceFilterMatcher = new DeviceFilterMatcher(c.getSupportedDevices());
DeviceFilter filter = deviceFilterMatcher.getFilter(usbDevice);
if (filter != null) {
DvbDevice dvbDevice = c.create(usbDevice, context, filter);
if (dvbDevice != null) return dvbDevice;
}
}
return null;
}
/**
* Gets a {@link DvbDevice} if a supported DVB USB dongle is connected to the system.
* If multiple dongles are connected, a {@link Collection} would be returned
* @param context a context for obtaining {@link Context#USB_SERVICE}
* @return a {@link Collection} of available {@link DvbDevice} devices. Can be empty.
*/
public static List<DvbDevice> getUsbDvbDevices(Context context) throws DvbException {
List<DvbDevice> availableDvbDevices = new ArrayList<>();
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
Collection<UsbDevice> availableDevices = manager.getDeviceList().values();
DvbException lastException = null;
for (UsbDevice usbDevice : availableDevices) {
try {
DvbDevice frontend = getDvbUsbDeviceFor(usbDevice, context);
if (frontend != null) availableDvbDevices.add(frontend);
} catch (DvbException e) {
// Failed to initialize this device, try next and capture exception
e.printStackTrace();
lastException = e;
}
}
if (availableDvbDevices.isEmpty()) {
if (lastException != null) throw lastException;
}
return availableDvbDevices;
}
}
| 4,197 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Si2157.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/silabs/Si2157.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.silabs;
import android.content.res.Resources;
import androidx.annotation.NonNull;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.I2cAdapter;
import info.martinmarinov.drivers.tools.ThrowingRunnable;
import info.martinmarinov.drivers.usb.DvbTuner;
import static info.martinmarinov.drivers.DeliverySystem.DVBC;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_TUNE_TO_FREQ;
import static info.martinmarinov.drivers.DvbException.ErrorCode.DVB_DEVICE_UNSUPPORTED;
import static info.martinmarinov.drivers.DvbException.ErrorCode.HARDWARE_EXCEPTION;
import static info.martinmarinov.drivers.DvbException.ErrorCode.IO_EXCEPTION;
import static info.martinmarinov.drivers.usb.silabs.Si2157.Type.SI2157_CHIPTYPE_SI2141;
import static info.martinmarinov.drivers.usb.silabs.Si2157.Type.SI2157_CHIPTYPE_SI2146;
public class Si2157 implements DvbTuner {
public enum Type {
SI2157_CHIPTYPE_SI2157,
SI2157_CHIPTYPE_SI2146,
SI2157_CHIPTYPE_SI2141
}
private final static String TAG = Si2157.class.getSimpleName();
private final static byte[] EMPTY = new byte[0];
private final static int TIMEOUT_MS = 500;
private final static int SI2157_ARGLEN = 30;
private final static boolean INVERSION = false;
private final static int SI2158_A20 = (('A' << 24) | (58 << 16) | ('2' << 8) | '0');
private final static int SI2148_A20 = (('A' << 24) | (48 << 16) | ('2' << 8) | '0');
private final static int SI2157_A30 = (('A' << 24) | (57 << 16) | ('3' << 8) | '0');
private final static int SI2147_A30 = (('A' << 24) | (47 << 16) | ('3' << 8) | '0');
private final static int SI2146_A10 = (('A' << 24) | (46 << 16) | ('1' << 8) | '0');
private final static int SI2141_A10 = (('A' << 24) | (41 << 16) | ('1' << 8) | '0');
private final Resources resources;
private final I2cAdapter i2c;
private final I2cAdapter.I2GateControl i2GateControl;
private final int addr;
private final boolean if_port;
private final Type chiptype;
private int if_frequency = 5_000_000; /* default value of property 0x0706 */
private boolean active = false;
public Si2157(Resources resources, I2cAdapter i2c, I2cAdapter.I2GateControl i2GateControl, int addr, boolean if_port, Type chiptype) {
this.resources = resources;
this.i2c = i2c;
this.i2GateControl = i2GateControl;
this.addr = addr;
this.if_port = if_port;
this.chiptype = chiptype;
}
private synchronized @NonNull byte[] si2157_cmd_execute(@NonNull byte[] wargs, int wlen, int rlen) throws DvbException {
if (wlen > 0 && wlen == wargs.length) {
i2c.send(addr, wargs, wlen);
} else {
if (wlen != 0) throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
if (rlen > 0) {
byte[] rout = new byte[rlen];
long startTime = System.nanoTime();
long endTime = startTime + TIMEOUT_MS * 1_000_000L;
while (System.nanoTime() < endTime) {
i2c.recv(addr, rout, rlen);
if ((((rout[0] & 0xFF) >> 7) & 0x01) != 0) {
break;
}
}
if ((((rout[0] & 0xFF) >> 7) & 0x01) == 0) {
throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.timed_out_read_from_register));
}
// Log.d(TAG,String.format("cmd execution took %d ms", (System.nanoTime() - startTime)/1000));
return rout;
}
return EMPTY;
}
@Override
public void attatch() throws DvbException {
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
/* check if the tuner is there */
si2157_cmd_execute(new byte[0], 0, 1);
Log.d(TAG, String.format("Silicon Labs %s successfully attached", ((chiptype == SI2157_CHIPTYPE_SI2141) ? "Si2141" : (chiptype == SI2157_CHIPTYPE_SI2146 ? "Si2146" : "Si2147/2148/2157/2158"))));
}
});
}
@Override
public void release() {
active = false;
try {
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
si2157_cmd_execute(new byte[]{(byte) 0x16, (byte) 0x00}, 2, 1);
}
});
} catch (DvbException e) {
e.printStackTrace();
}
}
@Override
public void init() throws DvbException {
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
/* Returned if_frequency is garbage when firmware is not running */
byte[] res = si2157_cmd_execute(new byte[]{(byte) 0x15, (byte) 0x00, (byte) 0x06, (byte) 0x07}, 4, 4);
int if_freq_khz = (res[2] & 0xFF) | ((res[3] & 0xFF) << 8);
Log.d(TAG, "if_frequency KHz " + if_freq_khz);
if (if_freq_khz != if_frequency / 1000) {
/* power up */
if (chiptype == SI2157_CHIPTYPE_SI2146) {
si2157_cmd_execute(new byte[]{(byte) 0xc0, (byte) 0x05, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x0b, (byte) 0x00, (byte) 0x00, (byte) 0x01}, 9, 1);
} else if (chiptype == SI2157_CHIPTYPE_SI2141) {
si2157_cmd_execute(new byte[]{(byte) 0xc0, (byte) 0x00, (byte) 0x0d, (byte) 0x0e, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x03}, 10, 1);
} else {
si2157_cmd_execute(new byte[]{(byte) 0xc0, (byte) 0x00, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x01}, 15, 1);
}
/* Si2141 needs a second command before it answers the revision query */
if (chiptype == SI2157_CHIPTYPE_SI2141) {
si2157_cmd_execute(new byte[]{(byte) 0xc0, (byte) 0x08, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x01}, 7, 1);
}
/* query chip revision */
res = si2157_cmd_execute(new byte[]{(byte) 0x02}, 1, 13);
int chip_id = ((res[1] & 0xFF) << 24) | ((res[2] & 0xFF) << 16) | ((res[3] & 0xFF) << 8) | (res[4] & 0xFF);
Log.d(TAG, "found a Silicon Labs Si21" + (res[2] & 0xFF) + "-" + ((char) (res[1] & 0xFF)) + " " + ((char) (res[3] & 0xFF)) + " " + ((char) (res[4] & 0xFF)));
int firmwareRawId = -1;
switch (chip_id) {
case SI2158_A20:
case SI2148_A20: {
firmwareRawId = R.raw.dvbtunersi2158a2001fw;
break;
}
case SI2141_A10: {
firmwareRawId = R.raw.dvbtunersi2141a1001fw;
break;
}
case SI2157_A30:
case SI2147_A30:
case SI2146_A10: {
firmwareRawId = 0;
Log.d(TAG, "No need to load fw");
break;
}
default:
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unsupported_tuner_on_device));
}
if (firmwareRawId > 0) {
loadFirmware(firmwareRawId);
}
/* reboot the tuner with new firmware? */
si2157_cmd_execute(new byte[]{(byte) 0x01, (byte) 0x01}, 2, 1);
/* query firmware version */
res = si2157_cmd_execute(new byte[]{(byte) 0x11}, 1, 10);
Log.d(TAG, "firmware version: " + ((char) (res[6] & 0xFF)) + "." + ((char) (res[7] & 0xFF)) + "." + (res[8] & 0xFF));
}
active = true;
}
});
}
private void loadFirmware(int firmware) throws DvbException {
try {
byte[] fw = readFirmware(firmware);
/* firmware should be n chunks of 17 bytes */
if (fw.length % 17 != 0) {
throw new DvbException(IO_EXCEPTION, resources.getString(R.string.cannot_load_firmware));
}
Log.d(TAG, "Downloading firmware");
for (int remaining = fw.length; remaining > 0; remaining -= 17) {
int len = fw[fw.length - remaining] & 0xFF;
if (len > SI2157_ARGLEN) {
throw new DvbException(IO_EXCEPTION, resources.getString(R.string.cannot_load_firmware));
}
byte[] args = new byte[len];
System.arraycopy(fw, fw.length - remaining + 1, args, 0, len);
si2157_cmd_execute(args, len, 1);
}
} catch (IOException e) {
throw new DvbException(IO_EXCEPTION, e);
}
}
private byte[] readFirmware(int resource) throws IOException {
InputStream inputStream = resources.openRawResource(resource);
//noinspection TryFinallyCanBeTryWithResources
try {
byte[] fw = new byte[inputStream.available()];
if (inputStream.read(fw) != fw.length) {
throw new DvbException(IO_EXCEPTION, resources.getString(R.string.cannot_load_firmware));
}
return fw;
} finally {
inputStream.close();
}
}
@Override
public void setParams(final long frequency, final long bandwidthHz, final DeliverySystem deliverySystem) throws DvbException {
if (!active) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
if (!active) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
int bandwidth;
if (bandwidthHz <= 6_000_000L) {
bandwidth = 0x06;
} else if (bandwidthHz <= 7_000_000L) {
bandwidth = 0x07;
} else if (bandwidthHz <= 8_000_000L) {
bandwidth = 0x08;
} else {
bandwidth = 0x0f;
}
int delivery_system;
int if_frequency = 5_000_000;
switch (deliverySystem) {
case DVBT:
case DVBT2: /* it seems DVB-T and DVB-T2 both are 0x20 here */
delivery_system = 0x20;
break;
case DVBC:
delivery_system = 0x30;
break;
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
si2157_cmd_execute(
new byte[]{
(byte) 0x14, (byte) 0x00, (byte) 0x03, (byte) 0x07, (byte) (delivery_system | bandwidth), (byte) (INVERSION ? 0x01 : 0x00)
}, 6, 4
);
/* set if_port */
if (chiptype == SI2157_CHIPTYPE_SI2146) {
si2157_cmd_execute(new byte[]{(byte) 0x14, (byte) 0x00, (byte) 0x02, (byte) 0x07, (byte) (if_port ? 1 : 0), (byte) 0x01}, 6, 4);
} else {
si2157_cmd_execute(new byte[]{(byte) 0x14, (byte) 0x00, (byte) 0x02, (byte) 0x07, (byte) (if_port ? 1 : 0), (byte) 0x00}, 6, 4);
}
/* set LIF out amp */
si2157_cmd_execute(new byte[]{(byte) 0x14, (byte) 0x00, (byte) 0x07, (byte) 0x07, (byte) 0x94, (byte) (deliverySystem == DVBC ? 0x2B : 0x20)}, 6, 4);
/* set if_frequency if needed */
if (if_frequency != Si2157.this.if_frequency) {
si2157_cmd_execute(new byte[]{(byte) 0x14, (byte) 0x00, (byte) 0x06, (byte) 0x07, (byte) ((if_frequency / 1000) & 0xff), (byte) (((if_frequency / 1000) >> 8) & 0xff)}, 6, 4);
Si2157.this.if_frequency = if_frequency;
}
/* set frequency */
si2157_cmd_execute(new byte[]{
(byte) 0x41, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) (frequency & 0xff),
(byte) ((frequency >> 8) & 0xff),
(byte) ((frequency >> 16) & 0xff),
(byte) ((frequency >> 24) & 0xff)
}, 8, 1);
}
});
}
@Override
public long getIfFrequency() throws DvbException {
return if_frequency;
}
@Override
public int readRfStrengthPercentage() throws DvbException {
if (!active) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
byte[] res = si2157_cmd_execute(new byte[] {0x42, 0x00}, 2, 12);
int raw = res[3] & 0xFF;
// raw is in decibels
// this below is a horrible way of doing some percentage conversion
raw -= 40;
return raw < 10 ? 10 : (raw > 100 ? 100 : raw);
}
}
| 15,044 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Si2168Data.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/silabs/Si2168Data.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.silabs;
import androidx.annotation.Nullable;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.SetUtils;
public class Si2168Data {
enum Si2168Chip {
SI2168_CHIP_ID_A20(('A' << 24) | (68 << 16) | ('2' << 8) | '0', R.raw.dvbdemodsi2168a2001fw),
SI2168_CHIP_ID_A30(('A' << 24) | (68 << 16) | ('3' << 8) | '0', R.raw.dvbdemodsi2168a3001fw),
SI2168_CHIP_ID_B40(('B' << 24) | (68 << 16) | ('4' << 8) | '0', R.raw.dvbdemodsi2168b4001fw),
SI2168_CHIP_ID_D60(('D' << 24) | (68 << 16) | ('6' << 8) | '0', R.raw.dvbdemodsi2168d6001fw);
private final int id;
final int firmwareFile;
Si2168Chip(int id, int firmwareFile) {
this.id = id;
this.firmwareFile = firmwareFile;
}
static @Nullable Si2168Chip fromId(int id) {
for (Si2168Chip chip : values()) {
if (chip.id == id) return chip;
}
return null;
}
}
final static DvbCapabilities CAPABILITIES = new DvbCapabilities(
42_000_000L,
870_000_000L,
166667L,
SetUtils.setOf(DeliverySystem.DVBT, DeliverySystem.DVBT2, DeliverySystem.DVBC));
}
| 2,226 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Si2168.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/silabs/Si2168.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.silabs;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_TUNE_TO_FREQ;
import static info.martinmarinov.drivers.DvbException.ErrorCode.DVB_DEVICE_UNSUPPORTED;
import static info.martinmarinov.drivers.DvbException.ErrorCode.HARDWARE_EXCEPTION;
import static info.martinmarinov.drivers.DvbException.ErrorCode.IO_EXCEPTION;
import static info.martinmarinov.drivers.DvbException.ErrorCode.UNSUPPORTED_BANDWIDTH;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_CARRIER;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_LOCK;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_SIGNAL;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_SYNC;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_VITERBI;
import static info.martinmarinov.drivers.usb.cxusb.CxUsbDvbDevice.SI2168_ARGLEN;
import android.content.res.Resources;
import android.util.Log;
import androidx.annotation.NonNull;
import java.io.IOException;
import java.io.InputStream;
import java.util.Set;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.DvbStatus;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.I2cAdapter;
import info.martinmarinov.drivers.tools.SetUtils;
import info.martinmarinov.drivers.usb.DvbFrontend;
import info.martinmarinov.drivers.usb.DvbTuner;
import info.martinmarinov.drivers.usb.DvbUsbDevice;
import info.martinmarinov.drivers.usb.cxusb.CxUsbDvbDevice;
public class Si2168 implements DvbFrontend {
private final static String TAG = Si2168.class.getSimpleName();
private final static byte[] EMPTY = new byte[0];
private final static int TIMEOUT_MS = 70;
private final static int NO_STREAM_ID_FILTER = 0xFFFFFFFF;
private final static int DVBT2_STREAM_ID = 0;
private final static int DVBC_SYMBOL_RATE = 0;
private final Resources resources;
private final I2cAdapter i2c;
private final int addr;
private final int ts_mode;
private final int ts_clock_mode;
private final boolean ts_clock_inv;
private final boolean ts_clock_gapped;
private DvbUsbDevice usbDevice;
private int version;
private boolean warm = false;
private boolean active = false;
private Si2168Data.Si2168Chip chip;
private DvbTuner tuner;
private DeliverySystem deliverySystem;
private boolean hasLockStatus = false;
public Si2168(DvbUsbDevice usbDevice, Resources resources, I2cAdapter i2c, int addr, int ts_mode, boolean ts_clock_inv, int ts_clock_mode, boolean ts_clock_gapped) {
this.usbDevice = usbDevice;
this.resources = resources;
this.i2c = i2c;
this.addr = addr;
this.ts_mode = ts_mode;
this.ts_clock_inv = ts_clock_inv;
this.ts_clock_mode = ts_clock_mode;
this.ts_clock_gapped = ts_clock_gapped;
}
private void si2168_cmd_execute_wr(byte[] wargs, int wlen) throws DvbException {
si2168_cmd_execute(wargs, wlen, 0);
}
private synchronized @NonNull byte[] si2168_cmd_execute(@NonNull byte[] wargs, int wlen, int rlen) throws DvbException {
if (wlen > 0 && wlen == wargs.length) {
i2c.send(addr, wargs, wlen);
} else {
if (wlen != 0) throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
if (rlen > 0) {
byte[] rout = new byte[rlen];
long endTime = System.nanoTime() + TIMEOUT_MS * 1_000_000L;
while (System.nanoTime() < endTime) {
i2c.recv(addr, rout, rlen);
if ((((rout[0] & 0xFF) >> 7) & 0x01) != 0) {
break;
}
}
if ((((rout[0] & 0xFF) >> 6) & 0x01) != 0) {
throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.failed_to_read_from_register));
}
if ((((rout[0] & 0xFF) >> 7) & 0x01) == 0) {
throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.timed_out_read_from_register));
}
return rout;
}
return EMPTY;
}
@Override
public synchronized DvbCapabilities getCapabilities() {
return Si2168Data.CAPABILITIES;
}
@Override
public synchronized void attach() throws DvbException {
/* Initialize */
si2168_cmd_execute_wr(
new byte[] {(byte) 0xc0, (byte) 0x12, (byte) 0x00, (byte) 0x0c, (byte) 0x00, (byte) 0x0d, (byte) 0x16, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00},
13
);
/* Power up */
si2168_cmd_execute(
new byte[] {(byte) 0xc0, (byte) 0x06, (byte) 0x01, (byte) 0x0f, (byte) 0x00, (byte) 0x20, (byte) 0x20, (byte) 0x01},
8, 1
);
/* Query chip revision */
byte[] chipInfo = si2168_cmd_execute(new byte[] {0x02}, 1, 13);
int chipId = ((chipInfo[1] & 0xFF) << 24) | ((chipInfo[2] & 0xFF) << 16) | ((chipInfo[3] & 0xFF) << 8) | (chipInfo[4] & 0xFF);
chip = Si2168Data.Si2168Chip.fromId(chipId);
if (chip == null) {
Log.w(TAG, String.format("unknown chip version Si21%d-%c%c%c", chipInfo[2] & 0xFF, chipInfo[1] & 0xFF, chipInfo[3] & 0xFF, chipInfo[4] & 0xFF));
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unsupported_tuner_on_device));
}
version = ((chipInfo[1] & 0xFF) << 24) | (((chipInfo[3] & 0xFF) - '0') << 16) | (((chipInfo[4] & 0xFF) - '0') << 8) | (chipInfo[5] & 0xFF);
Log.d(TAG, "Chip " + chip + " successfully identified");
}
@Override
public synchronized void release() {
active = false;
/* Firmware B 4.0-11 or later loses warm state during sleep */
if (version >= ('B' << 24 | 4 << 16 | 11)) {
warm = false;
}
try {
si2168_cmd_execute_wr(new byte[]{(byte) 0x13}, 1);
} catch (DvbException e) {
e.printStackTrace();
}
}
@Override
public synchronized void init(DvbTuner tuner) throws DvbException {
this.tuner = tuner;
/* initialize */
si2168_cmd_execute_wr(new byte[] {(byte) 0xc0, (byte) 0x12, (byte) 0x00, (byte) 0x0c, (byte) 0x00, (byte) 0x0d, (byte) 0x16, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00}, 13);
if (warm) {
/* resume */
si2168_cmd_execute(new byte[] {(byte) 0xc0, (byte) 0x06, (byte) 0x08, (byte) 0x0f, (byte) 0x00, (byte) 0x20, (byte) 0x21, (byte) 0x01}, 8, 1);
si2168_cmd_execute(new byte[] {(byte) 0x85}, 1, 1);
} else {
/* power up */
si2168_cmd_execute(new byte[] {(byte) 0xc0, (byte) 0x06, (byte) 0x01, (byte) 0x0f, (byte) 0x00, (byte) 0x20, (byte) 0x20, (byte) 0x01}, 8, 1);
Log.d(TAG, "Uploading firmware to "+chip);
try {
byte[] fw = readFirmware(chip.firmwareFile);
if ((fw.length % 17 == 0) && ((fw[0] & 0xFF) > 5)) {
Log.d(TAG, "firmware is in the new format");
for (int remaining = fw.length; remaining > 0; remaining -= 17) {
int len = fw[fw.length - remaining] & 0xFF;
if (len > SI2168_ARGLEN) {
throw new DvbException(IO_EXCEPTION, resources.getString(R.string.cannot_load_firmware));
}
byte[] args = new byte[len];
System.arraycopy(fw, fw.length - remaining + 1, args, 0, len);
si2168_cmd_execute(args, len, 1);
}
} else if (fw.length % 8 == 0) {
Log.d(TAG, "firmware is in the old format");
for (int remaining = fw.length; remaining > 0; remaining -= 8) {
int len = 8;
byte[] args = new byte[len];
System.arraycopy(fw, fw.length - remaining, args, 0, len);
si2168_cmd_execute(args, len, 1);
}
} else {
throw new DvbException(IO_EXCEPTION, resources.getString(R.string.cannot_load_firmware));
}
} catch (IOException e) {
throw new DvbException(IO_EXCEPTION, e);
}
si2168_cmd_execute(new byte[] {0x01, 0x01}, 2, 1);
/* query firmware version */
byte[] fwVerRaw = si2168_cmd_execute(new byte[] {(byte) 0x11}, 1, 10);
version = (((fwVerRaw[9] & 0xFF) + '@') << 24) | (((fwVerRaw[6] & 0xFF) - '0') << 16) | (((fwVerRaw[7] & 0xFF) - '0') << 8) | (fwVerRaw[8] & 0xFF);
Log.d(TAG, "firmware version: "+((char) ((version >> 24) & 0xff))+" "+((version >> 16) & 0xff)+"."+((version >> 8) & 0xff)+"."+(version & 0xff));
/* set ts mode */
byte[] args = new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x00};
args[4] |= ts_mode;
args[4] |= ts_clock_mode << 4;
if (ts_clock_gapped) {
args[4] |= 0x40;
}
si2168_cmd_execute(args, 6, 4);
/* set ts freq to 10Mhz*/
si2168_cmd_execute(new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x0d, (byte) 0x10, (byte) 0xe8, (byte) 0x03}, 6, 4);
warm = true;
}
tuner.init();
active = true;
}
private byte[] readFirmware(int resource) throws IOException {
InputStream inputStream = resources.openRawResource(resource);
//noinspection TryFinallyCanBeTryWithResources
try {
byte[] fw = new byte[inputStream.available()];
if (inputStream.read(fw) != fw.length) {
throw new DvbException(IO_EXCEPTION, resources.getString(R.string.cannot_load_firmware));
}
return fw;
} finally {
inputStream.close();
}
}
@Override
public synchronized void setParams(long frequency, long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException {
hasLockStatus = false;
if (!active) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
int delivery_system;
switch (deliverySystem) {
case DVBT:
delivery_system = 0x20;
break;
case DVBC:
delivery_system = 0x30;
break;
case DVBT2:
delivery_system = 0x70;
break;
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
int bandwidth;
if (bandwidthHz == 0) {
throw new DvbException(UNSUPPORTED_BANDWIDTH, resources.getString(R.string.invalid_bw));
} else if (bandwidthHz <= 2_000_000L) {
bandwidth = 0x02;
} else if (bandwidthHz <= 5_000_000L) {
bandwidth = 0x05;
} else if (bandwidthHz <= 6_000_000L) {
bandwidth = 0x06;
} else if (bandwidthHz <= 7_000_000L) {
bandwidth = 0x07;
} else if (bandwidthHz <= 8_000_000L) {
bandwidth = 0x08;
} else if (bandwidthHz <= 9_000_000L) {
bandwidth = 0x09;
} else if (bandwidthHz <= 10_000_000L) {
bandwidth = 0x0a;
} else {
bandwidth = 0x0f;
}
/* program tuner */
tuner.setParams(frequency, bandwidthHz, deliverySystem);
si2168_cmd_execute(new byte[] {(byte) 0x88, (byte) 0x02, (byte) 0x02, (byte) 0x02, (byte) 0x02}, 5, 5);
/* that has no big effect */
switch (deliverySystem) {
case DVBT:
si2168_cmd_execute(new byte[] {(byte) 0x89, (byte) 0x21, (byte) 0x06, (byte) 0x11, (byte) 0xff, (byte) 0x98}, 6, 3);
break;
case DVBC:
si2168_cmd_execute(new byte[] {(byte) 0x89, (byte) 0x21, (byte) 0x06, (byte) 0x11, (byte) 0x89, (byte) 0xf0}, 6, 3);
break;
case DVBT2:
si2168_cmd_execute(new byte[] {(byte) 0x89, (byte) 0x21, (byte) 0x06, (byte) 0x11, (byte) 0x89, (byte) 0x20}, 6, 3);
break;
}
if (deliverySystem == DeliverySystem.DVBT2) {
/* select PLP */
//noinspection PointlessBitwiseExpression,ConstantConditions
si2168_cmd_execute(new byte[] {
(byte) 0x52, (byte) (DVBT2_STREAM_ID & 0xFF), DVBT2_STREAM_ID == NO_STREAM_ID_FILTER ? 0 : (byte) 1
}, 3, 1);
}
si2168_cmd_execute(new byte[] {(byte) 0x51, (byte) 0x03}, 2, 12);
si2168_cmd_execute(new byte[] {(byte) 0x12, (byte) 0x08, (byte) 0x04}, 3, 3);
si2168_cmd_execute(new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x0c, (byte) 0x10, (byte) 0x12, (byte) 0x00}, 6, 4);
si2168_cmd_execute(new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x06, (byte) 0x10, (byte) 0x24, (byte) 0x00}, 6, 4);
si2168_cmd_execute(new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x07, (byte) 0x10, (byte) 0x00, (byte) 0x24}, 6, 4);
si2168_cmd_execute(new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x0a, (byte) 0x10, (byte) (delivery_system | bandwidth), (byte) 0x00}, 6, 4);
/* set DVB-C symbol rate */
if (deliverySystem == DeliverySystem.DVBC) {
//noinspection PointlessBitwiseExpression
si2168_cmd_execute(new byte[] {
(byte) 0x14, (byte) 0x00, (byte) 0x02 , (byte) 0x11, (byte) (((DVBC_SYMBOL_RATE / 1000) >> 0) & 0xff), (byte) ( ((DVBC_SYMBOL_RATE / 1000) >> 8) & 0xff)
}, 6, 4);
}
si2168_cmd_execute(new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x0f, (byte) 0x10, (byte) 0x10, (byte) 0x00}, 6, 4);
si2168_cmd_execute(new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x09, (byte) 0x10, (byte) 0xe3, (byte) (0x08 | (ts_clock_inv ? 0x00 : 0x10))}, 6, 4);
byte[] cmd = new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x08, (byte) 0x10, (byte) 0xd7, (byte) 0x05};
cmd[5] |= ts_clock_inv ? 0xd7 : 0xcf;
si2168_cmd_execute(cmd, 6, 4);
si2168_cmd_execute(new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x01, (byte) 0x12, (byte) 0x00, (byte) 0x00}, 6, 4);
si2168_cmd_execute(new byte[] {(byte) 0x14, (byte) 0x00, (byte) 0x01, (byte) 0x03, (byte) 0x0c, (byte) 0x00}, 6, 4);
si2168_cmd_execute(new byte[] {(byte) 0x85}, 1, 1);
this.deliverySystem = deliverySystem;
}
@Override
public int readSnr() throws DvbException {
return -1;
}
@Override
public int readRfStrengthPercentage() throws DvbException {
if (!getStatus().contains(FE_HAS_SIGNAL)) return 0;
return tuner.readRfStrengthPercentage();
}
@Override
public synchronized Set<DvbStatus> getStatus() throws DvbException {
if (!active) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
if (deliverySystem == null) return SetUtils.setOf();
byte[] res;
switch (deliverySystem) {
case DVBT:
res = si2168_cmd_execute(new byte[] {(byte) 0xa0, (byte) 0x01}, 2, 13);
break;
case DVBC:
res = si2168_cmd_execute(new byte[] {(byte) 0x90, (byte) 0x01}, 2, 9);
break;
case DVBT2:
res = si2168_cmd_execute(new byte[] {(byte) 0x50, (byte) 0x01}, 2, 14);
break;
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
Set<DvbStatus> resultStatus;
switch (((res[2] & 0xFF) >> 1) & 0x03) {
case 0x01:
resultStatus = SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER);
break;
case 0x03:
resultStatus = SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER, FE_HAS_VITERBI, FE_HAS_SYNC, FE_HAS_LOCK);
break;
default:
return SetUtils.setOf();
}
/* hook fe: need to resync the slave fifo when signal locks. */
/* it need resync slave fifo when signal change from unlock to lock.*/
if (!hasLockStatus && resultStatus.contains(FE_HAS_LOCK)) {
((CxUsbDvbDevice)usbDevice).cxusb_streaming_ctrl(true);
hasLockStatus = true;
}
return resultStatus;
}
@Override
public synchronized int readBer() throws DvbException {
if (!getStatus().contains(FE_HAS_VITERBI)) return 0xFFFF;
byte[] res = si2168_cmd_execute(new byte[] { (byte) 0x82, (byte) 0x00 }, 2, 3);
/*
* Firmware returns [0, 255] mantissa and [0, 8] exponent.
* Convert to DVB API: mantissa * 10^(8 - exponent) / 10^8
*/
int diff = 8 - (res[1] & 0xFF);
int utmp = diff < 0 ? 0 : (diff > 8 ? 8 : diff);
long bitErrors = 1;
for (int i = 0; i < utmp; i++) {
bitErrors = bitErrors * 10;
}
bitErrors = (res[2] & 0xFF) * bitErrors;
long bitCount = 10_000_000L; /* 10^8 */
return (int) ((bitErrors * 0xFFFF) / bitCount);
}
@Override
public void setPids(int... pids) throws DvbException {
// no-op
}
@Override
public void disablePidFilter() throws DvbException {
// no-op
}
public I2cAdapter.I2GateControl gateControl() {
return gateControl;
}
private final I2cAdapter.I2GateControl gateControl = new I2cAdapter.I2GateControl() {
@Override
protected synchronized void i2cGateCtrl(boolean enable) throws DvbException {
if (enable) {
si2168_cmd_execute_wr(new byte[] {(byte) 0xc0, (byte) 0x0d, (byte) 0x01}, 3);
} else {
si2168_cmd_execute_wr(new byte[] {(byte) 0xc0, (byte) 0x0d, (byte) 0x00}, 3);
}
}
};
}
| 19,290 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Af9033Data.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/af9035/Af9033Data.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.af9035;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.tools.SetUtils;
class Af9033Data {
final static DvbCapabilities CAPABILITIES = new DvbCapabilities(
174_000_000L,
862_000_000L,
250_000L,
SetUtils.setOf(DeliverySystem.DVBT)
);
static int[][] reg_val_mask_tab(int tuner, boolean ts_mode_serial, boolean ts_mode_parallel, int adc_multiplier) {
return new int[][] {
// { reg, value, mask }
{ 0x80fb24, 0x00, 0x08 },
{ 0x80004c, 0x00, 0xff },
{ 0x00f641, tuner, 0xff },
{ 0x80f5ca, 0x01, 0x01 },
{ 0x80f715, 0x01, 0x01 },
{ 0x00f41f, 0x04, 0x04 },
{ 0x00f41a, 0x01, 0x01 },
{ 0x80f731, 0x00, 0x01 },
{ 0x00d91e, 0x00, 0x01 },
{ 0x00d919, 0x00, 0x01 },
{ 0x80f732, 0x00, 0x01 },
{ 0x00d91f, 0x00, 0x01 },
{ 0x00d91a, 0x00, 0x01 },
{ 0x80f730, 0x00, 0x01 },
{ 0x80f778, 0x00, 0xff },
{ 0x80f73c, 0x01, 0x01 },
{ 0x80f776, 0x00, 0x01 },
{ 0x00d8fd, 0x01, 0xff },
{ 0x00d830, 0x01, 0xff },
{ 0x00d831, 0x00, 0xff },
{ 0x00d832, 0x00, 0xff },
{ 0x80f985, ts_mode_serial ? 1 : 0, 0x01 },
{ 0x80f986, ts_mode_parallel ? 1 : 0, 0x01 },
{ 0x00d827, 0x00, 0xff },
{ 0x00d829, 0x00, 0xff },
{ 0x800045, adc_multiplier, 0xff },
};
}
final static byte[] coeff_lut_12000000_8000000 = new byte[] {
(byte) 0x01, (byte) 0xce, (byte) 0x55, (byte) 0xc9, (byte) 0x00, (byte) 0xe7, (byte) 0x2a, (byte) 0xe4, (byte) 0x00, (byte) 0x73,
(byte) 0x99, (byte) 0x0f, (byte) 0x00, (byte) 0x73, (byte) 0x95, (byte) 0x72, (byte) 0x00, (byte) 0x73, (byte) 0x91, (byte) 0xd5,
(byte) 0x00, (byte) 0x39, (byte) 0xca, (byte) 0xb9, (byte) 0x00, (byte) 0xe7, (byte) 0x2a, (byte) 0xe4, (byte) 0x00, (byte) 0x73,
(byte) 0x95, (byte) 0x72, (byte) 0x37, (byte) 0x02, (byte) 0xce, (byte) 0x01
};
final static byte[] coeff_lut_12000000_7000000 = new byte[] {
(byte) 0x01, (byte) 0x94, (byte) 0x8b, (byte) 0x10, (byte) 0x00, (byte) 0xca, (byte) 0x45, (byte) 0x88, (byte) 0x00, (byte) 0x65,
(byte) 0x25, (byte) 0xed, (byte) 0x00, (byte) 0x65, (byte) 0x22, (byte) 0xc4, (byte) 0x00, (byte) 0x65, (byte) 0x1f, (byte) 0x9b,
(byte) 0x00, (byte) 0x32, (byte) 0x91, (byte) 0x62, (byte) 0x00, (byte) 0xca, (byte) 0x45, (byte) 0x88, (byte) 0x00, (byte) 0x65,
(byte) 0x22, (byte) 0xc4, (byte) 0x88, (byte) 0x02, (byte) 0x95, (byte) 0x01
};
final static byte[] coeff_lut_12000000_6000000 = new byte[] {
(byte) 0x01, (byte) 0x5a, (byte) 0xc0, (byte) 0x56, (byte) 0x00, (byte) 0xad, (byte) 0x60, (byte) 0x2b, (byte) 0x00, (byte) 0x56,
(byte) 0xb2, (byte) 0xcb, (byte) 0x00, (byte) 0x56, (byte) 0xb0, (byte) 0x15, (byte) 0x00, (byte) 0x56, (byte) 0xad, (byte) 0x60,
(byte) 0x00, (byte) 0x2b, (byte) 0x58, (byte) 0x0b, (byte) 0x00, (byte) 0xad, (byte) 0x60, (byte) 0x2b, (byte) 0x00, (byte) 0x56,
(byte) 0xb0, (byte) 0x15, (byte) 0xf4, (byte) 0x02, (byte) 0x5b, (byte) 0x01
};
/* NorDig power reference table */
final static int[][] power_reference = new int[][]{
{-93, -91, -90, -89, -88}, /* QPSK 1/2 ~ 7/8 */
{-87, -85, -84, -83, -82}, /* 16QAM 1/2 ~ 7/8 */
{-82, -80, -78, -77, -76}, /* 64QAM 1/2 ~ 7/8 */
};
/* Xtal clock vs. ADC clock lookup table */
final static int[][] clock_adc_lut = {
{ 16384000, 20480000 },
{ 20480000, 20480000 },
{ 36000000, 20250000 },
{ 30000000, 20156250 },
{ 26000000, 20583333 },
{ 28000000, 20416667 },
{ 32000000, 20500000 },
{ 34000000, 20187500 },
{ 24000000, 20500000 },
{ 22000000, 20625000 },
{ 12000000, 20250000 },
};
/* QPSK SNR lookup table */
final static int[][] qpsk_snr_lut = new int[][] {
{ 0x000000, 0 },
{ 0x0b4771, 0 },
{ 0x0c1aed, 1 },
{ 0x0d0d27, 2 },
{ 0x0e4d19, 3 },
{ 0x0e5da8, 4 },
{ 0x107097, 5 },
{ 0x116975, 6 },
{ 0x1252d9, 7 },
{ 0x131fa4, 8 },
{ 0x13d5e1, 9 },
{ 0x148e53, 10 },
{ 0x15358b, 11 },
{ 0x15dd29, 12 },
{ 0x168112, 13 },
{ 0x170b61, 14 },
{ 0xffffff, 15 },
};
/* QAM16 SNR lookup table */
final static int[][] qam16_snr_lut = new int[][] {
{ 0x000000, 0 },
{ 0x05eb62, 5 },
{ 0x05fecf, 6 },
{ 0x060b80, 7 },
{ 0x062501, 8 },
{ 0x064865, 9 },
{ 0x069604, 10 },
{ 0x06f356, 11 },
{ 0x07706a, 12 },
{ 0x0804d3, 13 },
{ 0x089d1a, 14 },
{ 0x093e3d, 15 },
{ 0x09e35d, 16 },
{ 0x0a7c3c, 17 },
{ 0x0afaf8, 18 },
{ 0x0b719d, 19 },
{ 0xffffff, 20 },
};
/* QAM64 SNR lookup table */
final static int[][] qam64_snr_lut = new int[][] {
{ 0x000000, 0 },
{ 0x03109b, 12 },
{ 0x0310d4, 13 },
{ 0x031920, 14 },
{ 0x0322d0, 15 },
{ 0x0339fc, 16 },
{ 0x0364a1, 17 },
{ 0x038bcc, 18 },
{ 0x03c7d3, 19 },
{ 0x0408cc, 20 },
{ 0x043bed, 21 },
{ 0x048061, 22 },
{ 0x04be95, 23 },
{ 0x04fa7d, 24 },
{ 0x052405, 25 },
{ 0x05570d, 26 },
{ 0xffffff, 27 },
};
/*
* Afatech AF9033 demod init
*/
final static int[][] ofsm_init = new int[][] {
{ 0x800051, 0x01 },
{ 0x800070, 0x0a },
{ 0x80007e, 0x04 },
{ 0x800081, 0x0a },
{ 0x80008a, 0x01 },
{ 0x80008e, 0x01 },
{ 0x800092, 0x06 },
{ 0x800099, 0x01 },
{ 0x80009f, 0xe1 },
{ 0x8000a0, 0xcf },
{ 0x8000a3, 0x01 },
{ 0x8000a5, 0x01 },
{ 0x8000a6, 0x01 },
{ 0x8000a9, 0x00 },
{ 0x8000aa, 0x01 },
{ 0x8000b0, 0x01 },
{ 0x8000c4, 0x05 },
{ 0x8000c8, 0x19 },
{ 0x80f000, 0x0f },
{ 0x80f016, 0x10 },
{ 0x80f017, 0x04 },
{ 0x80f018, 0x05 },
{ 0x80f019, 0x04 },
{ 0x80f01a, 0x05 },
{ 0x80f021, 0x03 },
{ 0x80f022, 0x0a },
{ 0x80f023, 0x0a },
{ 0x80f02b, 0x00 },
{ 0x80f02c, 0x01 },
{ 0x80f064, 0x03 },
{ 0x80f065, 0xf9 },
{ 0x80f066, 0x03 },
{ 0x80f067, 0x01 },
{ 0x80f06f, 0xe0 },
{ 0x80f070, 0x03 },
{ 0x80f072, 0x0f },
{ 0x80f073, 0x03 },
{ 0x80f078, 0x00 },
{ 0x80f087, 0x00 },
{ 0x80f09b, 0x3f },
{ 0x80f09c, 0x00 },
{ 0x80f09d, 0x20 },
{ 0x80f09e, 0x00 },
{ 0x80f09f, 0x0c },
{ 0x80f0a0, 0x00 },
{ 0x80f130, 0x04 },
{ 0x80f132, 0x04 },
{ 0x80f144, 0x1a },
{ 0x80f146, 0x00 },
{ 0x80f14a, 0x01 },
{ 0x80f14c, 0x00 },
{ 0x80f14d, 0x00 },
{ 0x80f14f, 0x04 },
{ 0x80f158, 0x7f },
{ 0x80f15a, 0x00 },
{ 0x80f15b, 0x08 },
{ 0x80f15d, 0x03 },
{ 0x80f15e, 0x05 },
{ 0x80f163, 0x05 },
{ 0x80f166, 0x01 },
{ 0x80f167, 0x40 },
{ 0x80f168, 0x0f },
{ 0x80f17a, 0x00 },
{ 0x80f17b, 0x00 },
{ 0x80f183, 0x01 },
{ 0x80f19d, 0x40 },
{ 0x80f1bc, 0x36 },
{ 0x80f1bd, 0x00 },
{ 0x80f1cb, 0xa0 },
{ 0x80f1cc, 0x01 },
{ 0x80f204, 0x10 },
{ 0x80f214, 0x00 },
{ 0x80f40e, 0x0a },
{ 0x80f40f, 0x40 },
{ 0x80f410, 0x08 },
{ 0x80f55f, 0x0a },
{ 0x80f561, 0x15 },
{ 0x80f562, 0x20 },
{ 0x80f5df, 0xfb },
{ 0x80f5e0, 0x00 },
{ 0x80f5e3, 0x09 },
{ 0x80f5e4, 0x01 },
{ 0x80f5e5, 0x01 },
{ 0x80f5f8, 0x01 },
{ 0x80f5fd, 0x01 },
{ 0x80f600, 0x05 },
{ 0x80f601, 0x08 },
{ 0x80f602, 0x0b },
{ 0x80f603, 0x0e },
{ 0x80f604, 0x11 },
{ 0x80f605, 0x14 },
{ 0x80f606, 0x17 },
{ 0x80f607, 0x1f },
{ 0x80f60e, 0x00 },
{ 0x80f60f, 0x04 },
{ 0x80f610, 0x32 },
{ 0x80f611, 0x10 },
{ 0x80f707, 0xfc },
{ 0x80f708, 0x00 },
{ 0x80f709, 0x37 },
{ 0x80f70a, 0x00 },
{ 0x80f78b, 0x01 },
{ 0x80f80f, 0x40 },
{ 0x80f810, 0x54 },
{ 0x80f811, 0x5a },
{ 0x80f905, 0x01 },
{ 0x80fb06, 0x03 },
{ 0x80fd8b, 0x00 },
};
/*
* Infineon TUA 9001 tuner init
* AF9033_TUNER_TUA9001 = 0x27
*/
final static int[][] tuner_init_tua9001 = new int[][] {
{ 0x800046, 0x27 },
{ 0x800057, 0x00 },
{ 0x800058, 0x01 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x80006d, 0x00 },
{ 0x800071, 0x05 },
{ 0x800072, 0x02 },
{ 0x800074, 0x01 },
{ 0x800075, 0x03 },
{ 0x800076, 0x02 },
{ 0x800077, 0x00 },
{ 0x800078, 0x01 },
{ 0x800079, 0x00 },
{ 0x80007a, 0x7e },
{ 0x80007b, 0x3e },
{ 0x800093, 0x00 },
{ 0x800094, 0x01 },
{ 0x800095, 0x02 },
{ 0x800096, 0x01 },
{ 0x800098, 0x0a },
{ 0x80009b, 0x05 },
{ 0x80009c, 0x80 },
{ 0x8000b3, 0x00 },
{ 0x8000c5, 0x01 },
{ 0x8000c6, 0x00 },
{ 0x8000c9, 0x5d },
{ 0x80f007, 0x00 },
{ 0x80f01f, 0x82 },
{ 0x80f020, 0x00 },
{ 0x80f029, 0x82 },
{ 0x80f02a, 0x00 },
{ 0x80f047, 0x00 },
{ 0x80f054, 0x00 },
{ 0x80f055, 0x00 },
{ 0x80f077, 0x01 },
{ 0x80f1e6, 0x00 },
};
/*
* Fitipower FC0011 tuner init
* AF9033_TUNER_FC0011 = 0x28
*/
final static int[][] tuner_init_fc0011 = new int[][] {
{ 0x800046, 0x28 },
{ 0x800057, 0x00 },
{ 0x800058, 0x01 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x800068, 0xa5 },
{ 0x80006e, 0x01 },
{ 0x800071, 0x0a },
{ 0x800072, 0x02 },
{ 0x800074, 0x01 },
{ 0x800079, 0x01 },
{ 0x800093, 0x00 },
{ 0x800094, 0x00 },
{ 0x800095, 0x00 },
{ 0x800096, 0x00 },
{ 0x80009b, 0x2d },
{ 0x80009c, 0x60 },
{ 0x80009d, 0x23 },
{ 0x8000a4, 0x50 },
{ 0x8000ad, 0x50 },
{ 0x8000b3, 0x01 },
{ 0x8000b7, 0x88 },
{ 0x8000b8, 0xa6 },
{ 0x8000c5, 0x01 },
{ 0x8000c6, 0x01 },
{ 0x8000c9, 0x69 },
{ 0x80f007, 0x00 },
{ 0x80f00a, 0x1b },
{ 0x80f00b, 0x1b },
{ 0x80f00c, 0x1b },
{ 0x80f00d, 0x1b },
{ 0x80f00e, 0xff },
{ 0x80f00f, 0x01 },
{ 0x80f010, 0x00 },
{ 0x80f011, 0x02 },
{ 0x80f012, 0xff },
{ 0x80f013, 0x01 },
{ 0x80f014, 0x00 },
{ 0x80f015, 0x02 },
{ 0x80f01b, 0xef },
{ 0x80f01c, 0x01 },
{ 0x80f01d, 0x0f },
{ 0x80f01e, 0x02 },
{ 0x80f01f, 0x6e },
{ 0x80f020, 0x00 },
{ 0x80f025, 0xde },
{ 0x80f026, 0x00 },
{ 0x80f027, 0x0a },
{ 0x80f028, 0x03 },
{ 0x80f029, 0x6e },
{ 0x80f02a, 0x00 },
{ 0x80f047, 0x00 },
{ 0x80f054, 0x00 },
{ 0x80f055, 0x00 },
{ 0x80f077, 0x01 },
{ 0x80f1e6, 0x00 },
};
/*
* Fitipower FC0012 tuner init
* AF9033_TUNER_FC0012 = 0x2e
*/
final static int[][] tuner_init_fc0012 = new int[][] {
{ 0x800046, 0x2e },
{ 0x800057, 0x00 },
{ 0x800058, 0x01 },
{ 0x800059, 0x01 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x80006d, 0x00 },
{ 0x800071, 0x05 },
{ 0x800072, 0x02 },
{ 0x800074, 0x01 },
{ 0x800075, 0x03 },
{ 0x800076, 0x02 },
{ 0x800077, 0x01 },
{ 0x800078, 0x00 },
{ 0x800079, 0x00 },
{ 0x80007a, 0x90 },
{ 0x80007b, 0x90 },
{ 0x800093, 0x00 },
{ 0x800094, 0x01 },
{ 0x800095, 0x02 },
{ 0x800096, 0x01 },
{ 0x800098, 0x0a },
{ 0x80009b, 0x05 },
{ 0x80009c, 0x80 },
{ 0x8000b3, 0x00 },
{ 0x8000c5, 0x01 },
{ 0x8000c6, 0x00 },
{ 0x8000c9, 0x5d },
{ 0x80f007, 0x00 },
{ 0x80f01f, 0xa0 },
{ 0x80f020, 0x00 },
{ 0x80f029, 0x82 },
{ 0x80f02a, 0x00 },
{ 0x80f047, 0x00 },
{ 0x80f054, 0x00 },
{ 0x80f055, 0x00 },
{ 0x80f077, 0x01 },
{ 0x80f1e6, 0x00 },
};
/*
* MaxLinear MxL5007T tuner init
* AF9033_TUNER_MXL5007T = 0xa0
*/
final static int[][] tuner_init_mxl5007t = new int[][] {
{ 0x800046, 0x1b },
{ 0x800057, 0x01 },
{ 0x800058, 0x01 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x800068, 0x96 },
{ 0x800071, 0x05 },
{ 0x800072, 0x02 },
{ 0x800074, 0x01 },
{ 0x800079, 0x01 },
{ 0x800093, 0x00 },
{ 0x800094, 0x00 },
{ 0x800095, 0x00 },
{ 0x800096, 0x00 },
{ 0x8000b3, 0x01 },
{ 0x8000c1, 0x01 },
{ 0x8000c2, 0x00 },
{ 0x80f007, 0x00 },
{ 0x80f00c, 0x19 },
{ 0x80f00d, 0x1a },
{ 0x80f012, 0xda },
{ 0x80f013, 0x00 },
{ 0x80f014, 0x00 },
{ 0x80f015, 0x02 },
{ 0x80f01f, 0x82 },
{ 0x80f020, 0x00 },
{ 0x80f029, 0x82 },
{ 0x80f02a, 0x00 },
{ 0x80f077, 0x02 },
{ 0x80f1e6, 0x00 },
};
/*
* NXP TDA18218HN tuner init
* AF9033_TUNER_TDA18218 = 0xa1
*/
final static int[][] tuner_init_tda18218 = new int[][] {
{0x800046, 0xa1},
{0x800057, 0x01},
{0x800058, 0x01},
{0x80005f, 0x00},
{0x800060, 0x00},
{0x800071, 0x05},
{0x800072, 0x02},
{0x800074, 0x01},
{0x800079, 0x01},
{0x800093, 0x00},
{0x800094, 0x00},
{0x800095, 0x00},
{0x800096, 0x00},
{0x8000b3, 0x01},
{0x8000c3, 0x01},
{0x8000c4, 0x00},
{0x80f007, 0x00},
{0x80f00c, 0x19},
{0x80f00d, 0x1a},
{0x80f012, 0xda},
{0x80f013, 0x00},
{0x80f014, 0x00},
{0x80f015, 0x02},
{0x80f01f, 0x82},
{0x80f020, 0x00},
{0x80f029, 0x82},
{0x80f02a, 0x00},
{0x80f077, 0x02},
{0x80f1e6, 0x00},
};
/*
* FCI FC2580 tuner init
* AF9033_TUNER_FC2580 = 0x32
*/
final static int[][] tuner_init_fc2580 = new int[][] {
{ 0x800046, 0x32 },
{ 0x800057, 0x01 },
{ 0x800058, 0x00 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x800071, 0x05 },
{ 0x800072, 0x02 },
{ 0x800074, 0x01 },
{ 0x800079, 0x01 },
{ 0x800093, 0x00 },
{ 0x800094, 0x00 },
{ 0x800095, 0x00 },
{ 0x800096, 0x05 },
{ 0x8000b3, 0x01 },
{ 0x8000c5, 0x01 },
{ 0x8000c6, 0x00 },
{ 0x8000d1, 0x01 },
{ 0x80f007, 0x00 },
{ 0x80f00c, 0x19 },
{ 0x80f00d, 0x1a },
{ 0x80f00e, 0x00 },
{ 0x80f00f, 0x02 },
{ 0x80f010, 0x00 },
{ 0x80f011, 0x02 },
{ 0x80f012, 0x00 },
{ 0x80f013, 0x02 },
{ 0x80f014, 0x00 },
{ 0x80f015, 0x02 },
{ 0x80f01f, 0x96 },
{ 0x80f020, 0x00 },
{ 0x80f029, 0x96 },
{ 0x80f02a, 0x00 },
{ 0x80f077, 0x01 },
{ 0x80f1e6, 0x01 },
};
/*
* IT9133 AX demod init
*/
final static int[][] ofsm_init_it9135_v1 = new int[][] {
{ 0x800051, 0x01 },
{ 0x800070, 0x0a },
{ 0x80007e, 0x04 },
{ 0x800081, 0x0a },
{ 0x80008a, 0x01 },
{ 0x80008e, 0x01 },
{ 0x800092, 0x06 },
{ 0x800099, 0x01 },
{ 0x80009f, 0xe1 },
{ 0x8000a0, 0xcf },
{ 0x8000a3, 0x01 },
{ 0x8000a5, 0x01 },
{ 0x8000a6, 0x01 },
{ 0x8000a9, 0x00 },
{ 0x8000aa, 0x01 },
{ 0x8000b0, 0x01 },
{ 0x8000c2, 0x05 },
{ 0x8000c6, 0x19 },
{ 0x80f000, 0x0f },
{ 0x80f016, 0x10 },
{ 0x80f017, 0x04 },
{ 0x80f018, 0x05 },
{ 0x80f019, 0x04 },
{ 0x80f01a, 0x05 },
{ 0x80f021, 0x03 },
{ 0x80f022, 0x0a },
{ 0x80f023, 0x0a },
{ 0x80f02b, 0x00 },
{ 0x80f02c, 0x01 },
{ 0x80f064, 0x03 },
{ 0x80f065, 0xf9 },
{ 0x80f066, 0x03 },
{ 0x80f067, 0x01 },
{ 0x80f06f, 0xe0 },
{ 0x80f070, 0x03 },
{ 0x80f072, 0x0f },
{ 0x80f073, 0x03 },
{ 0x80f078, 0x00 },
{ 0x80f087, 0x00 },
{ 0x80f09b, 0x3f },
{ 0x80f09c, 0x00 },
{ 0x80f09d, 0x20 },
{ 0x80f09e, 0x00 },
{ 0x80f09f, 0x0c },
{ 0x80f0a0, 0x00 },
{ 0x80f130, 0x04 },
{ 0x80f132, 0x04 },
{ 0x80f144, 0x1a },
{ 0x80f146, 0x00 },
{ 0x80f14a, 0x01 },
{ 0x80f14c, 0x00 },
{ 0x80f14d, 0x00 },
{ 0x80f14f, 0x04 },
{ 0x80f158, 0x7f },
{ 0x80f15a, 0x00 },
{ 0x80f15b, 0x08 },
{ 0x80f15d, 0x03 },
{ 0x80f15e, 0x05 },
{ 0x80f163, 0x05 },
{ 0x80f166, 0x01 },
{ 0x80f167, 0x40 },
{ 0x80f168, 0x0f },
{ 0x80f17a, 0x00 },
{ 0x80f17b, 0x00 },
{ 0x80f183, 0x01 },
{ 0x80f19d, 0x40 },
{ 0x80f1bc, 0x36 },
{ 0x80f1bd, 0x00 },
{ 0x80f1cb, 0xa0 },
{ 0x80f1cc, 0x01 },
{ 0x80f204, 0x10 },
{ 0x80f214, 0x00 },
{ 0x80f40e, 0x0a },
{ 0x80f40f, 0x40 },
{ 0x80f410, 0x08 },
{ 0x80f55f, 0x0a },
{ 0x80f561, 0x15 },
{ 0x80f562, 0x20 },
{ 0x80f5df, 0xfb },
{ 0x80f5e0, 0x00 },
{ 0x80f5e3, 0x09 },
{ 0x80f5e4, 0x01 },
{ 0x80f5e5, 0x01 },
{ 0x80f5f8, 0x01 },
{ 0x80f5fd, 0x01 },
{ 0x80f600, 0x05 },
{ 0x80f601, 0x08 },
{ 0x80f602, 0x0b },
{ 0x80f603, 0x0e },
{ 0x80f604, 0x11 },
{ 0x80f605, 0x14 },
{ 0x80f606, 0x17 },
{ 0x80f607, 0x1f },
{ 0x80f60e, 0x00 },
{ 0x80f60f, 0x04 },
{ 0x80f610, 0x32 },
{ 0x80f611, 0x10 },
{ 0x80f707, 0xfc },
{ 0x80f708, 0x00 },
{ 0x80f709, 0x37 },
{ 0x80f70a, 0x00 },
{ 0x80f78b, 0x01 },
{ 0x80f80f, 0x40 },
{ 0x80f810, 0x54 },
{ 0x80f811, 0x5a },
{ 0x80f905, 0x01 },
{ 0x80fb06, 0x03 },
{ 0x80fd8b, 0x00 },
};
/*
* ITE Tech IT9133 AX Omega tuner init
* AF9033_TUNER_IT9135_38 = 0x38
*/
final static int[][] tuner_init_it9135_38 = new int[][] {
{ 0x800043, 0x00 },
{ 0x800046, 0x38 },
{ 0x800051, 0x01 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x800068, 0x0a },
{ 0x800070, 0x0a },
{ 0x800071, 0x05 },
{ 0x800072, 0x02 },
{ 0x800075, 0x8c },
{ 0x800076, 0x8c },
{ 0x800077, 0x8c },
{ 0x800078, 0xc8 },
{ 0x800079, 0x01 },
{ 0x80007e, 0x04 },
{ 0x80007f, 0x00 },
{ 0x800081, 0x0a },
{ 0x800082, 0x12 },
{ 0x800083, 0x02 },
{ 0x800084, 0x0a },
{ 0x800085, 0x03 },
{ 0x800086, 0xc8 },
{ 0x800087, 0xb8 },
{ 0x800088, 0xd0 },
{ 0x800089, 0xc3 },
{ 0x80008a, 0x01 },
{ 0x80008e, 0x01 },
{ 0x800092, 0x06 },
{ 0x800093, 0x00 },
{ 0x800094, 0x00 },
{ 0x800095, 0x00 },
{ 0x800096, 0x00 },
{ 0x800099, 0x01 },
{ 0x80009b, 0x3c },
{ 0x80009c, 0x28 },
{ 0x80009f, 0xe1 },
{ 0x8000a0, 0xcf },
{ 0x8000a3, 0x01 },
{ 0x8000a4, 0x5a },
{ 0x8000a5, 0x01 },
{ 0x8000a6, 0x01 },
{ 0x8000a9, 0x00 },
{ 0x8000aa, 0x01 },
{ 0x8000b0, 0x01 },
{ 0x8000b3, 0x02 },
{ 0x8000b4, 0x32 },
{ 0x8000b6, 0x14 },
{ 0x8000c0, 0x11 },
{ 0x8000c1, 0x00 },
{ 0x8000c2, 0x05 },
{ 0x8000c4, 0x00 },
{ 0x8000c6, 0x19 },
{ 0x8000c7, 0x00 },
{ 0x8000cc, 0x2e },
{ 0x8000cd, 0x51 },
{ 0x8000ce, 0x33 },
{ 0x8000f3, 0x05 },
{ 0x8000f4, 0x8c },
{ 0x8000f5, 0x8c },
{ 0x8000f8, 0x03 },
{ 0x8000f9, 0x06 },
{ 0x8000fa, 0x06 },
{ 0x8000fc, 0x02 },
{ 0x8000fd, 0x02 },
{ 0x8000fe, 0x02 },
{ 0x8000ff, 0x09 },
{ 0x800100, 0x50 },
{ 0x800101, 0x7b },
{ 0x800102, 0x77 },
{ 0x800103, 0x00 },
{ 0x800104, 0x02 },
{ 0x800105, 0xc8 },
{ 0x800106, 0x05 },
{ 0x800107, 0x7b },
{ 0x800109, 0x02 },
{ 0x800115, 0x0a },
{ 0x800116, 0x03 },
{ 0x800117, 0x02 },
{ 0x800118, 0x80 },
{ 0x80011a, 0xc8 },
{ 0x80011b, 0x7b },
{ 0x80011c, 0x8a },
{ 0x80011d, 0xa0 },
{ 0x800122, 0x02 },
{ 0x800123, 0x18 },
{ 0x800124, 0xc3 },
{ 0x800127, 0x00 },
{ 0x800128, 0x07 },
{ 0x80012a, 0x53 },
{ 0x80012b, 0x51 },
{ 0x80012c, 0x4e },
{ 0x80012d, 0x43 },
{ 0x800137, 0x01 },
{ 0x800138, 0x00 },
{ 0x800139, 0x07 },
{ 0x80013a, 0x00 },
{ 0x80013b, 0x06 },
{ 0x80013d, 0x00 },
{ 0x80013e, 0x01 },
{ 0x80013f, 0x5b },
{ 0x800140, 0xc8 },
{ 0x800141, 0x59 },
{ 0x80f000, 0x0f },
{ 0x80f016, 0x10 },
{ 0x80f017, 0x04 },
{ 0x80f018, 0x05 },
{ 0x80f019, 0x04 },
{ 0x80f01a, 0x05 },
{ 0x80f01f, 0x8c },
{ 0x80f020, 0x00 },
{ 0x80f021, 0x03 },
{ 0x80f022, 0x0a },
{ 0x80f023, 0x0a },
{ 0x80f029, 0x8c },
{ 0x80f02a, 0x00 },
{ 0x80f02b, 0x00 },
{ 0x80f02c, 0x01 },
{ 0x80f064, 0x03 },
{ 0x80f065, 0xf9 },
{ 0x80f066, 0x03 },
{ 0x80f067, 0x01 },
{ 0x80f06f, 0xe0 },
{ 0x80f070, 0x03 },
{ 0x80f072, 0x0f },
{ 0x80f073, 0x03 },
{ 0x80f077, 0x01 },
{ 0x80f078, 0x00 },
{ 0x80f085, 0x00 },
{ 0x80f086, 0x02 },
{ 0x80f087, 0x00 },
{ 0x80f09b, 0x3f },
{ 0x80f09c, 0x00 },
{ 0x80f09d, 0x20 },
{ 0x80f09e, 0x00 },
{ 0x80f09f, 0x0c },
{ 0x80f0a0, 0x00 },
{ 0x80f130, 0x04 },
{ 0x80f132, 0x04 },
{ 0x80f144, 0x1a },
{ 0x80f146, 0x00 },
{ 0x80f14a, 0x01 },
{ 0x80f14c, 0x00 },
{ 0x80f14d, 0x00 },
{ 0x80f14f, 0x04 },
{ 0x80f158, 0x7f },
{ 0x80f15a, 0x00 },
{ 0x80f15b, 0x08 },
{ 0x80f15d, 0x03 },
{ 0x80f15e, 0x05 },
{ 0x80f163, 0x05 },
{ 0x80f166, 0x01 },
{ 0x80f167, 0x40 },
{ 0x80f168, 0x0f },
{ 0x80f17a, 0x00 },
{ 0x80f17b, 0x00 },
{ 0x80f183, 0x01 },
{ 0x80f19d, 0x40 },
{ 0x80f1bc, 0x36 },
{ 0x80f1bd, 0x00 },
{ 0x80f1cb, 0xa0 },
{ 0x80f1cc, 0x01 },
{ 0x80f204, 0x10 },
{ 0x80f214, 0x00 },
{ 0x80f24c, 0x88 },
{ 0x80f24d, 0x95 },
{ 0x80f24e, 0x9a },
{ 0x80f24f, 0x90 },
{ 0x80f25a, 0x07 },
{ 0x80f25b, 0xe8 },
{ 0x80f25c, 0x03 },
{ 0x80f25d, 0xb0 },
{ 0x80f25e, 0x04 },
{ 0x80f270, 0x01 },
{ 0x80f271, 0x02 },
{ 0x80f272, 0x01 },
{ 0x80f273, 0x02 },
{ 0x80f40e, 0x0a },
{ 0x80f40f, 0x40 },
{ 0x80f410, 0x08 },
{ 0x80f55f, 0x0a },
{ 0x80f561, 0x15 },
{ 0x80f562, 0x20 },
{ 0x80f5df, 0xfb },
{ 0x80f5e0, 0x00 },
{ 0x80f5e3, 0x09 },
{ 0x80f5e4, 0x01 },
{ 0x80f5e5, 0x01 },
{ 0x80f5f8, 0x01 },
{ 0x80f5fd, 0x01 },
{ 0x80f600, 0x05 },
{ 0x80f601, 0x08 },
{ 0x80f602, 0x0b },
{ 0x80f603, 0x0e },
{ 0x80f604, 0x11 },
{ 0x80f605, 0x14 },
{ 0x80f606, 0x17 },
{ 0x80f607, 0x1f },
{ 0x80f60e, 0x00 },
{ 0x80f60f, 0x04 },
{ 0x80f610, 0x32 },
{ 0x80f611, 0x10 },
{ 0x80f707, 0xfc },
{ 0x80f708, 0x00 },
{ 0x80f709, 0x37 },
{ 0x80f70a, 0x00 },
{ 0x80f78b, 0x01 },
{ 0x80f80f, 0x40 },
{ 0x80f810, 0x54 },
{ 0x80f811, 0x5a },
{ 0x80f905, 0x01 },
{ 0x80fb06, 0x03 },
{ 0x80fd8b, 0x00 },
};
/*
* ITE Tech IT9133 AX Omega LNA config 1 tuner init
* AF9033_TUNER_IT9135_51 = 0x51
*/
final static int[][] tuner_init_it9135_51 = new int[][] {
{ 0x800043, 0x00 },
{ 0x800046, 0x51 },
{ 0x800051, 0x01 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x800068, 0x0a },
{ 0x800070, 0x0a },
{ 0x800071, 0x06 },
{ 0x800072, 0x02 },
{ 0x800075, 0x8c },
{ 0x800076, 0x8c },
{ 0x800077, 0x8c },
{ 0x800078, 0xc8 },
{ 0x800079, 0x01 },
{ 0x80007e, 0x04 },
{ 0x80007f, 0x00 },
{ 0x800081, 0x0a },
{ 0x800082, 0x12 },
{ 0x800083, 0x02 },
{ 0x800084, 0x0a },
{ 0x800085, 0x03 },
{ 0x800086, 0xc0 },
{ 0x800087, 0x96 },
{ 0x800088, 0xcf },
{ 0x800089, 0xc3 },
{ 0x80008a, 0x01 },
{ 0x80008e, 0x01 },
{ 0x800092, 0x06 },
{ 0x800093, 0x00 },
{ 0x800094, 0x00 },
{ 0x800095, 0x00 },
{ 0x800096, 0x00 },
{ 0x800099, 0x01 },
{ 0x80009b, 0x3c },
{ 0x80009c, 0x28 },
{ 0x80009f, 0xe1 },
{ 0x8000a0, 0xcf },
{ 0x8000a3, 0x01 },
{ 0x8000a4, 0x5a },
{ 0x8000a5, 0x01 },
{ 0x8000a6, 0x01 },
{ 0x8000a9, 0x00 },
{ 0x8000aa, 0x01 },
{ 0x8000b0, 0x01 },
{ 0x8000b3, 0x02 },
{ 0x8000b4, 0x3c },
{ 0x8000b6, 0x14 },
{ 0x8000c0, 0x11 },
{ 0x8000c1, 0x00 },
{ 0x8000c2, 0x05 },
{ 0x8000c4, 0x00 },
{ 0x8000c6, 0x19 },
{ 0x8000c7, 0x00 },
{ 0x8000cc, 0x2e },
{ 0x8000cd, 0x51 },
{ 0x8000ce, 0x33 },
{ 0x8000f3, 0x05 },
{ 0x8000f4, 0x8c },
{ 0x8000f5, 0x8c },
{ 0x8000f8, 0x03 },
{ 0x8000f9, 0x06 },
{ 0x8000fa, 0x06 },
{ 0x8000fc, 0x03 },
{ 0x8000fd, 0x02 },
{ 0x8000fe, 0x02 },
{ 0x8000ff, 0x09 },
{ 0x800100, 0x50 },
{ 0x800101, 0x7a },
{ 0x800102, 0x77 },
{ 0x800103, 0x01 },
{ 0x800104, 0x02 },
{ 0x800105, 0xb0 },
{ 0x800106, 0x02 },
{ 0x800107, 0x7a },
{ 0x800109, 0x02 },
{ 0x800115, 0x0a },
{ 0x800116, 0x03 },
{ 0x800117, 0x02 },
{ 0x800118, 0x80 },
{ 0x80011a, 0xc0 },
{ 0x80011b, 0x7a },
{ 0x80011c, 0xac },
{ 0x80011d, 0x8c },
{ 0x800122, 0x02 },
{ 0x800123, 0x70 },
{ 0x800124, 0xa4 },
{ 0x800127, 0x00 },
{ 0x800128, 0x07 },
{ 0x80012a, 0x53 },
{ 0x80012b, 0x51 },
{ 0x80012c, 0x4e },
{ 0x80012d, 0x43 },
{ 0x800137, 0x01 },
{ 0x800138, 0x00 },
{ 0x800139, 0x07 },
{ 0x80013a, 0x00 },
{ 0x80013b, 0x06 },
{ 0x80013d, 0x00 },
{ 0x80013e, 0x01 },
{ 0x80013f, 0x5b },
{ 0x800140, 0xc0 },
{ 0x800141, 0x59 },
{ 0x80f000, 0x0f },
{ 0x80f016, 0x10 },
{ 0x80f017, 0x04 },
{ 0x80f018, 0x05 },
{ 0x80f019, 0x04 },
{ 0x80f01a, 0x05 },
{ 0x80f01f, 0x8c },
{ 0x80f020, 0x00 },
{ 0x80f021, 0x03 },
{ 0x80f022, 0x0a },
{ 0x80f023, 0x0a },
{ 0x80f029, 0x8c },
{ 0x80f02a, 0x00 },
{ 0x80f02b, 0x00 },
{ 0x80f02c, 0x01 },
{ 0x80f064, 0x03 },
{ 0x80f065, 0xf9 },
{ 0x80f066, 0x03 },
{ 0x80f067, 0x01 },
{ 0x80f06f, 0xe0 },
{ 0x80f070, 0x03 },
{ 0x80f072, 0x0f },
{ 0x80f073, 0x03 },
{ 0x80f077, 0x01 },
{ 0x80f078, 0x00 },
{ 0x80f085, 0xc0 },
{ 0x80f086, 0x01 },
{ 0x80f087, 0x00 },
{ 0x80f09b, 0x3f },
{ 0x80f09c, 0x00 },
{ 0x80f09d, 0x20 },
{ 0x80f09e, 0x00 },
{ 0x80f09f, 0x0c },
{ 0x80f0a0, 0x00 },
{ 0x80f130, 0x04 },
{ 0x80f132, 0x04 },
{ 0x80f144, 0x1a },
{ 0x80f146, 0x00 },
{ 0x80f14a, 0x01 },
{ 0x80f14c, 0x00 },
{ 0x80f14d, 0x00 },
{ 0x80f14f, 0x04 },
{ 0x80f158, 0x7f },
{ 0x80f15a, 0x00 },
{ 0x80f15b, 0x08 },
{ 0x80f15d, 0x03 },
{ 0x80f15e, 0x05 },
{ 0x80f163, 0x05 },
{ 0x80f166, 0x01 },
{ 0x80f167, 0x40 },
{ 0x80f168, 0x0f },
{ 0x80f17a, 0x00 },
{ 0x80f17b, 0x00 },
{ 0x80f183, 0x01 },
{ 0x80f19d, 0x40 },
{ 0x80f1bc, 0x36 },
{ 0x80f1bd, 0x00 },
{ 0x80f1cb, 0xa0 },
{ 0x80f1cc, 0x01 },
{ 0x80f204, 0x10 },
{ 0x80f214, 0x00 },
{ 0x80f24c, 0x88 },
{ 0x80f24d, 0x95 },
{ 0x80f24e, 0x9a },
{ 0x80f24f, 0x90 },
{ 0x80f25a, 0x07 },
{ 0x80f25b, 0xe8 },
{ 0x80f25c, 0x03 },
{ 0x80f25d, 0xb0 },
{ 0x80f25e, 0x04 },
{ 0x80f270, 0x01 },
{ 0x80f271, 0x02 },
{ 0x80f272, 0x01 },
{ 0x80f273, 0x02 },
{ 0x80f40e, 0x0a },
{ 0x80f40f, 0x40 },
{ 0x80f410, 0x08 },
{ 0x80f55f, 0x0a },
{ 0x80f561, 0x15 },
{ 0x80f562, 0x20 },
{ 0x80f5df, 0xfb },
{ 0x80f5e0, 0x00 },
{ 0x80f5e3, 0x09 },
{ 0x80f5e4, 0x01 },
{ 0x80f5e5, 0x01 },
{ 0x80f5f8, 0x01 },
{ 0x80f5fd, 0x01 },
{ 0x80f600, 0x05 },
{ 0x80f601, 0x08 },
{ 0x80f602, 0x0b },
{ 0x80f603, 0x0e },
{ 0x80f604, 0x11 },
{ 0x80f605, 0x14 },
{ 0x80f606, 0x17 },
{ 0x80f607, 0x1f },
{ 0x80f60e, 0x00 },
{ 0x80f60f, 0x04 },
{ 0x80f610, 0x32 },
{ 0x80f611, 0x10 },
{ 0x80f707, 0xfc },
{ 0x80f708, 0x00 },
{ 0x80f709, 0x37 },
{ 0x80f70a, 0x00 },
{ 0x80f78b, 0x01 },
{ 0x80f80f, 0x40 },
{ 0x80f810, 0x54 },
{ 0x80f811, 0x5a },
{ 0x80f905, 0x01 },
{ 0x80fb06, 0x03 },
{ 0x80fd8b, 0x00 },
};
/*
* ITE Tech IT9133 AX Omega LNA config 2 tuner init
* AF9033_TUNER_IT9135_52 = 0x52
*/
final static int[][] tuner_init_it9135_52 = new int[][] {
{ 0x800043, 0x00 },
{ 0x800046, 0x52 },
{ 0x800051, 0x01 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x800068, 0x10 },
{ 0x800070, 0x0a },
{ 0x800071, 0x05 },
{ 0x800072, 0x02 },
{ 0x800075, 0x8c },
{ 0x800076, 0x8c },
{ 0x800077, 0x8c },
{ 0x800078, 0xa0 },
{ 0x800079, 0x01 },
{ 0x80007e, 0x04 },
{ 0x80007f, 0x00 },
{ 0x800081, 0x0a },
{ 0x800082, 0x17 },
{ 0x800083, 0x03 },
{ 0x800084, 0x0a },
{ 0x800085, 0x03 },
{ 0x800086, 0xb3 },
{ 0x800087, 0x97 },
{ 0x800088, 0xc0 },
{ 0x800089, 0x9e },
{ 0x80008a, 0x01 },
{ 0x80008e, 0x01 },
{ 0x800092, 0x06 },
{ 0x800093, 0x00 },
{ 0x800094, 0x00 },
{ 0x800095, 0x00 },
{ 0x800096, 0x00 },
{ 0x800099, 0x01 },
{ 0x80009b, 0x3c },
{ 0x80009c, 0x28 },
{ 0x80009f, 0xe1 },
{ 0x8000a0, 0xcf },
{ 0x8000a3, 0x01 },
{ 0x8000a4, 0x5c },
{ 0x8000a5, 0x01 },
{ 0x8000a6, 0x01 },
{ 0x8000a9, 0x00 },
{ 0x8000aa, 0x01 },
{ 0x8000b0, 0x01 },
{ 0x8000b3, 0x02 },
{ 0x8000b4, 0x3c },
{ 0x8000b6, 0x14 },
{ 0x8000c0, 0x11 },
{ 0x8000c1, 0x00 },
{ 0x8000c2, 0x05 },
{ 0x8000c4, 0x00 },
{ 0x8000c6, 0x19 },
{ 0x8000c7, 0x00 },
{ 0x8000cc, 0x2e },
{ 0x8000cd, 0x51 },
{ 0x8000ce, 0x33 },
{ 0x8000f3, 0x05 },
{ 0x8000f4, 0x91 },
{ 0x8000f5, 0x8c },
{ 0x8000f8, 0x03 },
{ 0x8000f9, 0x06 },
{ 0x8000fa, 0x06 },
{ 0x8000fc, 0x03 },
{ 0x8000fd, 0x02 },
{ 0x8000fe, 0x02 },
{ 0x8000ff, 0x09 },
{ 0x800100, 0x50 },
{ 0x800101, 0x74 },
{ 0x800102, 0x77 },
{ 0x800103, 0x02 },
{ 0x800104, 0x02 },
{ 0x800105, 0xa4 },
{ 0x800106, 0x02 },
{ 0x800107, 0x6e },
{ 0x800109, 0x02 },
{ 0x800115, 0x0a },
{ 0x800116, 0x03 },
{ 0x800117, 0x02 },
{ 0x800118, 0x80 },
{ 0x80011a, 0xcd },
{ 0x80011b, 0x62 },
{ 0x80011c, 0xa4 },
{ 0x80011d, 0x8c },
{ 0x800122, 0x03 },
{ 0x800123, 0x18 },
{ 0x800124, 0x9e },
{ 0x800127, 0x00 },
{ 0x800128, 0x07 },
{ 0x80012a, 0x53 },
{ 0x80012b, 0x51 },
{ 0x80012c, 0x4e },
{ 0x80012d, 0x43 },
{ 0x800137, 0x00 },
{ 0x800138, 0x00 },
{ 0x800139, 0x07 },
{ 0x80013a, 0x00 },
{ 0x80013b, 0x06 },
{ 0x80013d, 0x00 },
{ 0x80013e, 0x01 },
{ 0x80013f, 0x5b },
{ 0x800140, 0xb6 },
{ 0x800141, 0x59 },
{ 0x80f000, 0x0f },
{ 0x80f016, 0x10 },
{ 0x80f017, 0x04 },
{ 0x80f018, 0x05 },
{ 0x80f019, 0x04 },
{ 0x80f01a, 0x05 },
{ 0x80f01f, 0x8c },
{ 0x80f020, 0x00 },
{ 0x80f021, 0x03 },
{ 0x80f022, 0x0a },
{ 0x80f023, 0x0a },
{ 0x80f029, 0x8c },
{ 0x80f02a, 0x00 },
{ 0x80f02b, 0x00 },
{ 0x80f02c, 0x01 },
{ 0x80f064, 0x03 },
{ 0x80f065, 0xf9 },
{ 0x80f066, 0x03 },
{ 0x80f067, 0x01 },
{ 0x80f06f, 0xe0 },
{ 0x80f070, 0x03 },
{ 0x80f072, 0x0f },
{ 0x80f073, 0x03 },
{ 0x80f077, 0x01 },
{ 0x80f078, 0x00 },
{ 0x80f085, 0xc0 },
{ 0x80f086, 0x01 },
{ 0x80f087, 0x00 },
{ 0x80f09b, 0x3f },
{ 0x80f09c, 0x00 },
{ 0x80f09d, 0x20 },
{ 0x80f09e, 0x00 },
{ 0x80f09f, 0x0c },
{ 0x80f0a0, 0x00 },
{ 0x80f130, 0x04 },
{ 0x80f132, 0x04 },
{ 0x80f144, 0x1a },
{ 0x80f146, 0x00 },
{ 0x80f14a, 0x01 },
{ 0x80f14c, 0x00 },
{ 0x80f14d, 0x00 },
{ 0x80f14f, 0x04 },
{ 0x80f158, 0x7f },
{ 0x80f15a, 0x00 },
{ 0x80f15b, 0x08 },
{ 0x80f15d, 0x03 },
{ 0x80f15e, 0x05 },
{ 0x80f163, 0x05 },
{ 0x80f166, 0x01 },
{ 0x80f167, 0x40 },
{ 0x80f168, 0x0f },
{ 0x80f17a, 0x00 },
{ 0x80f17b, 0x00 },
{ 0x80f183, 0x01 },
{ 0x80f19d, 0x40 },
{ 0x80f1bc, 0x36 },
{ 0x80f1bd, 0x00 },
{ 0x80f1cb, 0xa0 },
{ 0x80f1cc, 0x01 },
{ 0x80f204, 0x10 },
{ 0x80f214, 0x00 },
{ 0x80f24c, 0x88 },
{ 0x80f24d, 0x95 },
{ 0x80f24e, 0x9a },
{ 0x80f24f, 0x90 },
{ 0x80f25a, 0x07 },
{ 0x80f25b, 0xe8 },
{ 0x80f25c, 0x03 },
{ 0x80f25d, 0xb0 },
{ 0x80f25e, 0x04 },
{ 0x80f270, 0x01 },
{ 0x80f271, 0x02 },
{ 0x80f272, 0x01 },
{ 0x80f273, 0x02 },
{ 0x80f40e, 0x0a },
{ 0x80f40f, 0x40 },
{ 0x80f410, 0x08 },
{ 0x80f55f, 0x0a },
{ 0x80f561, 0x15 },
{ 0x80f562, 0x20 },
{ 0x80f5df, 0xfb },
{ 0x80f5e0, 0x00 },
{ 0x80f5e3, 0x09 },
{ 0x80f5e4, 0x01 },
{ 0x80f5e5, 0x01 },
{ 0x80f5f8, 0x01 },
{ 0x80f5fd, 0x01 },
{ 0x80f600, 0x05 },
{ 0x80f601, 0x08 },
{ 0x80f602, 0x0b },
{ 0x80f603, 0x0e },
{ 0x80f604, 0x11 },
{ 0x80f605, 0x14 },
{ 0x80f606, 0x17 },
{ 0x80f607, 0x1f },
{ 0x80f60e, 0x00 },
{ 0x80f60f, 0x04 },
{ 0x80f610, 0x32 },
{ 0x80f611, 0x10 },
{ 0x80f707, 0xfc },
{ 0x80f708, 0x00 },
{ 0x80f709, 0x37 },
{ 0x80f70a, 0x00 },
{ 0x80f78b, 0x01 },
{ 0x80f80f, 0x40 },
{ 0x80f810, 0x54 },
{ 0x80f811, 0x5a },
{ 0x80f905, 0x01 },
{ 0x80fb06, 0x03 },
{ 0x80fd8b, 0x00 },
};
/*
* ITE Tech IT9133 BX demod init
*/
final static int[][] ofsm_init_it9135_v2 = new int[][] {
{ 0x800051, 0x01 },
{ 0x800070, 0x0a },
{ 0x80007e, 0x04 },
{ 0x800081, 0x0a },
{ 0x80008a, 0x01 },
{ 0x80008e, 0x01 },
{ 0x800092, 0x06 },
{ 0x800099, 0x01 },
{ 0x80009f, 0xe1 },
{ 0x8000a0, 0xcf },
{ 0x8000a3, 0x01 },
{ 0x8000a5, 0x01 },
{ 0x8000a6, 0x01 },
{ 0x8000a9, 0x00 },
{ 0x8000aa, 0x01 },
{ 0x8000b0, 0x01 },
{ 0x8000c2, 0x05 },
{ 0x8000c6, 0x19 },
{ 0x80f000, 0x0f },
{ 0x80f02b, 0x00 },
{ 0x80f064, 0x03 },
{ 0x80f065, 0xf9 },
{ 0x80f066, 0x03 },
{ 0x80f067, 0x01 },
{ 0x80f06f, 0xe0 },
{ 0x80f070, 0x03 },
{ 0x80f072, 0x0f },
{ 0x80f073, 0x03 },
{ 0x80f078, 0x00 },
{ 0x80f087, 0x00 },
{ 0x80f09b, 0x3f },
{ 0x80f09c, 0x00 },
{ 0x80f09d, 0x20 },
{ 0x80f09e, 0x00 },
{ 0x80f09f, 0x0c },
{ 0x80f0a0, 0x00 },
{ 0x80f130, 0x04 },
{ 0x80f132, 0x04 },
{ 0x80f144, 0x1a },
{ 0x80f146, 0x00 },
{ 0x80f14a, 0x01 },
{ 0x80f14c, 0x00 },
{ 0x80f14d, 0x00 },
{ 0x80f14f, 0x04 },
{ 0x80f158, 0x7f },
{ 0x80f15a, 0x00 },
{ 0x80f15b, 0x08 },
{ 0x80f15d, 0x03 },
{ 0x80f15e, 0x05 },
{ 0x80f163, 0x05 },
{ 0x80f166, 0x01 },
{ 0x80f167, 0x40 },
{ 0x80f168, 0x0f },
{ 0x80f17a, 0x00 },
{ 0x80f17b, 0x00 },
{ 0x80f183, 0x01 },
{ 0x80f19d, 0x40 },
{ 0x80f1bc, 0x36 },
{ 0x80f1bd, 0x00 },
{ 0x80f1cb, 0xa0 },
{ 0x80f1cc, 0x01 },
{ 0x80f204, 0x10 },
{ 0x80f214, 0x00 },
{ 0x80f40e, 0x0a },
{ 0x80f40f, 0x40 },
{ 0x80f410, 0x08 },
{ 0x80f55f, 0x0a },
{ 0x80f561, 0x15 },
{ 0x80f562, 0x20 },
{ 0x80f5e3, 0x09 },
{ 0x80f5e4, 0x01 },
{ 0x80f5e5, 0x01 },
{ 0x80f600, 0x05 },
{ 0x80f601, 0x08 },
{ 0x80f602, 0x0b },
{ 0x80f603, 0x0e },
{ 0x80f604, 0x11 },
{ 0x80f605, 0x14 },
{ 0x80f606, 0x17 },
{ 0x80f607, 0x1f },
{ 0x80f60e, 0x00 },
{ 0x80f60f, 0x04 },
{ 0x80f610, 0x32 },
{ 0x80f611, 0x10 },
{ 0x80f707, 0xfc },
{ 0x80f708, 0x00 },
{ 0x80f709, 0x37 },
{ 0x80f70a, 0x00 },
{ 0x80f78b, 0x01 },
{ 0x80f80f, 0x40 },
{ 0x80f810, 0x54 },
{ 0x80f811, 0x5a },
{ 0x80f905, 0x01 },
{ 0x80fb06, 0x03 },
{ 0x80fd8b, 0x00 },
};
/*
* ITE Tech IT9133 BX Omega tuner init
* AF9033_TUNER_IT9135_60 = 0x60
*/
final static int[][] tuner_init_it9135_60 = new int[][] {
{ 0x800043, 0x00 },
{ 0x800046, 0x60 },
{ 0x800051, 0x01 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x800068, 0x0a },
{ 0x80006a, 0x03 },
{ 0x800070, 0x0a },
{ 0x800071, 0x0a },
{ 0x800072, 0x02 },
{ 0x800075, 0x8c },
{ 0x800076, 0x8c },
{ 0x800077, 0x8c },
{ 0x800078, 0x8c },
{ 0x800079, 0x01 },
{ 0x80007e, 0x04 },
{ 0x800081, 0x0a },
{ 0x800082, 0x18 },
{ 0x800084, 0x0a },
{ 0x800085, 0x33 },
{ 0x800086, 0xbe },
{ 0x800087, 0xa0 },
{ 0x800088, 0xc6 },
{ 0x800089, 0xb6 },
{ 0x80008a, 0x01 },
{ 0x80008e, 0x01 },
{ 0x800092, 0x06 },
{ 0x800093, 0x00 },
{ 0x800094, 0x00 },
{ 0x800095, 0x00 },
{ 0x800096, 0x00 },
{ 0x800099, 0x01 },
{ 0x80009b, 0x3c },
{ 0x80009c, 0x28 },
{ 0x80009f, 0xe1 },
{ 0x8000a0, 0xcf },
{ 0x8000a3, 0x01 },
{ 0x8000a4, 0x5a },
{ 0x8000a5, 0x01 },
{ 0x8000a6, 0x01 },
{ 0x8000a9, 0x00 },
{ 0x8000aa, 0x01 },
{ 0x8000b0, 0x01 },
{ 0x8000b3, 0x02 },
{ 0x8000b4, 0x3a },
{ 0x8000b6, 0x14 },
{ 0x8000c0, 0x11 },
{ 0x8000c1, 0x00 },
{ 0x8000c2, 0x05 },
{ 0x8000c3, 0x01 },
{ 0x8000c4, 0x00 },
{ 0x8000c6, 0x19 },
{ 0x8000c7, 0x00 },
{ 0x8000cb, 0x32 },
{ 0x8000cc, 0x2c },
{ 0x8000cd, 0x4f },
{ 0x8000ce, 0x30 },
{ 0x8000f3, 0x05 },
{ 0x8000f4, 0xa0 },
{ 0x8000f5, 0x8c },
{ 0x8000f8, 0x03 },
{ 0x8000f9, 0x06 },
{ 0x8000fa, 0x06 },
{ 0x8000fc, 0x03 },
{ 0x8000fd, 0x03 },
{ 0x8000fe, 0x02 },
{ 0x8000ff, 0x0a },
{ 0x800100, 0x50 },
{ 0x800101, 0x7b },
{ 0x800102, 0x8c },
{ 0x800103, 0x00 },
{ 0x800104, 0x02 },
{ 0x800105, 0xbe },
{ 0x800106, 0x00 },
{ 0x800115, 0x0a },
{ 0x800116, 0x03 },
{ 0x80011a, 0xbe },
{ 0x800124, 0xae },
{ 0x800127, 0x00 },
{ 0x80012a, 0x56 },
{ 0x80012b, 0x50 },
{ 0x80012c, 0x47 },
{ 0x80012d, 0x42 },
{ 0x800137, 0x00 },
{ 0x80013b, 0x08 },
{ 0x80013f, 0x5b },
{ 0x800141, 0x59 },
{ 0x800142, 0xf9 },
{ 0x800143, 0x19 },
{ 0x800144, 0x00 },
{ 0x800145, 0x8c },
{ 0x800146, 0x8c },
{ 0x800147, 0x8c },
{ 0x800148, 0x6e },
{ 0x800149, 0x8c },
{ 0x80014a, 0x50 },
{ 0x80014b, 0x8c },
{ 0x80014d, 0xac },
{ 0x80014e, 0xc6 },
{ 0x800151, 0x1e },
{ 0x800153, 0xbc },
{ 0x800178, 0x09 },
{ 0x800181, 0x94 },
{ 0x800182, 0x6e },
{ 0x800185, 0x24 },
{ 0x800189, 0xbe },
{ 0x80018c, 0x03 },
{ 0x80018d, 0x5f },
{ 0x80018f, 0xa0 },
{ 0x800190, 0x5a },
{ 0x800191, 0x00 },
{ 0x80ed02, 0x40 },
{ 0x80ee42, 0x40 },
{ 0x80ee82, 0x40 },
{ 0x80f000, 0x0f },
{ 0x80f01f, 0x8c },
{ 0x80f020, 0x00 },
{ 0x80f029, 0x8c },
{ 0x80f02a, 0x00 },
{ 0x80f02b, 0x00 },
{ 0x80f064, 0x03 },
{ 0x80f065, 0xf9 },
{ 0x80f066, 0x03 },
{ 0x80f067, 0x01 },
{ 0x80f06f, 0xe0 },
{ 0x80f070, 0x03 },
{ 0x80f072, 0x0f },
{ 0x80f073, 0x03 },
{ 0x80f077, 0x01 },
{ 0x80f078, 0x00 },
{ 0x80f087, 0x00 },
{ 0x80f09b, 0x3f },
{ 0x80f09c, 0x00 },
{ 0x80f09d, 0x20 },
{ 0x80f09e, 0x00 },
{ 0x80f09f, 0x0c },
{ 0x80f0a0, 0x00 },
{ 0x80f130, 0x04 },
{ 0x80f132, 0x04 },
{ 0x80f144, 0x1a },
{ 0x80f146, 0x00 },
{ 0x80f14a, 0x01 },
{ 0x80f14c, 0x00 },
{ 0x80f14d, 0x00 },
{ 0x80f14f, 0x04 },
{ 0x80f158, 0x7f },
{ 0x80f15a, 0x00 },
{ 0x80f15b, 0x08 },
{ 0x80f15d, 0x03 },
{ 0x80f15e, 0x05 },
{ 0x80f163, 0x05 },
{ 0x80f166, 0x01 },
{ 0x80f167, 0x40 },
{ 0x80f168, 0x0f },
{ 0x80f17a, 0x00 },
{ 0x80f17b, 0x00 },
{ 0x80f183, 0x01 },
{ 0x80f19d, 0x40 },
{ 0x80f1bc, 0x36 },
{ 0x80f1bd, 0x00 },
{ 0x80f1cb, 0xa0 },
{ 0x80f1cc, 0x01 },
{ 0x80f204, 0x10 },
{ 0x80f214, 0x00 },
{ 0x80f24c, 0x88 },
{ 0x80f24d, 0x95 },
{ 0x80f24e, 0x9a },
{ 0x80f24f, 0x90 },
{ 0x80f25a, 0x07 },
{ 0x80f25b, 0xe8 },
{ 0x80f25c, 0x03 },
{ 0x80f25d, 0xb0 },
{ 0x80f25e, 0x04 },
{ 0x80f270, 0x01 },
{ 0x80f271, 0x02 },
{ 0x80f272, 0x01 },
{ 0x80f273, 0x02 },
{ 0x80f40e, 0x0a },
{ 0x80f40f, 0x40 },
{ 0x80f410, 0x08 },
{ 0x80f55f, 0x0a },
{ 0x80f561, 0x15 },
{ 0x80f562, 0x20 },
{ 0x80f5e3, 0x09 },
{ 0x80f5e4, 0x01 },
{ 0x80f5e5, 0x01 },
{ 0x80f600, 0x05 },
{ 0x80f601, 0x08 },
{ 0x80f602, 0x0b },
{ 0x80f603, 0x0e },
{ 0x80f604, 0x11 },
{ 0x80f605, 0x14 },
{ 0x80f606, 0x17 },
{ 0x80f607, 0x1f },
{ 0x80f60e, 0x00 },
{ 0x80f60f, 0x04 },
{ 0x80f610, 0x32 },
{ 0x80f611, 0x10 },
{ 0x80f707, 0xfc },
{ 0x80f708, 0x00 },
{ 0x80f709, 0x37 },
{ 0x80f70a, 0x00 },
{ 0x80f78b, 0x01 },
{ 0x80f80f, 0x40 },
{ 0x80f810, 0x54 },
{ 0x80f811, 0x5a },
{ 0x80f905, 0x01 },
{ 0x80fb06, 0x03 },
{ 0x80fd8b, 0x00 },
};
/*
* ITE Tech IT9133 BX Omega LNA config 1 tuner init
* AF9033_TUNER_IT9135_61 = 0x61
*/
final static int[][] tuner_init_it9135_61 = new int[][] {
{ 0x800043, 0x00 },
{ 0x800046, 0x61 },
{ 0x800051, 0x01 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x800068, 0x06 },
{ 0x80006a, 0x03 },
{ 0x800070, 0x0a },
{ 0x800071, 0x05 },
{ 0x800072, 0x02 },
{ 0x800075, 0x8c },
{ 0x800076, 0x8c },
{ 0x800077, 0x8c },
{ 0x800078, 0x90 },
{ 0x800079, 0x01 },
{ 0x80007e, 0x04 },
{ 0x800081, 0x0a },
{ 0x800082, 0x12 },
{ 0x800084, 0x0a },
{ 0x800085, 0x33 },
{ 0x800086, 0xbc },
{ 0x800087, 0x9c },
{ 0x800088, 0xcc },
{ 0x800089, 0xa8 },
{ 0x80008a, 0x01 },
{ 0x80008e, 0x01 },
{ 0x800092, 0x06 },
{ 0x800093, 0x00 },
{ 0x800094, 0x00 },
{ 0x800095, 0x00 },
{ 0x800096, 0x00 },
{ 0x800099, 0x01 },
{ 0x80009b, 0x3c },
{ 0x80009c, 0x28 },
{ 0x80009f, 0xe1 },
{ 0x8000a0, 0xcf },
{ 0x8000a3, 0x01 },
{ 0x8000a4, 0x5c },
{ 0x8000a5, 0x01 },
{ 0x8000a6, 0x01 },
{ 0x8000a9, 0x00 },
{ 0x8000aa, 0x01 },
{ 0x8000b0, 0x01 },
{ 0x8000b3, 0x02 },
{ 0x8000b4, 0x3a },
{ 0x8000b6, 0x14 },
{ 0x8000c0, 0x11 },
{ 0x8000c1, 0x00 },
{ 0x8000c2, 0x05 },
{ 0x8000c3, 0x01 },
{ 0x8000c4, 0x00 },
{ 0x8000c6, 0x19 },
{ 0x8000c7, 0x00 },
{ 0x8000cb, 0x32 },
{ 0x8000cc, 0x2c },
{ 0x8000cd, 0x4f },
{ 0x8000ce, 0x30 },
{ 0x8000f3, 0x05 },
{ 0x8000f4, 0xa0 },
{ 0x8000f5, 0x8c },
{ 0x8000f8, 0x03 },
{ 0x8000f9, 0x06 },
{ 0x8000fa, 0x06 },
{ 0x8000fc, 0x03 },
{ 0x8000fd, 0x03 },
{ 0x8000fe, 0x02 },
{ 0x8000ff, 0x08 },
{ 0x800100, 0x50 },
{ 0x800101, 0x7b },
{ 0x800102, 0x8c },
{ 0x800103, 0x01 },
{ 0x800104, 0x02 },
{ 0x800105, 0xc8 },
{ 0x800106, 0x00 },
{ 0x800115, 0x0a },
{ 0x800116, 0x03 },
{ 0x80011a, 0xc6 },
{ 0x800124, 0xa8 },
{ 0x800127, 0x00 },
{ 0x80012a, 0x59 },
{ 0x80012b, 0x50 },
{ 0x80012c, 0x47 },
{ 0x80012d, 0x42 },
{ 0x800137, 0x00 },
{ 0x80013b, 0x05 },
{ 0x80013f, 0x5b },
{ 0x800141, 0x59 },
{ 0x800142, 0xf9 },
{ 0x800143, 0x59 },
{ 0x800144, 0x01 },
{ 0x800145, 0x8c },
{ 0x800146, 0x8c },
{ 0x800147, 0x8c },
{ 0x800148, 0x7b },
{ 0x800149, 0x8c },
{ 0x80014a, 0x50 },
{ 0x80014b, 0x8c },
{ 0x80014d, 0xa8 },
{ 0x80014e, 0xc6 },
{ 0x800151, 0x28 },
{ 0x800153, 0xcc },
{ 0x800178, 0x09 },
{ 0x800181, 0x9c },
{ 0x800182, 0x76 },
{ 0x800185, 0x28 },
{ 0x800189, 0xaa },
{ 0x80018c, 0x03 },
{ 0x80018d, 0x5f },
{ 0x80018f, 0xfb },
{ 0x800190, 0x5c },
{ 0x800191, 0x00 },
{ 0x80ed02, 0x40 },
{ 0x80ee42, 0x40 },
{ 0x80ee82, 0x40 },
{ 0x80f000, 0x0f },
{ 0x80f01f, 0x8c },
{ 0x80f020, 0x00 },
{ 0x80f029, 0x8c },
{ 0x80f02a, 0x00 },
{ 0x80f02b, 0x00 },
{ 0x80f064, 0x03 },
{ 0x80f065, 0xf9 },
{ 0x80f066, 0x03 },
{ 0x80f067, 0x01 },
{ 0x80f06f, 0xe0 },
{ 0x80f070, 0x03 },
{ 0x80f072, 0x0f },
{ 0x80f073, 0x03 },
{ 0x80f077, 0x01 },
{ 0x80f078, 0x00 },
{ 0x80f087, 0x00 },
{ 0x80f09b, 0x3f },
{ 0x80f09c, 0x00 },
{ 0x80f09d, 0x20 },
{ 0x80f09e, 0x00 },
{ 0x80f09f, 0x0c },
{ 0x80f0a0, 0x00 },
{ 0x80f130, 0x04 },
{ 0x80f132, 0x04 },
{ 0x80f144, 0x1a },
{ 0x80f146, 0x00 },
{ 0x80f14a, 0x01 },
{ 0x80f14c, 0x00 },
{ 0x80f14d, 0x00 },
{ 0x80f14f, 0x04 },
{ 0x80f158, 0x7f },
{ 0x80f15a, 0x00 },
{ 0x80f15b, 0x08 },
{ 0x80f15d, 0x03 },
{ 0x80f15e, 0x05 },
{ 0x80f163, 0x05 },
{ 0x80f166, 0x01 },
{ 0x80f167, 0x40 },
{ 0x80f168, 0x0f },
{ 0x80f17a, 0x00 },
{ 0x80f17b, 0x00 },
{ 0x80f183, 0x01 },
{ 0x80f19d, 0x40 },
{ 0x80f1bc, 0x36 },
{ 0x80f1bd, 0x00 },
{ 0x80f1cb, 0xa0 },
{ 0x80f1cc, 0x01 },
{ 0x80f204, 0x10 },
{ 0x80f214, 0x00 },
{ 0x80f24c, 0x88 },
{ 0x80f24d, 0x95 },
{ 0x80f24e, 0x9a },
{ 0x80f24f, 0x90 },
{ 0x80f25a, 0x07 },
{ 0x80f25b, 0xe8 },
{ 0x80f25c, 0x03 },
{ 0x80f25d, 0xb0 },
{ 0x80f25e, 0x04 },
{ 0x80f270, 0x01 },
{ 0x80f271, 0x02 },
{ 0x80f272, 0x01 },
{ 0x80f273, 0x02 },
{ 0x80f40e, 0x0a },
{ 0x80f40f, 0x40 },
{ 0x80f410, 0x08 },
{ 0x80f55f, 0x0a },
{ 0x80f561, 0x15 },
{ 0x80f562, 0x20 },
{ 0x80f5e3, 0x09 },
{ 0x80f5e4, 0x01 },
{ 0x80f5e5, 0x01 },
{ 0x80f600, 0x05 },
{ 0x80f601, 0x08 },
{ 0x80f602, 0x0b },
{ 0x80f603, 0x0e },
{ 0x80f604, 0x11 },
{ 0x80f605, 0x14 },
{ 0x80f606, 0x17 },
{ 0x80f607, 0x1f },
{ 0x80f60e, 0x00 },
{ 0x80f60f, 0x04 },
{ 0x80f610, 0x32 },
{ 0x80f611, 0x10 },
{ 0x80f707, 0xfc },
{ 0x80f708, 0x00 },
{ 0x80f709, 0x37 },
{ 0x80f70a, 0x00 },
{ 0x80f78b, 0x01 },
{ 0x80f80f, 0x40 },
{ 0x80f810, 0x54 },
{ 0x80f811, 0x5a },
{ 0x80f905, 0x01 },
{ 0x80fb06, 0x03 },
{ 0x80fd8b, 0x00 },
};
/*
* ITE Tech IT9133 BX Omega LNA config 2 tuner init
* AF9033_TUNER_IT9135_62 = 0x62
*/
final static int[][] tuner_init_it9135_62 = new int[][] {
{ 0x800043, 0x00 },
{ 0x800046, 0x62 },
{ 0x800051, 0x01 },
{ 0x80005f, 0x00 },
{ 0x800060, 0x00 },
{ 0x800068, 0x0a },
{ 0x80006a, 0x03 },
{ 0x800070, 0x0a },
{ 0x800071, 0x05 },
{ 0x800072, 0x02 },
{ 0x800075, 0x8c },
{ 0x800076, 0x8c },
{ 0x800077, 0x8c },
{ 0x800078, 0x8c },
{ 0x800079, 0x01 },
{ 0x80007e, 0x04 },
{ 0x800081, 0x0a },
{ 0x800082, 0x12 },
{ 0x800084, 0x0a },
{ 0x800085, 0x33 },
{ 0x800086, 0xb8 },
{ 0x800087, 0x9c },
{ 0x800088, 0xb2 },
{ 0x800089, 0xa6 },
{ 0x80008a, 0x01 },
{ 0x80008e, 0x01 },
{ 0x800092, 0x06 },
{ 0x800093, 0x00 },
{ 0x800094, 0x00 },
{ 0x800095, 0x00 },
{ 0x800096, 0x00 },
{ 0x800099, 0x01 },
{ 0x80009b, 0x3c },
{ 0x80009c, 0x28 },
{ 0x80009f, 0xe1 },
{ 0x8000a0, 0xcf },
{ 0x8000a3, 0x01 },
{ 0x8000a4, 0x5a },
{ 0x8000a5, 0x01 },
{ 0x8000a6, 0x01 },
{ 0x8000a9, 0x00 },
{ 0x8000aa, 0x01 },
{ 0x8000b0, 0x01 },
{ 0x8000b3, 0x02 },
{ 0x8000b4, 0x3a },
{ 0x8000b6, 0x14 },
{ 0x8000c0, 0x11 },
{ 0x8000c1, 0x00 },
{ 0x8000c2, 0x05 },
{ 0x8000c3, 0x01 },
{ 0x8000c4, 0x00 },
{ 0x8000c6, 0x19 },
{ 0x8000c7, 0x00 },
{ 0x8000cb, 0x32 },
{ 0x8000cc, 0x2c },
{ 0x8000cd, 0x4f },
{ 0x8000ce, 0x30 },
{ 0x8000f3, 0x05 },
{ 0x8000f4, 0x8c },
{ 0x8000f5, 0x8c },
{ 0x8000f8, 0x03 },
{ 0x8000f9, 0x06 },
{ 0x8000fa, 0x06 },
{ 0x8000fc, 0x02 },
{ 0x8000fd, 0x03 },
{ 0x8000fe, 0x02 },
{ 0x8000ff, 0x09 },
{ 0x800100, 0x50 },
{ 0x800101, 0x6e },
{ 0x800102, 0x8c },
{ 0x800103, 0x02 },
{ 0x800104, 0x02 },
{ 0x800105, 0xc2 },
{ 0x800106, 0x00 },
{ 0x800109, 0x02 },
{ 0x800115, 0x0a },
{ 0x800116, 0x03 },
{ 0x80011a, 0xb8 },
{ 0x800124, 0xa8 },
{ 0x800127, 0x00 },
{ 0x80012a, 0x53 },
{ 0x80012b, 0x51 },
{ 0x80012c, 0x4e },
{ 0x80012d, 0x43 },
{ 0x800137, 0x00 },
{ 0x80013b, 0x05 },
{ 0x80013f, 0x5b },
{ 0x800141, 0x59 },
{ 0x800142, 0xf9 },
{ 0x800143, 0x59 },
{ 0x800144, 0x00 },
{ 0x800145, 0x8c },
{ 0x800146, 0x8c },
{ 0x800147, 0x8c },
{ 0x800148, 0x7b },
{ 0x800149, 0x8c },
{ 0x80014a, 0x50 },
{ 0x80014b, 0x70 },
{ 0x80014d, 0x96 },
{ 0x80014e, 0xd0 },
{ 0x80014f, 0x03 },
{ 0x800151, 0x28 },
{ 0x800153, 0xb2 },
{ 0x800178, 0x09 },
{ 0x800181, 0x9c },
{ 0x800182, 0x6e },
{ 0x800185, 0x24 },
{ 0x800189, 0xb8 },
{ 0x80018c, 0x03 },
{ 0x80018d, 0x5f },
{ 0x80018f, 0xfb },
{ 0x800190, 0x5a },
{ 0x80ed02, 0xff },
{ 0x80ee42, 0xff },
{ 0x80ee82, 0xff },
{ 0x80f000, 0x0f },
{ 0x80f01f, 0x8c },
{ 0x80f020, 0x00 },
{ 0x80f029, 0x8c },
{ 0x80f02a, 0x00 },
{ 0x80f02b, 0x00 },
{ 0x80f064, 0x03 },
{ 0x80f065, 0xf9 },
{ 0x80f066, 0x03 },
{ 0x80f067, 0x01 },
{ 0x80f06f, 0xe0 },
{ 0x80f070, 0x03 },
{ 0x80f072, 0x0f },
{ 0x80f073, 0x03 },
{ 0x80f077, 0x01 },
{ 0x80f078, 0x00 },
{ 0x80f087, 0x00 },
{ 0x80f09b, 0x3f },
{ 0x80f09c, 0x00 },
{ 0x80f09d, 0x20 },
{ 0x80f09e, 0x00 },
{ 0x80f09f, 0x0c },
{ 0x80f0a0, 0x00 },
{ 0x80f130, 0x04 },
{ 0x80f132, 0x04 },
{ 0x80f144, 0x1a },
{ 0x80f146, 0x00 },
{ 0x80f14a, 0x01 },
{ 0x80f14c, 0x00 },
{ 0x80f14d, 0x00 },
{ 0x80f14f, 0x04 },
{ 0x80f158, 0x7f },
{ 0x80f15a, 0x00 },
{ 0x80f15b, 0x08 },
{ 0x80f15d, 0x03 },
{ 0x80f15e, 0x05 },
{ 0x80f163, 0x05 },
{ 0x80f166, 0x01 },
{ 0x80f167, 0x40 },
{ 0x80f168, 0x0f },
{ 0x80f17a, 0x00 },
{ 0x80f17b, 0x00 },
{ 0x80f183, 0x01 },
{ 0x80f19d, 0x40 },
{ 0x80f1bc, 0x36 },
{ 0x80f1bd, 0x00 },
{ 0x80f1cb, 0xa0 },
{ 0x80f1cc, 0x01 },
{ 0x80f204, 0x10 },
{ 0x80f214, 0x00 },
{ 0x80f24c, 0x88 },
{ 0x80f24d, 0x95 },
{ 0x80f24e, 0x9a },
{ 0x80f24f, 0x90 },
{ 0x80f25a, 0x07 },
{ 0x80f25b, 0xe8 },
{ 0x80f25c, 0x03 },
{ 0x80f25d, 0xb0 },
{ 0x80f25e, 0x04 },
{ 0x80f270, 0x01 },
{ 0x80f271, 0x02 },
{ 0x80f272, 0x01 },
{ 0x80f273, 0x02 },
{ 0x80f40e, 0x0a },
{ 0x80f40f, 0x40 },
{ 0x80f410, 0x08 },
{ 0x80f55f, 0x0a },
{ 0x80f561, 0x15 },
{ 0x80f562, 0x20 },
{ 0x80f5e3, 0x09 },
{ 0x80f5e4, 0x01 },
{ 0x80f5e5, 0x01 },
{ 0x80f600, 0x05 },
{ 0x80f601, 0x08 },
{ 0x80f602, 0x0b },
{ 0x80f603, 0x0e },
{ 0x80f604, 0x11 },
{ 0x80f605, 0x14 },
{ 0x80f606, 0x17 },
{ 0x80f607, 0x1f },
{ 0x80f60e, 0x00 },
{ 0x80f60f, 0x04 },
{ 0x80f610, 0x32 },
{ 0x80f611, 0x10 },
{ 0x80f707, 0xfc },
{ 0x80f708, 0x00 },
{ 0x80f709, 0x37 },
{ 0x80f70a, 0x00 },
{ 0x80f78b, 0x01 },
{ 0x80f80f, 0x40 },
{ 0x80f810, 0x54 },
{ 0x80f811, 0x5a },
{ 0x80f905, 0x01 },
{ 0x80fb06, 0x03 },
{ 0x80fd8b, 0x00 },
};
}
| 66,448 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Af9035DvbDevice.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/af9035/Af9035DvbDevice.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.af9035;
import static android.hardware.usb.UsbConstants.USB_DIR_IN;
import static android.hardware.usb.UsbConstants.USB_DIR_OUT;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.DVB_DEVICE_UNSUPPORTED;
import static info.martinmarinov.drivers.DvbException.ErrorCode.HARDWARE_EXCEPTION;
import static info.martinmarinov.drivers.DvbException.ErrorCode.IO_EXCEPTION;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_PID_AVERMEDIA_A867;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_PID_AVERMEDIA_TWINSTAR;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_VID_AVERMEDIA;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_ADC_MULTIPLIER_2X;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TS_MODE_SERIAL;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TS_MODE_USB;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_FC0011;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_FC0012;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_FC2580;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_38;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_51;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_52;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_60;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_61;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_62;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_MXL5007T;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_TDA18218;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_TUA9001;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CLOCK_LUT_AF9035;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CLOCK_LUT_IT9135;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_FW_BOOT;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_FW_DL;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_FW_DL_BEGIN;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_FW_DL_END;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_FW_QUERYINFO;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_FW_SCATTER_WR;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_GENERIC_I2C_RD;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_GENERIC_I2C_WR;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_I2C_RD;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_I2C_WR;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_MEM_RD;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.CMD_MEM_WR;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.EEPROM_1_IF_H;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.EEPROM_1_IF_L;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.EEPROM_1_TUNER_ID;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.EEPROM_2ND_DEMOD_ADDR;
import static info.martinmarinov.drivers.usb.af9035.Af9035Data.EEPROM_TS_MODE;
import static info.martinmarinov.drivers.usb.af9035.It913x.IT9133AX_TUNER;
import static info.martinmarinov.drivers.usb.af9035.It913x.IT9133BX_TUNER;
import static info.martinmarinov.drivers.usb.af9035.It913x.IT913X_ROLE_DUAL_MASTER;
import static info.martinmarinov.drivers.usb.af9035.It913x.IT913X_ROLE_SINGLE;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbDemux;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.I2cAdapter;
import info.martinmarinov.drivers.tools.SleepUtils;
import info.martinmarinov.drivers.usb.DvbFrontend;
import info.martinmarinov.drivers.usb.DvbTuner;
import info.martinmarinov.drivers.usb.generic.AbstractGenericDvbUsbDevice;
import info.martinmarinov.usbxfer.AlternateUsbInterface;
class Af9035DvbDevice extends AbstractGenericDvbUsbDevice {
private final static String TAG = Af9035DvbDevice.class.getSimpleName();
private final static boolean USB_SPEED_FULL = false; // this is tue only for USB 1.1 which is not on Android
private final UsbInterface iface;
private final UsbEndpoint endpoint;
private final I2cAdapter i2CAdapter = new Af9035I2cAdapter();
private int chip_version;
private int chip_type;
private int firmware;
private boolean dual_mode;
private boolean no_eeprom;
private boolean no_read;
private byte[] eeprom = new byte[256];
private int[] af9033_i2c_addr = new int[2];
private Af9033Config[] af9033_config;
Af9035DvbDevice(UsbDevice usbDevice, Context context, DeviceFilter filter) throws DvbException {
super(
usbDevice,
context,
filter,
DvbDemux.DvbDmxSwfilter(),
usbDevice.getInterface(0).getEndpoint(0),
usbDevice.getInterface(0).getEndpoint(1));
iface = usbDevice.getInterface(0);
endpoint = iface.getEndpoint(2);
// Endpoint 3 is a TS USB_DIR_IN endpoint with address 0x85
// but I don't know what it is used for
if (controlEndpointIn.getAddress() != 0x81 || controlEndpointIn.getDirection() != USB_DIR_IN)
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
if (controlEndpointOut.getAddress() != 0x02 || controlEndpointOut.getDirection() != USB_DIR_OUT)
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
if (endpoint.getAddress() != 0x84 || endpoint.getDirection() != USB_DIR_IN)
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
}
@Override
public String getDebugString() {
return "AF9035 device " + getDeviceFilter().getName();
}
@Override
protected void powerControl(boolean turnOn) throws DvbException {
// no-op
}
private boolean identifyState() throws DvbException {
byte[] rbuf = new byte[4];
rd_regs(0x1222, rbuf, 3);
chip_version = rbuf[0] & 0xFF;
chip_type = (rbuf[2] & 0xFF) << 8 | (rbuf[1] & 0xFF);
int prechip_version = rd_reg(0x384f);
Log.d(TAG, String.format("prechip_version=%02x chip_version=%02x chip_type=%04x", prechip_version, chip_version, chip_type));
int utmp;
no_eeprom = false;
int eeprom_addr = -1;
if (chip_type == 0x9135) {
if (chip_version == 0x02) {
firmware = R.raw.dvbusbit913502fw;
utmp = 0x00461d;
} else {
firmware = R.raw.dvbusbit913501fw;
utmp = 0x00461b;
}
/* Check if eeprom exists */
int tmp = rd_reg(utmp);
if (tmp == 0x00) {
Log.d(TAG, "no eeprom");
no_eeprom = true;
}
eeprom_addr = 0x4994; // EEPROM_BASE_IT9135
} else if (chip_type == 0x9306) {
firmware = R.raw.dvbusbit930301fw;
no_eeprom = true;
} else {
firmware = R.raw.dvbusbaf903502fw;
eeprom_addr = 0x42f5; //EEPROM_BASE_AF9035;
}
if (!no_eeprom) {
/* Read and store eeprom */
byte[] tempbuff = new byte[32];
for (int i = 0; i < 256; i += 32) {
rd_regs(eeprom_addr + i, tempbuff, 32);
System.arraycopy(tempbuff, 0, eeprom, i, 32);
}
/* check for dual tuner mode */
int tmp = eeprom[EEPROM_TS_MODE] & 0xFF;
boolean ts_mode_invalid = false;
switch (tmp) {
case 0:
break;
case 1:
case 3:
dual_mode = true;
break;
case 5:
if (chip_type != 0x9135 && chip_type != 0x9306) {
dual_mode = true; /* AF9035 */
} else {
ts_mode_invalid = true;
}
break;
default:
ts_mode_invalid = true;
}
Log.d(TAG, "ts mode=" + tmp + " dual mode=" + dual_mode);
if (ts_mode_invalid) {
Log.d(TAG, "ts mode=" + tmp + " not supported, defaulting to single tuner mode!");
}
}
ctrlMsg(CMD_FW_QUERYINFO, 0, 1, new byte[]{1}, rbuf.length, rbuf);
return rbuf[0] != 0 || rbuf[1] != 0 || rbuf[2] != 0 || rbuf[3] != 0;
}
private void download_firmware_old(byte[] fw_data) throws DvbException {
/*
* Thanks to Daniel Glöckner <[email protected]> about that info!
*
* byte 0: MCS 51 core
* There are two inside the AF9035 (1=Link and 2=OFDM) with separate
* address spaces
* byte 1-2: Big endian destination address
* byte 3-4: Big endian number of data bytes following the header
* byte 5-6: Big endian header checksum, apparently ignored by the chip
* Calculated as ~(h[0]*256+h[1]+h[2]*256+h[3]+h[4]*256)
*/
final int HDR_SIZE = 7;
final int MAX_DATA = 58;
byte[] tbuff = new byte[MAX_DATA];
int i;
for (i = fw_data.length; i > HDR_SIZE; ) {
int hdr_core = fw_data[fw_data.length - i] & 0xFF;
int hdr_addr = (fw_data[fw_data.length - i + 1] & 0xFF) << 8;
hdr_addr |= fw_data[fw_data.length - i + 2] & 0xFF;
int hdr_data_len = (fw_data[fw_data.length - i + 3] & 0xFF) << 8;
hdr_data_len |= fw_data[fw_data.length - i + 4] & 0xFF;
int hdr_checksum = (fw_data[fw_data.length - i + 5] & 0xFF) << 8;
hdr_checksum |= fw_data[fw_data.length - i + 6] & 0xFF;
Log.d(TAG, String.format("core=%d addr=%04x data_len=%d checksum=%04x",
hdr_core, hdr_addr, hdr_data_len, hdr_checksum));
if (((hdr_core != 1) && (hdr_core != 2)) || (hdr_data_len > i)) {
Log.e(TAG, "bad firmware");
break;
}
/* download begin packet */
ctrlMsg(CMD_FW_DL_BEGIN, 0, 0, null, 0, null);
/* download firmware packet(s) */
for (int j = HDR_SIZE + hdr_data_len; j > 0; j -= MAX_DATA) {
int len = j;
if (len > MAX_DATA) len = MAX_DATA;
System.arraycopy(fw_data, fw_data.length - i + HDR_SIZE + hdr_data_len - j, tbuff, 0, len);
ctrlMsg(CMD_FW_DL, 0, 0, tbuff, 0, null);
}
/* download end packet */
ctrlMsg(CMD_FW_DL_END, 0, 0, null, 0, null);
i -= hdr_data_len + HDR_SIZE;
Log.d(TAG, "data uploaded=" + (fw_data.length - i));
}
/* print warn if firmware is bad, continue and see what happens */
if (i != 0) {
Log.e(TAG, "bad firmware");
}
}
private void download_firmware_new(byte[] fw_data) throws DvbException {
final int HDR_SIZE = 7;
byte[] tbuff = new byte[fw_data.length];
/*
* There seems to be following firmware header. Meaning of bytes 0-3
* is unknown.
*
* 0: 3
* 1: 0, 1
* 2: 0
* 3: 1, 2, 3
* 4: addr MSB
* 5: addr LSB
* 6: count of data bytes ?
*/
for (int i = HDR_SIZE, i_prev = 0; i <= fw_data.length; i++) {
if (i == fw_data.length || (fw_data[i] == 0x03 && (fw_data[i + 1] == 0x00 || fw_data[i + 1] == 0x01) && fw_data[i + 2] == 0x00)) {
System.arraycopy(fw_data, i_prev, tbuff, 0, i - i_prev);
ctrlMsg(CMD_FW_SCATTER_WR, 0, i - i_prev, tbuff, 0, null);
i_prev = i;
}
}
}
private void download_firmware(byte[] fw_data) throws DvbException {
/*
* In case of dual tuner configuration we need to do some extra
* initialization in order to download firmware to slave demod too,
* which is done by master demod.
* Master feeds also clock and controls power via GPIO.
*/
if (dual_mode) {
/* configure gpioh1, reset & power slave demod */
wr_reg_mask(0x00d8b0, 0x01, 0x01);
wr_reg_mask(0x00d8b1, 0x01, 0x01);
wr_reg_mask(0x00d8af, 0x00, 0x01);
SleepUtils.usleep(50_000);
wr_reg_mask(0x00d8af, 0x01, 0x01);
/* tell the slave I2C address */
int tmp = eeprom[EEPROM_2ND_DEMOD_ADDR] & 0xFF;
/* Use default I2C address if eeprom has no address set */
if (tmp == 0) {
tmp = 0x1d << 1; /* 8-bit format used by chip */
}
if ((chip_type == 0x9135) || (chip_type == 0x9306)) {
wr_reg(0x004bfb, tmp);
} else {
wr_reg(0x00417f, tmp);
/* enable clock out */
wr_reg_mask(0x00d81a, 0x01, 0x01);
}
}
if (fw_data[0] == 0x01) {
download_firmware_old(fw_data);
} else {
download_firmware_new(fw_data);
}
/* firmware loaded, request boot */
ctrlMsg(CMD_FW_BOOT, 0, 0, null, 0, null);
/* ensure firmware starts */
byte[] rbuf = new byte[4];
ctrlMsg(CMD_FW_QUERYINFO, 0, 1, new byte[]{1}, 4, rbuf);
if (rbuf[0] == 0 && rbuf[1] == 0 && rbuf[2] == 0 && rbuf[3] == 0) {
throw new DvbException(IO_EXCEPTION, resources.getString(R.string.cannot_load_firmware));
}
Log.d(TAG, String.format("firmware version=%d.%d.%d.%d", rbuf[0], rbuf[1], rbuf[2], rbuf[3]));
}
private byte[] readFirmware(int resource) throws DvbException {
InputStream inputStream = resources.openRawResource(resource);
//noinspection TryFinallyCanBeTryWithResources
try {
byte[] fw = new byte[inputStream.available()];
if (inputStream.read(fw) != fw.length) {
throw new DvbException(IO_EXCEPTION, resources.getString(R.string.cannot_load_firmware));
}
return fw;
} catch (IOException e) {
throw new DvbException(IO_EXCEPTION, e);
} finally {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
protected synchronized void readConfig() throws DvbException {
boolean isWarm = identifyState();
Log.d(TAG, "Device is " + (isWarm ? "WARM" : "COLD"));
if (!isWarm) {
byte[] fw_data = readFirmware(firmware);
download_firmware(fw_data);
isWarm = identifyState();
if (!isWarm) throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.cannot_load_firmware));
Log.d(TAG, "Device is WARM");
}
// actual read_config
/* Demod I2C address */
af9033_i2c_addr[0] = 0x1c;
af9033_i2c_addr[1] = 0x1d;
int[] af9033_configadc_multiplier = new int[] { AF9033_ADC_MULTIPLIER_2X, AF9033_ADC_MULTIPLIER_2X };
int[] af9033_configts_mode = new int[] { AF9033_TS_MODE_USB, AF9033_TS_MODE_SERIAL };
boolean[] af9033_configdyn0_clk = new boolean[2];
boolean[] af9033_configspec_inv = new boolean[2];
int[] af9033_configtuner = new int[2];
int[] af9033_configclock = new int[2];
boolean skip_eeprom = false;
if (chip_type == 0x9135) {
/* feed clock for integrated RF tuner */
af9033_configdyn0_clk[0] = true;
af9033_configdyn0_clk[1] = true;
if (chip_version == 0x02) {
af9033_configtuner[0] = AF9033_TUNER_IT9135_60;
af9033_configtuner[1] = AF9033_TUNER_IT9135_60;
} else {
af9033_configtuner[0] = AF9033_TUNER_IT9135_38;
af9033_configtuner[1] = AF9033_TUNER_IT9135_38;
}
if (no_eeprom) {
/* skip rc stuff */
skip_eeprom = true;
}
} else if (chip_type == 0x9306) {
/*
* IT930x is an USB bridge, only single demod-single tuner
* configurations seen so far.
*/
return;
}
if (!skip_eeprom) {
/* Skip remote controller */
if (dual_mode) {
/* Read 2nd demodulator I2C address. 8-bit format on eeprom */
int tmp = eeprom[EEPROM_2ND_DEMOD_ADDR] & 0xFF;
if (tmp != 0) {
af9033_i2c_addr[1] = tmp >> 1;
}
}
int eeprom_offset = 0;
for (int i = 0; i < (dual_mode ? 2 : 1); i++) {
/* tuner */
int tmp = eeprom[EEPROM_1_TUNER_ID + eeprom_offset] & 0xFF;
/* tuner sanity check */
if (chip_type == 0x9135) {
if (chip_version == 0x02) {
/* IT9135 BX (v2) */
switch (tmp) {
case AF9033_TUNER_IT9135_60:
case AF9033_TUNER_IT9135_61:
case AF9033_TUNER_IT9135_62:
af9033_configtuner[i] = tmp;
break;
}
} else {
/* IT9135 AX (v1) */
switch (tmp) {
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
case AF9033_TUNER_IT9135_52:
af9033_configtuner[i] = tmp;
break;
}
}
} else {
/* AF9035 */
af9033_configtuner[i] = tmp;
}
if (af9033_configtuner[i] != tmp) {
Log.d(TAG, String.format("[%d] overriding tuner from %02x to %02x", i, tmp, af9033_configtuner[i]));
}
switch (af9033_configtuner[i]) {
case AF9033_TUNER_TUA9001:
case AF9033_TUNER_FC0011:
case AF9033_TUNER_MXL5007T:
case AF9033_TUNER_TDA18218:
case AF9033_TUNER_FC2580:
case AF9033_TUNER_FC0012:
af9033_configspec_inv[i] = true;
break;
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
case AF9033_TUNER_IT9135_52:
case AF9033_TUNER_IT9135_60:
case AF9033_TUNER_IT9135_61:
case AF9033_TUNER_IT9135_62:
break;
default:
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unsupported_tuner_on_device));
}
/* disable dual mode if driver does not support it */
if (i == 1) {
switch (af9033_configtuner[i]) {
case AF9033_TUNER_FC0012:
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
case AF9033_TUNER_IT9135_52:
case AF9033_TUNER_IT9135_60:
case AF9033_TUNER_IT9135_61:
case AF9033_TUNER_IT9135_62:
case AF9033_TUNER_MXL5007T:
break;
default:
dual_mode = false;
Log.w(TAG, "driver does not support 2nd tuner and will disable it");
}
}
/* tuner IF frequency */
tmp = eeprom[EEPROM_1_IF_L + eeprom_offset] & 0xFF;
int tmp16 = tmp;
tmp = eeprom[EEPROM_1_IF_H + eeprom_offset] & 0xFF;
tmp16 |= tmp << 8;
Log.d(TAG, String.format("[%d]IF=%d", i, tmp16));
eeprom_offset += 0x10; /* shift for the 2nd tuner params */
}
}
/* get demod clock */
int tmp = rd_reg(0x00d800) & 0x0f;
for (int i = 0; i < 2; i++) {
if (chip_type == 0x9135) {
af9033_configclock[i] = CLOCK_LUT_IT9135[tmp];
} else {
af9033_configclock[i] = CLOCK_LUT_AF9035[tmp];
}
}
no_read = false;
/* Some MXL5007T devices cannot properly handle tuner I2C read ops. */
if (af9033_configtuner[0] == AF9033_TUNER_MXL5007T && getDeviceFilter().getVendorId() == USB_VID_AVERMEDIA)
switch (getDeviceFilter().getProductId()) {
case USB_PID_AVERMEDIA_A867:
case USB_PID_AVERMEDIA_TWINSTAR:
Log.w(TAG, "Device may have issues with I2C read operations. Enabling fix.");
no_read = true;
break;
}
af9033_config = new Af9033Config[] {
new Af9033Config(af9033_configdyn0_clk[0], af9033_configadc_multiplier[0], af9033_configtuner[0], af9033_configts_mode[0], af9033_configclock[0], af9033_configspec_inv[0]),
new Af9033Config(af9033_configdyn0_clk[1], af9033_configadc_multiplier[1], af9033_configtuner[1], af9033_configts_mode[1], af9033_configclock[1], af9033_configspec_inv[1])
};
// init
int frame_size = (USB_SPEED_FULL ? 5 : 87) * 188 / 4;
int packet_size = (USB_SPEED_FULL ? 64 : 512) / 4;
int[][] tab = Af9035Data.reg_val_mask_tab(frame_size, packet_size, dual_mode);
/* init endpoints */
for (int[] aTab : tab) {
wr_reg_mask(aTab[0], aTab[1], aTab[2]);
}
}
@Override
protected DvbFrontend frontendAttatch() throws DvbException {
return new Af9033Frontend(resources, af9033_config[0], af9033_i2c_addr[0], i2CAdapter);
}
@Override
protected DvbTuner tunerAttatch() throws DvbException {
int role = dual_mode ? IT913X_ROLE_DUAL_MASTER : IT913X_ROLE_SINGLE;
switch (af9033_config[0].tuner) {
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
case AF9033_TUNER_IT9135_52:
return new It913x(resources, ((Af9033Frontend) frontend).regMap, IT9133AX_TUNER, role);
case AF9033_TUNER_IT9135_60:
case AF9033_TUNER_IT9135_61:
case AF9033_TUNER_IT9135_62:
return new It913x(resources, ((Af9033Frontend) frontend).regMap, IT9133BX_TUNER, role);
default:
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unsupported_tuner_on_device));
}
}
@Override
protected synchronized void init() throws DvbException {
}
@Override
protected AlternateUsbInterface getUsbInterface() {
return AlternateUsbInterface.forUsbInterface(usbDeviceConnection, iface).get(0);
}
@Override
protected UsbEndpoint getUsbEndpoint() {
return endpoint;
}
// communication
private final static int MAX_XFER_SIZE = 64;
private final static int BUF_LEN = 64;
private final static int REQ_HDR_LEN = 4;
private final static int ACK_HDR_LEN = 3;
private final static int CHECKSUM_LEN = 2;
private final Object usbLock = new Object();
private final byte[] sbuf = new byte[BUF_LEN];
private int seq = 0;
private int checksum(byte[] buf, int len) {
int checksum = 0;
for (int i = 1; i < len; i++) {
if ((i % 2) != 0) {
checksum += (buf[i] & 0xFF) << 8;
} else {
checksum += (buf[i] & 0xFF);
}
// simulate 16-bit overflow
if (checksum > 0xFFFF) {
checksum -= 0x10000;
}
}
checksum = ~checksum;
return checksum & 0xFFFF;
}
private void ctrlMsg(int cmd, int mbox, int o_wlen, byte[] wbuf, int o_rlen, byte[] rbuf) throws DvbException {
/* buffer overflow check */
if (o_wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) || o_rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) {
Log.e(TAG, "too much data wlen=" + o_wlen + " rlen=" + o_rlen);
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
synchronized (sbuf) {
sbuf[0] = (byte) (REQ_HDR_LEN + o_wlen + CHECKSUM_LEN - 1);
sbuf[1] = (byte) mbox;
sbuf[2] = (byte) cmd;
sbuf[3] = (byte) seq++;
// simulate 8-bit overflow
if (seq > 0xFF) seq -= 0x100;
if (o_wlen > 0) {
System.arraycopy(wbuf, 0, sbuf, REQ_HDR_LEN, o_wlen);
}
int wlen = REQ_HDR_LEN + o_wlen + CHECKSUM_LEN;
int rlen = ACK_HDR_LEN + o_rlen + CHECKSUM_LEN;
/* calc and add checksum */
int checksum = checksum(sbuf, (sbuf[0] & 0xFF) - 1);
sbuf[(sbuf[0] & 0xFF) - 1] = (byte) (checksum >> 8);
sbuf[sbuf[0] & 0xFF] = (byte) (checksum & 0xFF);
/* no ack for these packets */
if (cmd == CMD_FW_DL) {
rlen = 0;
}
dvb_usb_generic_rw(sbuf, wlen, sbuf, rlen);
/* no ack for those packets */
if (cmd == CMD_FW_DL) return;
/* verify checksum */
checksum = checksum(sbuf, rlen - 2);
int tmp_checksum = ((sbuf[rlen - 2] & 0xFF) << 8) | (sbuf[rlen - 1] & 0xFF);
if (tmp_checksum != checksum) {
Log.e(TAG, "command=0x" + Integer.toHexString(cmd) + " checksum mismatch (0x" + Integer.toHexString(tmp_checksum) + " != 0x" + Integer.toHexString(checksum) + ")");
throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.cannot_send_control_message_checksum));
}
/* check status */
if (sbuf[2] != 0) {
Log.e(TAG, "command=0x" + Integer.toHexString(cmd) + " failed fw error=" + (sbuf[2] & 0xFF));
throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.cannot_send_control_message, sbuf[2] & 0xFF));
}
/* read request, copy returned data to return buf */
if (o_rlen > 0) {
System.arraycopy(sbuf, ACK_HDR_LEN, rbuf, 0, o_rlen);
}
}
}
/* write multiple registers */
private void wr_regs(int reg, byte[] val, int len) throws DvbException {
if (6 + len > MAX_XFER_SIZE) {
Log.e(TAG, "i2c wr: len=" + len + " is too big!");
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
byte[] wbuf = new byte[6 + len];
wbuf[0] = (byte) len;
wbuf[1] = 2;
wbuf[2] = 0;
wbuf[3] = 0;
wbuf[4] = (byte) (reg >> 8);
wbuf[5] = (byte) reg;
System.arraycopy(val, 0, wbuf, 6, len);
int mbox = (reg >> 16) & 0xff;
ctrlMsg(CMD_MEM_WR, mbox, 6 + len, wbuf, 0, null);
}
/* read multiple registers */
private void rd_regs(int reg, byte[] val, int len) throws DvbException {
byte[] wbuf = new byte[]{(byte) len, 2, 0, 0, (byte) (reg >> 8), (byte) reg};
int mbox = (reg >> 16) & 0xff;
ctrlMsg(CMD_MEM_RD, mbox, wbuf.length, wbuf, len, val);
}
/* write single register */
private void wr_reg(int reg, int val) throws DvbException {
wr_regs(reg, new byte[]{(byte) val}, 1);
}
/* read single register */
private int rd_reg(int reg) throws DvbException {
byte[] res = new byte[1];
rd_regs(reg, res, 1);
return res[0] & 0xFF;
}
/* write single register with mask */
private void wr_reg_mask(int reg, int val, int mask) throws DvbException {
/* no need for read if whole reg is written */
if (mask != 0xff) {
int tmp = rd_reg(reg);
val &= mask;
tmp &= ~mask;
val |= tmp;
}
wr_reg(reg, val);
}
// I2C
private static boolean AF9035_IS_I2C_XFER_WRITE_READ(I2cAdapter.I2cMessage[] _msg) {
return _msg.length == 2 && ((_msg[0].flags & I2C_M_RD) == 0) && ((_msg[1].flags & I2C_M_RD) != 0);
}
private static boolean AF9035_IS_I2C_XFER_WRITE(I2cAdapter.I2cMessage[] _msg) {
return _msg.length == 1 && ((_msg[0].flags & I2C_M_RD) == 0);
}
private static boolean AF9035_IS_I2C_XFER_READ(I2cAdapter.I2cMessage[] _msg) {
return _msg.length == 1 && ((_msg[0].flags & I2C_M_RD) != 0);
}
private class Af9035I2cAdapter extends I2cAdapter {
@Override
protected int masterXfer(I2cMessage[] msg) throws DvbException {
/*
* AF9035 I2C sub header is 5 bytes long. Meaning of those bytes are:
* 0: data len
* 1: I2C addr << 1
* 2: reg addr len
* byte 3 and 4 can be used as reg addr
* 3: reg addr MSB
* used when reg addr len is set to 2
* 4: reg addr LSB
* used when reg addr len is set to 1 or 2
*
* For the simplify we do not use register addr at all.
* NOTE: As a firmware knows tuner type there is very small possibility
* there could be some tuner I2C hacks done by firmware and this may
* lead problems if firmware expects those bytes are used.
*
* TODO: Here is few hacks. AF9035 chip integrates AF9033 demodulator.
* IT9135 chip integrates AF9033 demodulator and RF tuner. For dual
* tuner devices, there is also external AF9033 demodulator connected
* via external I2C bus. All AF9033 demod I2C traffic, both single and
* dual tuner configuration, is covered by firmware - actual USB IO
* looks just like a memory access.
* In case of IT913x chip, there is own tuner driver. It is implemented
* currently as a I2C driver, even tuner IP block is likely build
* directly into the demodulator memory space and there is no own I2C
* bus. I2C subsystem does not allow register multiple devices to same
* bus, having same slave address. Due to that we reuse demod address,
* shifted by one bit, on that case.
*
* For IT930x we use a different command and the sub header is
* different as well:
* 0: data len
* 1: I2C bus (0x03 seems to be only value used)
* 2: I2C addr << 1
*/
if (AF9035_IS_I2C_XFER_WRITE_READ(msg)) {
if (msg[0].len > 40 || msg[1].len > 40) {
/* TODO: correct limits > 40 */
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.unsuported_i2c_operation));
} else if ((msg[0].addr == af9033_i2c_addr[0]) || (msg[0].addr == af9033_i2c_addr[1])){
/* demod access via firmware interface */
int reg = ((msg[0].buf[0] & 0xFF) << 16) | ((msg[0].buf[1] & 0xFF) << 8) | (msg[0].buf[2] & 0xFF);
if (msg[0].addr == af9033_i2c_addr[1]) {
reg |= 0x100000;
}
rd_regs(reg, msg[1].buf, msg[1].len);
} else if (no_read) {
for (int i = 0; i < msg[1].len; i++) msg[1].buf[i] = 0;
return 0;
} else {
/* I2C write + read */
byte[] buf = new byte[ MAX_XFER_SIZE];
int cmd = CMD_I2C_RD;
int wlen = 5 + msg[0].len;
if (chip_type == 0x9306) {
cmd = CMD_GENERIC_I2C_RD;
wlen = 3 + msg[0].len;
}
int mbox = ((msg[0].addr & 0x80) >> 3);
buf[0] = (byte) msg[1].len;
if (chip_type == 0x9306) {
buf[1] = 0x03; /* I2C bus */
buf[2] = (byte) (msg[0].addr << 1);
System.arraycopy(msg[0].buf, 0, buf, 3, msg[0].len);
} else {
buf[1] = (byte) (msg[0].addr << 1);
buf[3] = 0x00; /* reg addr MSB */
buf[4] = 0x00; /* reg addr LSB */
/* Keep prev behavior for write req len > 2*/
if (msg[0].len > 2) {
buf[2] = 0x00; /* reg addr len */
System.arraycopy(msg[0].buf, 0, buf, 5, msg[0].len);
/* Use reg addr fields if write req len <= 2 */
} else {
wlen = 5;
buf[2] = (byte) msg[0].len;
if (msg[0].len == 2) {
buf[3] = msg[0].buf[0];
buf[4] = msg[0].buf[1];
} else if (msg[0].len == 1) {
buf[4] = msg[0].buf[0];
}
}
}
ctrlMsg(cmd, mbox, wlen, buf, msg[1].len, msg[1].buf);
}
} else if (AF9035_IS_I2C_XFER_WRITE(msg)) {
if (msg[0].len > 40) {
/* TODO: correct limits > 40 */
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.unsuported_i2c_operation));
} else if ((msg[0].addr == af9033_i2c_addr[0]) || (msg[0].addr == af9033_i2c_addr[1])){
/* demod access via firmware interface */
int reg = ((msg[0].buf[0] & 0xFF) << 16) | ((msg[0].buf[1] & 0xFF) << 8) | (msg[0].buf[2] & 0xFF);
if (msg[0].addr == af9033_i2c_addr[1]) {
reg |= 0x100000;
}
byte[] tmp2 = new byte[msg[0].len - 3];
System.arraycopy(msg[0].buf, 3, tmp2, 0, tmp2.length);
wr_regs(reg, tmp2, tmp2.length);
} else {
/* I2C write */
byte[] buf = new byte[ MAX_XFER_SIZE];
int cmd = CMD_I2C_WR;
int wlen = 5 + msg[0].len;
if (chip_type == 0x9306) {
cmd = CMD_GENERIC_I2C_WR;
wlen = 3 + msg[0].len;
}
int mbox = ((msg[0].addr & 0x80) >> 3);
buf[0] = (byte) msg[0].len;
if (chip_type == 0x9306) {
buf[1] = 0x03; /* I2C bus */
buf[2] = (byte) (msg[0].addr << 1);
System.arraycopy(msg[0].buf, 0, buf, 3, msg[0].len);
} else {
buf[1] = (byte) (msg[0].addr << 1);
buf[2] = 0x00; /* reg addr len */
buf[3] = 0x00; /* reg addr MSB */
buf[4] = 0x00; /* reg addr LSB */
System.arraycopy(msg[0].buf, 0, buf, 5, msg[0].len);
}
ctrlMsg(cmd, mbox, wlen, buf, 0, null);
}
} else if (AF9035_IS_I2C_XFER_READ(msg)) {
if (msg[0].len > 40) {
/* TODO: correct limits > 40 */
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.unsuported_i2c_operation));
} else if (no_read) {
for (int i = 0; i < msg[0].len; i++) msg[0].buf[i] = 0;
return 0;
} else {
/* I2C read */
byte[] buf = new byte[5];
int cmd = CMD_I2C_RD;
int wlen = buf.length;
if (chip_type == 0x9306) {
cmd = CMD_GENERIC_I2C_RD;
wlen = 3;
}
int mbox = ((msg[0].addr & 0x80) >> 3);
buf[0] = (byte) msg[0].len;
if (chip_type == 0x9306) {
buf[1] = 0x03; /* I2C bus */
buf[2] = (byte) (msg[0].addr << 1);
} else {
buf[1] = (byte) (msg[0].addr << 1);
buf[2] = 0x00; /* reg addr len */
buf[3] = 0x00; /* reg addr MSB */
buf[4] = 0x00; /* reg addr LSB */
}
ctrlMsg(cmd, mbox, wlen, buf, msg[0].len, msg[0].buf);
return msg.length;
}
} else {
/*
* We support only three kind of I2C transactions:
* 1) 1 x write + 1 x read (repeated start)
* 2) 1 x write
* 3) 1 x read
*/
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.unsuported_i2c_operation));
}
return msg.length;
}
}
@Override
protected int getNumPacketsPerRequest() {
return 87;
}
@Override
protected int getNumRequests() {
return 10;
}
}
| 39,410 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Af9035Data.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/af9035/Af9035Data.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.af9035;
class Af9035Data {
final static int EEPROM_BASE_AF9035 = 0x42f5;
final static int EEPROM_BASE_IT9135 = 0x4994;
final static int EEPROM_SHIFT = 0x10;
final static int EEPROM_IR_MODE = 0x18;
final static int EEPROM_TS_MODE = 0x31;
final static int EEPROM_2ND_DEMOD_ADDR = 0x32;
final static int EEPROM_IR_TYPE = 0x34;
final static int EEPROM_1_IF_L = 0x38;
final static int EEPROM_1_IF_H = 0x39;
final static int EEPROM_1_TUNER_ID = 0x3c;
final static int EEPROM_2_IF_L = 0x48;
final static int EEPROM_2_IF_H = 0x49;
final static int EEPROM_2_TUNER_ID = 0x4c;
/* USB commands */
final static int CMD_MEM_RD = 0x00;
final static int CMD_MEM_WR = 0x01;
final static int CMD_I2C_RD = 0x02;
final static int CMD_I2C_WR = 0x03;
final static int CMD_IR_GET = 0x18;
final static int CMD_FW_DL = 0x21;
final static int CMD_FW_QUERYINFO = 0x22;
final static int CMD_FW_BOOT = 0x23;
final static int CMD_FW_DL_BEGIN = 0x24;
final static int CMD_FW_DL_END = 0x25;
final static int CMD_FW_SCATTER_WR = 0x29;
final static int CMD_GENERIC_I2C_RD = 0x2a;
final static int CMD_GENERIC_I2C_WR = 0x2b;
final static int[] CLOCK_LUT_AF9035 = new int[] {
20480000, /* FPGA */
16384000, /* 16.38 MHz */
20480000, /* 20.48 MHz */
36000000, /* 36.00 MHz */
30000000, /* 30.00 MHz */
26000000, /* 26.00 MHz */
28000000, /* 28.00 MHz */
32000000, /* 32.00 MHz */
34000000, /* 34.00 MHz */
24000000, /* 24.00 MHz */
22000000, /* 22.00 MHz */
12000000, /* 12.00 MHz */
};
final static int[] CLOCK_LUT_IT9135 = new int[] {
12000000, /* 12.00 MHz */
20480000, /* 20.48 MHz */
36000000, /* 36.00 MHz */
30000000, /* 30.00 MHz */
26000000, /* 26.00 MHz */
28000000, /* 28.00 MHz */
32000000, /* 32.00 MHz */
34000000, /* 34.00 MHz */
24000000, /* 24.00 MHz */
22000000, /* 22.00 MHz */
};
static int[][] reg_val_mask_tab(int frame_size, int packet_size, boolean dual_mode) {
return new int[][] {
{ 0x80f99d, 0x01, 0x01 },
{ 0x80f9a4, 0x01, 0x01 },
{ 0x00dd11, 0x00, 0x20 },
{ 0x00dd11, 0x00, 0x40 },
{ 0x00dd13, 0x00, 0x20 },
{ 0x00dd13, 0x00, 0x40 },
{ 0x00dd11, 0x20, 0x20 },
{ 0x00dd88, (frame_size) & 0xff, 0xff},
{ 0x00dd89, (frame_size >> 8) & 0xff, 0xff},
{ 0x00dd0c, packet_size, 0xff},
{ 0x00dd11, (dual_mode ? 1 : 0) << 6, 0x40 },
{ 0x00dd8a, (frame_size) & 0xff, 0xff},
{ 0x00dd8b, (frame_size >> 8) & 0xff, 0xff},
{ 0x00dd0d, packet_size, 0xff },
{ 0x80f9a3, (dual_mode ? 1 : 0), 0x01 },
{ 0x80f9cd, (dual_mode ? 1 : 0), 0x01 },
{ 0x80f99d, 0x00, 0x01 },
{ 0x80f9a4, 0x00, 0x01 },
};
}
}
| 4,397 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Af9033Frontend.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/af9035/Af9033Frontend.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.af9035;
import static java.util.Collections.unmodifiableSet;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_TUNE_TO_FREQ;
import static info.martinmarinov.drivers.DvbException.ErrorCode.DVB_DEVICE_UNSUPPORTED;
import static info.martinmarinov.drivers.DvbException.ErrorCode.UNSUPPORTED_BANDWIDTH;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_CARRIER;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_LOCK;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_SIGNAL;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_SYNC;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_VITERBI;
import static info.martinmarinov.drivers.tools.SetUtils.setOf;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_ADC_MULTIPLIER_2X;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TS_MODE_PARALLEL;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TS_MODE_SERIAL;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TS_MODE_USB;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_FC0011;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_FC0012;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_FC2580;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_38;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_51;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_52;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_60;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_61;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_IT9135_62;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_MXL5007T;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_TDA18218;
import static info.martinmarinov.drivers.usb.af9035.Af9033Config.AF9033_TUNER_TUA9001;
import android.content.res.Resources;
import android.util.Log;
import androidx.annotation.NonNull;
import java.util.Collections;
import java.util.Set;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.DvbStatus;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.DvbMath;
import info.martinmarinov.drivers.tools.I2cAdapter;
import info.martinmarinov.drivers.tools.RegMap;
import info.martinmarinov.drivers.tools.SleepUtils;
import info.martinmarinov.drivers.usb.DvbFrontend;
import info.martinmarinov.drivers.usb.DvbTuner;
class Af9033Frontend implements DvbFrontend {
private final static Set<DvbStatus> NO_SIGNAL = unmodifiableSet(Collections.<DvbStatus>emptySet());
private final static Set<DvbStatus> HAS_SIGNAL = unmodifiableSet(setOf(FE_HAS_SIGNAL));
private final static Set<DvbStatus> HAS_VITERBI = unmodifiableSet(setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER,
FE_HAS_VITERBI));
private final static Set<DvbStatus> HAS_LOCK = unmodifiableSet(setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER,
FE_HAS_VITERBI, FE_HAS_SYNC,
FE_HAS_LOCK));
private final static int PID_FILTER_COUNT = 32;
private final static String TAG = Af9033Frontend.class.getSimpleName();
private final Resources resources;
private final Af9033Config config;
final RegMap regMap;
private boolean ts_mode_parallel, ts_mode_serial;
private boolean is_af9035;
private long frequency, bandwidth_hz;
private DvbTuner tuner;
Af9033Frontend(Resources resources, Af9033Config config, int address, I2cAdapter i2CAdapter) {
this.resources = resources;
this.config = config;
this.regMap = new RegMap(address, 24, i2CAdapter);
}
@Override
public DvbCapabilities getCapabilities() {
return Af9033Data.CAPABILITIES;
}
@Override
public synchronized void attach() throws DvbException {
// probe
/* Setup the state */
switch (config.ts_mode) {
case AF9033_TS_MODE_PARALLEL:
ts_mode_parallel = true;
break;
case AF9033_TS_MODE_SERIAL:
ts_mode_serial = true;
break;
case AF9033_TS_MODE_USB:
/* USB mode for AF9035 */
default:
break;
}
if (config.clock != 12000000) {
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.usupported_clock_speed));
}
/* Create regmap */
/* Firmware version */
int reg;
switch (config.tuner) {
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
case AF9033_TUNER_IT9135_52:
case AF9033_TUNER_IT9135_60:
case AF9033_TUNER_IT9135_61:
case AF9033_TUNER_IT9135_62:
reg = 0x004bfc;
break;
default:
is_af9035 = true;
reg = 0x0083e9;
break;
}
byte[] buf = new byte[8];
regMap.read_regs(reg, buf, 0, 4);
regMap.read_regs(0x804191, buf, 4, 4);
Log.d(TAG, String.format("firmware version: LINK %d.%d.%d.%d - OFDM %d.%d.%d.%d",
buf[0], buf[1], buf[2], buf[3],
buf[4], buf[5], buf[6], buf[7]));
/* Sleep as chip seems to be partly active by default */
switch (config.tuner) {
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
case AF9033_TUNER_IT9135_52:
case AF9033_TUNER_IT9135_60:
case AF9033_TUNER_IT9135_61:
case AF9033_TUNER_IT9135_62:
/* IT9135 did not like to sleep at that early */
break;
default:
regMap.write_reg(0x80004c, 0x01);
regMap.write_reg(0x800000, 0x00);
}
}
@Override
public synchronized void release() {
// sleep
try {
regMap.write_reg(0x80004c, 0x01);
regMap.write_reg(0x800000, 0x00);
// regmap_read_poll_timeout
for (int i = 100, tmp = 1; i > 0 && tmp != 0; i--) {
tmp = regMap.read_reg(0x80004c);
SleepUtils.usleep(10_000);
}
regMap.update_bits(0x80fb24, 0x08, 0x08);
/* Prevent current leak by setting TS interface to parallel mode */
if (config.ts_mode == AF9033_TS_MODE_SERIAL) {
/* Enable parallel TS */
regMap.update_bits(0x00d917, 0x01, 0x00);
regMap.update_bits(0x00d916, 0x01, 0x01);
}
} catch (DvbException e) {
e.printStackTrace();
}
}
/* Write reg val table using reg addr auto increment */
private synchronized void wr_reg_val_tab(int[][] tab) throws DvbException {
// tab[i][0] is reg
// tab[i][1] is val
final int MAX_TAB_LEN = 212;
Log.d(TAG, "tab_len"+tab.length);
if (tab.length > MAX_TAB_LEN) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
byte[] buf = new byte[1 + MAX_TAB_LEN];
for (int i = 0, j = 0; i < tab.length; i++) {
buf[j] = (byte) tab[i][1];
if (i == tab.length - 1 || tab[i][0] != tab[i + 1][0] - 1) {
regMap.bulk_write(tab[i][0] - j, buf, j + 1);
j = 0;
} else {
j++;
}
}
}
@Override
public synchronized void init(DvbTuner tuner) throws DvbException {
this.tuner = tuner;
/* Main clk control */
long utmp = DvbMath.divU64(config.clock * 0x80000L, 1_000_000L);
byte[] buf = new byte[4];
buf[0] = (byte) (utmp);
buf[1] = (byte) (utmp >> 8);
buf[2] = (byte) (utmp >> 16);
buf[3] = (byte) (utmp >> 24);
Log.d(TAG, String.format("clock=%d clock_cw=%08x", config.clock, utmp));
regMap.bulk_write(0x800025, buf);
/* ADC clk control */
int i;
for (i = 0; i < Af9033Data.clock_adc_lut.length; i++) {
if (Af9033Data.clock_adc_lut[i][0] == config.clock)
break;
}
if (i == Af9033Data.clock_adc_lut.length) {
Log.e(TAG, "Couldn't find ADC config for clock " + config.clock);
throw new DvbException(DvbException.ErrorCode.HARDWARE_EXCEPTION, resources.getString(R.string.failed_callibration_step));
}
utmp = DvbMath.divU64((long) Af9033Data.clock_adc_lut[i][1] * 0x80000L, 1_000_000L);
buf[0] = (byte) (utmp);
buf[1] = (byte) (utmp >> 8);
buf[2] = (byte) (utmp >> 16);
Log.d(TAG, String.format("adc=%d adc_cw=%06x", Af9033Data.clock_adc_lut[i][1], utmp));
regMap.bulk_write(0x80f1cd, buf, 3);
/* Config register table */
int[][] tab = Af9033Data.reg_val_mask_tab(config.tuner, ts_mode_serial, ts_mode_parallel, config.adc_multiplier);
for (i = 0; i < tab.length; i++) {
regMap.update_bits(tab[i][0] /* reg */, tab[i][2] /* mask */, tab[i][1] /* val */);
}
/* Demod clk output */
if (config.dyn0_clk) {
regMap.write_reg(0x80fba8, 0x00);
}
/* TS interface */
if (config.ts_mode == AF9033_TS_MODE_USB) {
regMap.update_bits(0x80f9a5, 0x01, 0x00);
regMap.update_bits(0x80f9b5, 0x01, 0x01);
} else {
regMap.update_bits(0x80f990, 0x01, 0x00);
regMap.update_bits(0x80f9b5, 0x01, 0x00);
}
/* Demod core settings */
int[][] init;
switch (config.tuner) {
case AF9033_TUNER_IT9135_38:
case AF9033_TUNER_IT9135_51:
case AF9033_TUNER_IT9135_52:
init = Af9033Data.ofsm_init_it9135_v1;
break;
case AF9033_TUNER_IT9135_60:
case AF9033_TUNER_IT9135_61:
case AF9033_TUNER_IT9135_62:
init = Af9033Data.ofsm_init_it9135_v2;
break;
default:
init = Af9033Data.ofsm_init;
break;
}
wr_reg_val_tab(init);
/* Demod tuner specific settings */
switch (config.tuner) {
case AF9033_TUNER_TUA9001:
init = Af9033Data.tuner_init_tua9001;
break;
case AF9033_TUNER_FC0011:
init = Af9033Data.tuner_init_fc0011;
break;
case AF9033_TUNER_MXL5007T:
init = Af9033Data.tuner_init_mxl5007t;
break;
case AF9033_TUNER_TDA18218:
init = Af9033Data.tuner_init_tda18218;
break;
case AF9033_TUNER_FC2580:
init = Af9033Data.tuner_init_fc2580;
break;
case AF9033_TUNER_FC0012:
init = Af9033Data.tuner_init_fc0012;
break;
case AF9033_TUNER_IT9135_38:
init = Af9033Data.tuner_init_it9135_38;
break;
case AF9033_TUNER_IT9135_51:
init = Af9033Data.tuner_init_it9135_51;
break;
case AF9033_TUNER_IT9135_52:
init = Af9033Data.tuner_init_it9135_52;
break;
case AF9033_TUNER_IT9135_60:
init = Af9033Data.tuner_init_it9135_60;
break;
case AF9033_TUNER_IT9135_61:
init = Af9033Data.tuner_init_it9135_61;
break;
case AF9033_TUNER_IT9135_62:
init = Af9033Data.tuner_init_it9135_62;
break;
default:
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unsupported_tuner_on_device));
}
wr_reg_val_tab(init);
if (config.ts_mode == AF9033_TS_MODE_SERIAL) {
regMap.update_bits(0x00d91c, 0x01, 0x01);
regMap.update_bits(0x00d917, 0x01, 0x00);
regMap.update_bits(0x00d916, 0x01, 0x00);
}
switch (config.tuner) {
case AF9033_TUNER_IT9135_60:
case AF9033_TUNER_IT9135_61:
case AF9033_TUNER_IT9135_62:
regMap.write_reg(0x800000, 0x01);
}
bandwidth_hz = 0; /* Force to program all parameters */
tuner.init();
}
@Override
public synchronized void setParams(long frequency, long bandwidth_hz, @NonNull DeliverySystem deliverySystem) throws DvbException {
if (deliverySystem != DeliverySystem.DVBT) {
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
int bandwidth_reg_val;
/* Check bandwidth */
switch ((int) bandwidth_hz) {
case 6_000_000:
bandwidth_reg_val = 0x00;
break;
case 7_000_000:
bandwidth_reg_val = 0x01;
break;
case 8_000_000:
bandwidth_reg_val = 0x02;
break;
default:
throw new DvbException(UNSUPPORTED_BANDWIDTH, resources.getString(R.string.invalid_bw));
}
/* Program tuner */
tuner.setParams(frequency, bandwidth_hz, deliverySystem);
/* Coefficients */
if (bandwidth_hz != this.bandwidth_hz) {
if (config.clock != 12_000_000) {
throw new IllegalStateException("Clock that are not 12 MHz should have been filtered already!");
}
switch ((int) bandwidth_hz) {
case 6_000_000:
regMap.bulk_write(0x800001, Af9033Data.coeff_lut_12000000_6000000);
break;
case 7_000_000:
regMap.bulk_write(0x800001, Af9033Data.coeff_lut_12000000_7000000);
break;
case 8_000_000:
regMap.bulk_write(0x800001, Af9033Data.coeff_lut_12000000_8000000);
break;
default:
throw new IllegalStateException("Invalid bandwidth that was already checked");
}
}
/* IF frequency control */
if (bandwidth_hz != this.bandwidth_hz) {
int i;
for (i = 0; i < Af9033Data.clock_adc_lut.length; i++) {
if (Af9033Data.clock_adc_lut[i][0] == config.clock)
break;
}
if (i == Af9033Data.clock_adc_lut.length) {
throw new DvbException(DvbException.ErrorCode.HARDWARE_EXCEPTION, resources.getString(R.string.failed_callibration_step));
}
int adc_freq = Af9033Data.clock_adc_lut[i][1];
if (config.adc_multiplier == AF9033_ADC_MULTIPLIER_2X) {
adc_freq = 2 * adc_freq;
}
/* Get used IF frequency */
long if_frequency = tuner.getIfFrequency();
long utmp = DvbMath.divRoundClosest(if_frequency * 0x800000L, adc_freq);
if (!config.speck_inv && if_frequency > 0) {
utmp = 0x800000 - utmp;
}
byte[] buf = new byte[3];
buf[0] = (byte) (utmp);
buf[1] = (byte) (utmp >> 8);
buf[2] = (byte) (utmp >> 16);
regMap.bulk_write(0x800029, buf, 3);
this.bandwidth_hz = bandwidth_hz;
}
regMap.update_bits(0x80f904, 0x03, bandwidth_reg_val);
regMap.write_reg(0x800040, 0x00);
regMap.write_reg(0x800047, 0x00);
regMap.update_bits(0x80f999, 0x01, 0x00);
int tmp;
if (frequency <= 230_000_000L) {
tmp = 0x00; /* VHF */
} else {
tmp = 0x01; /* UHF */
}
regMap.write_reg(0x80004b, tmp);
/* Reset FSM */
regMap.write_reg(0x800000, 0x00);
this.frequency = frequency;
}
@Override
public synchronized int readSnr() throws DvbException {
if (!getStatus().contains(FE_HAS_VITERBI)) return -1;
byte[] buf = new byte[7];
/* read value */
regMap.read_regs(0x80002c, buf, 0, 3);
int snr_val = ((buf[2] & 0xFF) << 16) | ((buf[1] & 0xFF) << 8) | (buf[0] & 0xFF);
/* read superframe number */
int u8tmp = regMap.read_reg(0x80f78b);
if (u8tmp > 0) {
snr_val /= u8tmp;
}
/* read current transmission mode */
u8tmp = regMap.read_reg(0x80f900);
switch (u8tmp & 3) {
case 0:
snr_val *= 4;
break;
case 1:
snr_val *= 1;
break;
case 2:
snr_val *= 2;
break;
default:
return -1;
}
/* read current modulation */
u8tmp = regMap.read_reg(0x80f903);
int[][] snr_lut;
switch (u8tmp & 3) {
case 0:
snr_lut = Af9033Data.qpsk_snr_lut;
break;
case 1:
snr_lut = Af9033Data.qam16_snr_lut;
break;
case 2:
snr_lut = Af9033Data.qam64_snr_lut;
break;
default:
return -1;
}
// FE_SCALE_DECIBEL
for (int[] aSnr_lut : snr_lut) {
if (snr_val < aSnr_lut[0]) {
return aSnr_lut[1] * 1000;
}
}
return -1;
}
@Override
public synchronized int readRfStrengthPercentage() throws DvbException {
if (is_af9035) {
/* Read signal strength of 0-100 scale */
return regMap.read_reg(0x800048);
} else {
int utmp = regMap.read_reg(0x8000f7);
byte[] buf = new byte[7];
regMap.read_regs(0x80f900, buf, 0, 7);
int gain_offset;
if (frequency <= 300_000_000) {
gain_offset = 7; /* VHF */
} else {
gain_offset = 4; /* UHF */
}
int power_real = (utmp - 100 - gain_offset) -
Af9033Data.power_reference[((buf[3] & 0xFF) & 3)][((buf[6] & 0xFF) & 7)];
if (power_real < -15) {
return 0;
} else if ((power_real >= -15) && (power_real < 0)) {
return (2 * (power_real + 15)) / 3;
} else if ((power_real >= 0) && (power_real < 20)) {
return 4 * power_real + 10;
} else if ((power_real >= 20) && (power_real < 35)) {
return (2 * (power_real - 20)) / 3 + 90;
} else {
return 100;
}
}
}
@Override
public synchronized int readBer() throws DvbException {
if (!getStatus().contains(FE_HAS_LOCK)) return 0xFFFF;
/*
* Packet count used for measurement is 10000
* (rsd_packet_count). Maybe it should be increased?
*/
byte[] buf = new byte[7];
regMap.read_regs(0x800032, buf, 0, 7);
int rsd_bit_err_count = ((buf[4] & 0xFF) << 16) | ((buf[3] & 0xFF) << 8) | (buf[2] & 0xFF);
int rsd_packet_count = ((buf[6] & 0xFF) << 8) | (buf[5] & 0xFF);
return (int) ((rsd_bit_err_count * 0xFFFFL) / (rsd_packet_count * 204 * 8));
}
@Override
public synchronized Set<DvbStatus> getStatus() throws DvbException {
Set<DvbStatus> status = NO_SIGNAL;
/* Radio channel status: 0=no result, 1=has signal, 2=no signal */
int utmp = regMap.read_reg(0x800047);
/* Has signal */
if (utmp == 0x01) status = HAS_SIGNAL;
if (utmp != 0x02) {
boolean tps_lock = (regMap.read_reg(0x80f5a9) & 0x01) != 0;
if (tps_lock) {
status = HAS_VITERBI;
}
boolean full_lock = (regMap.read_reg(0x80f999) & 0x01) != 0;
if (full_lock) {
status = HAS_LOCK;
}
}
return status;
}
@Override
public synchronized void setPids(int... pids) throws DvbException {
pid_filter_ctrl(true);
for (int i = 0; i < pids.length; i++) {
pid_filter(i, pids[i], true);
}
}
@Override
public synchronized void disablePidFilter() throws DvbException {
pid_filter_ctrl(false);
}
private void pid_filter_ctrl(boolean enable) throws DvbException {
regMap.update_bits(0x80f993, 0x01, enable ? 1 : 0);
}
private void pid_filter(int index, int pid, boolean onoff) throws DvbException {
if (pid > 0x1fff) return;
regMap.bulk_write(0x80f996, new byte[] {(byte) pid, (byte) (pid >> 8)});
regMap.write_reg(0x80f994, onoff ? 1 : 0);
regMap.write_reg(0x80f995, index);
}
}
| 22,011 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Af9033Config.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/af9035/Af9033Config.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.af9035;
class Af9033Config {
/*
* clock Hz
* 12000000, 22000000, 24000000, 34000000, 32000000, 28000000, 26000000,
* 30000000, 36000000, 20480000, 16384000
*/
final int clock;
final boolean dyn0_clk;
final boolean speck_inv;
/*
* ADC multiplier
*/
static final int AF9033_ADC_MULTIPLIER_1X = 0;
static final int AF9033_ADC_MULTIPLIER_2X = 1;
final int adc_multiplier;
/*
* tuner
*/
static final int AF9033_TUNER_TUA9001 = 0x27; /* Infineon TUA 9001 */
static final int AF9033_TUNER_FC0011 = 0x28; /* Fitipower FC0011 */
static final int AF9033_TUNER_FC0012 = 0x2e; /* Fitipower FC0012 */
static final int AF9033_TUNER_MXL5007T = 0xa0; /* MaxLinear MxL5007T */
static final int AF9033_TUNER_TDA18218 = 0xa1; /* NXP TDA 18218HN */
static final int AF9033_TUNER_FC2580 = 0x32; /* FCI FC2580 */
/* 50-5f Omega */
static final int AF9033_TUNER_IT9135_38 = 0x38; /* Omega */
static final int AF9033_TUNER_IT9135_51 = 0x51; /* Omega LNA config 1 */
static final int AF9033_TUNER_IT9135_52 = 0x52; /* Omega LNA config 2 */
/* 60-6f Omega v2 */
static final int AF9033_TUNER_IT9135_60 = 0x60; /* Omega v2 */
static final int AF9033_TUNER_IT9135_61 = 0x61; /* Omega v2 LNA config 1 */
static final int AF9033_TUNER_IT9135_62 = 0x62; /* Omega v2 LNA config 2 */
final int tuner;
/*
* TS settings
*/
static final int AF9033_TS_MODE_USB = 0;
static final int AF9033_TS_MODE_PARALLEL = 1;
static final int AF9033_TS_MODE_SERIAL = 2;
final int ts_mode;
Af9033Config(boolean dyn0_clk, int adc_multiplier, int tuner, int ts_mode, int clock, boolean speck_inv) {
this.dyn0_clk = dyn0_clk;
this.adc_multiplier = adc_multiplier;
this.tuner = tuner;
this.ts_mode = ts_mode;
this.clock = clock;
this.speck_inv = speck_inv;
}
}
| 2,871 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
It913x.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/af9035/It913x.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.af9035;
import android.content.res.Resources;
import android.util.Log;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.RegMap;
import info.martinmarinov.drivers.tools.SleepUtils;
import info.martinmarinov.drivers.usb.DvbTuner;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_TUNE_TO_FREQ;
import static info.martinmarinov.drivers.DvbException.ErrorCode.DVB_DEVICE_UNSUPPORTED;
class It913x implements DvbTuner {
private final static String TAG = It913x.class.getSimpleName();
final static int IT9133AX_TUNER = 1;
final static int IT9133BX_TUNER = 2;
final static int IT913X_ROLE_SINGLE = 0;
final static int IT913X_ROLE_DUAL_MASTER = 1;
// final static int IT913X_ROLE_DUAL_SLAVE = 2;
private final static int TIMEOUT = 50;
private final static int[] nv = new int[] {48, 32, 24, 16, 12, 8, 6, 4, 2};
private final Resources resources;
private final RegMap regMap;
private final int chip_ver;
private final int role;
private boolean active = false;
private int clk_mode, xtal, fdiv, fn_min;
It913x(Resources resources, RegMap regMap, int chip_ver, int role) {
this.resources = resources;
this.regMap = regMap;
this.chip_ver = chip_ver;
this.role = role;
}
@Override
public void attatch() throws DvbException {
// no-op
Log.d(TAG, "chip_ver "+chip_ver+", role "+role);
}
@Override
public synchronized void release() {
// sleep
active = false;
try {
regMap.bulk_write(0x80ec40, new byte[]{0x00});
/*
* Writing '0x00' to master tuner register '0x80ec08' causes slave tuner
* communication lost. Due to that, we cannot put master full sleep.
*/
if (role == IT913X_ROLE_DUAL_MASTER) {
regMap.bulk_write(0x80ec02, new byte[]{0x3f,0x1f,0x3f,0x3e});
} else {
regMap.bulk_write(0x80ec02, new byte[]{0x3f,0x1f,0x3f,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00});
}
regMap.bulk_write(0x80ec12, new byte[]{0x00,0x00,0x00,0x00});
regMap.bulk_write(0x80ec17, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00});
regMap.bulk_write(0x80ec22, new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00});
regMap.bulk_write(0x80ec20, new byte[]{0x00});
regMap.bulk_write(0x80ec3f, new byte[]{0x01});
} catch (DvbException e) {
e.printStackTrace();
}
}
@Override
public synchronized void init() throws DvbException {
Log.d(TAG, "role "+role);
regMap.write_reg(0x80ec4c, 0x68);
SleepUtils.usleep(100_000L);
int utmp = regMap.read_reg(0x80ec86);
int iqik_m_cal;
switch (utmp) {
case 0:
/* 12.000 MHz */
clk_mode = utmp;
xtal = 2000;
fdiv = 3;
iqik_m_cal = 16;
break;
case 1:
/* 20.480 MHz */
clk_mode = utmp;
xtal = 640;
fdiv = 1;
iqik_m_cal = 6;
break;
default:
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.usupported_clock_speed));
}
utmp = regMap.read_reg(0x80ed03);
int nv_val;
if (utmp < nv.length) {
nv_val = nv[utmp];
} else {
nv_val = 2;
}
byte[] buf = new byte[2];
for (int i = 0; i < 10; i++) {
SleepUtils.mdelay(TIMEOUT / 10);
regMap.read_regs(0x80ed23, buf, 0, 2);
utmp = ((buf[1] & 0xFF) << 8) | (buf[0] & 0xFF);
if (utmp != 0) break;
}
fn_min = xtal * utmp;
fn_min /= (fdiv * nv_val);
fn_min *= 1000;
Log.d(TAG, "fn_min "+fn_min);
/*
* Chip version BX never sets that flag so we just wait 50ms in that
* case. It is possible poll BX similarly than AX and then timeout in
* order to get 50ms delay, but that causes about 120 extra I2C
* messages. As for now, we just wait and reduce IO.
*/
if (chip_ver == 1) {
for (int i = 0; i < 10; i++) {
SleepUtils.mdelay(TIMEOUT / 10);
utmp = regMap.read_reg(0x80ec82);
if (utmp != 0) break;
}
} else {
SleepUtils.mdelay(TIMEOUT);
}
regMap.write_reg(0x80ed81, iqik_m_cal);
regMap.write_reg(0x80ec57, 0x00);
regMap.write_reg(0x80ec58, 0x00);
regMap.write_reg(0x80ec40, 0x01);
active = true;
}
@Override
public void setParams(long frequency, long bandwidth_hz, DeliverySystem deliverySystem) throws DvbException {
if (!active) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
if (deliverySystem != DeliverySystem.DVBT) {
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
int n, n_div;
if (frequency <= 74_000_000L) {
n_div = 48;
n = 0;
} else if (frequency <= 111_000_000L) {
n_div = 32;
n = 1;
} else if (frequency <= 148_000_000L) {
n_div = 24;
n = 2;
} else if (frequency <= 222_000_000L) {
n_div = 16;
n = 3;
} else if (frequency <= 296_000_000L) {
n_div = 12;
n = 4;
} else if (frequency <= 445_000_000L) {
n_div = 8;
n = 5;
} else if (frequency <= fn_min) {
n_div = 6;
n = 6;
} else if (frequency <= 950_000_000L) {
n_div = 4;
n = 7;
} else {
n_div = 2;
n = 0;
}
long utmp = regMap.read_reg(0x80ed81);
long iqik_m_cal = utmp * n_div;
if (utmp < 0x20) {
if (clk_mode == 0) {
iqik_m_cal = (iqik_m_cal * 9) >> 5;
} else {
iqik_m_cal >>= 1;
}
} else {
iqik_m_cal = 0x40 - iqik_m_cal;
if (clk_mode == 0) {
iqik_m_cal = (~((iqik_m_cal * 9) >> 5)) & 0xFFFF;
} else {
iqik_m_cal = (~(iqik_m_cal >> 1)) & 0xFFFF;
}
}
long t_cal_freq = (frequency / 1_000L) * n_div * fdiv;
long pre_lo_freq = t_cal_freq / xtal;
utmp = pre_lo_freq * xtal;
if ((t_cal_freq - utmp) >= (xtal >> 1)) {
pre_lo_freq++;
}
pre_lo_freq += ((long) n) << 13;
/* Frequency OMEGA_IQIK_M_CAL_MID*/
t_cal_freq = pre_lo_freq + iqik_m_cal;
Log.d(TAG, String.format("t_cal_freq %d, pre_lo_freq %d", t_cal_freq, pre_lo_freq));
int l_band, lna_band;
if (frequency <= 440_000_000L) {
l_band = 0;
lna_band = 0;
} else if (frequency <= 484_000_000L) {
l_band = 1;
lna_band = 1;
} else if (frequency <= 533_000_000L) {
l_band = 1;
lna_band = 2;
} else if (frequency <= 587_000_000L) {
l_band = 1;
lna_band = 3;
} else if (frequency <= 645_000_000L) {
l_band = 1;
lna_band = 4;
} else if (frequency <= 710_000_000L) {
l_band = 1;
lna_band = 5;
} else if (frequency <= 782_000_000L) {
l_band = 1;
lna_band = 6;
} else if (frequency <= 860_000_000L) {
l_band = 1;
lna_band = 7;
} else if (frequency <= 1_492_000_000L) {
l_band = 1;
lna_band = 0;
} else if (frequency <= 1_685_000_000L) {
l_band = 1;
lna_band = 1;
} else {
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.cannot_tune, frequency / 1_000_000));
}
/* XXX: latest windows driver does not set that at all */
regMap.write_reg(0x80ee06, lna_band);
int u8tmp;
if (bandwidth_hz <= 5_000_000L) {
u8tmp = 0;
} else if (bandwidth_hz <= 6_000_000L) {
u8tmp = 2;
} else if (bandwidth_hz <= 7_000_000L) {
u8tmp = 4;
} else {
u8tmp = 6; /* 8_000_000 */
}
regMap.write_reg(0x80ec56, u8tmp);
/* XXX: latest windows driver sets different value (a8 != 68) */
regMap.write_reg(0x80ec4c, (0xa0 | (l_band << 3)) & 0xff);
regMap.write_reg(0x80ec4d, (int) (t_cal_freq & 0xff));
regMap.write_reg(0x80ec4e, (int) ((t_cal_freq >> 8) & 0xff));
regMap.write_reg(0x80011e, (int) (pre_lo_freq & 0xff));
regMap.write_reg(0x80011f, (int) ((pre_lo_freq >> 8) & 0xff));
}
@Override
public long getIfFrequency() throws DvbException {
return 0;
}
@Override
public int readRfStrengthPercentage() throws DvbException {
return 0;
}
}
| 10,367 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Af9035DvbDeviceCreator.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/af9035/Af9035DvbDeviceCreator.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.af9035;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import java.util.Set;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbDevice;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.usb.DvbUsbDevice;
import info.martinmarinov.drivers.usb.DvbUsbIds;
import static info.martinmarinov.drivers.tools.SetUtils.setOf;
public class Af9035DvbDeviceCreator implements DvbUsbDevice.Creator {
private final static Set<DeviceFilter> AF9035_DEVICES = setOf(
/* AF9035 devices */
new DeviceFilter(DvbUsbIds.USB_VID_AFATECH, DvbUsbIds.USB_PID_AFATECH_AF9035_9035, "Afatech AF9035 reference design"),
new DeviceFilter(DvbUsbIds.USB_VID_AFATECH, DvbUsbIds.USB_PID_AFATECH_AF9035_1000, "Afatech AF9035 reference design"),
new DeviceFilter(DvbUsbIds.USB_VID_AFATECH, DvbUsbIds.USB_PID_AFATECH_AF9035_1001, "Afatech AF9035 reference design"),
new DeviceFilter(DvbUsbIds.USB_VID_AFATECH, DvbUsbIds.USB_PID_AFATECH_AF9035_1002, "Afatech AF9035 reference design"),
new DeviceFilter(DvbUsbIds.USB_VID_AFATECH, DvbUsbIds.USB_PID_AFATECH_AF9035_1003, "Afatech AF9035 reference design"),
new DeviceFilter(DvbUsbIds.USB_VID_TERRATEC, DvbUsbIds.USB_PID_TERRATEC_CINERGY_T_STICK, "TerraTec Cinergy T Stick"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_A835, "AVerMedia AVerTV Volar HD/PRO (A835)"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_B835, "AVerMedia AVerTV Volar HD/PRO (A835)"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_1867, "AVerMedia HD Volar (A867)"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_A867, "AVerMedia HD Volar (A867)"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_TWINSTAR, "AVerMedia Twinstar (A825)"),
new DeviceFilter(DvbUsbIds.USB_VID_ASUS, DvbUsbIds.USB_PID_ASUS_U3100MINI_PLUS, "Asus U3100Mini Plus"),
new DeviceFilter(DvbUsbIds.USB_VID_TERRATEC, 0x00aa, "TerraTec Cinergy T Stick (rev. 2)"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, 0x0337, "AVerMedia HD Volar (A867)"),
new DeviceFilter(DvbUsbIds.USB_VID_GTEK, DvbUsbIds.USB_PID_EVOLVEO_XTRATV_STICK, "EVOLVEO XtraTV stick"),
/* IT9135 devices */
new DeviceFilter(DvbUsbIds.USB_VID_ITETECH, DvbUsbIds.USB_PID_ITETECH_IT9135, "ITE 9135 Generic"),
new DeviceFilter(DvbUsbIds.USB_VID_ITETECH, DvbUsbIds.USB_PID_ITETECH_IT9135_9005, "ITE 9135(9005) Generic"),
new DeviceFilter(DvbUsbIds.USB_VID_ITETECH, DvbUsbIds.USB_PID_ITETECH_IT9135_9006, "ITE 9135(9006) Generic"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_A835B_1835, "Avermedia A835B(1835)"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_A835B_2835, "Avermedia A835B(2835)"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_A835B_3835, "Avermedia A835B(3835)"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_A835B_4835, "Avermedia A835B(4835)"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_TD110, "Avermedia AverTV Volar HD 2 (TD110)"),
new DeviceFilter(DvbUsbIds.USB_VID_AVERMEDIA, DvbUsbIds.USB_PID_AVERMEDIA_H335, "Avermedia H335"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, DvbUsbIds.USB_PID_KWORLD_UB499_2T_T09, "Kworld UB499-2T T09"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, DvbUsbIds.USB_PID_SVEON_STV22_IT9137, "Sveon STV22 Dual DVB-T HDTV"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, DvbUsbIds.USB_PID_CTVDIGDUAL_V2, "Digital Dual TV Receiver CTVDIGDUAL_V2"),
/* XXX: that same ID [0ccd:0099] is used by af9015 driver too */
// new DeviceFilter(DvbUsbIds.USB_VID_TERRATEC, 0x0099, "TerraTec Cinergy T Stick Dual RC (rev. 2)"), // This is not supported since there are two devices with same ids with only manufacturer being different meaning we can't use this due to auto start issues
new DeviceFilter(DvbUsbIds.USB_VID_LEADTEK, 0x6a05, "Leadtek WinFast DTV Dongle Dual"),
new DeviceFilter(DvbUsbIds.USB_VID_HAUPPAUGE, 0xf900, "Hauppauge WinTV-MiniStick 2"),
new DeviceFilter(DvbUsbIds.USB_VID_PCTV, DvbUsbIds.USB_PID_PCTV_78E, "PCTV AndroiDTV (78e)"),
new DeviceFilter(DvbUsbIds.USB_VID_PCTV, DvbUsbIds.USB_PID_PCTV_79E, "PCTV microStick (79e)")
/* IT930x devices not supported by this driver */
);
@Override
public Set<DeviceFilter> getSupportedDevices() {
return AF9035_DEVICES;
}
@Override
public DvbDevice create(UsbDevice usbDevice, Context context, DeviceFilter filter) throws DvbException {
return new Af9035DvbDevice(usbDevice, context, filter);
}
}
| 5,972 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
MygicaT230C.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/cxusb/MygicaT230C.java | package info.martinmarinov.drivers.usb.cxusb;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.tools.SleepUtils;
import info.martinmarinov.drivers.usb.DvbFrontend;
import info.martinmarinov.drivers.usb.DvbTuner;
import info.martinmarinov.drivers.usb.DvbUsbIds;
import info.martinmarinov.drivers.usb.silabs.Si2157;
import info.martinmarinov.drivers.usb.silabs.Si2168;
import static info.martinmarinov.drivers.usb.silabs.Si2157.Type.SI2157_CHIPTYPE_SI2141;
/**
* @author dmgouriev
*/
public class MygicaT230C extends CxUsbDvbDevice {
public final static String MYGICA_NAME = "Mygica T230C DVB-T/T2/C";
final static DeviceFilter MYGICA_T230C = new DeviceFilter(DvbUsbIds.USB_VID_CONEXANT, DvbUsbIds.USB_PID_GENIATECH_T230C, MYGICA_NAME);
private Si2168 frontend;
MygicaT230C(UsbDevice usbDevice, Context context) throws DvbException {
super(usbDevice, context, MYGICA_T230C);
}
@Override
public String getDebugString() {
return MYGICA_NAME;
}
@Override
synchronized protected void powerControl(boolean onoff) throws DvbException {
cxusb_d680_dmb_power_ctrl(onoff);
cxusb_streaming_ctrl(onoff);
}
private void cxusb_d680_dmb_power_ctrl(boolean onoff) throws DvbException {
cxusb_power_ctrl(onoff);
if (!onoff) return;
SleepUtils.mdelay(128);
cxusb_ctrl_msg(CMD_DIGITAL, new byte[0], 0, new byte[1], 1);
SleepUtils.mdelay(100);
}
@Override
protected void readConfig() throws DvbException {
// no-op
}
@Override
protected DvbFrontend frontendAttatch() throws DvbException {
return frontend = new Si2168(this, resources, i2CAdapter, 0x64, SI2168_TS_PARALLEL, true, SI2168_TS_CLK_AUTO_ADAPT, false);
}
@Override
protected DvbTuner tunerAttatch() throws DvbException {
return new Si2157(resources, i2CAdapter, frontend.gateControl(), 0x60, false, SI2157_CHIPTYPE_SI2141);
}
@Override
protected void init() throws DvbException {
// no-op
}
}
| 2,207 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
CxUsbDvbDevice.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/cxusb/CxUsbDvbDevice.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.cxusb;
import static android.hardware.usb.UsbConstants.USB_DIR_IN;
import static android.hardware.usb.UsbConstants.USB_DIR_OUT;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.DVB_DEVICE_UNSUPPORTED;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
import static info.martinmarinov.drivers.usb.DvbUsbIds.USB_VID_MEDION;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbDemux;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.I2cAdapter;
import info.martinmarinov.drivers.usb.generic.AbstractGenericDvbUsbDevice;
import info.martinmarinov.usbxfer.AlternateUsbInterface;
public abstract class CxUsbDvbDevice extends AbstractGenericDvbUsbDevice {
private final static String TAG = CxUsbDvbDevice.class.getSimpleName();
private final static byte CMD_I2C_WRITE = 0x08;
private final static byte CMD_I2C_READ = 0x09;
private final static byte CMD_GPIO_WRITE = 0x0e;
private final static byte CMD_GPIO_READ = 0x0d;
private final static byte GPIO_TUNER = 0x02;
private final static byte CMD_POWER_OFF = (byte) 0xdc;
private final static byte CMD_POWER_ON = (byte) 0xde;
private final static byte CMD_STREAMING_ON = 0x36;
private final static byte CMD_STREAMING_OFF = 0x37;
private final static byte CMD_AVER_STREAM_ON = 0x18;
private final static byte CMD_AVER_STREAM_OFF = 0x19;
private final static byte CMD_GET_IR_CODE = 0x47;
public final static byte CMD_ANALOG = 0x50;
public final static byte CMD_DIGITAL = 0x51;
public static final int SI2168_TS_PARALLEL = 0x06;
public static final int SI2168_TS_SERIAL = 0x03;
public static final int SI2168_MP_NOT_USED = 1;
public static final int SI2168_MP_A = 2;
public static final int SI2168_MP_B = 3;
public static final int SI2168_MP_C = 4;
public static final int SI2168_MP_D = 5;
public final static int SI2168_TS_CLK_AUTO_FIXED = 0;
public final static int SI2168_TS_CLK_AUTO_ADAPT = 1;
public final static int SI2168_TS_CLK_MANUAL = 2;
public final static int SI2168_ARGLEN = 30;
/* Max transfer size done by I2C transfer functions */
private final static int MAX_XFER_SIZE = 80;
private boolean gpio_tuner_write_state = false;
private final UsbInterface iface;
private final UsbEndpoint endpoint;
final I2cAdapter i2CAdapter = new CxUsbDvbDeviceI2cAdapter();
CxUsbDvbDevice(UsbDevice usbDevice, Context context, DeviceFilter filter) throws DvbException {
super(
usbDevice,
context,
filter,
DvbDemux.DvbDmxSwfilter(),
usbDevice.getInterface(0).getEndpoint(0),
usbDevice.getInterface(0).getEndpoint(1)
);
iface = usbDevice.getInterface(0);
endpoint = iface.getEndpoint(2);
if (controlEndpointIn.getAddress() != 0x81 || controlEndpointIn.getDirection() != USB_DIR_IN) throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
if (controlEndpointOut.getAddress() != 0x01 || controlEndpointOut.getDirection() != USB_DIR_OUT) throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
if (endpoint.getAddress() != 0x82 || endpoint.getDirection() != USB_DIR_IN) throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
}
@Override
protected AlternateUsbInterface getUsbInterface() {
return AlternateUsbInterface.forUsbInterface(usbDeviceConnection, iface).get(0);
}
@Override
protected UsbEndpoint getUsbEndpoint() {
return endpoint;
}
public void cxusb_streaming_ctrl(boolean onoff) throws DvbException {
byte[] buf = new byte[]{ 0x03, 0x00 };
if (onoff) {
cxusb_ctrl_msg(CMD_STREAMING_ON, buf, 2);
} else {
cxusb_ctrl_msg(CMD_STREAMING_OFF, new byte[0], 0);
}
}
void cxusb_power_ctrl(boolean onoff) throws DvbException {
if (onoff) {
cxusb_ctrl_msg(CMD_POWER_ON, new byte[1], 1);
} else {
cxusb_ctrl_msg(CMD_POWER_OFF, new byte[1], 1);
}
}
@SuppressWarnings("WeakerAccess")
synchronized void cxusb_ctrl_msg(byte cmd, @NonNull byte[] wbuf, int wlen) throws DvbException {
cxusb_ctrl_msg(cmd, wbuf, wlen, null, Integer.MIN_VALUE);
}
synchronized void cxusb_ctrl_msg(byte cmd, @NonNull byte[] wbuf, int wlen, @Nullable byte[] rbuf, int rlen) throws DvbException {
if (1 + wlen > MAX_XFER_SIZE) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage) + "\n" + "i2c wr: len=" + wlen + " is too big!");
}
if (rlen > MAX_XFER_SIZE) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage) + "\n" + "i2c rd: len=" + rlen + " is too big!");
}
byte[] data = new byte[Math.max(wlen + 1, rlen)];
data[0] = cmd;
System.arraycopy(wbuf, 0, data, 1, wlen);
dvb_usb_generic_rw(data, 1 + wlen, data, rlen);
if (rbuf != null) {
System.arraycopy(data, 0, rbuf, 0, rlen);
}
}
private void cxusb_gpio_tuner(boolean onoff) throws DvbException {
if (gpio_tuner_write_state == onoff) {
return;
}
byte[] o = new byte[] {GPIO_TUNER, (onoff ? (byte) 1 : 0)};
byte[] i = new byte[1];
cxusb_ctrl_msg(CMD_GPIO_WRITE, o, 2, i, 1);
if (i[0] != 0x01) {
Log.w(TAG, "gpio_write failed.");
}
gpio_tuner_write_state = onoff;
}
private class CxUsbDvbDeviceI2cAdapter extends I2cAdapter {
@Override
protected int masterXfer(I2cMessage[] msg) throws DvbException {
for (int i = 0; i < msg.length; i++) {
if (getDeviceFilter().getVendorId() == USB_VID_MEDION) {
switch (msg[i].addr) {
case 0x63:
cxusb_gpio_tuner(false);
break;
default:
cxusb_gpio_tuner(true);
break;
}
}
if ((msg[i].flags & I2C_M_RD) != 0) {
/* read only */
byte[] obuf = new byte[3];
byte[] ibuf = new byte[MAX_XFER_SIZE];
if (1 + msg[i].len > ibuf.length) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
obuf[0] = 0;
obuf[1] = (byte) msg[i].len;
obuf[2] = (byte) msg[i].addr;
cxusb_ctrl_msg(CMD_I2C_READ, obuf, 3, ibuf, 1+msg[i].len);
System.arraycopy(ibuf, 1, msg[i].buf, 0, msg[i].len);
} else if (i+1 < msg.length && ((msg[i+1].flags & I2C_M_RD) != 0) && msg[i].addr == msg[i+1].addr) {
/* write to then read from same address */
byte[] obuf = new byte[MAX_XFER_SIZE];
byte[] ibuf = new byte[MAX_XFER_SIZE];
if (3 + msg[i].len > obuf.length) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
if (1 + msg[i + 1].len > ibuf.length) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
obuf[0] = (byte) msg[i].len;
obuf[1] = (byte) msg[i+1].len;
obuf[2] = (byte) msg[i].addr;
System.arraycopy(msg[i].buf, 0, obuf, 3, msg[i].len);
cxusb_ctrl_msg(CMD_I2C_READ, obuf, 3+msg[i].len, ibuf, 1+msg[i+1].len);
// if (ibuf[0] != 0x08) {
// Log.w(TAG, "i2c read may have failed");
// }
System.arraycopy(ibuf, 1, msg[i+1].buf, 0, msg[i+1].len);
i++;
} else {
/* write only */
byte[] obuf = new byte[MAX_XFER_SIZE];
byte[] ibuf = new byte[1];
if (2 + msg[i].len > obuf.length) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
}
obuf[0] = (byte) msg[i].addr;
obuf[1] = (byte) msg[i].len;
System.arraycopy(msg[i].buf, 0, obuf, 2, msg[i].len);
cxusb_ctrl_msg(CMD_I2C_WRITE, obuf, 2+msg[i].len, ibuf, 1);
// if (ibuf[0] != 0x08){
// Log.w(TAG, "i2c read may have failed");
// }
}
}
return msg.length;
}
}
}
| 10,367 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
CxUsbDvbDeviceCreator.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/cxusb/CxUsbDvbDeviceCreator.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.cxusb;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import java.util.Set;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.usb.DvbUsbDevice;
import static info.martinmarinov.drivers.tools.SetUtils.setOf;
import static info.martinmarinov.drivers.usb.cxusb.MygicaT230.MYGICA_T230;
import static info.martinmarinov.drivers.usb.cxusb.MygicaT230C.MYGICA_T230C;
public class CxUsbDvbDeviceCreator implements DvbUsbDevice.Creator {
private final static Set<DeviceFilter> CXUSB_DEVICES = setOf(MYGICA_T230, MYGICA_T230C);
@Override
public Set<DeviceFilter> getSupportedDevices() {
return CXUSB_DEVICES;
}
@Override
public DvbUsbDevice create(UsbDevice usbDevice, Context context, DeviceFilter filter) throws DvbException {
if (MYGICA_T230C.matches(usbDevice)) {
return new MygicaT230C(usbDevice, context);
} else {
return new MygicaT230(usbDevice, context);
}
}
}
| 1,958 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
MygicaT230.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/cxusb/MygicaT230.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.cxusb;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.tools.SleepUtils;
import info.martinmarinov.drivers.usb.DvbFrontend;
import info.martinmarinov.drivers.usb.DvbTuner;
import info.martinmarinov.drivers.usb.DvbUsbIds;
import info.martinmarinov.drivers.usb.silabs.Si2157;
import info.martinmarinov.drivers.usb.silabs.Si2168;
import static info.martinmarinov.drivers.usb.silabs.Si2157.Type.SI2157_CHIPTYPE_SI2157;
class MygicaT230 extends CxUsbDvbDevice {
private final static String MYGICA_NAME = "Mygica T230 DVB-T/T2/C";
final static DeviceFilter MYGICA_T230 = new DeviceFilter(DvbUsbIds.USB_VID_CONEXANT, DvbUsbIds.USB_PID_MYGICA_T230, MYGICA_NAME);
private Si2168 frontend;
MygicaT230(UsbDevice usbDevice, Context context) throws DvbException {
super(usbDevice, context, MYGICA_T230);
}
@Override
public String getDebugString() {
return MYGICA_NAME;
}
@Override
synchronized protected void powerControl(boolean onoff) throws DvbException {
cxusb_d680_dmb_power_ctrl(onoff);
cxusb_streaming_ctrl(onoff);
}
private void cxusb_d680_dmb_power_ctrl(boolean onoff) throws DvbException {
cxusb_power_ctrl(onoff);
if (!onoff) return;
SleepUtils.mdelay(128);
cxusb_ctrl_msg(CMD_DIGITAL, new byte[0], 0, new byte[1], 1);
SleepUtils.mdelay(100);
}
@Override
protected void readConfig() throws DvbException {
// no-op
}
@Override
protected DvbFrontend frontendAttatch() throws DvbException {
return frontend = new Si2168(this, resources, i2CAdapter, 0x64, SI2168_TS_PARALLEL, true, SI2168_TS_CLK_AUTO_FIXED, false);
}
@Override
protected DvbTuner tunerAttatch() throws DvbException {
return new Si2157(resources, i2CAdapter, frontend.gateControl(), 0x60, true, SI2157_CHIPTYPE_SI2157);
}
@Override
protected void init() throws DvbException {
// no-op
}
}
| 3,020 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Rtl2xx2DvbDeviceCreator.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Rtl2xx2DvbDeviceCreator.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import java.util.Set;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.usb.DvbUsbDevice;
import info.martinmarinov.drivers.usb.DvbUsbIds;
import static info.martinmarinov.drivers.tools.SetUtils.setOf;
public class Rtl2xx2DvbDeviceCreator implements DvbUsbDevice.Creator {
private final static Set<DeviceFilter> RTL2832_DEVICES = setOf(
new DeviceFilter(DvbUsbIds.USB_VID_REALTEK, 0x2832, "Realtek RTL2832U reference design"),
new DeviceFilter(DvbUsbIds.USB_VID_REALTEK, 0x2838, "Realtek RTL2832U reference design"),
new DeviceFilter(DvbUsbIds.USB_VID_TERRATEC, DvbUsbIds.USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1, "TerraTec Cinergy T Stick Black"),
new DeviceFilter(DvbUsbIds.USB_VID_GTEK, DvbUsbIds.USB_PID_DELOCK_USB2_DVBT, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T"),
new DeviceFilter(DvbUsbIds.USB_VID_TERRATEC, DvbUsbIds.USB_PID_NOXON_DAB_STICK, "TerraTec NOXON DAB Stick"),
new DeviceFilter(DvbUsbIds.USB_VID_TERRATEC, DvbUsbIds.USB_PID_NOXON_DAB_STICK_REV2, "TerraTec NOXON DAB Stick (rev 2)"),
new DeviceFilter(DvbUsbIds.USB_VID_TERRATEC, DvbUsbIds.USB_PID_NOXON_DAB_STICK_REV3, "TerraTec NOXON DAB Stick (rev 3)"),
new DeviceFilter(DvbUsbIds.USB_VID_GTEK, DvbUsbIds.USB_PID_TREKSTOR_TERRES_2_0, "Trekstor DVB-T Stick Terres 2.0"),
new DeviceFilter(DvbUsbIds.USB_VID_DEXATEK, 0x1101, "Dexatek DK DVB-T Dongle"),
new DeviceFilter(DvbUsbIds.USB_VID_LEADTEK, 0x6680, "DigitalNow Quad DVB-T Receiver"),
new DeviceFilter(DvbUsbIds.USB_VID_LEADTEK, DvbUsbIds.USB_PID_WINFAST_DTV_DONGLE_MINID, "Leadtek Winfast DTV Dongle Mini D"),
new DeviceFilter(DvbUsbIds.USB_VID_LEADTEK, DvbUsbIds.USB_PID_WINFAST_DTV2000DS_PLUS, "Leadtek WinFast DTV2000DS Plus"),
new DeviceFilter(DvbUsbIds.USB_VID_TERRATEC, 0x00d3, "TerraTec Cinergy T Stick RC (Rev. 3)"),
new DeviceFilter(DvbUsbIds.USB_VID_DEXATEK, 0x1102, "Dexatek DK mini DVB-T Dongle"),
new DeviceFilter(DvbUsbIds.USB_VID_TERRATEC, 0x00d7, "TerraTec Cinergy T Stick+"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, 0xd3a8, "ASUS My Cinema-U3100Mini Plus V2"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, 0xd393, "GIGABYTE U7300"),
new DeviceFilter(DvbUsbIds.USB_VID_DEXATEK, 0x1104, "MSI DIGIVOX Micro HD"),
new DeviceFilter(DvbUsbIds.USB_VID_COMPRO, 0x0620, "Compro VideoMate U620F"),
new DeviceFilter(DvbUsbIds.USB_VID_COMPRO, 0x0650, "Compro VideoMate U650F"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, 0xd394, "MaxMedia HU394-T"),
new DeviceFilter(DvbUsbIds.USB_VID_LEADTEK, 0x6a03, "Leadtek WinFast DTV Dongle mini"),
new DeviceFilter(DvbUsbIds.USB_VID_GTEK, DvbUsbIds.USB_PID_CPYTO_REDI_PC50A, "Crypto ReDi PC 50 A"),
new DeviceFilter(DvbUsbIds.USB_VID_KYE, 0x707f, "Genius TVGo DVB-T03"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, 0xd395, "Peak DVB-T USB"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, DvbUsbIds.USB_PID_SVEON_STV20_RTL2832U, "Sveon STV20"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, DvbUsbIds.USB_PID_SVEON_STV21, "Sveon STV21"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, DvbUsbIds.USB_PID_SVEON_STV27, "Sveon STV27"),
new DeviceFilter(DvbUsbIds.USB_VID_KWORLD_2, DvbUsbIds.USB_PID_TURBOX_DTT_2000, "TURBO-X Pure TV Tuner DTT-2000"),
/* RTL2832P devices: */
new DeviceFilter(DvbUsbIds.USB_VID_HANFTEK, 0x0131, "Astrometa DVB-T2"),
new DeviceFilter(0x5654, 0xca42, "GoTView MasterHD 3")
);
@Override
public Set<DeviceFilter> getSupportedDevices() {
return RTL2832_DEVICES;
}
@Override
public DvbUsbDevice create(UsbDevice usbDevice, Context context, DeviceFilter filter) throws DvbException {
return new Rtl2832DvbDevice(usbDevice, context, filter);
}
}
| 5,046 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Rtl28xxTunerType.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Rtl28xxTunerType.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import static info.martinmarinov.drivers.DvbException.ErrorCode.DVB_DEVICE_UNSUPPORTED;
import static info.martinmarinov.drivers.tools.SleepUtils.mdelay;
import static info.martinmarinov.drivers.usb.rtl28xx.R820tTuner.RafaelChip.CHIP_R820T;
import static info.martinmarinov.drivers.usb.rtl28xx.R820tTuner.RafaelChip.CHIP_R828D;
import android.content.res.Resources;
import androidx.annotation.NonNull;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.Check;
import info.martinmarinov.drivers.tools.I2cAdapter.I2GateControl;
import info.martinmarinov.drivers.usb.DvbTuner;
import info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxDvbDevice.Rtl28xxI2cAdapter;
enum Rtl28xxTunerType {
RTL2832_E4000(
device -> {
byte[] data = new byte[1];
device.ctrlMsg(0x02c8, Rtl28xxConst.CMD_I2C_RD, data);
return (data[0] & 0xff) == 0x40;
},
(resources, device) -> Rtl28xxSlaveType.SLAVE_DEMOD_NONE, (adapter, i2GateControl, resources, tunerCallback) -> {
// The tuner uses sames XTAL as the frontend at 28.8 MHz
return new E4000Tuner(0x64, adapter, 28_800_000L, i2GateControl, resources);
}
),
RTL2832_FC0012(
device -> {
byte[] data = new byte[1];
device.ctrlMsg(0x00c6, Rtl28xxConst.CMD_I2C_RD, data);
return (data[0] & 0xff) == 0xa1;
},
(resources, device) -> Rtl28xxSlaveType.SLAVE_DEMOD_NONE, (adapter, i2GateControl, resources, tunerCallback) -> {
// The tuner uses sames XTAL as the frontend at 28.8 MHz
return new FC0012Tuner(0xc6>>1, adapter, 28_800_000L, i2GateControl, tunerCallback);
}
),
RTL2832_FC0013(
device -> {
byte[] data = new byte[1];
device.ctrlMsg(0x00c6, Rtl28xxConst.CMD_I2C_RD, data);
return (data[0] & 0xff) == 0xa3;
},
(resources, device) -> Rtl28xxSlaveType.SLAVE_DEMOD_NONE, (adapter, i2GateControl, resources, tunerCallback) -> {
// The tuner uses sames XTAL as the frontend at 28.8 MHz
return new FC0013Tuner(0xc6>>1, adapter, 28_800_000L, i2GateControl);
}
),
RTL2832_R820T(
device -> {
byte[] data = new byte[1];
device.ctrlMsg(0x0034, Rtl28xxConst.CMD_I2C_RD, data);
return (data[0] & 0xff) == 0x69;
},
(resources, device) -> Rtl28xxSlaveType.SLAVE_DEMOD_NONE, (adapter, i2GateControl, resources, tunerCallback) -> {
// The tuner uses sames XTAL as the frontend at 28.8 MHz
return new R820tTuner(0x1a, adapter, CHIP_R820T, 28_800_000L, i2GateControl, resources);
}
),
RTL2832_R828D(
device -> {
byte[] data = new byte[1];
device.ctrlMsg(0x0074, Rtl28xxConst.CMD_I2C_RD, data);
return (data[0] & 0xff) == 0x69;
},
(resources, device) -> {
/* power off slave demod on GPIO0 to reset CXD2837ER */
device.wrReg(Rtl28xxConst.SYS_GPIO_OUT_VAL, 0x00, 0x01);
device.wrReg(Rtl28xxConst.SYS_GPIO_OUT_EN, 0x00, 0x01);
mdelay(50);
/* power on MN88472 demod on GPIO0 */
device.wrReg(Rtl28xxConst.SYS_GPIO_OUT_VAL, 0x01, 0x01);
device.wrReg(Rtl28xxConst.SYS_GPIO_DIR, 0x00, 0x01);
device.wrReg(Rtl28xxConst.SYS_GPIO_OUT_EN, 0x01, 0x01);
/* check MN88472 answers */
byte[] data = new byte[1];
try {
device.ctrlMsg(0xff38, Rtl28xxConst.CMD_I2C_RD, data);
} catch (DvbException e) {
// cxd2837er fails to read the mn88472/ mn88473 register
device.ctrlMsg(0xfdd8, Rtl28xxConst.CMD_I2C_RD, data);
}
switch (data[0] & 0xFF) {
case 0x02:
return Rtl28xxSlaveType.SLAVE_DEMOD_MN88472;
case 0x03:
return Rtl28xxSlaveType.SLAVE_DEMOD_MN88473;
case 0xb1:
return Rtl28xxSlaveType.SLAVE_DEMOD_CXD2837ER;
default:
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unsupported_slave_on_tuner));
}
}, (adapter, i2GateControl, resources, tunerCallback) -> {
// Actual tuner xtal and frontend crystals are different
return new R820tTuner(0x3a, adapter, CHIP_R828D, 16_000_000L, i2GateControl, resources);
}
);
private final IsPresent isPresent;
private final SlaveParser slaveParser;
private final DvbTunerCreator creator;
Rtl28xxTunerType(IsPresent isPresent, SlaveParser slaveParser, DvbTunerCreator creator) {
this.isPresent = isPresent;
this.slaveParser = slaveParser;
this.creator = creator;
}
public static @NonNull Rtl28xxTunerType detectTuner(Resources resources, Rtl28xxDvbDevice device) throws DvbException {
for (Rtl28xxTunerType tuner : values()) {
try {
if (tuner.isPresent.isPresent(device)) return tuner;
} catch (DvbException ignored) {
// Do nothing, if it is not the correct tuner, the control message
// will throw an exception and that's ok
}
}
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unrecognized_tuner_on_device));
}
public @NonNull Rtl28xxSlaveType detectSlave(Resources resources, Rtl28xxDvbDevice device) throws DvbException {
return slaveParser.getSlave(resources, device);
}
public @NonNull DvbTuner createTuner(Rtl28xxI2cAdapter adapter, I2GateControl i2GateControl, Resources resources, Rtl28xxDvbDevice.TunerCallback tunerCallback) throws DvbException {
return creator.create(adapter, Check.notNull(i2GateControl), resources, tunerCallback);
}
private interface IsPresent {
boolean isPresent(Rtl28xxDvbDevice device) throws DvbException;
}
private interface DvbTunerCreator {
@NonNull DvbTuner create(Rtl28xxI2cAdapter adapter, I2GateControl i2GateControl, Resources resources, Rtl28xxDvbDevice.TunerCallback tunerCallback) throws DvbException;
}
private interface SlaveParser {
@NonNull Rtl28xxSlaveType getSlave(Resources resources, Rtl28xxDvbDevice device) throws DvbException;
}
}
| 7,671 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Rtl28xxDvbDevice.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Rtl28xxDvbDevice.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.DVB_DEVICE_UNSUPPORTED;
import static info.martinmarinov.drivers.DvbException.ErrorCode.HARDWARE_EXCEPTION;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_DEMOD_WR;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_I2C_DA_RD;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_I2C_DA_WR;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_I2C_RD;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_I2C_WR;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_IR_RD;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_IR_WR;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_SYS_RD;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_SYS_WR;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_USB_RD;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_USB_WR;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.CMD_WR_FLAG;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.SYS_GPIO_OUT_VAL;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.USB_EPA_FIFO_CFG;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.USB_EPA_MAXPKT;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.USB_SYSCTL_0;
import android.content.Context;
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import android.os.Build;
import java.util.concurrent.locks.ReentrantLock;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbDemux;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.I2cAdapter;
import info.martinmarinov.drivers.usb.DvbUsbDevice;
import info.martinmarinov.usbxfer.AlternateUsbInterface;
abstract class Rtl28xxDvbDevice extends DvbUsbDevice {
private final static int DEFAULT_USB_COMM_TIMEOUT_MS = 100;
private final static long DEFAULT_READ_OR_WRITE_TIMEOUT_MS = 1000L;
private final ReentrantLock reentrantLock = new ReentrantLock();
private final UsbInterface iface;
private final UsbEndpoint endpoint;
final Rtl28xxI2cAdapter i2CAdapter = new Rtl28xxI2cAdapter();
final TunerCallbackBuilder tunerCallbackBuilder = new TunerCallbackBuilder();
Rtl28xxDvbDevice(UsbDevice usbDevice, Context context, DeviceFilter deviceFilter) throws DvbException {
super(usbDevice, context, deviceFilter, DvbDemux.DvbDmxSwfilter());
iface = usbDevice.getInterface(0);
endpoint = iface.getEndpoint(0);
if (endpoint.getAddress() != 0x81) throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
}
private int controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int offset, int length) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
return usbDeviceConnection.controlTransfer(requestType, request, value, index, buffer, offset, buffer.length, DEFAULT_USB_COMM_TIMEOUT_MS);
} else if (offset == 0) {
return usbDeviceConnection.controlTransfer(requestType, request, value, index, buffer, buffer.length, DEFAULT_USB_COMM_TIMEOUT_MS);
} else {
byte[] tempbuff = new byte[length - offset];
if ((requestType & UsbConstants.USB_DIR_IN) == 0) {
System.arraycopy(buffer, offset, tempbuff, 0, length - offset);
return usbDeviceConnection.controlTransfer(requestType, request, value, index, tempbuff, tempbuff.length, DEFAULT_USB_COMM_TIMEOUT_MS);
} else {
int read = usbDeviceConnection.controlTransfer(requestType, request, value, index, tempbuff, tempbuff.length, DEFAULT_USB_COMM_TIMEOUT_MS);
if (read <= 0) {
return read;
}
System.arraycopy(tempbuff, 0, buffer, offset, read);
return read;
}
}
}
synchronized void ctrlMsg(int value, int index, byte[] data) throws DvbException {
ctrlMsg(value, index, data, data.length);
}
synchronized void ctrlMsg(int value, int index, byte[] data, int length) throws DvbException {
long startTime = System.currentTimeMillis();
int requestType;
if ((index & CMD_WR_FLAG) != 0) {
// write
requestType = UsbConstants.USB_TYPE_VENDOR;
} else {
// read
requestType = UsbConstants.USB_TYPE_VENDOR | UsbConstants.USB_DIR_IN;
}
reentrantLock.lock();
try {
int bytesTransferred = 0;
while (bytesTransferred < length) {
int actlen = controlTransfer(requestType, 0, value, index, data, bytesTransferred, length - bytesTransferred);
if (System.currentTimeMillis() - startTime > DEFAULT_READ_OR_WRITE_TIMEOUT_MS) {
actlen = -99999999;
}
if (actlen < 0) {
throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.cannot_send_control_message, actlen));
}
bytesTransferred += actlen;
}
} finally {
reentrantLock.unlock();
}
}
synchronized void wrReg(int reg, byte[] val) throws DvbException {
int index;
if (reg < 0x3000) {
index = CMD_USB_WR;
} else if (reg < 0x4000) {
index = CMD_SYS_WR;
} else {
index = CMD_IR_WR;
}
ctrlMsg(reg, index, val);
}
synchronized void wrReg(int reg, int onebyte) throws DvbException {
byte[] data = new byte[] { (byte) onebyte };
wrReg(reg, data);
}
synchronized void wrReg(int reg, int val, int mask) throws DvbException {
if (mask != 0xff) {
int tmp = rdReg(reg);
val &= mask;
tmp &= ~mask;
val |= tmp;
}
wrReg(reg, val);
}
synchronized private void rdReg(int reg, byte[] val) throws DvbException {
int index;
if (reg < 0x3000) {
index = CMD_USB_RD;
} else if (reg < 0x4000) {
index = CMD_SYS_RD;
} else {
index = CMD_IR_RD;
}
ctrlMsg(reg, index, val);
}
synchronized int rdReg(int reg) throws DvbException {
byte[] result = new byte[1];
rdReg(reg, result);
return result[0] & 0xFF;
}
@Override
protected synchronized void init() throws DvbException {
/* init USB endpoints */
int val = rdReg(USB_SYSCTL_0);
/* enable DMA and Full Packet Mode*/
val |= 0x09;
wrReg(USB_SYSCTL_0, val);
/* set EPA maximum packet size to 0x0200 */
wrReg(USB_EPA_MAXPKT, new byte[] { 0x00, 0x02, 0x00, 0x00 });
/* change EPA FIFO length */
wrReg(USB_EPA_FIFO_CFG, new byte[] { 0x14, 0x00, 0x00, 0x00 });
}
class Rtl28xxI2cAdapter extends I2cAdapter {
int page = -1;
@Override
protected int masterXfer(I2cMessage[] msg) throws DvbException {
/*
* It is not known which are real I2C bus xfer limits, but testing
* with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
*/
/*
* I2C adapter logic looks rather complicated due to fact it handles
* three different access methods. Those methods are;
* 1) integrated demod access
* 2) old I2C access
* 3) new I2C access
*
* Used method is selected in order 1, 2, 3. Method 3 can handle all
* requests but there is two reasons why not use it always;
* 1) It is most expensive, usually two USB messages are needed
* 2) At least RTL2831U does not support it
*
* Method 3 is needed in case of I2C write+read (typical register read)
* where write is more than one byte.
*/
if (msg.length == 2 && (msg[0].flags & I2cMessage.I2C_M_RD) == 0 &&
(msg[1].flags & I2cMessage.I2C_M_RD) != 0) {
if (msg[0].len > 24 || msg[1].len > 24) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.unsuported_i2c_operation));
} else if (msg[0].addr == 0x10) {
/* method 1 - integrated demod */
ctrlMsg(((msg[0].buf[0] & 0xFF) << 8) | (msg[0].addr << 1),
page,
msg[1].buf,
msg[1].len);
} else if (msg[0].len < 2) {
/* method 2 - old I2C */
ctrlMsg(((msg[0].buf[0] & 0xFF) << 8) | (msg[0].addr << 1),
CMD_I2C_RD,
msg[1].buf,
msg[1].len);
} else {
/* method 3 - new I2C */
ctrlMsg(msg[0].addr << 1, CMD_I2C_DA_WR, msg[0].buf, msg[0].len);
ctrlMsg(msg[0].addr << 1, CMD_I2C_DA_RD, msg[1].buf, msg[1].len);
}
} else if (msg.length == 1 && (msg[0].flags & I2cMessage.I2C_M_RD) == 0) {
if (msg[0].len > 22) {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.unsuported_i2c_operation));
} else if (msg[0].addr == 0x10) {
/* method 1 - integrated demod */
if (msg[0].buf[0] == 0x00) {
/* save demod page for later demod access */
page = msg[0].buf[1] & 0xFF;
} else {
byte[] newdata = new byte[msg[0].len-1];
System.arraycopy(msg[0].buf, 1, newdata, 0, newdata.length);
ctrlMsg(((msg[0].buf[0] & 0xFF) << 8) | (msg[0].addr << 1),
CMD_DEMOD_WR | page,
newdata);
}
} else if (msg[0].len < 23) {
/* method 2 - old I2C */
byte[] newdata = new byte[msg[0].len-1];
System.arraycopy(msg[0].buf, 1, newdata, 0, newdata.length);
ctrlMsg(((msg[0].buf[0] & 0xFF) << 8) | (msg[0].addr << 1),
CMD_I2C_WR,
newdata);
} else {
/* method 3 - new I2C */
ctrlMsg(msg[0].addr << 1, CMD_I2C_DA_WR, msg[0].buf, msg[0].len);
}
} else {
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.unsuported_i2c_operation));
}
return msg.length;
}
}
@Override
protected UsbEndpoint getUsbEndpoint() {
return endpoint;
}
@Override
protected AlternateUsbInterface getUsbInterface() {
return AlternateUsbInterface.forUsbInterface(usbDeviceConnection, iface).get(0);
}
@SuppressWarnings("WeakerAccess") // This is a false warning
class TunerCallbackBuilder {
TunerCallback forTuner(final Rtl28xxTunerType tuner) {
return new TunerCallback() {
@Override
public void onFeVhfEnable(boolean enable) throws DvbException {
if (tuner == Rtl28xxTunerType.RTL2832_FC0012) {
/* set output values */
int val = rdReg(SYS_GPIO_OUT_VAL);
if (enable) {
val &= 0xbf; /* set GPIO6 low */
} else {
val |= 0x40; /* set GPIO6 high */
}
wrReg(SYS_GPIO_OUT_VAL, val);
} else {
throw new DvbException(BAD_API_USAGE, "Unexpected tuner asks callback");
}
}
};
}
}
interface TunerCallback {
void onFeVhfEnable(boolean enable) throws DvbException;
}
}
| 13,427 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Cxd2841er.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Cxd2841er.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import static java.util.Collections.addAll;
import static java.util.Collections.emptySet;
import static info.martinmarinov.drivers.DeliverySystem.DVBC;
import static info.martinmarinov.drivers.DeliverySystem.DVBT2;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_TUNE_TO_FREQ;
import static info.martinmarinov.drivers.DvbException.ErrorCode.DVB_DEVICE_UNSUPPORTED;
import static info.martinmarinov.drivers.DvbException.ErrorCode.UNSUPPORTED_BANDWIDTH;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_SIGNAL;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_VITERBI;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
import static info.martinmarinov.drivers.tools.SetUtils.setOf;
import static info.martinmarinov.drivers.tools.SleepUtils.usleep;
import android.content.res.Resources;
import android.util.Log;
import androidx.annotation.NonNull;
import java.util.LinkedHashSet;
import java.util.Set;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.DvbStatus;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.Check;
import info.martinmarinov.drivers.tools.ThrowingRunnable;
import info.martinmarinov.drivers.usb.DvbFrontend;
import info.martinmarinov.drivers.usb.DvbTuner;
import info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxDvbDevice.Rtl28xxI2cAdapter;
public class Cxd2841er implements DvbFrontend {
private final static String TAG = Cxd2841er.class.getSimpleName();
private ChipId chipId;
private DvbTuner tuner;
enum Xtal {
SONY_XTAL_20500(
new byte[]{0x11, (byte) 0xF0, 0x00, 0x00, 0x00},
new byte[]{0x14, (byte) 0x80, 0x00, 0x00, 0x00},
new byte[]{0x17, (byte) 0xEA, (byte) 0xAA, (byte) 0xAA, (byte) 0xAA},
new byte[]{0x1C, (byte) 0xB3, 0x33, 0x33, 0x33},
new byte[]{0x58, (byte) 0xE2, (byte) 0xAF, (byte) 0xE0, (byte) 0xBC}),
SONY_XTAL_24000(
new byte[]{0x15, 0x00, 0x00, 0x00, 0x00},
new byte[]{0x18, 0x00, 0x00, 0x00, 0x00},
new byte[]{0x1C, 0x00, 0x00, 0x00, 0x00},
new byte[]{0x21, (byte) 0x99, (byte) 0x99, (byte) 0x99, (byte) 0x99},
new byte[]{0x68, 0x0F, (byte) 0xA2, 0x32, (byte) 0xD0}),
SONY_XTAL_41000(
new byte[]{0x11, (byte) 0xF0, 0x00, 0x00, 0x00},
new byte[]{0x14, (byte) 0x80, 0x00, 0x00, 0x00},
new byte[]{0x17, (byte) 0xEA, (byte) 0xAA, (byte) 0xAA, (byte) 0xAA},
new byte[]{0x1C, (byte) 0xB3, 0x33, 0x33, 0x33},
new byte[]{0x58, (byte) 0xE2, (byte) 0xAF, (byte) 0xE0, (byte) 0xBC});
private final byte[] nominalRate8bw, nominalRate7bw, nominalRate6bw, nominalRate5bw, nominalRate17bw;
Xtal(byte[] nominalRate8bw, byte[] nominalRate7bw, byte[] nominalRate6bw, byte[] nominalRate5bw, byte[] nominalRate17bw) {
this.nominalRate8bw = nominalRate8bw;
this.nominalRate7bw = nominalRate7bw;
this.nominalRate6bw = nominalRate6bw;
this.nominalRate5bw = nominalRate5bw;
this.nominalRate17bw = nominalRate17bw;
}
}
private enum State {
SHUTDOWN,
SLEEP_TC,
ACTIVE_TC
}
private enum ChipId {
CXD2837ER(0xb1, new DvbCapabilities(
42_000_000L,
1002_000_000L,
166667L,
setOf(DeliverySystem.DVBT, DVBT2, DVBC)
)),
CXD2841ER(0xa7, new DvbCapabilities(
42_000_000L,
1002_000_000L,
166667L,
setOf(DeliverySystem.DVBT, DVBT2, DVBC)
)),
CXD2843ER(0xa4, new DvbCapabilities(
42_000_000L,
1002_000_000L,
166667L,
setOf(DeliverySystem.DVBT, DVBT2, DVBC)
)),
CXD2854ER(0xc1, new DvbCapabilities(
42_000_000L,
1002_000_000L,
166667L,
setOf(DeliverySystem.DVBT, DVBT2) // also ISDBT
));
private final int chip_id;
final @NonNull
DvbCapabilities dvbCapabilities;
ChipId(int chip_id, @NonNull DvbCapabilities dvbCapabilities) {
this.chip_id = chip_id;
this.dvbCapabilities = dvbCapabilities;
}
}
private enum I2C {
SLVX,
SLVT
}
private final static int MAX_WRITE_REGSIZE = 16;
private final Rtl28xxI2cAdapter i2cAdapter;
private final Resources resources;
private final Xtal xtal;
private final int i2c_addr_slvx, i2c_addr_slvt;
private final boolean tsbits, no_agcneg, ts_serial, early_tune;
private State state = State.SHUTDOWN;
private DeliverySystem currentDeliverySystem = null;
public Cxd2841er(
Rtl28xxI2cAdapter i2cAdapter,
Resources resources,
Xtal xtal,
int ic2_addr,
boolean tsbits,
boolean no_agcneg,
boolean ts_serial,
boolean early_tune) {
this.i2cAdapter = i2cAdapter;
this.resources = resources;
this.xtal = xtal;
this.i2c_addr_slvx = (ic2_addr + 4) >> 1;
this.i2c_addr_slvt = ic2_addr >> 1;
this.tsbits = tsbits;
this.no_agcneg = no_agcneg;
this.ts_serial = ts_serial;
this.early_tune = early_tune;
}
@Override
public DvbCapabilities getCapabilities() {
Check.notNull(chipId, "Capabilities check before tuner is attached");
return chipId.dvbCapabilities;
}
@Override
public void attach() throws DvbException {
this.chipId = cxd2841erChipId();
Log.d(TAG, "Chip found: " + chipId);
}
@Override
public void release() {
chipId = null;
currentDeliverySystem = null;
try {
sleepTcToShutdown();
} catch (DvbException e) {
e.printStackTrace();
}
}
@Override
public void init(DvbTuner tuner) throws DvbException {
this.tuner = tuner;
shutdownToSleepTc();
/* SONY_DEMOD_CONFIG_IFAGCNEG = 1 (0 for NO_AGCNEG */
writeReg(I2C.SLVT, 0x00, 0x10);
setRegBits(I2C.SLVT, 0xcb, (no_agcneg ? 0x00 : 0x40), 0x40);
/* SONY_DEMOD_CONFIG_IFAGC_ADC_FS = 0 */
writeReg(I2C.SLVT, 0xcd, 0x50);
/* SONY_DEMOD_CONFIG_PARALLEL_SEL = 1 */
writeReg(I2C.SLVT, 0x00, 0x00);
setRegBits(I2C.SLVT, 0xc4, (ts_serial ? 0x80 : 0x00), 0x80);
/* clear TSCFG bits 3+4 */
if (tsbits) {
setRegBits(I2C.SLVT, 0xc4, 0x00, 0x18);
}
tuner.init();
}
@Override
public void setParams(long frequency, long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException {
if (early_tune) {
tuner.setParams(frequency, bandwidthHz, deliverySystem);
}
/* deconfigure/put demod to sleep on delsys switch if active */
if (state == State.ACTIVE_TC && deliverySystem != currentDeliverySystem) {
sleepTc();
}
switch (deliverySystem) {
case DVBT:
currentDeliverySystem = DeliverySystem.DVBT;
switch (state) {
case SLEEP_TC:
sleepTcToActiveT(bandwidthHz);
break;
case ACTIVE_TC:
retuneActive(bandwidthHz, deliverySystem);
break;
default:
throw new IllegalStateException("Device in bad state "+state);
}
break;
case DVBT2:
currentDeliverySystem = DVBT2;
switch (state) {
case SLEEP_TC:
sleepTcToActiveT2(bandwidthHz);
break;
case ACTIVE_TC:
retuneActive(bandwidthHz, deliverySystem);
break;
default:
throw new IllegalStateException("Device in bad state "+state);
}
break;
case DVBC:
currentDeliverySystem = DVBC;
if (bandwidthHz != 6000000L && bandwidthHz != 7000000L && bandwidthHz != 8000000L) {
bandwidthHz = 8000000L;
Log.d(TAG, "Forcing bandwidth to " + bandwidthHz);
}
switch (state) {
case SLEEP_TC:
sleepTcToActiveC(bandwidthHz);
break;
case ACTIVE_TC:
retuneActive(bandwidthHz, deliverySystem);
break;
default:
throw new IllegalStateException("Device in bad state "+state);
}
break;
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
if (!early_tune) {
tuner.setParams(frequency, bandwidthHz, deliverySystem);
}
tuneDone();
}
private void tuneDone() throws DvbException {
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0, 0);
/* SW Reset */
writeReg(I2C.SLVT, 0xfe, 0x01);
/* Enable TS output */
writeReg(I2C.SLVT, 0xc3, 0x00);
}
private void retuneActive(long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException {
if (state != State.ACTIVE_TC) {
throw new IllegalStateException("Device in bad state "+state);
}
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* disable TS output */
writeReg(I2C.SLVT, 0xc3, 0x01);
switch (deliverySystem) {
case DVBT:
sleepTcToActiveTBand(bandwidthHz);
break;
case DVBT2:
sleepTcToActiveT2Band(bandwidthHz);
break;
case DVBC:
sleepTcToActiveCBand(bandwidthHz);
break;
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
}
private void sleepTcToActiveT(long bandwidthHz) throws DvbException {
setTsClockMode(DeliverySystem.DVBT);
/* Set SLV-X Bank : 0x00 */
writeReg(I2C.SLVX, 0x00, 0x00);
/* Set demod mode */
writeReg(I2C.SLVX, 0x17, 0x01);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* Enable demod clock */
writeReg(I2C.SLVT, 0x2c, 0x01);
/* Disable RF level monitor */
writeReg(I2C.SLVT, 0x2f, 0x00);
/* Enable ADC clock */
writeReg(I2C.SLVT, 0x30, 0x00);
/* Enable ADC 1 */
writeReg(I2C.SLVT, 0x41, 0x1a);
/* Enable ADC 2 & 3 */
if (xtal == Xtal.SONY_XTAL_41000) {
write(I2C.SLVT, 0x43, new byte[]{0x0A, (byte) 0xD4});
} else {
write(I2C.SLVT, 0x43, new byte[]{0x09, 0x54});
}
/* Enable ADC 4 */
writeReg(I2C.SLVX, 0x18, 0x00);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* IFAGC gain settings */
setRegBits(I2C.SLVT, 0xd2, 0x0c, 0x1f);
/* Set SLV-T Bank : 0x11 */
writeReg(I2C.SLVT, 0x00, 0x11);
/* BBAGC TARGET level setting */
writeReg(I2C.SLVT, 0x6a, 0x50);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* ASCOT setting */
setRegBits(I2C.SLVT, 0xa5, 0x00, 0x01);
/* Set SLV-T Bank : 0x18 */
writeReg(I2C.SLVT, 0x00, 0x18);
/* Pre-RS BER monitor setting */
setRegBits(I2C.SLVT, 0x36, 0x40, 0x07);
/* FEC Auto Recovery setting */
setRegBits(I2C.SLVT, 0x30, 0x01, 0x01);
setRegBits(I2C.SLVT, 0x31, 0x01, 0x01);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* TSIF setting */
setRegBits(I2C.SLVT, 0xce, 0x01, 0x01);
setRegBits(I2C.SLVT, 0xcf, 0x01, 0x01);
if (xtal == Xtal.SONY_XTAL_24000) {
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
writeReg(I2C.SLVT, 0xBF, 0x60);
writeReg(I2C.SLVT, 0x00, 0x18);
write(I2C.SLVT, 0x24, new byte[]{(byte) 0xDC, 0x6C, 0x00});
}
sleepTcToActiveTBand(bandwidthHz);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* Disable HiZ Setting 1 */
writeReg(I2C.SLVT, 0x80, 0x28);
/* Disable HiZ Setting 2 */
writeReg(I2C.SLVT, 0x81, 0x00);
state = State.ACTIVE_TC;
}
private void sleepTcToActiveT2(long bandwidthHz) throws DvbException {
setTsClockMode(DVBT2);
/* Set SLV-X Bank : 0x00 */
writeReg(I2C.SLVX, 0x00, 0x00);
/* Set demod mode */
writeReg(I2C.SLVX, 0x17, 0x02);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* Enable demod clock */
writeReg(I2C.SLVT, 0x2c, 0x01);
/* Disable RF level monitor */
writeReg(I2C.SLVT, 0x59, 0x00);
writeReg(I2C.SLVT, 0x2f, 0x00);
/* Enable ADC clock */
writeReg(I2C.SLVT, 0x30, 0x00);
/* Enable ADC 1 */
writeReg(I2C.SLVT, 0x41, 0x1a);
if (xtal == Xtal.SONY_XTAL_41000) {
write(I2C.SLVT, 0x43, new byte[]{0x0A, (byte) 0xD4});
} else {
write(I2C.SLVT, 0x43, new byte[]{0x09, 0x54});
}
/* Enable ADC 4 */
writeReg(I2C.SLVX, 0x18, 0x00);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* IFAGC gain settings */
setRegBits(I2C.SLVT, 0xd2, 0x0c, 0x1f);
/* Set SLV-T Bank : 0x11 */
writeReg(I2C.SLVT, 0x00, 0x11);
/* BBAGC TARGET level setting */
writeReg(I2C.SLVT, 0x6a, 0x50);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* ASCOT setting */
setRegBits(I2C.SLVT, 0xa5, 0x00, 0x01);
/* Set SLV-T Bank : 0x20 */
writeReg(I2C.SLVT, 0x00, 0x20);
/* Acquisition optimization setting */
writeReg(I2C.SLVT, 0x8b, 0x3c);
/* Set SLV-T Bank : 0x2b */
writeReg(I2C.SLVT, 0x00, 0x2b);
setRegBits(I2C.SLVT, 0x76, 0x20, 0x70);
/* Set SLV-T Bank : 0x23 */
writeReg(I2C.SLVT, 0x00, 0x23);
/* L1 Control setting */
setRegBits(I2C.SLVT, 0xE6, 0x00, 0x03);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* TSIF setting */
setRegBits(I2C.SLVT, 0xce, 0x01, 0x01);
setRegBits(I2C.SLVT, 0xcf, 0x01, 0x01);
/* DVB-T2 initial setting */
writeReg(I2C.SLVT, 0x00, 0x13);
writeReg(I2C.SLVT, 0x83, 0x10);
writeReg(I2C.SLVT, 0x86, 0x34);
setRegBits(I2C.SLVT, 0x9e, 0x09, 0x0f);
writeReg(I2C.SLVT, 0x9f, 0xd8);
/* Set SLV-T Bank : 0x2a */
writeReg(I2C.SLVT, 0x00, 0x2a);
setRegBits(I2C.SLVT, 0x38, 0x04, 0x0f);
/* Set SLV-T Bank : 0x2b */
writeReg(I2C.SLVT, 0x00, 0x2b);
setRegBits(I2C.SLVT, 0x11, 0x20, 0x3f);
/* 24MHz Xtal setting */
if (xtal == Xtal.SONY_XTAL_24000) {
/* Set SLV-T Bank : 0x11 */
writeReg(I2C.SLVT, 0x00, 0x11);
write(I2C.SLVT, 0x33, new byte[]{(byte) 0xEB, 0x03, 0x3B});
/* Set SLV-T Bank : 0x20 */
writeReg(I2C.SLVT, 0x00, 0x20);
write(I2C.SLVT, 0x95, new byte[]{0x5E, 0x5E, 0x47});
writeReg(I2C.SLVT, 0x99, 0x18);
write(I2C.SLVT, 0xD9, new byte[]{0x3F, (byte) 0xFF});
/* Set SLV-T Bank : 0x24 */
writeReg(I2C.SLVT, 0x00, 0x24);
write(I2C.SLVT, 0x34, new byte[]{0x0B, 0x72});
write(I2C.SLVT, 0xD2, new byte[]{(byte) 0x93, (byte) 0xF3, 0x00});
write(I2C.SLVT, 0xDD, new byte[]{0x05, (byte) 0xB8, (byte) 0xD8});
writeReg(I2C.SLVT, 0xE0, 0x00);
/* Set SLV-T Bank : 0x25 */
writeReg(I2C.SLVT, 0x00, 0x25);
writeReg(I2C.SLVT, 0xED, 0x60);
/* Set SLV-T Bank : 0x27 */
writeReg(I2C.SLVT, 0x00, 0x27);
writeReg(I2C.SLVT, 0xFA, 0x34);
/* Set SLV-T Bank : 0x2B */
writeReg(I2C.SLVT, 0x00, 0x2B);
writeReg(I2C.SLVT, 0x4B, 0x2F);
writeReg(I2C.SLVT, 0x9E, 0x0E);
/* Set SLV-T Bank : 0x2D */
writeReg(I2C.SLVT, 0x00, 0x2D);
write(I2C.SLVT, 0x24, new byte[]{(byte) 0x89, (byte) 0x89});
/* Set SLV-T Bank : 0x5E */
writeReg(I2C.SLVT, 0x00, 0x5E);
write(I2C.SLVT, 0x8C, new byte[]{0x24, (byte) 0x95});
}
sleepTcToActiveT2Band(bandwidthHz);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* Disable HiZ Setting 1 */
writeReg(I2C.SLVT, 0x80, 0x28);
/* Disable HiZ Setting 2 */
writeReg(I2C.SLVT, 0x81, 0x00);
state = State.ACTIVE_TC;
}
private void sleepTcToActiveC(long bandwidthHz) throws DvbException {
setTsClockMode(DVBC);
/* Set SLV-X Bank : 0x00 */
writeReg(I2C.SLVX, 0x00, 0x00);
/* Set demod mode */
writeReg(I2C.SLVX, 0x17, 0x04);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* Enable demod clock */
writeReg(I2C.SLVT, 0x2c, 0x01);
/* Disable RF level monitor */
writeReg(I2C.SLVT, 0x59, 0x00);
writeReg(I2C.SLVT, 0x2f, 0x00);
/* Enable ADC clock */
writeReg(I2C.SLVT, 0x30, 0x00);
/* Enable ADC 1 */
writeReg(I2C.SLVT, 0x41, 0x1a);
/* xtal freq 20.5MHz */
write(I2C.SLVT, 0x43, new byte[]{0x09, 0x54});
/* Enable ADC 4 */
writeReg(I2C.SLVX, 0x18, 0x00);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* IFAGC gain settings */
setRegBits(I2C.SLVT, 0xd2, 0x09, 0x1f);
/* Set SLV-T Bank : 0x11 */
writeReg(I2C.SLVT, 0x00, 0x11);
/* BBAGC TARGET level setting */
writeReg(I2C.SLVT, 0x6a, 0x48);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* ASCOT setting */
setRegBits(I2C.SLVT, 0xa5, 0x00, 0x01);
/* Set SLV-T Bank : 0x40 */
writeReg(I2C.SLVT, 0x00, 0x40);
/* Demod setting */
setRegBits(I2C.SLVT, 0xc3, 0x00, 0x04);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* TSIF setting */
setRegBits(I2C.SLVT, 0xce, 0x01, 0x01);
setRegBits(I2C.SLVT, 0xcf, 0x01, 0x01);
sleepTcToActiveCBand(bandwidthHz);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* Disable HiZ Setting 1 */
writeReg(I2C.SLVT, 0x80, 0x28);
/* Disable HiZ Setting 2 */
writeReg(I2C.SLVT, 0x81, 0x00);
state = State.ACTIVE_TC;
}
private void sleepTcToActiveTBand(long bandwidthHz) throws DvbException {
/* Set SLV-T Bank : 0x13 */
writeReg(I2C.SLVT, 0x00, 0x13);
/* Echo performance optimization setting */
write(I2C.SLVT, 0x9C, new byte[]{0x01, 0x14});
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
long iffreq = calcIffreqXtal();
switch ((int) bandwidthHz) {
case 8000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate8bw);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x00, 0x07);
/* Demod core latency setting */
if (xtal == Xtal.SONY_XTAL_24000) {
write(I2C.SLVT, 0xD9, new byte[]{0x15, 0x28});
} else {
write(I2C.SLVT, 0xD9, new byte[]{0x01, (byte) 0xE0});
}
/* Notch filter setting */
writeReg(I2C.SLVT, 0x00, 0x17);
write(I2C.SLVT, 0x38, new byte[]{0x01, 0x02});
break;
case 7000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate7bw);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x02, 0x07);
/* Demod core latency setting */
if (xtal == Xtal.SONY_XTAL_24000) {
write(I2C.SLVT, 0xD9, new byte[]{0x1F, (byte) 0xF8});
} else {
write(I2C.SLVT, 0xD9, new byte[]{0x12, (byte) 0xF8});
}
/* Notch filter setting */
writeReg(I2C.SLVT, 0x00, 0x17);
write(I2C.SLVT, 0x38, new byte[]{0x00, 0x03});
break;
case 6000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate6bw);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x04, 0x07);
/* Demod core latency setting */
if (xtal == Xtal.SONY_XTAL_24000) {
write(I2C.SLVT, 0xD9, new byte[]{0x25, 0x4C});
} else {
write(I2C.SLVT, 0xD9, new byte[]{0x1F, (byte) 0xDC});
}
/* Notch filter setting */
writeReg(I2C.SLVT, 0x00, 0x17);
write(I2C.SLVT, 0x38, new byte[]{0x00, 0x03});
break;
case 5000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate5bw);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x06, 0x07);
/* Demod core latency setting */
if (xtal == Xtal.SONY_XTAL_24000) {
write(I2C.SLVT, 0xD9, new byte[]{0x2C, (byte) 0xC2});
} else {
write(I2C.SLVT, 0xD9, new byte[]{0x26, 0x3C});
}
/* Notch filter setting */
writeReg(I2C.SLVT, 0x00, 0x17);
write(I2C.SLVT, 0x38, new byte[]{0x00, 0x03});
break;
default:
throw new DvbException(UNSUPPORTED_BANDWIDTH, resources.getString(R.string.invalid_bw));
}
}
private void sleepTcToActiveT2Band(long bandwidthHz) throws DvbException {
/* Set SLV-T Bank : 0x20 */
writeReg(I2C.SLVT, 0x00, 0x20);
long iffreq = calcIffreqXtal();
switch ((int) bandwidthHz) {
case 8000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate8bw);
/* Set SLV-T Bank : 0x27 */
writeReg(I2C.SLVT, 0x00, 0x27);
setRegBits(I2C.SLVT, 0x7a, 0x00, 0x0f);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x00, 0x07);
break;
case 7000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate7bw);
/* Set SLV-T Bank : 0x27 */
writeReg(I2C.SLVT, 0x00, 0x27);
setRegBits(I2C.SLVT, 0x7a, 0x00, 0x0f);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x02, 0x07);
break;
case 6000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate6bw);
/* Set SLV-T Bank : 0x27 */
writeReg(I2C.SLVT, 0x00, 0x27);
setRegBits(I2C.SLVT, 0x7a, 0x00, 0x0f);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x04, 0x07);
break;
case 5000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate5bw);
/* Set SLV-T Bank : 0x27 */
writeReg(I2C.SLVT, 0x00, 0x27);
setRegBits(I2C.SLVT, 0x7a, 0x00, 0x0f);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x06, 0x07);
break;
case 1712000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate17bw);
/* Set SLV-T Bank : 0x27 */
writeReg(I2C.SLVT, 0x00, 0x27);
setRegBits(I2C.SLVT, 0x7a, 0x03, 0x0f);
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x03, 0x07);
break;
default:
throw new DvbException(UNSUPPORTED_BANDWIDTH, resources.getString(R.string.invalid_bw));
}
}
private void sleepTcToActiveCBand(long bandwidthHz) throws DvbException {
/* Set SLV-T Bank : 0x13 */
writeReg(I2C.SLVT, 0x00, 0x13);
/* Echo performance optimization setting */
write(I2C.SLVT, 0x9C, new byte[]{0x01, 0x14});
/* Set SLV-T Bank : 0x10 */
writeReg(I2C.SLVT, 0x00, 0x10);
long iffreq = calcIffreqXtal();
switch ((int) bandwidthHz) {
case 8000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate8bw);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x00, 0x07);
/* Demod core latency setting */
if (xtal == Xtal.SONY_XTAL_24000) {
write(I2C.SLVT, 0xD9, new byte[]{0x15, 0x28});
} else {
write(I2C.SLVT, 0xD9, new byte[]{0x01, (byte) 0xE0});
}
/* Notch filter setting */
writeReg(I2C.SLVT, 0x00, 0x17);
write(I2C.SLVT, 0x38, new byte[]{0x01, 0x02});
break;
case 7000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate7bw);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x02, 0x07);
/* Demod core latency setting */
if (xtal == Xtal.SONY_XTAL_24000) {
write(I2C.SLVT, 0xD9, new byte[]{0x1F, (byte) 0xF8});
} else {
write(I2C.SLVT, 0xD9, new byte[]{0x12, (byte) 0xF8});
}
/* Notch filter setting */
writeReg(I2C.SLVT, 0x00, 0x17);
write(I2C.SLVT, 0x38, new byte[]{0x00, 0x03});
break;
case 6000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate6bw);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x04, 0x07);
/* Demod core latency setting */
if (xtal == Xtal.SONY_XTAL_24000) {
write(I2C.SLVT, 0xD9, new byte[]{0x25, 0x4C});
} else {
write(I2C.SLVT, 0xD9, new byte[]{0x1F, (byte) 0xDC});
}
/* Notch filter setting */
writeReg(I2C.SLVT, 0x00, 0x17);
write(I2C.SLVT, 0x38, new byte[]{0x00, 0x03});
break;
case 5000000:
/* <Timing Recovery setting> */
write(I2C.SLVT, 0x9F, xtal.nominalRate5bw);
/* <IF freq setting> */
write(I2C.SLVT, 0xB6, new byte[]{(byte) ((iffreq >> 16) & 0xff), (byte) ((iffreq >> 8) & 0xff), (byte) (iffreq & 0xff)});
/* System bandwidth setting */
setRegBits(I2C.SLVT, 0xD7, 0x06, 0x07);
/* Demod core latency setting */
if (xtal == Xtal.SONY_XTAL_24000) {
write(I2C.SLVT, 0xD9, new byte[]{0x2C, (byte) 0xC2});
} else {
write(I2C.SLVT, 0xD9, new byte[]{0x26, 0x3C});
}
/* Notch filter setting */
writeReg(I2C.SLVT, 0x00, 0x17);
write(I2C.SLVT, 0x38, new byte[]{0x00, 0x03});
break;
default:
throw new DvbException(UNSUPPORTED_BANDWIDTH, resources.getString(R.string.invalid_bw));
}
}
private long calcIffreqXtal() throws DvbException {
long ifhz = tuner.getIfFrequency() * 16777216L;
return ifhz / (xtal == Xtal.SONY_XTAL_24000 ? 48000000L : 41000000L);
}
private void setTsClockMode(DeliverySystem system) throws DvbException {
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
setRegBits(I2C.SLVT, 0xc4, ts_serial ? 0x01 : 0x00, 0x03);
setRegBits(I2C.SLVT, 0xd1, ts_serial ? 0x01 : 0x00, 0x03);
writeReg(I2C.SLVT, 0xd9, 0x08);
setRegBits(I2C.SLVT, 0x32, 0x00, 0x01);
setRegBits(I2C.SLVT, 0x33, ts_serial ? 0x01 : 0x00, 0x03);
setRegBits(I2C.SLVT, 0x32, 0x01, 0x01);
if (system == DeliverySystem.DVBT) {
/* Enable parity period for DVB-T */
writeReg(I2C.SLVT, 0x00, 0x10);
setRegBits(I2C.SLVT, 0x66, 0x01, 0x01);
} else if (system == DVBC) {
/* Enable parity period for DVB-C */
writeReg(I2C.SLVT, 0x00, 0x40);
setRegBits(I2C.SLVT, 0x66, 0x01, 0x01);
}
}
@Override
public int readSnr() throws DvbException {
if (currentDeliverySystem == null) {
return -1;
}
byte[] data = new byte[2];
withFrozenRegisters(() -> {
writeReg(I2C.SLVT, 0x00, 0x10);
read(I2C.SLVT, 0x28, data, data.length);
});
int reg = ((data[0] & 0xFF) << 8) | (data[1] & 0xFF);
if (reg == 0) {
return -1;
}
switch (currentDeliverySystem) {
case DVBT:
if (reg > 4996) {
reg = 4996;
}
return 100 * (intlog10x100(reg) - intlog10x100(5350 - reg) + 285);
case DVBT2:
if (reg > 10876) {
reg = 10876;
}
return 100 * (intlog10x100(reg) - intlog10x100(12600 - reg) + 320);
}
// Unsupported for DVBC
return -1;
}
@Override
public int readRfStrengthPercentage() throws DvbException {
if (state != State.ACTIVE_TC) {
return 0;
}
// Fallback to dumb heuristics for DVB-C
Set<DvbStatus> cachedStatus = getStatus();
if (!cachedStatus.contains(FE_HAS_SIGNAL)) return 0;
return 100;
}
@Override
public int readBer() throws DvbException {
Set<DvbStatus> cachedStatus = getStatus();
if (!cachedStatus.contains(FE_HAS_VITERBI)) return 0xFFFF;
return 0;
}
@Override
public Set<DvbStatus> getStatus() throws DvbException {
if (state != State.ACTIVE_TC) {
return emptySet();
}
Set<DvbStatus> statuses = new LinkedHashSet<>();
switch (currentDeliverySystem) {
case DVBT:
writeReg(I2C.SLVT, 0x00, 0x10);
break;
case DVBT2:
writeReg(I2C.SLVT, 0x00, 0x20);
break;
case DVBC:
writeReg(I2C.SLVT, 0x00, 0x40);
break;
default:
throw new IllegalStateException("Unexpected delivery system");
}
int data;
switch (currentDeliverySystem) {
case DVBT:
case DVBT2:
data = readReg(I2C.SLVT, 0x10);
if ((data & 0x07) != 0x07) {
if ((data & 0x10) != 0) {
// unlock
return emptySet();
}
if ((data & 0x07) == 0x6) {
// sync
addAll(
statuses,
DvbStatus.FE_HAS_SIGNAL,
DvbStatus.FE_HAS_CARRIER,
DvbStatus.FE_HAS_VITERBI,
DvbStatus.FE_HAS_SYNC
);
}
if ((data & 0x20) != 0) {
statuses.add(DvbStatus.FE_HAS_LOCK);
}
}
break;
case DVBC:
data = readReg(I2C.SLVT, 0x88);
if ((data & 0x01) != 0) {
data = readReg(I2C.SLVT, 0x10);
if ((data & 0x20) != 0) {
addAll(
statuses,
DvbStatus.FE_HAS_LOCK,
DvbStatus.FE_HAS_SIGNAL,
DvbStatus.FE_HAS_CARRIER,
DvbStatus.FE_HAS_VITERBI,
DvbStatus.FE_HAS_SYNC
);
}
}
break;
}
return statuses;
}
@Override
public void setPids(int... pids) throws DvbException {
// Not supported
}
@Override
public void disablePidFilter() throws DvbException {
// Not supported
}
private ChipId cxd2841erChipId() throws DvbException {
int chip_id;
try {
writeReg(I2C.SLVT, 0, 0);
chip_id = readReg(I2C.SLVT, 0xfd);
} catch (Throwable t) {
writeReg(I2C.SLVX, 0, 0);
chip_id = readReg(I2C.SLVX, 0xfd);
}
for (ChipId c : ChipId.values()) {
if (c.chip_id == chip_id) {
return c;
}
}
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_chip_id));
}
private void shutdownToSleepTc() throws DvbException {
/* Set SLV-X Bank : 0x00 */
writeReg(I2C.SLVX, 0x00, 0x00);
/* Clear all demodulator registers */
writeReg(I2C.SLVX, 0x02, 0x00);
usleep(5000);
/* Set SLV-X Bank : 0x00 */
writeReg(I2C.SLVX, 0x00, 0x00);
/* Set demod SW reset */
writeReg(I2C.SLVX, 0x10, 0x01);
/* Select ADC clock mode */
writeReg(I2C.SLVX, 0x13, 0x00);
int data;
switch (xtal) {
case SONY_XTAL_20500:
data = 0x0;
break;
case SONY_XTAL_24000:
writeReg(I2C.SLVX, 0x12, 0x00);
data = 0x3;
break;
case SONY_XTAL_41000:
writeReg(I2C.SLVX, 0x12, 0x00);
data = 0x1;
break;
default:
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.usupported_clock_speed));
}
writeReg(I2C.SLVX, 0x14, data);
/* Clear demod SW reset */
writeReg(I2C.SLVX, 0x10, 0x00);
usleep(5000);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* TADC Bias On */
writeReg(I2C.SLVT, 0x43, 0x0a);
writeReg(I2C.SLVT, 0x41, 0x0a);
/* SADC Bias On */
writeReg(I2C.SLVT, 0x63, 0x16);
writeReg(I2C.SLVT, 0x65, 0x27);
writeReg(I2C.SLVT, 0x69, 0x06);
state = State.SLEEP_TC;
}
private void sleepTcToShutdown() throws DvbException {
/* Set SLV-X Bank : 0x00 */
writeReg(I2C.SLVX, 0x00, 0x00);
/* Disable oscillator */
writeReg(I2C.SLVX, 0x15, 0x01);
/* Set demod mode */
writeReg(I2C.SLVX, 0x17, 0x01);
state = State.SHUTDOWN;
}
private void sleepTc() throws DvbException {
if (state == State.ACTIVE_TC) {
switch (currentDeliverySystem) {
case DVBT:
activeTToSleepTc();
break;
case DVBT2:
activeT2ToSleepTc();
break;
case DVBC:
activeCToSleepTc();
break;
}
}
if (state != State.SLEEP_TC) {
throw new IllegalStateException("Device in bad state "+state);
}
}
private void activeTToSleepTc() throws DvbException {
if (state != State.ACTIVE_TC) {
throw new IllegalStateException("Device in bad state "+state);
}
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* disable TS output */
writeReg(I2C.SLVT, 0xc3, 0x01);
/* enable Hi-Z setting 1 */
writeReg(I2C.SLVT, 0x80, 0x3f);
/* enable Hi-Z setting 2 */
writeReg(I2C.SLVT, 0x81, 0xff);
/* Set SLV-X Bank : 0x00 */
writeReg(I2C.SLVX, 0x00, 0x00);
/* disable ADC 1 */
writeReg(I2C.SLVX, 0x18, 0x01);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* Disable ADC 2 */
writeReg(I2C.SLVT, 0x43, 0x0a);
/* Disable ADC 3 */
writeReg(I2C.SLVT, 0x41, 0x0a);
/* Disable ADC clock */
writeReg(I2C.SLVT, 0x30, 0x00);
/* Disable RF level monitor */
writeReg(I2C.SLVT, 0x2f, 0x00);
/* Disable demod clock */
writeReg(I2C.SLVT, 0x2c, 0x00);
state = State.SLEEP_TC;
}
private void activeT2ToSleepTc() throws DvbException {
if (state != State.ACTIVE_TC) {
throw new IllegalStateException("Device in bad state "+state);
}
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* disable TS output */
writeReg(I2C.SLVT, 0xc3, 0x01);
/* enable Hi-Z setting 1 */
writeReg(I2C.SLVT, 0x80, 0x3f);
/* enable Hi-Z setting 2 */
writeReg(I2C.SLVT, 0x81, 0xff);
/* Cancel DVB-T2 setting */
writeReg(I2C.SLVT, 0x00, 0x13);
writeReg(I2C.SLVT, 0x83, 0x40);
writeReg(I2C.SLVT, 0x86, 0x21);
setRegBits(I2C.SLVT, 0x9e, 0x09, 0x0f);
writeReg(I2C.SLVT, 0x9f, 0xfb);
writeReg(I2C.SLVT, 0x00, 0x2a);
setRegBits(I2C.SLVT, 0x38, 0x00, 0x0f);
writeReg(I2C.SLVT, 0x00, 0x2b);
setRegBits(I2C.SLVT, 0x11, 0x00, 0x3f);
/* Set SLV-X Bank : 0x00 */
writeReg(I2C.SLVX, 0x00, 0x00);
/* disable ADC 1 */
writeReg(I2C.SLVX, 0x18, 0x01);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* Disable ADC 2 */
writeReg(I2C.SLVT, 0x43, 0x0a);
/* Disable ADC 3 */
writeReg(I2C.SLVT, 0x41, 0x0a);
/* Disable ADC clock */
writeReg(I2C.SLVT, 0x30, 0x00);
/* Disable RF level monitor */
writeReg(I2C.SLVT, 0x2f, 0x00);
/* Disable demod clock */
writeReg(I2C.SLVT, 0x2c, 0x00);
state = State.SLEEP_TC;
}
private void activeCToSleepTc() throws DvbException {
if (state != State.ACTIVE_TC) {
throw new IllegalStateException("Device in bad state "+state);
}
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* disable TS output */
writeReg(I2C.SLVT, 0xc3, 0x01);
/* enable Hi-Z setting 1 */
writeReg(I2C.SLVT, 0x80, 0x3f);
/* enable Hi-Z setting 2 */
writeReg(I2C.SLVT, 0x81, 0xff);
/* Cancel DVB-C setting */
writeReg(I2C.SLVT, 0x00, 0x11);
setRegBits(I2C.SLVT, 0xa3, 0x00, 0x1f);
/* Set SLV-X Bank : 0x00 */
writeReg(I2C.SLVX, 0x00, 0x00);
/* disable ADC 1 */
writeReg(I2C.SLVX, 0x18, 0x01);
/* Set SLV-T Bank : 0x00 */
writeReg(I2C.SLVT, 0x00, 0x00);
/* Disable ADC 2 */
writeReg(I2C.SLVT, 0x43, 0x0a);
/* Disable ADC 3 */
writeReg(I2C.SLVT, 0x41, 0x0a);
/* Disable ADC clock */
writeReg(I2C.SLVT, 0x30, 0x00);
/* Disable RF level monitor */
writeReg(I2C.SLVT, 0x2f, 0x00);
/* Disable demod clock */
writeReg(I2C.SLVT, 0x2c, 0x00);
state = State.SLEEP_TC;
}
private void withFrozenRegisters(ThrowingRunnable<DvbException> r) throws DvbException {
try {
/*
* Freeze registers: ensure multiple separate register reads
* are from the same snapshot
*/
writeReg(I2C.SLVT, 0x01, 0x01);
r.run();
} finally {
writeReg(I2C.SLVT, 0x01, 0x00);
}
}
synchronized void write(I2C i2C_addr, int reg, byte[] bytes) throws DvbException {
write(i2C_addr, reg, bytes, bytes.length);
}
synchronized void write(I2C i2C_addr, int reg, byte[] value, int len) throws DvbException {
if (len + 1 > MAX_WRITE_REGSIZE)
throw new DvbException(BAD_API_USAGE, resources.getString(R.string.i2c_communication_failure));
int i2c_addr = (i2C_addr == I2C.SLVX ? i2c_addr_slvx : i2c_addr_slvt);
byte[] buf = new byte[len + 1];
buf[0] = (byte) reg;
System.arraycopy(value, 0, buf, 1, len);
i2cAdapter.transfer(i2c_addr, 0, buf, len + 1);
}
synchronized void writeReg(I2C i2C_addr, int reg, int val) throws DvbException {
write(i2C_addr, reg, new byte[]{(byte) val});
}
synchronized void setRegBits(I2C i2C_addr, int reg, int data, int mask) throws DvbException {
if (mask != 0xFF) {
int rdata = readReg(i2C_addr, reg);
data = (data & mask) | (rdata & (mask ^ 0xFF));
}
writeReg(i2C_addr, reg, data);
}
synchronized void read(I2C i2C_addr, int reg, byte[] val, int len) throws DvbException {
int i2c_addr = (i2C_addr == I2C.SLVX ? i2c_addr_slvx : i2c_addr_slvt);
i2cAdapter.transfer(
i2c_addr, 0, new byte[]{(byte) reg}, 1,
i2c_addr, I2C_M_RD, val, len
);
}
synchronized int readReg(I2C i2C_addr, int reg) throws DvbException {
byte[] ans = new byte[1];
read(i2C_addr, reg, ans, ans.length);
return ans[0] & 0xFF;
}
private static int intlog10x100(double reg) {
return (int) Math.round(Math.log10(reg) * 100.0);
}
}
| 46,352 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Rtl28xxConst.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Rtl28xxConst.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
@SuppressWarnings({"unused", "SpellCheckingInspection"})
class Rtl28xxConst {
// These go int the index parameter when calling ctrlMsg in Rtl28xxDvbDevice
static final int DEMOD = 0x0000;
static final int USB = 0x0100;
static final int SYS = 0x0200;
static final int I2C = 0x0300;
static final int I2C_DA = 0x0600;
static final int CMD_WR_FLAG = 0x0010;
static final int CMD_DEMOD_RD = 0x0000;
static final int CMD_DEMOD_WR = 0x0010;
static final int CMD_USB_RD = 0x0100;
static final int CMD_USB_WR = 0x0110;
static final int CMD_SYS_RD = 0x0200;
static final int CMD_IR_RD = 0x0201;
static final int CMD_IR_WR = 0x0211;
static final int CMD_SYS_WR = 0x0210;
static final int CMD_I2C_RD = 0x0300;
static final int CMD_I2C_WR = 0x0310;
static final int CMD_I2C_DA_RD = 0x0600;
static final int CMD_I2C_DA_WR = 0x0610;
// USB registers
/* SIE Control Registers */
static final int USB_SYSCTL = 0x2000 /* USB system control */;
static final int USB_SYSCTL_0 = 0x2000 /* USB system control */;
static final int USB_SYSCTL_1 = 0x2001 /* USB system control */;
static final int USB_SYSCTL_2 = 0x2002 /* USB system control */;
static final int USB_SYSCTL_3 = 0x2003 /* USB system control */;
static final int USB_IRQSTAT = 0x2008 /* SIE interrupt status */;
static final int USB_IRQEN = 0x200C /* SIE interrupt enable */;
static final int USB_CTRL = 0x2010 /* USB control */;
static final int USB_STAT = 0x2014 /* USB status */;
static final int USB_DEVADDR = 0x2018 /* USB device address */;
static final int USB_TEST = 0x201C /* USB test mode */;
static final int USB_FRAME_NUMBER = 0x2020 /* frame number */;
static final int USB_FIFO_ADDR = 0x2028 /* address of SIE FIFO RAM */;
static final int USB_FIFO_CMD = 0x202A /* SIE FIFO RAM access command */;
static final int USB_FIFO_DATA = 0x2030 /* SIE FIFO RAM data */;
/* Endpoint Registers */
static final int EP0_SETUPA = 0x20F8 /* EP 0 setup packet lower byte */;
static final int EP0_SETUPB = 0x20FC /* EP 0 setup packet higher byte */;
static final int USB_EP0_CFG = 0x2104 /* EP 0 configure */;
static final int USB_EP0_CTL = 0x2108 /* EP 0 control */;
static final int USB_EP0_STAT = 0x210C /* EP 0 status */;
static final int USB_EP0_IRQSTAT = 0x2110 /* EP 0 interrupt status */;
static final int USB_EP0_IRQEN = 0x2114 /* EP 0 interrupt enable */;
static final int USB_EP0_MAXPKT = 0x2118 /* EP 0 max packet size */;
static final int USB_EP0_BC = 0x2120 /* EP 0 FIFO byte counter */;
static final int USB_EPA_CFG = 0x2144 /* EP A configure */;
static final int USB_EPA_CFG_0 = 0x2144 /* EP A configure */;
static final int USB_EPA_CFG_1 = 0x2145 /* EP A configure */;
static final int USB_EPA_CFG_2 = 0x2146 /* EP A configure */;
static final int USB_EPA_CFG_3 = 0x2147 /* EP A configure */;
static final int USB_EPA_CTL = 0x2148 /* EP A control */;
static final int USB_EPA_CTL_0 = 0x2148 /* EP A control */;
static final int USB_EPA_CTL_1 = 0x2149 /* EP A control */;
static final int USB_EPA_CTL_2 = 0x214A /* EP A control */;
static final int USB_EPA_CTL_3 = 0x214B /* EP A control */;
static final int USB_EPA_STAT = 0x214C /* EP A status */;
static final int USB_EPA_IRQSTAT = 0x2150 /* EP A interrupt status */;
static final int USB_EPA_IRQEN = 0x2154 /* EP A interrupt enable */;
static final int USB_EPA_MAXPKT = 0x2158 /* EP A max packet size */;
static final int USB_EPA_MAXPKT_0 = 0x2158 /* EP A max packet size */;
static final int USB_EPA_MAXPKT_1 = 0x2159 /* EP A max packet size */;
static final int USB_EPA_MAXPKT_2 = 0x215A /* EP A max packet size */;
static final int USB_EPA_MAXPKT_3 = 0x215B /* EP A max packet size */;
static final int USB_EPA_FIFO_CFG = 0x2160 /* EP A FIFO configure */;
static final int USB_EPA_FIFO_CFG_0 = 0x2160 /* EP A FIFO configure */;
static final int USB_EPA_FIFO_CFG_1 = 0x2161 /* EP A FIFO configure */;
static final int USB_EPA_FIFO_CFG_2 = 0x2162 /* EP A FIFO configure */;
static final int USB_EPA_FIFO_CFG_3 = 0x2163 /* EP A FIFO configure */;
/* Debug Registers */
static final int USB_PHYTSTDIS = 0x2F04 /* PHY test disable */;
static final int USB_TOUT_VAL = 0x2F08 /* USB time-out time */;
static final int USB_VDRCTRL = 0x2F10 /* UTMI vendor signal control */;
static final int USB_VSTAIN = 0x2F14 /* UTMI vendor signal status in */;
static final int USB_VLOADM = 0x2F18 /* UTMI load vendor signal status in */;
static final int USB_VSTAOUT = 0x2F1C /* UTMI vendor signal status out */;
static final int USB_UTMI_TST = 0x2F80 /* UTMI test */;
static final int USB_UTMI_STATUS = 0x2F84 /* UTMI status */;
static final int USB_TSTCTL = 0x2F88 /* test control */;
static final int USB_TSTCTL2 = 0x2F8C /* test control 2 */;
static final int USB_PID_FORCE = 0x2F90 /* force PID */;
static final int USB_PKTERR_CNT = 0x2F94 /* packet error counter */;
static final int USB_RXERR_CNT = 0x2F98 /* RX error counter */;
static final int USB_MEM_BIST = 0x2F9C /* MEM BIST test */;
static final int USB_SLBBIST = 0x2FA0 /* self-loop-back BIST */;
static final int USB_CNTTEST = 0x2FA4 /* counter test */;
static final int USB_PHYTST = 0x2FC0 /* USB PHY test */;
static final int USB_DBGIDX = 0x2FF0 /* select individual block debug signal */;
static final int USB_DBGMUX = 0x2FF4 /* debug signal module mux */;
// SYS registers
/* demod control registers */
static final int SYS_SYS0 = 0x3000 /* include DEMOD_CTL, GPO, GPI, GPOE */;
static final int SYS_DEMOD_CTL = 0x3000 /* control register for DVB-T demodulator */;
/* GPIO registers */
static final int SYS_GPIO_OUT_VAL = 0x3001 /* output value of GPIO */;
static final int SYS_GPIO_IN_VAL = 0x3002 /* input value of GPIO */;
static final int SYS_GPIO_OUT_EN = 0x3003 /* output enable of GPIO */;
static final int SYS_SYS1 = 0x3004 /* include GPD, SYSINTE, SYSINTS, GP_CFG0 */;
static final int SYS_GPIO_DIR = 0x3004 /* direction control for GPIO */;
static final int SYS_SYSINTE = 0x3005 /* system interrupt enable */;
static final int SYS_SYSINTS = 0x3006 /* system interrupt status */;
static final int SYS_GPIO_CFG0 = 0x3007 /* PAD configuration for GPIO0-GPIO3 */;
static final int SYS_SYS2 = 0x3008 /* include GP_CFG1 and 3 reserved bytes */;
static final int SYS_GPIO_CFG1 = 0x3008 /* PAD configuration for GPIO4 */;
static final int SYS_DEMOD_CTL1 = 0x300B;
/* IrDA registers */
static final int SYS_IRRC_PSR = 0x3020 /* IR protocol selection */;
static final int SYS_IRRC_PER = 0x3024 /* IR protocol extension */;
static final int SYS_IRRC_SF = 0x3028 /* IR sampling frequency */;
static final int SYS_IRRC_DPIR = 0x302C /* IR data package interval */;
static final int SYS_IRRC_CR = 0x3030 /* IR control */;
static final int SYS_IRRC_RP = 0x3034 /* IR read port */;
static final int SYS_IRRC_SR = 0x3038 /* IR status */;
/* I2C master registers */
static final int SYS_I2CCR = 0x3040 /* I2C clock */;
static final int SYS_I2CMCR = 0x3044 /* I2C master control */;
static final int SYS_I2CMSTR = 0x3048 /* I2C master SCL timing */;
static final int SYS_I2CMSR = 0x304C /* I2C master status */;
static final int SYS_I2CMFR = 0x3050 /* I2C master FIFO */;
// IR registers
static final int IR_RX_BUF = 0xFC00;
static final int IR_RX_IE = 0xFD00;
static final int IR_RX_IF = 0xFD01;
static final int IR_RX_CTRL = 0xFD02;
static final int IR_RX_CFG = 0xFD03;
static final int IR_MAX_DURATION0 = 0xFD04;
static final int IR_MAX_DURATION1 = 0xFD05;
static final int IR_IDLE_LEN0 = 0xFD06;
static final int IR_IDLE_LEN1 = 0xFD07;
static final int IR_GLITCH_LEN = 0xFD08;
static final int IR_RX_BUF_CTRL = 0xFD09;
static final int IR_RX_BUF_DATA = 0xFD0A;
static final int IR_RX_BC = 0xFD0B;
static final int IR_RX_CLK = 0xFD0C;
static final int IR_RX_C_COUNT_L = 0xFD0D;
static final int IR_RX_C_COUNT_H = 0xFD0E;
static final int IR_SUSPEND_CTRL = 0xFD10;
static final int IR_ERR_TOL_CTRL = 0xFD11;
static final int IR_UNIT_LEN = 0xFD12;
static final int IR_ERR_TOL_LEN = 0xFD13;
static final int IR_MAX_H_TOL_LEN = 0xFD14;
static final int IR_MAX_L_TOL_LEN = 0xFD15;
static final int IR_MASK_CTRL = 0xFD16;
static final int IR_MASK_DATA = 0xFD17;
static final int IR_RES_MASK_ADDR = 0xFD18;
static final int IR_RES_MASK_T_LEN = 0xFD19;
}
| 10,435 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
FC0013Tuner.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/FC0013Tuner.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.tools.I2cAdapter;
import info.martinmarinov.drivers.tools.SleepUtils;
import info.martinmarinov.drivers.tools.ThrowingRunnable;
import info.martinmarinov.drivers.usb.DvbTuner;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
class FC0013Tuner implements DvbTuner {
private final static boolean DUAL_MASTER = false;
private final int i2cAddr;
private final Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter;
private final long xtal;
private final I2cAdapter.I2GateControl i2GateControl;
FC0013Tuner(int i2cAddr, Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter, long xtal, I2cAdapter.I2GateControl i2GateControl) {
this.i2cAddr = i2cAddr;
this.i2cAdapter = i2cAdapter;
this.xtal = xtal;
this.i2GateControl = i2GateControl;
}
private void wr(int reg, int val) throws DvbException {
i2cAdapter.transfer(i2cAddr, 0, new byte[] { (byte) reg, (byte) val });
}
private int rd(int reg) throws DvbException {
byte[] response = new byte[1];
i2cAdapter.transfer(
i2cAddr, 0, new byte[] { (byte) reg },
i2cAddr, I2C_M_RD, response
);
return response[0] & 0xFF;
}
@Override
public void attatch() throws DvbException {
// no-op
}
@Override
public void release() {
// no-op
}
@Override
public void init() throws DvbException {
final int[] reg = new int[] {
0x00, /* reg. 0x00: dummy */
0x09, /* reg. 0x01 */
0x16, /* reg. 0x02 */
0x00, /* reg. 0x03 */
0x00, /* reg. 0x04 */
0x17, /* reg. 0x05 */
0x02, /* reg. 0x06 */
0x0a, /* reg. 0x07: CHECK */
0xff, /* reg. 0x08: AGC Clock divide by 256, AGC gain 1/256,
Loop Bw 1/8 */
0x6f, /* reg. 0x09: enable LoopThrough */
0xb8, /* reg. 0x0a: Disable LO Test Buffer */
0x82, /* reg. 0x0b: CHECK */
0xfc, /* reg. 0x0c: depending on AGC Up-Down mode, may need 0xf8 */
0x01, /* reg. 0x0d: AGC Not Forcing & LNA Forcing, may need 0x02 */
0x00, /* reg. 0x0e */
0x00, /* reg. 0x0f */
0x00, /* reg. 0x10 */
0x00, /* reg. 0x11 */
0x00, /* reg. 0x12 */
0x00, /* reg. 0x13 */
0x50, /* reg. 0x14: DVB-t High Gain, UHF.
Middle Gain: 0x48, Low Gain: 0x40 */
0x01, /* reg. 0x15 */
};
if (xtal == 27_000_000L || xtal == 28_800_000L) {
reg[0x07] |= 0x20;
}
if (DUAL_MASTER) {
reg[0x0c] |= 0x02;
}
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
for (int i = 1; i < reg.length; i++) {
wr(i, reg[i]);
}
}
});
}
@Override
public void setParams(long frequency, final long bandwidthHz, DeliverySystem ignored) throws DvbException {
final long freq = frequency / 1_000L;
final int xtalFreqKhz2;
switch ((int) xtal) {
case 27_000_000:
xtalFreqKhz2 = 27000 / 2;
break;
case 36_000_000:
xtalFreqKhz2 = 36000 / 2;
break;
case 28_800_000:
default:
xtalFreqKhz2 = 28800 / 2;
break;
}
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
setVhfTrack(freq);
if (freq < 300000) {
/* enable VHF filter */
int tmp = rd(0x07);
wr(0x07, tmp | 0x10);
/* disable UHF & disable GPS */
tmp = rd(0x14);
wr(0x14, tmp & 0x1f);
} else if (freq <= 862000) {
/* disable VHF filter */
int tmp = rd(0x07);
wr(0x07, tmp & 0xef);
/* enable UHF & disable GPS */
tmp = rd(0x14);
wr(0x14, (tmp & 0x1f) | 0x40);
} else {
/* disable VHF filter */
int tmp = rd(0x07);
wr(0x07, tmp & 0xef);
/* disable UHF & enable GPS */
tmp = rd(0x14);
wr(0x14, (tmp & 0x1f) | 0x20);
}
int[] reg = new int[7];
int multi;
/* select frequency divider and the frequency of VCO */
if (freq < 37084) { /* freq * 96 < 3560000 */
multi = 96;
reg[5] = 0x82;
reg[6] = 0x00;
} else if (freq < 55625) { /* freq * 64 < 3560000 */
multi = 64;
reg[5] = 0x02;
reg[6] = 0x02;
} else if (freq < 74167) { /* freq * 48 < 3560000 */
multi = 48;
reg[5] = 0x42;
reg[6] = 0x00;
} else if (freq < 111250) { /* freq * 32 < 3560000 */
multi = 32;
reg[5] = 0x82;
reg[6] = 0x02;
} else if (freq < 148334) { /* freq * 24 < 3560000 */
multi = 24;
reg[5] = 0x22;
reg[6] = 0x00;
} else if (freq < 222500) { /* freq * 16 < 3560000 */
multi = 16;
reg[5] = 0x42;
reg[6] = 0x02;
} else if (freq < 296667) { /* freq * 12 < 3560000 */
multi = 12;
reg[5] = 0x12;
reg[6] = 0x00;
} else if (freq < 445000) { /* freq * 8 < 3560000 */
multi = 8;
reg[5] = 0x22;
reg[6] = 0x02;
} else if (freq < 593334) { /* freq * 6 < 3560000 */
multi = 6;
reg[5] = 0x0a;
reg[6] = 0x00;
} else if (freq < 950000) { /* freq * 4 < 3800000 */
multi = 4;
reg[5] = 0x12;
reg[6] = 0x02;
} else {
multi = 2;
reg[5] = 0x0a;
reg[6] = 0x02;
}
long f_vco = freq * multi;
boolean vco_select = false;
if (f_vco >= 3_060_000L) {
reg[6] |= 0x08;
vco_select = true;
}
if (freq >= 45_000L) {
/* From divided value (XDIV) determined the FA and FP value */
long xdiv = (f_vco / xtalFreqKhz2);
if ((f_vco - xdiv * xtalFreqKhz2) >= (xtalFreqKhz2 / 2)) {
xdiv++;
}
int pm = (int) (xdiv / 8);
int am = (int) (xdiv - (8 * pm));
if (am < 2) {
reg[1] = am + 8;
reg[2] = pm - 1;
} else {
reg[1] = am;
reg[2] = pm;
}
} else {
/* fix for frequency less than 45 MHz */
reg[1] = 0x06;
reg[2] = 0x11;
}
/* fix clock out */
reg[6] |= 0x20;
/* From VCO frequency determines the XIN ( fractional part of Delta
Sigma PLL) and divided value (XDIV) */
int xin = (int) (f_vco - (f_vco / xtalFreqKhz2) * xtalFreqKhz2);
xin = (xin << 15) / xtalFreqKhz2;
if (xin >= 16384) {
xin += 32768;
}
reg[3] = xin >> 8;
reg[4] = xin & 0xff;
reg[6] &= 0x3f; /* bits 6 and 7 describe the bandwidth */
switch ((int) bandwidthHz) {
case 6000000:
reg[6] |= 0x80;
break;
case 7000000:
reg[6] |= 0x40;
break;
case 8000000:
default:
break;
}
/* modified for Realtek demod */
reg[5] |= 0x07;
for (int i = 1; i <= 6; i++) {
wr(i, reg[i]);
}
int tmp = rd(0x11);
if (multi == 64) {
wr(0x11, tmp | 0x04);
} else {
wr(0x11, tmp & 0xfb);
}
/* VCO Calibration */
wr(0x0e, 0x80);
wr(0x0e, 0x00);
/* VCO Re-Calibration if needed */
wr(0x0e, 0x00);
SleepUtils.mdelay(10);
tmp = rd(0x0e);
/* vco selection */
tmp &= 0x3f;
if (vco_select) {
if (tmp > 0x3c) {
reg[6] &= (~0x08) & 0xFF;
wr(0x06, reg[6]);
wr(0x0e, 0x80);
wr(0x0e, 0x00);
}
} else {
if (tmp < 0x02) {
reg[6] |= 0x08;
wr(0x06, reg[6]);
wr(0x0e, 0x80);
wr(0x0e, 0x00);
}
}
}
});
}
private void setVhfTrack(long freq) throws DvbException {
int tmp = rd(0x1d);
tmp &= 0xe3;
if (freq <= 177500) { /* VHF Track: 7 */
wr(0x1d, tmp | 0x1c);
} else if (freq <= 184500) { /* VHF Track: 6 */
wr(0x1d, tmp | 0x18);
} else if (freq <= 191500) { /* VHF Track: 5 */
wr(0x1d, tmp | 0x14);
} else if (freq <= 198500) { /* VHF Track: 4 */
wr(0x1d, tmp | 0x10);
} else if (freq <= 205500) { /* VHF Track: 3 */
wr(0x1d, tmp | 0x0c);
} else if (freq <= 219500) { /* VHF Track: 2 */
wr(0x1d, tmp | 0x08);
} else if (freq < 300000) { /* VHF Track: 1 */
wr(0x1d, tmp | 0x04);
} else { /* UHF and GPS */
wr(0x1d, tmp | 0x1c);
}
}
@Override
public long getIfFrequency() throws DvbException {
/* always ? */
return 0;
}
@Override
public int readRfStrengthPercentage() throws DvbException {
throw new UnsupportedOperationException();
}
}
| 12,042 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Rtl28xxSlaveType.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Rtl28xxSlaveType.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import android.content.res.Resources;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.usb.DvbFrontend;
enum Rtl28xxSlaveType {
SLAVE_DEMOD_NONE((rtl28xxDvbDevice, tuner, i2CAdapter, resources) -> new Rtl2832Frontend(tuner, i2CAdapter, resources)),
SLAVE_DEMOD_MN88472((rtl28xxDvbDevice, tuner, i2CAdapter, resources) -> {
if (tuner != Rtl28xxTunerType.RTL2832_R828D)
throw new DvbException(DvbException.ErrorCode.BAD_API_USAGE, resources.getString(R.string.unsupported_slave_on_tuner));
Rtl2832Frontend master = new Rtl2832Frontend(tuner, i2CAdapter, resources);
Mn88472 slave = new Mn88472(i2CAdapter, resources);
return new Rtl2832pFrontend(master, rtl28xxDvbDevice, slave, false);
}),
SLAVE_DEMOD_MN88473((rtl28xxDvbDevice, tuner, i2CAdapter, resources) -> {
if (tuner != Rtl28xxTunerType.RTL2832_R828D)
throw new DvbException(DvbException.ErrorCode.BAD_API_USAGE, resources.getString(R.string.unsupported_slave_on_tuner));
Rtl2832Frontend master = new Rtl2832Frontend(tuner, i2CAdapter, resources);
Mn88473 slave = new Mn88473(i2CAdapter, resources);
return new Rtl2832pFrontend(master, rtl28xxDvbDevice, slave, false);
}),
SLAVE_DEMOD_CXD2837ER((rtl28xxDvbDevice, tuner, i2CAdapter, resources) -> {
if (tuner != Rtl28xxTunerType.RTL2832_R828D)
throw new DvbException(DvbException.ErrorCode.BAD_API_USAGE, resources.getString(R.string.unsupported_slave_on_tuner));
Rtl2832Frontend master = new Rtl2832Frontend(tuner, i2CAdapter, resources);
Cxd2841er slave = new Cxd2841er(
i2CAdapter,
resources,
Cxd2841er.Xtal.SONY_XTAL_20500,
0xd8,
true,
true,
true,
true);
return new Rtl2832pFrontend(master, rtl28xxDvbDevice, slave, true);
});
private final FrontendCreator frontendCreator;
Rtl28xxSlaveType(FrontendCreator frontendCreator) {
this.frontendCreator = frontendCreator;
}
DvbFrontend createFrontend(Rtl28xxDvbDevice rtl28xxDvbDevice, Rtl28xxTunerType tunerType, Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter, Resources resources) throws DvbException {
return frontendCreator.createFrontend(rtl28xxDvbDevice, tunerType, i2cAdapter, resources);
}
private interface FrontendCreator {
DvbFrontend createFrontend(Rtl28xxDvbDevice rtl28xxDvbDevice, Rtl28xxTunerType tunerType, Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter, Resources resources) throws DvbException;
}
}
| 3,599 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
E4000Tuner.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/E4000Tuner.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import android.content.res.Resources;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.I2cAdapter.I2GateControl;
import info.martinmarinov.drivers.tools.ThrowingRunnable;
import info.martinmarinov.drivers.usb.DvbTuner;
import info.martinmarinov.drivers.usb.rtl28xx.E4000TunerData.E4000Pll;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_TUNE_TO_FREQ;
import static info.martinmarinov.drivers.DvbException.ErrorCode.HARDWARE_EXCEPTION;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
import static info.martinmarinov.drivers.usb.rtl28xx.E4000TunerData.E4000_FREQ_BANDS;
import static info.martinmarinov.drivers.usb.rtl28xx.E4000TunerData.E4000_IF_LUT;
import static info.martinmarinov.drivers.usb.rtl28xx.E4000TunerData.E4000_LNA_LUT;
import static info.martinmarinov.drivers.usb.rtl28xx.E4000TunerData.E4000_PLL_LUT;
class E4000Tuner implements DvbTuner {
private final static int MAX_XFER_SIZE = 64;
private final int i2cAddress;
private final Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter;
private final long xtal;
private final I2GateControl i2GateControl;
private final Resources resources;
E4000Tuner(int i2cAddress, Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter, long xtal, I2GateControl i2GateControl, Resources resources) {
this.i2cAddress = i2cAddress;
this.i2cAdapter = i2cAdapter;
this.xtal = xtal;
this.i2GateControl = i2GateControl;
this.resources = resources;
}
private void wrRegs(int reg, byte[] val) throws DvbException {
wrRegs(reg, val, val.length);
}
private void wrRegs(int reg, byte[] val, int length) throws DvbException {
if (length + 1 > MAX_XFER_SIZE) throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
byte[] buf = new byte[length + 1];
buf[0] = (byte) reg;
System.arraycopy(val, 0, buf, 1, length);
i2cAdapter.transfer(i2cAddress, 0, buf);
}
private void readRegs(int reg, byte[] out) throws DvbException {
readRegs(reg, out, out.length);
}
private void readRegs(int reg, byte[] buf, int length) throws DvbException {
if (length > MAX_XFER_SIZE) throw new DvbException(BAD_API_USAGE, resources.getString(R.string.bad_api_usage));
i2cAdapter.transfer(
i2cAddress, 0, new byte[] { (byte) reg }, 1,
i2cAddress, I2C_M_RD, buf, length
);
}
private void wrReg(int reg, int val) throws DvbException {
i2cAdapter.transfer(i2cAddress, 0, new byte[] { (byte) reg, (byte) val });
}
private int rdReg(int reg) throws DvbException {
byte[] val = new byte[1];
readRegs(reg, val);
return val[0] & 0xFF;
}
@Override
public void init() throws DvbException {
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
/* dummy I2C to ensure I2C wakes up */
wrReg(0x02, 0x40);
/* reset */
wrReg(0x00, 0x01);
/* disable output clock */
wrReg(0x06, 0x00);
wrReg(0x7a, 0x96);
/* configure gains */
wrRegs(0x7e, new byte[]{(byte) 0x01, (byte) 0xFE});
wrReg(0x82, 0x00);
wrReg(0x24, 0x05);
wrRegs(0x87, new byte[]{(byte) 0x20, (byte) 0x01});
wrRegs(0x9f, new byte[]{(byte) 0x7F, (byte) 0x07});
/* DC offset control */
wrReg(0x2d, 0x1f);
wrRegs(0x70, new byte[]{(byte) 0x01, (byte) 0x01});
/* gain control */
wrReg(0x1a, 0x17);
wrReg(0x1f, 0x1a);
}
});
}
private void sleep() throws DvbException {
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
wrReg(0x00, 0x00);
}
});
}
@Override
public void attatch() throws DvbException {
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
int chipId = rdReg(0x02);
if (chipId != 0x40) throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.unexpected_chip_id));
// put sleep as chip seems to be in normal mode by default
wrReg(0x00, 0x00);
}
});
}
@Override
public void release() {
try {
sleep();
} catch (DvbException ignored) {}
}
@Override
public void setParams(final long frequency, final long bandwidthHz, DeliverySystem ignored) throws DvbException {
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
/* gain control manual */
wrReg(0x1a, 0x00);
int i;
/* PLL */
for (i = 0; i < E4000_PLL_LUT.length; i++) {
if (frequency <= E4000_PLL_LUT[i].freq) {
break;
}
}
if (i == E4000_PLL_LUT.length) throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.cannot_tune, frequency / 1_000_000L));
/*
* Note: Currently f_VCO overflows when c->frequency is 1 073 741 824 Hz
* or more.
*/
byte[] buf = new byte[5];
E4000Pll pllLut = E4000_PLL_LUT[i];
long f_VCO = frequency * pllLut.mul;
long sigma_delta = 0x10000L * (f_VCO % xtal) / xtal;
buf[0] = (byte) (f_VCO / xtal);
buf[1] = (byte) sigma_delta;
buf[2] = (byte) (sigma_delta >> 8);
buf[3] = (byte) 0x00;
buf[4] = (byte) pllLut.div;
wrRegs(0x09, buf);
/* LNA filter (RF filter) */
for (i = 0; i < E4000_LNA_LUT.length; i++) {
if (frequency <= E4000_LNA_LUT[i].freq) {
break;
}
}
if (i == E4000_LNA_LUT.length) throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.cannot_tune, frequency / 1_000_000L));
wrReg(0x10, E4000_LNA_LUT[i].val);
/* IF filters */
for (i = 0; i < E4000_IF_LUT.length; i++) {
if (bandwidthHz <= E4000_IF_LUT[i].freq) {
break;
}
}
if (i == E4000_IF_LUT.length) throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.cannot_tune, frequency / 1_000_000L));
buf[0] = (byte) E4000_IF_LUT[i].reg11val;
buf[1] = (byte) E4000_IF_LUT[i].reg12val;
wrRegs(0x11, buf, 2);
/* frequency band */
for (i = 0; i < E4000_FREQ_BANDS.length; i++) {
if (frequency <= E4000_FREQ_BANDS[i].freq) {
break;
}
}
if (i == E4000_FREQ_BANDS.length) throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.cannot_tune, frequency / 1_000_000L));
wrReg(0x07, E4000_FREQ_BANDS[i].reg07val);
wrReg(0x78, E4000_FREQ_BANDS[i].reg78val);
/* DC offset */
byte[] i_data = new byte[4];
byte[] q_data = new byte[4];
for (i = 0; i < 4; i++) {
if (i == 0) {
wrRegs(0x15, new byte[] {(byte) 0x00, (byte) 0x7e, (byte) 0x24});
} else if (i == 1) {
wrRegs(0x15, new byte[] {(byte) 0x00, (byte) 0x7f});
} else if (i == 2) {
wrRegs(0x15, new byte[] {(byte) 0x01});
} else {
wrRegs(0x16, new byte[] {(byte) 0x7e});
}
wrReg(0x29, 0x01);
readRegs(0x2a, buf, 3);
i_data[i] = (byte) (((buf[2] & 0x3) << 6) | (buf[0] & 0x3f));
q_data[i] = (byte) (((((buf[2] & 0xFF) >> 4) & 0x3) << 6) | (buf[1] & 0x3f));
}
swap(q_data, 2, 3);
swap(i_data, 2, 3);
wrRegs(0x50, q_data, 4);
wrRegs(0x60, i_data, 4);
/* gain control auto */
wrReg(0x1a, 0x17);
}
});
}
private static void swap(byte[] arr, int id1, int id2) {
byte tmp = arr[id1];
arr[id1] = arr[id2];
arr[id2] = tmp;
}
@Override
public long getIfFrequency() throws DvbException {
return 0; // Zero-IF
}
@Override
public int readRfStrengthPercentage() throws DvbException {
throw new UnsupportedOperationException();
}
}
| 10,346 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Rtl2832pFrontend.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Rtl2832pFrontend.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl2832FrontendData.DvbtRegBitName.DVBT_PIP_ON;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl2832FrontendData.DvbtRegBitName.DVBT_SOFT_RST;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.SYS_DEMOD_CTL;
import androidx.annotation.NonNull;
import java.util.Set;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.DvbStatus;
import info.martinmarinov.drivers.usb.DvbFrontend;
import info.martinmarinov.drivers.usb.DvbTuner;
class Rtl2832pFrontend implements DvbFrontend {
private final Rtl2832Frontend rtl2832Frontend;
private final Rtl28xxDvbDevice rtl28xxDvbDevice;
private final DvbFrontend slave;
private final boolean forceSlave;
private DvbCapabilities rtl2832Capabilities;
private boolean slaveEnabled;
Rtl2832pFrontend(Rtl2832Frontend rtl2832Frontend, Rtl28xxDvbDevice rtl28xxDvbDevice, DvbFrontend slave, boolean forceSlave) throws DvbException {
this.rtl2832Frontend = rtl2832Frontend;
this.rtl28xxDvbDevice = rtl28xxDvbDevice;
this.slave = slave;
this.forceSlave = forceSlave;
}
@Override
public DvbCapabilities getCapabilities() {
return slave.getCapabilities();
}
@Override
public synchronized void attach() throws DvbException {
rtl2832Frontend.attach();
rtl2832Capabilities = rtl2832Frontend.getCapabilities();
slave.attach();
}
@Override
public synchronized void release() {
slave.release();
rtl2832Frontend.release();
}
@Override
public synchronized void init(DvbTuner tuner) throws DvbException {
enableSlave(false);
rtl2832Frontend.init(tuner);
enableSlave(true);
slave.init(tuner);
}
@Override
public synchronized void setParams(long frequency, long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException {
enableSlave(false);
if (forceSlave || !rtl2832Capabilities.getSupportedDeliverySystems().contains(deliverySystem)) {
enableSlave(true);
}
activeFrontend().setParams(frequency, bandwidthHz, deliverySystem);
}
@Override
public synchronized int readSnr() throws DvbException {
return activeFrontend().readSnr();
}
@Override
public synchronized int readRfStrengthPercentage() throws DvbException {
return activeFrontend().readRfStrengthPercentage();
}
@Override
public synchronized int readBer() throws DvbException {
return activeFrontend().readBer();
}
@Override
public synchronized Set<DvbStatus> getStatus() throws DvbException {
return activeFrontend().getStatus();
}
private DvbFrontend activeFrontend() {
return slaveEnabled ? slave : rtl2832Frontend;
}
private void enableSlave(boolean enable) throws DvbException {
if (enable) {
rtl2832Frontend.wrDemodReg(DVBT_SOFT_RST, 0x0);
rtl2832Frontend.wr(0x0c, 1, new byte[]{(byte) 0x5f, (byte) 0xff});
rtl2832Frontend.wrDemodReg(DVBT_PIP_ON, 0x1);
rtl2832Frontend.wr(0xbc, 0, new byte[]{(byte) 0x18});
rtl2832Frontend.wr(0x92, 1, new byte[]{(byte) 0x7f, (byte) 0xf7, (byte) 0xff});
rtl28xxDvbDevice.wrReg(SYS_DEMOD_CTL, 0x00, 0x48); // disable ADC
} else {
rtl2832Frontend.wr(0x92, 1, new byte[]{(byte) 0x00, (byte) 0x0f, (byte) 0xff});
rtl2832Frontend.wr(0xbc, 0, new byte[]{(byte) 0x08});
rtl2832Frontend.wrDemodReg(DVBT_PIP_ON, 0x0);
rtl2832Frontend.wr(0x0c, 1, new byte[]{(byte) 0x00, (byte) 0x00});
rtl2832Frontend.wrDemodReg(DVBT_SOFT_RST, 0x1);
rtl28xxDvbDevice.wrReg(SYS_DEMOD_CTL, 0x48, 0x48); // enable ADC
}
this.slaveEnabled = enable;
}
@Override
public synchronized void disablePidFilter() throws DvbException {
rtl2832Frontend.disablePidFilter(slaveEnabled);
}
@Override
public synchronized void setPids(int... pids) throws DvbException {
rtl2832Frontend.setPids(slaveEnabled, pids);
}
}
| 5,203 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Mn88473.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Mn88473.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import android.content.res.Resources;
import androidx.annotation.NonNull;
import java.util.Set;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.DvbStatus;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.DvbMath;
import info.martinmarinov.drivers.tools.SetUtils;
import info.martinmarinov.drivers.usb.DvbTuner;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_TUNE_TO_FREQ;
import static info.martinmarinov.drivers.DvbException.ErrorCode.UNSUPPORTED_BANDWIDTH;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_CARRIER;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_LOCK;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_SIGNAL;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_SYNC;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_VITERBI;
class Mn88473 extends Mn8847X {
private final static int DVBT2_STREAM_ID = 0;
private final static long XTAL = 25_000_000L;
private DeliverySystem currentDeliverySystem = null;
private DvbTuner tuner;
Mn88473(Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter, Resources resources) {
super(i2cAdapter, resources, 0x03);
}
@Override
public synchronized void release() {
try {
// sleep
writeReg(2, 0x05, 0x3e);
} catch (DvbException e) {
e.printStackTrace();
}
}
@Override
public synchronized void init(DvbTuner tuner) throws DvbException {
this.tuner = tuner;
loadFirmware(R.raw.mn8847301fw);
/* TS config */
writeReg(2, 0x09, 0x08);
writeReg(2, 0x08, 0x1d);
tuner.init();
}
@Override
public synchronized void setParams(long frequency, long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException {
int deliverySystemVal, regBank22dval, regBank0d2val;
switch (deliverySystem) {
case DVBT:
deliverySystemVal = 0x02;
regBank22dval = 0x23;
regBank0d2val = 0x2a;
break;
case DVBT2:
deliverySystemVal = 0x03;
regBank22dval = 0x3b;
regBank0d2val = 0x29;
break;
case DVBC:
deliverySystemVal = 0x04;
regBank22dval = 0x3b;
regBank0d2val = 0x29;
break;
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
byte[] confValPtr;
switch (deliverySystem) {
case DVBT:
case DVBT2:
switch ((int) bandwidthHz) {
case 6_000_000:
confValPtr = new byte[] {(byte) 0xe9, (byte) 0x55, (byte) 0x55, (byte) 0x1c, (byte) 0x29, (byte) 0x1c, (byte) 0x29};
break;
case 7_000_000:
confValPtr = new byte[] {(byte) 0xc8, (byte) 0x00, (byte) 0x00, (byte) 0x17, (byte) 0x0a, (byte) 0x17, (byte) 0x0a};
break;
case 8_000_000:
confValPtr = new byte[] {(byte) 0xaf, (byte) 0x00, (byte) 0x00, (byte) 0x11, (byte) 0xec, (byte) 0x11, (byte) 0xec};
break;
default:
throw new DvbException(UNSUPPORTED_BANDWIDTH, resources.getString(R.string.invalid_bw));
}
break;
case DVBC:
confValPtr = new byte[] {(byte) 0x10, (byte) 0xab, (byte) 0x0d, (byte) 0xae, (byte) 0x1d, (byte) 0x9d};
break;
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
tuner.setParams(frequency, bandwidthHz, deliverySystem);
long ifFrequency = tuner.getIfFrequency();
long itmp = DvbMath.divRoundClosest(ifFrequency * 0x1000000L, XTAL);
writeReg(2, 0x05, 0x00);
writeReg(2, 0xfb, 0x13);
writeReg(2, 0xef, 0x13);
writeReg(2, 0xf9, 0x13);
writeReg(2, 0x00, 0x18);
writeReg(2, 0x01, 0x01);
writeReg(2, 0x02, 0x21);
writeReg(2, 0x03, deliverySystemVal);
writeReg(2, 0x0b, 0x00);
writeReg(2, 0x10, (int) ((itmp >> 16) & 0xff));
writeReg(2, 0x11, (int) ((itmp >> 8) & 0xff));
writeReg(2, 0x12, (int) (itmp & 0xff));
switch (deliverySystem) {
case DVBT:
case DVBT2:
for (int i = 0; i < 7; i++) {
writeReg(2, 0x13 + i, confValPtr[i] & 0xFF);
}
break;
case DVBC:
write(1, 0x10, confValPtr, 6);
break;
}
writeReg(2, 0x2d, regBank22dval);
writeReg(2, 0x2e, 0x00);
writeReg(2, 0x56, 0x0d);
write(0, 0x01, new byte[] { (byte) 0xba, (byte) 0x13, (byte) 0x80, (byte) 0xba, (byte) 0x91, (byte) 0xdd, (byte) 0xe7, (byte) 0x28 });
writeReg(0, 0x0a, 0x1a);
writeReg(0, 0x13, 0x1f);
writeReg(0, 0x19, 0x03);
writeReg(0, 0x1d, 0xb0);
writeReg(0, 0x2a, 0x72);
writeReg(0, 0x2d, 0x00);
writeReg(0, 0x3c, 0x00);
writeReg(0, 0x3f, 0xf8);
write(0, 0x40, new byte[] { (byte) 0xf4, (byte) 0x08 });
writeReg(0, 0xd2, regBank0d2val);
writeReg(0, 0xd4, 0x55);
writeReg(1, 0xbe, 0x08);
writeReg(0, 0xb2, 0x37);
writeReg(0, 0xd7, 0x04);
/* PLP */
if (deliverySystem == DeliverySystem.DVBT2) {
writeReg(2, 0x36, DVBT2_STREAM_ID);
}
/* Reset FSM */
writeReg(2, 0xf8, 0x9f);
this.currentDeliverySystem = deliverySystem;
}
@Override
public synchronized int readSnr() throws DvbException {
Set<DvbStatus> cachedStatus = getStatus();
if (!cachedStatus.contains(FE_HAS_VITERBI)) return 0;
byte[] buf = new byte[4];
int[] ibuf = new int[3];
int tmp, tmp1, tmp2;
switch (currentDeliverySystem) {
case DVBT:
read(0, 0x8f, buf, 2);
tmp = ((buf[0] & 0xFF) << 8) | (buf[1] & 0xFF);
if (tmp != 0) {
/* CNR[dB]: 10 * (log10(65536 / value) + 0.2) */
/* log10(65536) = 80807124, 0.2 = 3355443 */
return (int) DvbMath.divU64((80807124L - DvbMath.intlog10(tmp) + 3355443L) * 10000L, 1 << 24);
} else {
return 0;
}
case DVBT2:
ibuf[0] = readReg(2, 0xb7);
ibuf[1] = readReg(2, 0xb8);
ibuf[2] = readReg(2, 0xb9);
tmp = (ibuf[1] << 8) | ibuf[2];
tmp1 = (ibuf[0] >> 2) & 0x01; /* 0=SISO, 1=MISO */
if (tmp != 0) {
if (tmp1 != 0) {
/* CNR[dB]: 10 * (log10(16384 / value) - 0.6) */
/* log10(16384) = 70706234, 0.6 = 10066330 */
return (int) DvbMath.divU64((70706234L - DvbMath.intlog10(tmp) - 10066330L) * 10000L, 1 << 24);
} else {
/* CNR[dB]: 10 * (log10(65536 / value) + 0.2) */
/* log10(65536) = 80807124, 0.2 = 3355443 */
return (int) DvbMath.divU64((80807124L - DvbMath.intlog10(tmp) + 3355443L) * 10000L, 1 << 24);
}
} else {
return 0;
}
case DVBC:
read(1, 0xa1, buf, 4);
tmp1 = ((buf[0] & 0xFF) << 8) | (buf[1] & 0xFF); /* signal */
tmp2 = ((buf[2] & 0xFF) << 8) | (buf[3] & 0xFF); /* noise */
if (tmp1 != 0 && tmp2 != 0) {
/* CNR[dB]: 10 * log10(8 * (signal / noise)) */
/* log10(8) = 15151336 */
return (int) DvbMath.divU64((15151336L + DvbMath.intlog10(tmp1) - DvbMath.intlog10(tmp2)) * 10000L, 1 << 24);
} else {
return 0;
}
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
}
@Override
public synchronized int readRfStrengthPercentage() throws DvbException {
Set<DvbStatus> cachedStatus = getStatus();
if (!cachedStatus.contains(FE_HAS_SIGNAL)) return 0;
// There's signal, read it
int[] buf = new int[2];
buf[0] = readReg(2, 0x86);
buf[1] = readReg(2, 0x87);
/* AGCRD[15:6] gives us a 10bit value ([5:0] are always 0) */
int strength = (buf[0] << 8) | buf[1] | (buf[0] >> 2);
return (100 * strength) / 0xffff;
}
@Override
public synchronized int readBer() throws DvbException {
Set<DvbStatus> cachedStatus = getStatus();
if (!cachedStatus.contains(FE_HAS_LOCK)) return 0xFFFF;
byte[] buf = new byte[5];
read(0, 0x92, buf, 5);
int bitErrors = ((buf[0] & 0xFF) << 16) | ((buf[1] & 0xFF) << 8) | (buf[2] & 0xFF);
int tmp2 = ((buf[3] & 0xFF) << 8) | (buf[4] & 0xFF);
int bitCount = tmp2 * 8 * 204;
if (bitCount == 0) return 100;
// Default unit is bit error per 1MB
return (int) ((bitErrors * 0xFFFFL) / bitCount);
}
@Override
public synchronized Set<DvbStatus> getStatus() throws DvbException {
if (currentDeliverySystem == null) return SetUtils.setOf();
int tmp;
switch (currentDeliverySystem) {
case DVBT:
tmp = readReg(0, 0x62);
if ((tmp & 0xa0) == 0) {
if ((tmp & 0x0f) >= 0x09) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER,
FE_HAS_VITERBI, FE_HAS_SYNC,
FE_HAS_LOCK);
} else if ((tmp & 0x0f) >= 0x03) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER);
} else {
return SetUtils.setOf();
}
} else {
return SetUtils.setOf();
}
case DVBT2:
tmp = readReg(2, 0x8b);
if ((tmp & 0x40) == 0) {
if ((tmp & 0x0f) >= 0x0d) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER,
FE_HAS_VITERBI, FE_HAS_SYNC,
FE_HAS_LOCK);
} else if ((tmp & 0x0f) >= 0x0a) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER,
FE_HAS_VITERBI);
} else if ((tmp & 0x0f) >= 0x07) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER);
} else {
return SetUtils.setOf();
}
} else {
return SetUtils.setOf();
}
case DVBC:
tmp = readReg(1, 0x85);
if ((tmp & 0x40) == 0) {
tmp = readReg(1, 0x89);
if ((tmp & 0x01) != 0) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER,
FE_HAS_VITERBI, FE_HAS_SYNC,
FE_HAS_LOCK);
} else {
return SetUtils.setOf();
}
} else {
return SetUtils.setOf();
}
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
}
}
| 12,910 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
R820tTunerData.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/R820tTunerData.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import android.util.Pair;
import java.util.Arrays;
import java.util.List;
import info.martinmarinov.drivers.usb.rtl28xx.R820tTuner.XtalCapValue;
import static info.martinmarinov.drivers.usb.rtl28xx.R820tTuner.XtalCapValue.XTAL_HIGH_CAP_0P;
import static info.martinmarinov.drivers.usb.rtl28xx.R820tTuner.XtalCapValue.XTAL_LOW_CAP_0P;
import static info.martinmarinov.drivers.usb.rtl28xx.R820tTuner.XtalCapValue.XTAL_LOW_CAP_10P;
import static info.martinmarinov.drivers.usb.rtl28xx.R820tTuner.XtalCapValue.XTAL_LOW_CAP_20P;
import static info.martinmarinov.drivers.usb.rtl28xx.R820tTuner.XtalCapValue.XTAL_LOW_CAP_30P;
class R820tTunerData {
static final List<Pair<Integer, XtalCapValue>> XTAL_CAPS = Arrays.asList(
new Pair<>(0x0b, XTAL_LOW_CAP_30P),
new Pair<>(0x02, XTAL_LOW_CAP_20P),
new Pair<>(0x01, XTAL_LOW_CAP_10P),
new Pair<>(0x00, XTAL_LOW_CAP_0P),
new Pair<>(0x10, XTAL_HIGH_CAP_0P)
);
static final byte[] INIT_REGS = new byte[] {
(byte) 0x83, (byte) 0x32, (byte) 0x75, /* 05 to 07 */
(byte) 0xc0, (byte) 0x40, (byte) 0xd6, (byte) 0x6c, /* 08 to 0b */
(byte) 0xf5, (byte) 0x63, (byte) 0x75, (byte) 0x68, /* 0c to 0f */
(byte) 0x6c, (byte) 0x83, (byte) 0x80, (byte) 0x00, /* 10 to 13 */
(byte) 0x0f, (byte) 0x00, (byte) 0xc0, (byte) 0x30, /* 14 to 17 */
(byte) 0x48, (byte) 0xcc, (byte) 0x60, (byte) 0x00, /* 18 to 1b */
(byte) 0x54, (byte) 0xae, (byte) 0x4a, (byte) 0xc0 /* 1c to 1f */
};
static final FreqRange[] FREQ_RANGES = new FreqRange[]{
new FreqRange(
0,
0x08, /* low */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0xdf, /* R27[7:0] band2,band0 */
0x02, /* R16[1:0] 20pF (10) */
0x01,
0x00,
0),
new FreqRange(
50, /* Start freq, in MHz */
0x08, /* low */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0xbe, /* R27[7:0] band4,band1 */
0x02, /* R16[1:0] 20pF (10) */
0x01,
0x00,
0),
new FreqRange(
55, /* Start freq, in MHz */
0x08, /* low */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x8b, /* R27[7:0] band7,band4 */
0x02, /* R16[1:0] 20pF (10) */
0x01,
0x00,
0),
new FreqRange(
60, /* Start freq, in MHz */
0x08, /* low */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x7b, /* R27[7:0] band8,band4 */
0x02, /* R16[1:0] 20pF (10) */
0x01,
0x00,
0),
new FreqRange(
65, /* Start freq, in MHz */
0x08, /* low */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x69, /* R27[7:0] band9,band6 */
0x02, /* R16[1:0] 20pF (10) */
0x01,
0x00,
0),
new FreqRange(
70, /* Start freq, in MHz */
0x08, /* low */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x58, /* R27[7:0] band10,band7 */
0x02, /* R16[1:0] 20pF (10) */
0x01,
0x00,
0),
new FreqRange(
75, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x44, /* R27[7:0] band11,band11 */
0x02, /* R16[1:0] 20pF (10) */
0x01,
0x00,
0),
new FreqRange(
80, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x44, /* R27[7:0] band11,band11 */
0x02, /* R16[1:0] 20pF (10) */
0x01,
0x00,
0),
new FreqRange(
90, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x34, /* R27[7:0] band12,band11 */
0x01, /* R16[1:0] 10pF (01) */
0x01,
0x00,
0),
new FreqRange(
100, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x34, /* R27[7:0] band12,band11 */
0x01, /* R16[1:0] 10pF (01) */
0x01,
0x00,
0),
new FreqRange(
110, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x24, /* R27[7:0] band13,band11 */
0x01, /* R16[1:0] 10pF (01) */
0x01,
0x00,
1),
new FreqRange(
120, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x24, /* R27[7:0] band13,band11 */
0x01, /* R16[1:0] 10pF (01) */
0x01,
0x00,
1),
new FreqRange(
140, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x14, /* R27[7:0] band14,band11 */
0x01, /* R16[1:0] 10pF (01) */
0x01,
0x00,
1),
new FreqRange(
180, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x13, /* R27[7:0] band14,band12 */
0x00, /* R16[1:0] 0pF (00) */
0x00,
0x00,
1),
new FreqRange(
220, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x13, /* R27[7:0] band14,band12 */
0x00, /* R16[1:0] 0pF (00) */
0x00,
0x00,
2),
new FreqRange(
250, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x11, /* R27[7:0] highest,highest */
0x00, /* R16[1:0] 0pF (00) */
0x00,
0x00,
2),
new FreqRange(
280, /* Start freq, in MHz */
0x00, /* high */
0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
0x00, /* R27[7:0] highest,highest */
0x00, /* R16[1:0] 0pF (00) */
0x00,
0x00,
2),
new FreqRange(
310, /* Start freq, in MHz */
0x00, /* high */
0x41, /* R26[7:6]=1 (bypass) R26[1:0]=1 (middle) */
0x00, /* R27[7:0] highest,highest */
0x00, /* R16[1:0] 0pF (00) */
0x00,
0x00,
2),
new FreqRange(
450, /* Start freq, in MHz */
0x00, /* high */
0x41, /* R26[7:6]=1 (bypass) R26[1:0]=1 (middle) */
0x00, /* R27[7:0] highest,highest */
0x00, /* R16[1:0] 0pF (00) */
0x00,
0x00,
3),
new FreqRange(
588, /* Start freq, in MHz */
0x00, /* high */
0x40, /* R26[7:6]=1 (bypass) R26[1:0]=0 (highest) */
0x00, /* R27[7:0] highest,highest */
0x00, /* R16[1:0] 0pF (00) */
0x00,
0x00,
3),
new FreqRange(
650, /* Start freq, in MHz */
0x00, /* high */
0x40, /* R26[7:6]=1 (bypass) R26[1:0]=0 (highest) */
0x00, /* R27[7:0] highest,highest */
0x00, /* R16[1:0] 0pF (00) */
0x00,
0x00,
4)
};
static class FreqRange {
final long freq;
final int openD;
final int rfMuxPloy;
final int tfC;
final int xtalCap20p;
final int xtalCap10p;
final int xtalCap0p;
final int imrMem;
FreqRange(long freq, int openD, int rfMuxPloy, int tfC, int xtalCap20p, int xtalCap10p, int xtalCap0p, int imrMem) {
this.freq = freq;
this.openD = openD;
this.rfMuxPloy = rfMuxPloy;
this.tfC = tfC;
this.xtalCap20p = xtalCap20p;
this.xtalCap10p = xtalCap10p;
this.xtalCap0p = xtalCap0p;
this.imrMem = imrMem;
}
}
}
| 10,984 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Mn8847X.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Mn8847X.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import static info.martinmarinov.drivers.DvbException.ErrorCode.BAD_API_USAGE;
import static info.martinmarinov.drivers.DvbException.ErrorCode.HARDWARE_EXCEPTION;
import static info.martinmarinov.drivers.DvbException.ErrorCode.IO_EXCEPTION;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
import android.content.res.Resources;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.SetUtils;
import info.martinmarinov.drivers.usb.DvbFrontend;
abstract class Mn8847X implements DvbFrontend {
private final static String TAG = Mn8847X.class.getSimpleName();
private final static int I2C_WR_MAX = 22;
private final static int[] I2C_ADDRESS = new int[] { 0x18, 0x1a, 0x1c };
private final static DvbCapabilities CAPABILITIES = new DvbCapabilities(
174000000L,
862000000L,
166667L,
SetUtils.setOf(DeliverySystem.DVBT, DeliverySystem.DVBT2, DeliverySystem.DVBC));
private final Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter;
protected final Resources resources;
private final int expectedChipId;
Mn8847X(Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter, Resources resources, int expectedChipId) {
this.i2cAdapter = i2cAdapter;
this.resources = resources;
this.expectedChipId = expectedChipId;
}
synchronized void write(int addressId, int reg, byte[] bytes) throws DvbException {
write(addressId, reg, bytes, bytes.length);
}
synchronized void write(int addressId, int reg, byte[] value, int len) throws DvbException {
if (len + 1 > I2C_WR_MAX) throw new DvbException(BAD_API_USAGE, resources.getString(R.string.i2c_communication_failure));
byte[] buf = new byte[len+1];
buf[0] = (byte) reg;
System.arraycopy(value, 0, buf, 1, len);
i2cAdapter.transfer(I2C_ADDRESS[addressId], 0, buf, len + 1);
}
synchronized void writeReg(int addressId, int reg, int val) throws DvbException {
write(addressId, reg, new byte[] { (byte) val });
}
synchronized void read(int addressId, int reg, byte[] val, int len) throws DvbException {
i2cAdapter.transfer(
I2C_ADDRESS[addressId], 0, new byte[] {(byte) reg}, 1,
I2C_ADDRESS[addressId], I2C_M_RD, val, len
);
}
synchronized int readReg(int addressId, int reg) throws DvbException {
byte[] ans = new byte[1];
read(addressId, reg, ans, ans.length);
return ans[0] & 0xFF;
}
@Override
public synchronized DvbCapabilities getCapabilities() {
return CAPABILITIES;
}
@Override
public synchronized void attach() throws DvbException {
if (readReg(2, 0xFF) != expectedChipId) throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.unsupported_tuner_on_device));
/* Sleep because chip is active by default */
writeReg(2, 0x05, 0x3e);
}
void loadFirmware(int firmwareResource) throws DvbException {
boolean isWarm = (readReg(0, 0xf5) & 0x01) == 0;
if (!isWarm) {
Log.d(TAG, "Loading firmware");
writeReg(0, 0xf5, 0x03);
InputStream inputStream = resources.openRawResource(firmwareResource);
try {
byte[] buff = new byte[I2C_WR_MAX - 1];
int remain = inputStream.available();
while (remain > 0) {
int toRead = remain > buff.length ? buff.length : remain;
int read = inputStream.read(buff, 0, toRead);
write(0, 0xf6, buff, read);
remain -= read;
}
} catch (IOException e) {
throw new DvbException(IO_EXCEPTION, e);
} finally {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/* Parity check of firmware */
if ((readReg(0, 0xf8) & 0x10) != 0) {
throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.cannot_load_firmware));
}
writeReg(0, 0xf5, 0x00);
}
Log.d(TAG, "Device is warm");
}
@Override
public void setPids(int... pids) throws DvbException {
// Not supported
}
@Override
public void disablePidFilter() throws DvbException {
// Not supported
}
}
| 5,654 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
FC0012Tuner.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/FC0012Tuner.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.tools.I2cAdapter;
import info.martinmarinov.drivers.tools.SleepUtils;
import info.martinmarinov.drivers.tools.ThrowingRunnable;
import info.martinmarinov.drivers.usb.DvbTuner;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
class FC0012Tuner implements DvbTuner {
private final static boolean DUAL_MASTER = false;
private final static boolean LOOP_TRHOUGH = false;
private final int i2cAddr;
private final Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter;
private final long xtal;
private final I2cAdapter.I2GateControl i2GateControl;
private final Rtl28xxDvbDevice.TunerCallback tunerCallback;
FC0012Tuner(int i2cAddr, Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter, long xtal, I2cAdapter.I2GateControl i2GateControl, Rtl28xxDvbDevice.TunerCallback tunerCallback) {
this.i2cAddr = i2cAddr;
this.i2cAdapter = i2cAdapter;
this.xtal = xtal;
this.i2GateControl = i2GateControl;
this.tunerCallback = tunerCallback;
}
private void wr(int reg, int val) throws DvbException {
i2cAdapter.transfer(i2cAddr, 0, new byte[] { (byte) reg, (byte) val });
}
private int rd(int reg) throws DvbException {
byte[] response = new byte[1];
i2cAdapter.transfer(
i2cAddr, 0, new byte[] { (byte) reg },
i2cAddr, I2C_M_RD, response
);
return response[0] & 0xFF;
}
@Override
public void attatch() throws DvbException {
// no-op
}
@Override
public void release() {
// no-op
}
@Override
public void init() throws DvbException {
final int[] reg = new int[] {
0x00, /* dummy reg. 0 */
0x05, /* reg. 0x01 */
0x10, /* reg. 0x02 */
0x00, /* reg. 0x03 */
0x00, /* reg. 0x04 */
0x0f, /* reg. 0x05: may also be 0x0a */
0x00, /* reg. 0x06: divider 2, VCO slow */
0x00, /* reg. 0x07: may also be 0x0f */
0xff, /* reg. 0x08: AGC Clock divide by 256, AGC gain 1/256,
Loop Bw 1/8 */
0x6e, /* reg. 0x09: Disable LoopThrough, Enable LoopThrough: 0x6f */
0xb8, /* reg. 0x0a: Disable LO Test Buffer */
0x82, /* reg. 0x0b: Output Clock is same as clock frequency,
may also be 0x83 */
0xfc, /* reg. 0x0c: depending on AGC Up-Down mode, may need 0xf8 */
0x02, /* reg. 0x0d: AGC Not Forcing & LNA Forcing, 0x02 for DVB-T */
0x00, /* reg. 0x0e */
0x00, /* reg. 0x0f */
0x00, /* reg. 0x10: may also be 0x0d */
0x00, /* reg. 0x11 */
0x1f, /* reg. 0x12: Set to maximum gain */
0x08, /* reg. 0x13: Set to Middle Gain: 0x08,
Low Gain: 0x00, High Gain: 0x10, enable IX2: 0x80 */
0x00, /* reg. 0x14 */
0x04, /* reg. 0x15: Enable LNA COMPS */
};
if (xtal == 27_000_000L || xtal == 28_800_000L) {
reg[0x07] |= 0x20;
}
if (DUAL_MASTER) {
reg[0x0c] |= 0x02;
}
if (LOOP_TRHOUGH) {
reg[0x09] |= 0x01;
}
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
for (int i = 1; i < reg.length; i++) {
wr(i, reg[i]);
}
}
});
}
@Override
public void setParams(long frequency, long bandwidthHz, DeliverySystem ignored) throws DvbException {
long freq = frequency / 1_000L;
tunerCallback.onFeVhfEnable(freq <= 300000);
int xtalFreqKhz2;
switch ((int) xtal) {
case 27_000_000:
xtalFreqKhz2 = 27000 / 2;
break;
case 36_000_000:
xtalFreqKhz2 = 36000 / 2;
break;
case 28_800_000:
default:
xtalFreqKhz2 = 28800 / 2;
break;
}
int multi;
final int[] reg = new int[7];
/* select frequency divider and the frequency of VCO */
if (freq < 37084) { /* freq * 96 < 3560000 */
multi = 96;
reg[5] = 0x82;
reg[6] = 0x00;
} else if (freq < 55625) { /* freq * 64 < 3560000 */
multi = 64;
reg[5] = 0x82;
reg[6] = 0x02;
} else if (freq < 74167) { /* freq * 48 < 3560000 */
multi = 48;
reg[5] = 0x42;
reg[6] = 0x00;
} else if (freq < 111250) { /* freq * 32 < 3560000 */
multi = 32;
reg[5] = 0x42;
reg[6] = 0x02;
} else if (freq < 148334) { /* freq * 24 < 3560000 */
multi = 24;
reg[5] = 0x22;
reg[6] = 0x00;
} else if (freq < 222500) { /* freq * 16 < 3560000 */
multi = 16;
reg[5] = 0x22;
reg[6] = 0x02;
} else if (freq < 296667) { /* freq * 12 < 3560000 */
multi = 12;
reg[5] = 0x12;
reg[6] = 0x00;
} else if (freq < 445000) { /* freq * 8 < 3560000 */
multi = 8;
reg[5] = 0x12;
reg[6] = 0x02;
} else if (freq < 593334) { /* freq * 6 < 3560000 */
multi = 6;
reg[5] = 0x0a;
reg[6] = 0x00;
} else {
multi = 4;
reg[5] = 0x0a;
reg[6] = 0x02;
}
long f_vco = freq * multi;
final boolean vco_select = f_vco >= 3060000;
if (vco_select) {
reg[6] |= 0x08;
}
if (freq >= 45000) {
/* From divided value (XDIV) determined the FA and FP value */
int xdiv = (int) (f_vco / xtalFreqKhz2);
if ((f_vco - xdiv * xtalFreqKhz2) >= (xtalFreqKhz2 / 2)) {
xdiv++;
}
int pm = xdiv / 8;
int am = xdiv - (8 * pm);
if (am < 2) {
reg[1] = am + 8;
reg[2] = pm - 1;
} else {
reg[1] = am;
reg[2] = pm;
}
} else {
/* fix for frequency less than 45 MHz */
reg[1] = 0x06;
reg[2] = 0x11;
}
/* fix clock out */
reg[6] |= 0x20;
/* From VCO frequency determines the XIN ( fractional part of Delta
Sigma PLL) and divided value (XDIV) */
int xin = (int)(f_vco - (f_vco / xtalFreqKhz2) * xtalFreqKhz2);
xin = (xin << 15) / xtalFreqKhz2;
if (xin >= 16384) {
xin += 32768;
}
reg[3] = xin >> 8; /* xin with 9 bit resolution */
reg[4] = xin & 0xff;
reg[6] &= 0x3f; /* bits 6 and 7 describe the bandwidth */
switch ((int) bandwidthHz) {
case 6000000:
reg[6] |= 0x80;
break;
case 7000000:
reg[6] |= 0x40;
break;
case 8000000:
default:
break;
}
/* modified for Realtek demod */
reg[5] |= 0x07;
i2GateControl.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
for (int i = 1; i <= 6; i++) {
wr(i, reg[i]);
}
/* VCO Calibration */
wr(0x0e, 0x80);
wr(0x0e, 0x00);
/* VCO Re-Calibration if needed */
wr(0x0e, 0x00);
SleepUtils.mdelay(10);
int tmp = rd(0x0e);
/* vco selection */
tmp &= 0x3f;
if (vco_select) {
if (tmp > 0x3c) {
reg[6] &= (~0x08) & 0xFF;
wr(0x06, reg[6]);
wr(0x0e, 0x80);
wr(0x0e, 0x00);
}
} else {
if (tmp < 0x02) {
reg[6] |= 0x08;
wr(0x06, reg[6]);
wr(0x0e, 0x80);
wr(0x0e, 0x00);
}
}
}
});
}
@Override
public long getIfFrequency() throws DvbException {
/* always ? */
return 0;
}
@Override
public int readRfStrengthPercentage() throws DvbException {
throw new UnsupportedOperationException();
}
}
| 9,687 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Rtl2832DvbDevice.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Rtl2832DvbDevice.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import static info.martinmarinov.drivers.tools.Check.notNull;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.SYS_DEMOD_CTL;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.SYS_DEMOD_CTL1;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.SYS_GPIO_OUT_VAL;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxConst.USB_EPA_CTL;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.util.Log;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.tools.I2cAdapter.I2GateControl;
import info.martinmarinov.drivers.tools.ThrowingRunnable;
import info.martinmarinov.drivers.usb.DvbFrontend;
import info.martinmarinov.drivers.usb.DvbTuner;
class Rtl2832DvbDevice extends Rtl28xxDvbDevice {
private final static String TAG = Rtl2832DvbDevice.class.getSimpleName();
private Rtl28xxTunerType tuner;
private Rtl28xxSlaveType slave;
Rtl2832DvbDevice(UsbDevice usbDevice, Context context, DeviceFilter deviceFilter) throws DvbException {
super(usbDevice, context, deviceFilter);
}
@Override
protected synchronized void powerControl(boolean turnOn) throws DvbException {
Log.d(TAG, "Turning "+(turnOn ? "on" : "off"));
if (turnOn) {
/* GPIO3=1, GPIO4=0 */
wrReg(SYS_GPIO_OUT_VAL, 0x08, 0x18);
/* suspend? */
wrReg(SYS_DEMOD_CTL1, 0x00, 0x10);
/* enable PLL */
wrReg(SYS_DEMOD_CTL, 0x80, 0x80);
/* disable reset */
wrReg(SYS_DEMOD_CTL, 0x20, 0x20);
/* streaming EP: clear stall & reset */
wrReg(USB_EPA_CTL, new byte[] {(byte) 0x00, (byte) 0x00});
/* enable ADC */
wrReg(SYS_DEMOD_CTL, 0x48, 0x48);
} else {
/* GPIO4=1 */
wrReg(SYS_GPIO_OUT_VAL, 0x10, 0x10);
/* disable PLL */
wrReg(SYS_DEMOD_CTL, 0x00, 0x80);
/* streaming EP: set stall & reset */
wrReg(USB_EPA_CTL, new byte[] {(byte) 0x10, (byte) 0x02});
/* disable ADC */
wrReg(SYS_DEMOD_CTL, 0x00, 0x48);
}
}
@Override
protected synchronized void readConfig() throws DvbException {
/* enable GPIO3 and GPIO6 as output */
wrReg(Rtl28xxConst.SYS_GPIO_DIR, 0x00, 0x40);
wrReg(Rtl28xxConst.SYS_GPIO_OUT_EN, 0x48, 0x48);
/*
* Probe used tuner. We need to know used tuner before demod attach
* since there is some demod params needed to set according to tuner.
*/
/* open demod I2C gate */
i2GateController.runInOpenGate(new ThrowingRunnable<DvbException>() {
@Override
public void run() throws DvbException {
tuner = Rtl28xxTunerType.detectTuner(resources, Rtl2832DvbDevice.this);
slave = tuner.detectSlave(resources, Rtl2832DvbDevice.this);
}
});
Log.d(TAG, "Detected tuner " + tuner + " with slave demod "+slave);
}
@Override
protected synchronized DvbFrontend frontendAttatch() throws DvbException {
notNull(tuner, "Initialize tuner first!");
return slave.createFrontend(this, tuner, i2CAdapter, resources);
}
@Override
protected synchronized DvbTuner tunerAttatch() throws DvbException {
notNull(tuner, "Initialize tuner first!");
notNull(frontend, "Initialize frontend first!");
return tuner.createTuner(i2CAdapter, i2GateController, resources, tunerCallbackBuilder.forTuner(tuner));
}
@Override
public String getDebugString() {
StringBuilder sb = new StringBuilder("RTL2832 ");
if (tuner != null) sb.append(tuner.name()).append(' ');
if (slave != null) sb.append(slave.name()).append(' ');
return sb.toString();
}
private final I2GateControl i2GateController = new I2GateControl() {
private boolean i2cGateState = false;
@Override
protected synchronized void i2cGateCtrl(boolean enable) throws DvbException {
if (i2cGateState == enable) return;
if (enable) {
ctrlMsg(0x0120, 0x0011, new byte[] {(byte) 0x18});
} else {
ctrlMsg(0x0120, 0x0011, new byte[] {(byte) 0x10});
}
i2cGateState = enable;
}
};
}
| 5,292 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Rtl2832Frontend.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Rtl2832Frontend.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import static java.util.Collections.emptySet;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_TUNE_TO_FREQ;
import static info.martinmarinov.drivers.DvbException.ErrorCode.DVB_DEVICE_UNSUPPORTED;
import static info.martinmarinov.drivers.DvbException.ErrorCode.HARDWARE_EXCEPTION;
import static info.martinmarinov.drivers.DvbException.ErrorCode.UNSUPPORTED_BANDWIDTH;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
import static info.martinmarinov.drivers.tools.SetUtils.setOf;
import static info.martinmarinov.drivers.usb.rtl28xx.Rtl2832FrontendData.DvbtRegBitName.DVBT_SOFT_RST;
import android.content.res.Resources;
import android.util.Log;
import androidx.annotation.NonNull;
import java.util.Set;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.DvbStatus;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.Check;
import info.martinmarinov.drivers.tools.DvbMath;
import info.martinmarinov.drivers.usb.DvbFrontend;
import info.martinmarinov.drivers.usb.DvbTuner;
import info.martinmarinov.drivers.usb.rtl28xx.Rtl2832FrontendData.DvbtRegBitName;
import info.martinmarinov.drivers.usb.rtl28xx.Rtl2832FrontendData.RegValue;
import info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxDvbDevice.Rtl28xxI2cAdapter;
class Rtl2832Frontend implements DvbFrontend {
private final static String TAG = Rtl2832Frontend.class.getSimpleName();
private final static int I2C_ADDRESS = 0x10;
private final static long XTAL = 28_800_000L;
private final Rtl28xxTunerType tunerType;
private final Rtl28xxI2cAdapter i2cAdapter;
private final Resources resources;
private DvbTuner tuner;
Rtl2832Frontend(Rtl28xxTunerType tunerType, Rtl28xxI2cAdapter i2cAdapter, Resources resources) {
this.tunerType = tunerType;
this.i2cAdapter = i2cAdapter;
this.resources = resources;
}
@Override
public DvbCapabilities getCapabilities() {
return Rtl2832FrontendData.CAPABILITIES;
}
private void wr(int reg, byte[] val) throws DvbException {
wr(reg, val, val.length);
}
private synchronized void wr(int reg, byte[] val, int length) throws DvbException {
byte[] buf = new byte[length + 1];
System.arraycopy(val, 0, buf, 1, length);
buf[0] = (byte) reg;
i2cAdapter.transfer(I2C_ADDRESS, 0, buf);
}
synchronized void wr(int reg, int page, byte[] val) throws DvbException {
wr(reg, page, val, val.length);
}
private synchronized void wr(int reg, int page, int val) throws DvbException {
wr(reg, page, new byte[] {(byte) val});
}
private synchronized void wr(int reg, int page, byte[] val, int length) throws DvbException {
if (page != i2cAdapter.page) {
wr(0x00, new byte[] {(byte) page});
i2cAdapter.page = page;
}
wr(reg, val, length);
}
private synchronized void wrMask(int reg, int page, int mask, int val) throws DvbException {
int orig = rd(reg, page);
int tmp = (orig & ~mask) | (val & mask);
wr(reg, page, new byte[] {(byte) tmp});
}
private static int calcBit(int val) {
return 1 << val;
}
private static int calcRegMask(int val) {
return calcBit(val + 1) - 1;
}
synchronized void wrDemodReg(DvbtRegBitName reg, long val) throws DvbException {
int len = (reg.msb >> 3) + 1;
byte[] reading = new byte[len];
byte[] writing = new byte[len];
int mask = calcRegMask(reg.msb - reg.lsb);
rd(reg.startAddress, reg.page, reading);
int readingTmp = 0;
for (int i = 0; i < len; i++) {
readingTmp |= (reading[i] & 0xFF) << ((len - 1 - i) * 8);
}
int writingTmp = readingTmp & ~(mask << reg.lsb);
writingTmp |= ((val & mask) << reg.lsb);
for (int i = 0; i < len; i++) {
writing[i] = (byte) (writingTmp >> ((len - 1 - i) * 8));
}
wr(reg.startAddress, reg.page, writing);
}
private synchronized void wrDemodRegs(RegValue[] values) throws DvbException {
for (RegValue regValue : values) wrDemodReg(regValue.reg, regValue.val);
}
private synchronized void rd(int reg, byte[] val) throws DvbException {
i2cAdapter.transfer(
I2C_ADDRESS, 0, new byte[] {(byte) reg},
I2C_ADDRESS, I2C_M_RD, val
);
}
private synchronized void rd(int reg, int page, byte[] val) throws DvbException {
if (page != i2cAdapter.page) {
wr(0x00, new byte[] {(byte) page});
i2cAdapter.page = page;
}
rd(reg, val);
}
private synchronized int rd(int reg, int page) throws DvbException {
byte[] result = new byte[1];
rd(reg, page, result);
return result[0] & 0xFF;
}
private synchronized long rdDemodReg(DvbtRegBitName reg) throws DvbException {
int len = (reg.msb >> 3) + 1;
byte[] reading = new byte[len];
int mask = calcRegMask(reg.msb - reg.lsb);
rd(reg.startAddress, reg.page, reading);
long readingTmp = 0;
for (int i = 0; i < len; i++) {
readingTmp |= ((long) (reading[i] & 0xFF)) << ((len - 1 - i) * 8);
}
return (readingTmp >> reg.lsb) & mask;
}
private void setIf(long if_freq) throws DvbException {
int en_bbin = (if_freq == 0 ? 0x1 : 0x0);
/*
* PSET_IFFREQ = - floor((IfFreqHz % CrystalFreqHz) * pow(2, 22)
* / CrystalFreqHz)
*/
long pset_iffreq = if_freq % XTAL;
pset_iffreq *= 0x400000;
pset_iffreq = DvbMath.divU64(pset_iffreq, XTAL);
pset_iffreq = -pset_iffreq;
pset_iffreq = pset_iffreq & 0x3fffff;
wrDemodReg(DvbtRegBitName.DVBT_EN_BBIN, en_bbin);
wrDemodReg(DvbtRegBitName.DVBT_PSET_IFFREQ, pset_iffreq);
}
@Override
public synchronized void attach() throws DvbException {
/* check if the demod is there */
rd(0, 0);
wrDemodReg(DVBT_SOFT_RST, 0x1);
}
@Override
public synchronized void release() {
try {
wrDemodReg(DVBT_SOFT_RST, 0x1);
} catch (DvbException e) {
e.printStackTrace();
}
}
@Override
public synchronized void init(DvbTuner tuner) throws DvbException {
this.tuner = tuner;
unsetSdrMode();
wrDemodReg(DVBT_SOFT_RST, 0x0);
wrDemodRegs(Rtl2832FrontendData.INITIAL_REGS);
switch (tunerType) {
case RTL2832_E4000:
wrDemodRegs(Rtl2832FrontendData.TUNER_INIT_E4000);
break;
case RTL2832_R820T:
case RTL2832_R828D:
wrDemodRegs(Rtl2832FrontendData.TUNER_INIT_R820T);
break;
case RTL2832_FC0012:
case RTL2832_FC0013:
wrDemodRegs(Rtl2832FrontendData.TUNER_INIT_FC0012);
break;
default:
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unsupported_tuner_on_device));
}
// Skipping IF since no tuners support IF from what I can see
/*
* r820t NIM code does a software reset here at the demod -
* may not be needed, as there's already a software reset at set_params()
*/
wrDemodReg(DVBT_SOFT_RST, 0x1);
wrDemodReg(DVBT_SOFT_RST, 0x0);
tuner.init();
}
private void unsetSdrMode() throws DvbException {
/* PID filter */
wr(0x61, 0, 0xe0);
/* mode */
wr(0x19, 0, 0x20);
wr(0x17, 0, new byte[] {(byte) 0x11, (byte) 0x10});
/* FSM */
wr(0x92, 1, new byte[] {(byte) 0x00, (byte) 0x0f, (byte) 0xff});
wr(0x3e, 1, new byte[] {(byte) 0x40, (byte) 0x00});
wr(0x15, 1, new byte[] {(byte) 0x06, (byte) 0x3f, (byte) 0xce, (byte) 0xcc});
}
@Override
public synchronized void setParams(long frequency, long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException {
Check.notNull(tuner);
if (deliverySystem != DeliverySystem.DVBT) throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
tuner.setParams(frequency, bandwidthHz, deliverySystem);
setIf(tuner.getIfFrequency());
int i;
long bwMode;
switch ((int) bandwidthHz) {
case 6000000:
i = 0;
bwMode = 48000000;
break;
case 7000000:
i = 1;
bwMode = 56000000;
break;
case 8000000:
i = 2;
bwMode = 64000000;
break;
default:
throw new DvbException(UNSUPPORTED_BANDWIDTH, resources.getString(R.string.invalid_bw));
}
byte[] byteToSend = new byte[1];
for (int j = 0; j < Rtl2832FrontendData.BW_PARAMS[0].length; j++) {
byteToSend[0] = Rtl2832FrontendData.BW_PARAMS[i][j];
wr(0x1c+j, 1, byteToSend);
}
/* calculate and set resample ratio
* RSAMP_RATIO = floor(CrystalFreqHz * 7 * pow(2, 22)
* / ConstWithBandwidthMode)
*/
long num = XTAL * 7;
num *= 0x400000L;
num = DvbMath.divU64(num, bwMode);
long resampRatio = num & 0x3ffffff;
wrDemodReg(DvbtRegBitName.DVBT_RSAMP_RATIO, resampRatio);
/* calculate and set cfreq off ratio
* CFREQ_OFF_RATIO = - floor(ConstWithBandwidthMode * pow(2, 20)
* / (CrystalFreqHz * 7))
*/
num = bwMode << 20;
long num2 = XTAL * 7;
num = DvbMath.divU64(num, num2);
num = -num;
long cfreqOffRatio = num & 0xfffff;
wrDemodReg(DvbtRegBitName.DVBT_CFREQ_OFF_RATIO, cfreqOffRatio);
/* soft reset */
wrDemodReg(DVBT_SOFT_RST, 0x1);
wrDemodReg(DVBT_SOFT_RST, 0x0);
}
@Override
public synchronized int readSnr() throws DvbException {
/* reports SNR in resolution of 0.1 dB */
int tmp = rd(0x3c, 3);
int constellation = (tmp >> 2) & 0x03; /* [3:2] */
if (constellation >= Rtl2832FrontendData.CONSTELLATION_NUM) throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.cannot_read_snr));
int hierarchy = (tmp >> 4) & 0x07; /* [6:4] */
if (hierarchy >= Rtl2832FrontendData.HIERARCHY_NUM) throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.cannot_read_snr));
byte[] buf = new byte[2];
rd(0x0c, 4, buf);
int tmp16 = (buf[0] & 0xFF) << 8 | (buf[1] & 0xFF);
if (tmp16 == 0) return 0;
return (Rtl2832FrontendData.SNR_CONSTANTS[constellation][hierarchy] - DvbMath.intlog10(tmp16)) / ((1 << 24) / 100);
}
@Override
public synchronized int readRfStrengthPercentage() throws DvbException {
long tmp = rdDemodReg(DvbtRegBitName.DVBT_FSM_STAGE);
if (tmp == 10 || tmp == 11) {
// If it has signal
int u8tmp = rd(0x05, 3);
u8tmp = (~u8tmp) & 0xFF;
int strength = u8tmp << 8 | u8tmp;
return (100 * strength) / 0xffff;
} else {
return 0;
}
}
@Override
public synchronized int readBer() throws DvbException {
byte[] buf = new byte[2];
rd(0x4e, 3, buf);
// Default unit is bit error per 1MB
return (buf[0] & 0xFF) << 8 | (buf[1] & 0xFF);
}
@Override
public synchronized Set<DvbStatus> getStatus() throws DvbException {
long tmp = rdDemodReg(DvbtRegBitName.DVBT_FSM_STAGE);
if (tmp == 11) {
return setOf(DvbStatus.FE_HAS_SIGNAL, DvbStatus.FE_HAS_CARRIER,
DvbStatus.FE_HAS_VITERBI, DvbStatus.FE_HAS_SYNC, DvbStatus.FE_HAS_LOCK);
} else if (tmp == 10) {
return setOf(DvbStatus.FE_HAS_SIGNAL, DvbStatus.FE_HAS_CARRIER,
DvbStatus.FE_HAS_VITERBI);
}
return emptySet();
}
@Override
public synchronized void setPids(int... pids) throws DvbException {
setPids(false, pids);
}
@Override
public synchronized void disablePidFilter() throws DvbException {
disablePidFilter(false);
}
void setPids(boolean slaveTs, int ... pids) throws DvbException {
if (!hardwareSupportsPidFilterOf(pids)) {
// if can't do hardware filtering, fallback to software
Log.d(TAG, "Falling back to software PID filtering");
disablePidFilter(slaveTs);
return;
}
enablePidFilter(slaveTs);
long pidFilter = 0;
for (int index = 0; index < pids.length; index++) {
pidFilter |= 1 << index;
}
// write mask
byte[] buf = new byte[] {
(byte) (pidFilter & 0xFF),
(byte) ((pidFilter >> 8) & 0xFF),
(byte) ((pidFilter >> 16) & 0xFF),
(byte) ((pidFilter >> 24) & 0xFF)
};
if (slaveTs) {
wr(0x22, 0, buf);
} else {
wr(0x62, 0, buf);
}
for (int index = 0; index < pids.length; index++) {
int pid = pids[index];
buf[0] = (byte) ((pid >> 8) & 0xFF);
buf[1] = (byte) (pid & 0xFF);
if (slaveTs) {
wr(0x26 + 2 * index, 0, buf, 2);
} else {
wr(0x66 + 2 * index, 0, buf, 2);
}
}
}
void disablePidFilter(boolean slaveTs) throws DvbException {
if (slaveTs) {
wrMask(0x21, 0, 0xc0, 0xc0);
} else {
wrMask(0x61, 0, 0xc0, 0xc0);
}
}
private void enablePidFilter(boolean slaveTs) throws DvbException {
if (slaveTs) {
wrMask(0x21, 0, 0xc0, 0x80);
} else {
wrMask(0x61, 0, 0xc0, 0x80);
}
}
private static boolean hardwareSupportsPidFilterOf(int ... pids) {
if (pids.length > 32) {
return false;
}
// Avoid unnecessary unpacking, ignore Android Studio warning
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < pids.length; i++) {
if (pids[i] < 0 || pids[i] > 0x1FFF) return false;
}
return true;
}
}
| 15,450 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
R820tTuner.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/R820tTuner.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_TUNE_TO_FREQ;
import static info.martinmarinov.drivers.DvbException.ErrorCode.HARDWARE_EXCEPTION;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
import android.content.res.Resources;
import android.util.Log;
import android.util.Pair;
import androidx.annotation.NonNull;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.BitReverse;
import info.martinmarinov.drivers.tools.I2cAdapter.I2GateControl;
import info.martinmarinov.drivers.tools.SleepUtils;
import info.martinmarinov.drivers.usb.DvbTuner;
import info.martinmarinov.drivers.usb.rtl28xx.Rtl28xxDvbDevice.Rtl28xxI2cAdapter;
class R820tTuner implements DvbTuner {
private final static int MAX_I2C_MSG_LEN = 2;
private final static String TAG = R820tTuner.class.getSimpleName();
@SuppressWarnings("unused")
enum RafaelChip {
CHIP_R820T, CHIP_R620D, CHIP_R828D, CHIP_R828, CHIP_R828S, CHIP_R820C
}
@SuppressWarnings("unused")
enum XtalCapValue {
XTAL_LOW_CAP_30P,
XTAL_LOW_CAP_20P,
XTAL_LOW_CAP_10P,
XTAL_LOW_CAP_0P,
XTAL_HIGH_CAP_0P
}
private final int i2cAddress;
private final Rtl28xxI2cAdapter i2cAdapter;
private final RafaelChip rafaelChip;
private final long xtal;
private final I2GateControl i2GateControl;
private final Resources resources;
private final static int VCO_POWER_REF = 0x02;
private final static int VER_NUM = 49;
private final static int NUM_REGS = 27;
private final static int REG_SHADOW_START = 5;
private final byte[] regs = new byte[NUM_REGS];
private final static int NUM_IMR = 5;
private final static int IMR_TRIAL = 9;
private final SectType[] imrData = SectType.newArray(NUM_IMR);
private XtalCapValue xtalCapValue;
private boolean hasLock = false;
private boolean imrDone = false;
private boolean initDone = false;
private long intFreq = 0;
private long mBw;
private int filCalCode;
R820tTuner(int i2cAddress, Rtl28xxI2cAdapter i2cAdapter, RafaelChip rafaelChip, long xtal, I2GateControl i2GateControl, Resources resources) {
this.i2cAddress = i2cAddress;
this.i2cAdapter = i2cAdapter;
this.rafaelChip = rafaelChip;
this.xtal = xtal;
this.i2GateControl = i2GateControl;
this.resources = resources;
}
// IO
private void shadowStore(int reg, byte[] val) {
int len = val.length;
int r = reg - REG_SHADOW_START;
if (r < 0) {
len += r;
r = 0;
}
if (len <= 0) {
return;
}
if (len > NUM_REGS) {
len = NUM_REGS;
}
System.arraycopy(val, 0, regs, r, len);
}
private void write(int reg, byte[] val) throws DvbException {
shadowStore(reg, val);
int len = val.length;
int pos = 0;
byte[] buf = new byte[len+1];
do {
int size = len > MAX_I2C_MSG_LEN - 1 ? MAX_I2C_MSG_LEN - 1 : len;
buf[0] = (byte) reg;
System.arraycopy(val, pos, buf, 1, size);
i2cAdapter.transfer(i2cAddress, 0, buf, size + 1);
reg += size;
len -= size;
pos += size;
} while (len > 0);
}
private void writeReg(int reg, int val) throws DvbException {
write(reg, new byte[] {(byte) val});
}
private void writeRegMask(int reg, int val, int bitMask) throws DvbException {
int rc = readCacheReg(reg);
val = (rc & ~bitMask) | (val & bitMask);
write(reg, new byte[] {(byte) val});
}
private void read(int reg, byte[] val, int len) throws DvbException {
i2cAdapter.transfer(
i2cAddress, 0, new byte[] {(byte) reg}, 1,
i2cAddress, I2C_M_RD, val, len
);
for (int i = 0; i < len; i++) val[i] = BitReverse.bitRev8(val[i]);
}
private void read(int reg, byte[] val) throws DvbException {
read(reg, val, val.length);
}
private int readCacheReg(int reg) {
reg -= REG_SHADOW_START;
if (reg < 0 || reg >= NUM_REGS) throw new IllegalArgumentException();
return regs[reg] & 0xFF;
}
private int multiRead() throws DvbException {
int sum = 0;
int min = 255;
int max = 0;
byte[] data = new byte[2];
SleepUtils.usleep(5_000);
for (int i = 0; i < 6; i++) {
read(0, data);
int dataVal = data[1] & 0xFF;
sum += dataVal;
if (dataVal < min) min = dataVal;
if (dataVal > max) max = dataVal;
}
int rc = sum - max - min;
if (rc < 0) throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.failed_callibration_step));
return rc;
}
// Logic
private void initRegs() throws DvbException {
write(REG_SHADOW_START, R820tTunerData.INIT_REGS);
}
private void imrPrepare() throws DvbException {
/* Initialize the shadow registers */
System.arraycopy(R820tTunerData.INIT_REGS, 0, regs, 0, R820tTunerData.INIT_REGS.length);
/* lna off (air-in off) */
writeRegMask(0x05, 0x20, 0x20);
/* mixer gain mode = manual */
writeRegMask(0x07, 0, 0x10);
/* filter corner = lowest */
writeRegMask(0x0a, 0x0f, 0x0f);
/* filter bw=+2cap, hp=5M */
writeRegMask(0x0b, 0x60, 0x6f);
/* adc=on, vga code mode, gain = 26.5dB */
writeRegMask(0x0c, 0x0b, 0x9f);
/* ring clk = on */
writeRegMask(0x0f, 0, 0x08);
/* ring power = on */
writeRegMask(0x18, 0x10, 0x10);
/* from ring = ring pll in */
writeRegMask(0x1c, 0x02, 0x02);
/* sw_pdect = det3 */
writeRegMask(0x1e, 0x80, 0x80);
/* Set filt_3dB */
writeRegMask(0x06, 0x20, 0x20);
}
private void vgaAdjust() throws DvbException {
/* increase vga power to let image significant */
for (int vgaCount = 12; vgaCount < 16; vgaCount++) {
writeRegMask(0x0c, vgaCount, 0x0f);
SleepUtils.usleep(10_000L);
int rc = multiRead();
if (rc > 40 * 4) break;
}
}
private boolean imrCross(SectType[] iqPoint) throws DvbException {
SectType[] cross = SectType.newArray(5);
int reg08 = readCacheReg(0x08) & 0xc0;
int reg09 = readCacheReg(0x09) & 0xc0;
SectType tmp = new SectType();
tmp.value = 255;
for (int i = 0; i < 5; i++) {
switch (i) {
case 0:
cross[i].gainX = reg08;
cross[i].phaseY = reg09;
break;
case 1:
cross[i].gainX = reg08; /* 0 */
cross[i].phaseY = reg09 + 1; /* Q-1 */
break;
case 2:
cross[i].gainX = reg08; /* 0 */
cross[i].phaseY = (reg09 | 0x20) + 1; /* I-1 */
break;
case 3:
cross[i].gainX = reg08 + 1; /* Q-1 */
cross[i].phaseY = reg09;
break;
default:
cross[i].gainX = (reg08 | 0x20) + 1; /* I-1 */
cross[i].phaseY = reg09;
}
writeReg(0x08, cross[i].gainX);
writeReg(0x09, cross[i].phaseY);
cross[i].value = multiRead();
if (cross[i].value < tmp.value) tmp.copyFrom(cross[i]);
}
if ((tmp.phaseY & 0x1f) == 1) { /* y-direction */
iqPoint[0].copyFrom(cross[0]);
iqPoint[1].copyFrom(cross[1]);
iqPoint[2].copyFrom(cross[2]);
return false;
} else { /* (0,0) or x-direction */
iqPoint[0].copyFrom(cross[0]);
iqPoint[1].copyFrom(cross[3]);
iqPoint[2].copyFrom(cross[4]);
return true;
}
}
private static void compreCor(SectType[] iq) {
for (int i = 3; i > 0; i--) {
int otherId = i - 1;
if (iq[0].value > iq[otherId].value) {
SectType temp = new SectType();
temp.copyFrom(iq[0]);
iq[0].copyFrom(iq[otherId]);
iq[otherId].copyFrom(temp);
}
}
}
private void compreSep(SectType[] iq, int reg) throws DvbException {
/*
* Purpose: if (Gain<9 or Phase<9), Gain+1 or Phase+1 and compare
* with min value:
* new < min => update to min and continue
* new > min => Exit
*/
SectType tmp = new SectType();
/* min value already saved in iq[0] */
tmp.phaseY = iq[0].phaseY;
tmp.gainX = iq[0].gainX;
while (((tmp.gainX & 0x1f) < IMR_TRIAL) &&
((tmp.phaseY & 0x1f) < IMR_TRIAL)) {
if (reg == 0x08)
tmp.gainX++;
else
tmp.phaseY++;
writeReg(0x08, tmp.gainX);
writeReg(0x09, tmp.phaseY);
tmp.value = multiRead();
if (tmp.value <= iq[0].value) {
iq[0].gainX = tmp.gainX;
iq[0].phaseY = tmp.phaseY;
iq[0].value = tmp.value;
} else {
return;
}
}
}
private void iqTree(SectType[] iq, int fixVal, int varVal, int fixReg) throws DvbException {
/*
* record IMC results by input gain/phase location then adjust
* gain or phase positive 1 step and negtive 1 step,
* both record results
*/
int varReg = fixReg == 0x08 ? 0x09 : 0x08;
for (int i = 0; i < 3; i++) {
writeReg(fixReg, fixVal);
writeReg(varReg, varVal);
iq[i].value = multiRead();
if (fixReg == 0x08) {
iq[i].gainX = fixVal;
iq[i].phaseY = varVal;
} else {
iq[i].phaseY = fixVal;
iq[i].gainX = varVal;
}
if (i == 0) { /* try right-side point */
varVal++;
} else if (i == 1) { /* try left-side point */
/* if absolute location is 1, change I/Q direction */
if ((varVal & 0x1f) < 0x02) {
int tmp = 2 - (varVal & 0x1f);
/* b[5]:I/Q selection. 0:Q-path, 1:I-path */
if ((varVal & 0x20) != 0) {
varVal &= 0xc0;
varVal |= tmp;
} else {
varVal |= 0x20 | tmp;
}
} else {
varVal -= 2;
}
}
}
}
private void section(SectType iqPoint) throws DvbException {
SectType[] compareIq = SectType.newArray(3);
SectType[] compareBet = SectType.newArray(3);
/* Try X-1 column and save min result to compare_bet[0] */
if ((iqPoint.gainX & 0x1f) == 0) {
compareIq[0].gainX = ((iqPoint.gainX) & 0xdf) + 1; /* Q-path, Gain=1 */
} else {
compareIq[0].gainX = iqPoint.gainX - 1; /* left point */
}
compareIq[0].phaseY = iqPoint.phaseY;
/* y-direction */
iqTree(compareIq, compareIq[0].gainX, compareIq[0].phaseY, 0x08);
compreCor(compareIq);
compareBet[0].copyFrom(compareIq[0]);
/* Try X column and save min result to compare_bet[1] */
compareIq[0].gainX = iqPoint.gainX;
compareIq[0].phaseY = iqPoint.phaseY;
iqTree(compareIq, compareIq[0].gainX, compareIq[0].phaseY, 0x08);
compreCor(compareIq);
compareBet[1].copyFrom(compareIq[0]);
/* Try X+1 column and save min result to compare_bet[2] */
if ((iqPoint.gainX & 0x1f) == 0x00) {
compareIq[0].gainX = ((iqPoint.gainX) | 0x20) + 1; /* I-path, Gain=1 */
} else {
compareIq[0].gainX = iqPoint.gainX + 1;
}
compareIq[0].phaseY = iqPoint.phaseY;
iqTree(compareIq, compareIq[0].gainX, compareIq[0].phaseY, 0x08);
compreCor(compareIq);
compareBet[2].copyFrom(compareIq[0]);
compreCor(compareBet);
iqPoint.copyFrom(compareBet[0]);
}
private SectType iq() throws DvbException {
vgaAdjust();
SectType[] compareIq = SectType.newArray(3);
boolean xDirection = imrCross(compareIq);
int dirReg, otherReg;
if (xDirection) {
dirReg = 0x08;
otherReg = 0x09;
} else {
dirReg = 0x09;
otherReg = 0x08;
}
/* compare and find min of 3 points. determine i/q direction */
compreCor(compareIq);
/* increase step to find min value of this direction */
compreSep(compareIq, dirReg);
/* the other direction */
iqTree(compareIq, compareIq[0].gainX, compareIq[0].phaseY, dirReg);
/* compare and find min of 3 points. determine i/q direction */
compreCor(compareIq);
/* increase step to find min value on this direction */
compreSep(compareIq, otherReg);
/* check 3 points again */
iqTree(compareIq, compareIq[0].gainX, compareIq[0].phaseY, otherReg);
compreCor(compareIq);
section(compareIq[0]);
/* reset gain/phase control setting */
writeRegMask(0x08, 0, 0x3f);
writeRegMask(0x09, 0, 0x3f);
return compareIq[0];
}
private void fImr(SectType iqPoint) throws DvbException {
vgaAdjust();
/*
* search surrounding points from previous point
* try (x-1), (x), (x+1) columns, and find min IMR result point
*/
section(iqPoint);
}
private void setMux(long freq) throws DvbException {
/* Get the proper frequency range */
freq = freq / 1_000_000L;
R820tTunerData.FreqRange range = R820tTunerData.FREQ_RANGES[R820tTunerData.FREQ_RANGES.length - 1];
for (int i = 0; i < R820tTunerData.FREQ_RANGES.length - 1; i++) {
if (freq < R820tTunerData.FREQ_RANGES[i + 1].freq) {
range = R820tTunerData.FREQ_RANGES[i];
break;
}
}
/* Open Drain */
writeRegMask(0x17, range.openD, 0x08);
/* RF_MUX,Polymux */
writeRegMask(0x1a, range.rfMuxPloy, 0xc3);
/* TF BAND */
writeReg(0x1b, range.tfC);
/* XTAL CAP & Drive */
int val;
switch (xtalCapValue) {
case XTAL_LOW_CAP_30P:
case XTAL_LOW_CAP_20P:
val = range.xtalCap20p | 0x08;
break;
case XTAL_LOW_CAP_10P:
val = range.xtalCap10p | 0x08;
break;
case XTAL_HIGH_CAP_0P:
val = range.xtalCap0p;
break;
default:
case XTAL_LOW_CAP_0P:
val = range.xtalCap0p | 0x08;
break;
}
writeRegMask(0x10, val, 0x0b);
int reg08, reg09;
if (imrDone) {
reg08 = imrData[range.imrMem].gainX;
reg09 = imrData[range.imrMem].phaseY;
} else {
reg08 = 0;
reg09 = 0;
}
writeRegMask(0x08, reg08, 0x3f);
writeRegMask(0x09, reg09, 0x3f);
}
private void setPll(long freq) throws DvbException {
/* Frequency in kHz */
freq = freq / 1_000L;
long pllRef = xtal / 1_000L;
// refdiv2 which is disabled in original driver
writeRegMask(0x10, 0x00, 0x10);
/* set pll autotune = 128kHz */
writeRegMask(0x1a, 0x00, 0x0c);
/* set VCO current = 100 */
writeRegMask(0x12, 0x80, 0xe0);
/* Calculate divider */
int mixDiv = 2;
int divNum = 0;
long vcoMin = 1_770_000L;
long vcoMax = vcoMin * 2;
while (mixDiv <= 64) {
if (((freq * mixDiv) >= vcoMin) &&
((freq * mixDiv) < vcoMax)) {
int divBuf = mixDiv;
while (divBuf > 2) {
divBuf = divBuf >> 1;
divNum++;
}
break;
}
mixDiv = mixDiv << 1;
}
byte[] data = new byte[5];
read(0x00, data);
int vcoFineTune = (data[4] & 0x30) >> 4;
if (rafaelChip != RafaelChip.CHIP_R828D) {
if (vcoFineTune > VCO_POWER_REF) {
divNum--;
} else if (vcoFineTune < VCO_POWER_REF) {
divNum++;
}
}
writeRegMask(0x10, divNum << 5, 0xe0);
long vcoFreq = freq * mixDiv;
long nint = vcoFreq / (2 * pllRef);
long vcoFra = vcoFreq - 2 * pllRef * nint;
/* boundary spur prevention */
if (vcoFra < pllRef / 64) {
vcoFra = 0;
} else if (vcoFra > pllRef * 127 / 64) {
vcoFra = 0;
nint++;
} else if ((vcoFra > pllRef * 127 / 128) && (vcoFra < pllRef)) {
vcoFra = pllRef * 127 / 128;
} else if ((vcoFra > pllRef) && (vcoFra < pllRef * 129 / 128)) {
vcoFra = pllRef * 129 / 128;
}
long ni = (nint - 13) / 4;
long si = nint - 4 * ni - 13;
writeReg(0x14, (int) (ni + (si << 6)));
/* pw_sdm */
int val = vcoFra == 0 ? 0x08 : 0x00;
writeRegMask(0x12, val, 0x08);
/* sdm calculator */
int nSdm = 2;
int sdm = 0;
while (vcoFra > 1) {
if (vcoFra > (2 * pllRef / nSdm)) {
sdm = sdm + 32768 / (nSdm / 2);
vcoFra = vcoFra - 2 * pllRef / nSdm;
if (nSdm >= 0x8000)
break;
}
nSdm = nSdm << 1;
}
writeReg(0x16, sdm >> 8);
writeReg(0x15, sdm & 0xFF);
for (int i = 0; i < 2; i++) {
SleepUtils.usleep(1_0000L);
/* Check if PLL has locked */
read(0x00, data, 3);
if ((data[2] & 0x40) != 0)
break;
if (i == 0) {
/* Didn't lock. Increase VCO current */
writeRegMask(0x12, 0x60, 0xe0);
}
}
if ((data[2] & 0x40) == 0) {
hasLock = false;
} else {
hasLock = true;
Log.d(TAG, String.format("tuner has lock at frequency %d kHz\n", freq));
writeRegMask(0x1a, 0x08, 0x08);
}
}
private void imr(int imrMem, boolean imFlag) throws DvbException {
long ringRef = xtal > 24_000_000L ? xtal / 2_000L : xtal / 1_000L;
int nRing = 15;
for (int n = 0; n < 16; n++) {
if ((16L + n) * 8L * ringRef >= 3_100_000L) {
nRing = n;
break;
}
}
int reg18 = readCacheReg(0x18);
int reg19 = readCacheReg(0x19);
int reg1f = readCacheReg(0x1f);
reg18 &= 0xf0; /* set ring[3:0] */
reg18 |= nRing;
long ringVco = (16L + nRing) * 8L * ringRef;
reg18 &= 0xdf; /* clear ring_se23 */
reg19 &= 0xfc; /* clear ring_seldiv */
reg1f &= 0xfc; /* clear ring_att */
long ringFreq;
switch (imrMem) {
case 0:
ringFreq = ringVco / 48;
reg18 |= 0x20; /* ring_se23 = 1 */
reg19 |= 0x03; /* ring_seldiv = 3 */
reg1f |= 0x02; /* ring_att 10 */
break;
case 1:
ringFreq = ringVco / 16;
reg18 |= 0x00; /* ring_se23 = 0 */
reg19 |= 0x02; /* ring_seldiv = 2 */
reg1f |= 0x00; /* pw_ring 00 */
break;
case 2:
ringFreq = ringVco / 8;
reg18 |= 0x00; /* ring_se23 = 0 */
reg19 |= 0x01; /* ring_seldiv = 1 */
reg1f |= 0x03; /* pw_ring 11 */
break;
case 3:
ringFreq = ringVco / 6;
reg18 |= 0x20; /* ring_se23 = 1 */
reg19 |= 0x00; /* ring_seldiv = 0 */
reg1f |= 0x03; /* pw_ring 11 */
break;
default:
ringFreq = ringVco / 4;
reg18 |= 0x00; /* ring_se23 = 0 */
reg19 |= 0x00; /* ring_seldiv = 0 */
reg1f |= 0x01; /* pw_ring 01 */
break;
}
/* write pw_ring, n_ring, ringdiv2 registers */
/* n_ring, ring_se23 */
writeReg(0x18, reg18);
/* ring_sediv */
writeReg(0x19, reg19);
/* pw_ring */
writeReg(0x1f, reg1f);
/* mux input freq ~ rf_in freq */
setMux((ringFreq - 5_300L) * 1_000L);
setPll((ringFreq - 5_300L) * 1_000L);
if (!hasLock) throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.cannot_calibrate_tuner));
SectType imrPoint;
if (imFlag) {
imrPoint = iq();
} else {
imrPoint = new SectType();
imrPoint.copyFrom(imrData[3]);
fImr(imrPoint);
}
imrData[imrMem >= NUM_IMR ? NUM_IMR - 1 : imrMem].copyFrom(imrPoint);
}
private @NonNull XtalCapValue xtalCheck() throws DvbException {
initRegs();
/* cap 30pF & Drive Low */
writeRegMask(0x10, 0x0b, 0x0b);
/* set pll autotune = 128kHz */
writeRegMask(0x1a, 0x00, 0x0c);
/* set manual initial reg = 111111; */
writeRegMask(0x13, 0x7f, 0x7f);
/* set auto */
writeRegMask(0x13, 0x00, 0x40);
/* Try several xtal capacitor alternatives */
byte[] data = new byte[3];
for (Pair<Integer, XtalCapValue> xtalCap : R820tTunerData.XTAL_CAPS) {
writeRegMask(0x10, xtalCap.first, 0x1b);
SleepUtils.usleep(6_000L);
read(0x00, data);
if ((data[2] & 0x40) == 0) {
continue;
}
int val = data[2] & 0x3f;
if (xtal == 16_000_000L && (val > 29 || val < 23)) {
return xtalCap.second;
}
if (val != 0x3f) {
return xtalCap.second;
}
}
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.cannot_calibrate_tuner));
}
private void imrCalibrate() throws DvbException {
if (initDone) return;
if (rafaelChip == RafaelChip.CHIP_R820T ||
rafaelChip == RafaelChip.CHIP_R828S ||
rafaelChip == RafaelChip.CHIP_R820C) {
xtalCapValue = XtalCapValue.XTAL_HIGH_CAP_0P;
} else {
for (int i = 0; i < 3; i++) {
XtalCapValue detectedCap = xtalCheck();
if (i == 0 || detectedCap.ordinal() > xtalCapValue.ordinal()) {
xtalCapValue = detectedCap;
}
}
}
initRegs();
imrPrepare();
imr(3, true);
imr(1, false);
imr(0, false);
imr(2, false);
imr(4, false);
imrDone = true;
initDone = true;
}
private void standby() throws DvbException {
/* If device was not initialized yet, don't need to standby */
if (!initDone) return;
writeReg(0x06, 0xb1);
writeReg(0x05, 0x03);
writeReg(0x07, 0x3a);
writeReg(0x08, 0x40);
writeReg(0x09, 0xc0);
writeReg(0x0a, 0x36);
writeReg(0x0c, 0x35);
writeReg(0x0f, 0x68);
writeReg(0x11, 0x03);
writeReg(0x17, 0xf4);
writeReg(0x19, 0x0c);
}
private void setTvStandard(long bw) throws DvbException {
long ifKhz, filtCalLo;
int filtGain, imgR, filtQ, hpCor, extEnable, loopThrough;
int ltAtt, fltExtWidest, polyfilCur;
if (bw <= 6) {
ifKhz = 3570;
filtCalLo = 56000; /* 52000->56000 */
filtGain = 0x10; /* +3db, 6mhz on */
imgR = 0x00; /* image negative */
filtQ = 0x10; /* r10[4]:low q(1'b1) */
hpCor = 0x6b; /* 1.7m disable, +2cap, 1.0mhz */
extEnable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */
loopThrough = 0x00; /* r5[7], lt on */
ltAtt = 0x00; /* r31[7], lt att enable */
fltExtWidest = 0x00; /* r15[7]: flt_ext_wide off */
polyfilCur = 0x60; /* r25[6:5]:min */
} else if (bw == 7) {
/* 7 MHz, second table */
ifKhz = 4570;
filtCalLo = 63000;
filtGain = 0x10; /* +3db, 6mhz on */
imgR = 0x00; /* image negative */
filtQ = 0x10; /* r10[4]:low q(1'b1) */
hpCor = 0x2a; /* 1.7m disable, +1cap, 1.25mhz */
extEnable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */
loopThrough = 0x00; /* r5[7], lt on */
ltAtt = 0x00; /* r31[7], lt att enable */
fltExtWidest = 0x00; /* r15[7]: flt_ext_wide off */
polyfilCur = 0x60; /* r25[6:5]:min */
} else {
ifKhz = 4570;
filtCalLo = 68500;
filtGain = 0x10; /* +3db, 6mhz on */
imgR = 0x00; /* image negative */
filtQ = 0x10; /* r10[4]:low q(1'b1) */
hpCor = 0x0b; /* 1.7m disable, +0cap, 1.0mhz */
extEnable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */
loopThrough = 0x00; /* r5[7], lt on */
ltAtt = 0x00; /* r31[7], lt att enable */
fltExtWidest = 0x00; /* r15[7]: flt_ext_wide off */
polyfilCur = 0x60; /* r25[6:5]:min */
}
/* Initialize the shadow registers */
System.arraycopy(R820tTunerData.INIT_REGS, 0, regs, 0, R820tTunerData.INIT_REGS.length);
/* Init Flag & Xtal_check Result */
writeRegMask(0x0c, imrDone ? 1 | (xtalCapValue.ordinal() << 1) : 0, 0x0f);
/* version */
writeRegMask(0x13, VER_NUM, 0x3f);
/* for LT Gain test */
writeRegMask(0x1d, 0x00, 0x38);
SleepUtils.usleep(1_000);
intFreq = ifKhz * 1_000;
/* Check if standard changed. If so, filter calibration is needed */
boolean needCalibration = bw != mBw;
if (needCalibration) {
byte[] data = new byte[5];
for (int i = 0; i < 2; i++) {
/* Set filt_cap */
writeRegMask(0x0b, hpCor, 0x60);
/* set cali clk =on */
writeRegMask(0x0f, 0x04, 0x04);
/* X'tal cap 0pF for PLL */
writeRegMask(0x10, 0x00, 0x03);
setPll(filtCalLo * 1_000L);
if (!hasLock) throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.cannot_tune, filtCalLo / 1_000L));
/* Start Trigger */
writeRegMask(0x0b, 0x10, 0x10);
SleepUtils.usleep(1_000L);
/* Stop Trigger */
writeRegMask(0x0b, 0x00, 0x10);
/* set cali clk =off */
writeRegMask(0x0f, 0x00, 0x04);
/* Check if calibration worked */
read(0x00, data);
filCalCode = data[4] & 0x0f;
if (filCalCode != 0 && filCalCode != 0x0f) {
break;
}
}
/* narrowest */
if (filCalCode == 0x0f) filCalCode = 0;
}
writeRegMask(0x0a, filtQ | filCalCode, 0x1f);
/* Set BW, Filter_gain, & HP corner */
writeRegMask(0x0b, hpCor, 0xef);
/* Set Img_R */
writeRegMask(0x07, imgR, 0x80);
/* Set filt_3dB, V6MHz */
writeRegMask(0x06, filtGain, 0x30);
/* channel filter extension */
writeRegMask(0x1e, extEnable, 0x60);
/* Loop through */
writeRegMask(0x05, loopThrough, 0x80);
/* Loop through attenuation */
writeRegMask(0x1f, ltAtt, 0x80);
/* filter extension widest */
writeRegMask(0x0f, fltExtWidest, 0x80);
/* RF poly filter current */
writeRegMask(0x19, polyfilCur, 0x60);
/* Store current standard. If it changes, re-calibrate the tuner */
mBw = bw;
}
private void sysFreqSel(long freq, DeliverySystem deliverySystem) throws DvbException {
int mixerTop, lnaTop, cpCur, divBufCur;
int lnaVthL, mixerVthL, airCable1In, cable2In, lnaDischarge, filterCur;
switch (deliverySystem) {
case DVBT:
if ((freq == 506000000L) || (freq == 666000000L) ||
(freq == 818000000L)) {
mixerTop = 0x14; /* mixer top:14 , top-1, low-discharge */
lnaTop = 0xe5; /* detect bw 3, lna top:4, predet top:2 */
cpCur = 0x28; /* 101, 0.2 */
divBufCur = 0x20; /* 10, 200u */
} else {
mixerTop = 0x24; /* mixer top:13 , top-1, low-discharge */
lnaTop = 0xe5; /* detect bw 3, lna top:4, predet top:2 */
cpCur = 0x38; /* 111, auto */
divBufCur = 0x30; /* 11, 150u */
}
lnaVthL = 0x53; /* lna vth 0.84 , vtl 0.64 */
mixerVthL = 0x75; /* mixer vth 1.04, vtl 0.84 */
airCable1In = 0x00;
cable2In = 0x00;
lnaDischarge = 14;
filterCur = 0x40; /* 10, low */
break;
case DVBT2:
mixerTop = 0x24; /* mixer top:13 , top-1, low-discharge */
lnaTop = 0xe5; /* detect bw 3, lna top:4, predet top:2 */
lnaVthL = 0x53; /* lna vth 0.84 , vtl 0.64 */
mixerVthL = 0x75; /* mixer vth 1.04, vtl 0.84 */
airCable1In = 0x00;
cable2In = 0x00;
lnaDischarge = 14;
cpCur = 0x38; /* 111, auto */
divBufCur = 0x30; /* 11, 150u */
filterCur = 0x40; /* 10, low */
break;
case DVBC:
mixerTop = 0x24; /* mixer top:13 , top-1, low-discharge */
lnaTop = 0xe5;
lnaVthL = 0x62;
mixerVthL = 0x75;
airCable1In = 0x60;
cable2In = 0x00;
lnaDischarge = 14;
cpCur = 0x38; /* 111, auto */
divBufCur = 0x30; /* 11, 150u */
filterCur = 0x40; /* 10, low */
break;
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
// Skipping diplexer since it doesn't seem to be happening for R820t
// Skipping predetect since it doesn't seem to be happening for R820t
writeRegMask(0x1d, lnaTop, 0xc7);
writeRegMask(0x1c, mixerTop, 0xf8);
writeReg(0x0d, lnaVthL);
writeReg(0x0e, mixerVthL);
/* Air-IN only for Astrometa */
writeRegMask(0x05, airCable1In, 0x60);
writeRegMask(0x06, cable2In, 0x08);
writeRegMask(0x11, cpCur, 0x38);
writeRegMask(0x17, divBufCur, 0x30);
writeRegMask(0x0a, filterCur, 0x60);
/*
* Original driver initializes regs 0x05 and 0x06 with the
* same value again on this point. Probably, it is just an
* error there
*/
/*
* Set LNA
*/
/* LNA TOP: lowest */
writeRegMask(0x1d, 0, 0x38);
/* 0: normal mode */
writeRegMask(0x1c, 0, 0x04);
/* 0: PRE_DECT off */
writeRegMask(0x06, 0, 0x40);
/* agc clk 250hz */
writeRegMask(0x1a, 0x30, 0x30);
SleepUtils.mdelay(250);
/* write LNA TOP = 3 */
writeRegMask(0x1d, 0x18, 0x38);
/*
* write discharge mode
* what's there at the original driver
*/
writeRegMask(0x1c, mixerTop, 0x04);
/* LNA discharge current */
writeRegMask(0x1e, lnaDischarge, 0x1f);
/* agc clk 60hz */
writeRegMask(0x1a, 0x20, 0x30);
}
private void genericSetFreq(long freq /* in Hz */, long bw, DeliverySystem deliverySystem) throws DvbException {
setTvStandard(bw);
long loFreq = freq + intFreq;
setMux(loFreq);
setPll(loFreq);
if (!hasLock) throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.cannot_tune, freq / 1_000_000));
sysFreqSel(freq, deliverySystem);
}
// API
@Override
public void init() throws DvbException {
if (initDone) {
Log.d(TAG, "Already initialized, no need to re-initialize");
return;
}
i2GateControl.runInOpenGate(() -> {
imrCalibrate();
initRegs();
});
}
@Override
public void setParams(final long frequency, final long bandwidthHz, final DeliverySystem deliverySystem) throws DvbException {
i2GateControl.runInOpenGate(() -> {
long bw = (bandwidthHz + 500_000L) / 1_000_000L;
if (bw == 0) bw = 8;
genericSetFreq(frequency, bw, deliverySystem);
});
}
@Override
public void attatch() throws DvbException {
i2GateControl.runInOpenGate(() -> {
byte[] data = new byte[5];
read(0x00, data);
standby();
});
Log.d(TAG, "Rafael Micro r820t successfully identified");
}
@Override
public void release() {
try {
i2GateControl.runInOpenGate(() -> standby());
} catch (DvbException e) {
e.printStackTrace();
}
}
@Override
public long getIfFrequency() throws DvbException {
return intFreq;
}
@Override
public int readRfStrengthPercentage() throws DvbException {
throw new UnsupportedOperationException();
}
// Helper classes
private static class SectType {
private int phaseY;
private int gainX;
private int value;
private void copyFrom(SectType src) {
phaseY = src.phaseY;
gainX = src.gainX;
value = src.value;
}
private static SectType[] newArray(int elements) {
SectType[] array = new SectType[elements];
for (int i = 0; i < array.length; i++) array[i] = new SectType();
return array;
}
}
}
| 35,673 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
E4000TunerData.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/E4000TunerData.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
class E4000TunerData {
// PLL
final static E4000Pll[] E4000_PLL_LUT = new E4000Pll[] {
new E4000Pll( 72_400_000L, 0x0f, 48 ), /* .......... 3475200000 */
new E4000Pll( 81_200_000L, 0x0e, 40 ), /* 2896000000 3248000000 */
new E4000Pll( 108_300_000L, 0x0d, 32 ), /* 2598400000 3465600000 */
new E4000Pll( 162_500_000L, 0x0c, 24 ), /* 2599200000 3900000000 */
new E4000Pll( 216_600_000L, 0x0b, 16 ), /* 2600000000 3465600000 */
new E4000Pll( 325_000_000L, 0x0a, 12 ), /* 2599200000 3900000000 */
new E4000Pll( 350_000_000L, 0x09, 8 ), /* 2600000000 2800000000 */
new E4000Pll( 432_000_000L, 0x03, 8 ), /* 2800000000 3456000000 */
new E4000Pll( 667_000_000L, 0x02, 6 ), /* 2592000000 4002000000 */
new E4000Pll(1_200_000_000L, 0x01, 4 ), /* 2668000000 4800000000 */
new E4000Pll( 0xffffffffL, 0x00, 2 ) /* 2400000000 .......... */
};
static class E4000Pll {
final long freq;
final int div;
final int mul;
private E4000Pll(long freq, int div, int mul) {
this.freq = freq;
this.div = div;
this.mul = mul;
}
}
// LNA
final static E4000Lna[] E4000_LNA_LUT = new E4000Lna[] {
new E4000Lna( 370_000_000L, 0 ),
new E4000Lna( 392_500_000L, 1 ),
new E4000Lna( 415_000_000L, 2 ),
new E4000Lna( 437_500_000L, 3 ),
new E4000Lna( 462_500_000L, 4 ),
new E4000Lna( 490_000_000L, 5 ),
new E4000Lna( 522_500_000L, 6 ),
new E4000Lna( 557_500_000L, 7 ),
new E4000Lna( 595_000_000L, 8 ),
new E4000Lna( 642_500_000L, 9 ),
new E4000Lna( 695_000_000L, 10 ),
new E4000Lna( 740_000_000L, 11 ),
new E4000Lna( 800_000_000L, 12 ),
new E4000Lna( 865_000_000L, 13 ),
new E4000Lna( 930_000_000L, 14 ),
new E4000Lna( 1_000_000_000L, 15 ),
new E4000Lna( 1_310_000_000L, 0 ),
new E4000Lna( 1_340_000_000L, 1 ),
new E4000Lna( 1_385_000_000L, 2 ),
new E4000Lna( 1_427_500_000L, 3 ),
new E4000Lna( 1_452_500_000L, 4 ),
new E4000Lna( 1_475_000_000L, 5 ),
new E4000Lna( 1_510_000_000L, 6 ),
new E4000Lna( 1_545_000_000L, 7 ),
new E4000Lna( 1_575_000_000L, 8 ),
new E4000Lna( 1_615_000_000L, 9 ),
new E4000Lna( 1_650_000_000L, 10 ),
new E4000Lna( 1_670_000_000L, 11 ),
new E4000Lna( 1_690_000_000L, 12 ),
new E4000Lna( 1_710_000_000L, 13 ),
new E4000Lna( 1_735_000_000L, 14 ),
new E4000Lna( 0xffffffffL, 15 )
};
static class E4000Lna {
final long freq;
final int val;
E4000Lna(long freq, int val) {
this.freq = freq;
this.val = val;
}
}
// IF
final static E4000If[] E4000_IF_LUT = new E4000If[] {
new E4000If( 4_300_000L, 0xfd, 0x1f ),
new E4000If( 4_400_000L, 0xfd, 0x1e ),
new E4000If( 4_480_000L, 0xfc, 0x1d ),
new E4000If( 4_560_000L, 0xfc, 0x1c ),
new E4000If( 4_600_000L, 0xfc, 0x1b ),
new E4000If( 4_800_000L, 0xfc, 0x1a ),
new E4000If( 4_900_000L, 0xfc, 0x19 ),
new E4000If( 5_000_000L, 0xfc, 0x18 ),
new E4000If( 5_100_000L, 0xfc, 0x17 ),
new E4000If( 5_200_000L, 0xfc, 0x16 ),
new E4000If( 5_400_000L, 0xfc, 0x15 ),
new E4000If( 5_500_000L, 0xfc, 0x14 ),
new E4000If( 5_600_000L, 0xfc, 0x13 ),
new E4000If( 5_800_000L, 0xfb, 0x12 ),
new E4000If( 5_900_000L, 0xfb, 0x11 ),
new E4000If( 6_000_000L, 0xfb, 0x10 ),
new E4000If( 6_200_000L, 0xfb, 0x0f ),
new E4000If( 6_400_000L, 0xfa, 0x0e ),
new E4000If( 6_600_000L, 0xfa, 0x0d ),
new E4000If( 6_800_000L, 0xf9, 0x0c ),
new E4000If( 7_200_000L, 0xf9, 0x0b ),
new E4000If( 7_400_000L, 0xf9, 0x0a ),
new E4000If( 7_600_000L, 0xf8, 0x09 ),
new E4000If( 7_800_000L, 0xf8, 0x08 ),
new E4000If( 8_200_000L, 0xf8, 0x07 ),
new E4000If( 8_600_000L, 0xf7, 0x06 ),
new E4000If( 8_800_000L, 0xf7, 0x05 ),
new E4000If( 9_200_000L, 0xf7, 0x04 ),
new E4000If( 9_600_000L, 0xf6, 0x03 ),
new E4000If( 10_000_000L, 0xf6, 0x02 ),
new E4000If( 10_600_000L, 0xf5, 0x01 ),
new E4000If( 11_000_000L, 0xf5, 0x00 ),
new E4000If( 0xffffffffL, 0x00, 0x20 )
};
static class E4000If {
final long freq;
final int reg11val, reg12val;
E4000If(long freq, int reg11val, int reg12val) {
this.freq = freq;
this.reg11val = reg11val;
this.reg12val = reg12val;
}
}
// Bands
final static E4000band[] E4000_FREQ_BANDS = new E4000band[] {
new E4000band( 140_000_000L, 0x01, 0x03 ),
new E4000band( 350_000_000L, 0x03, 0x03 ),
new E4000band( 1_000_000_000L, 0x05, 0x03 ),
new E4000band( 0xffffffffL, 0x07, 0x00 )
};
static class E4000band {
final long freq;
final int reg07val, reg78val;
E4000band(long freq, int reg07val, int reg78val) {
this.freq = freq;
this.reg07val = reg07val;
this.reg78val = reg78val;
}
}
}
| 6,689 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Mn88472.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Mn88472.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import android.content.res.Resources;
import androidx.annotation.NonNull;
import java.util.Set;
import info.martinmarinov.drivers.DeliverySystem;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.DvbStatus;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.DvbMath;
import info.martinmarinov.drivers.tools.SetUtils;
import info.martinmarinov.drivers.usb.DvbTuner;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_TUNE_TO_FREQ;
import static info.martinmarinov.drivers.DvbException.ErrorCode.UNSUPPORTED_BANDWIDTH;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_CARRIER;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_LOCK;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_SIGNAL;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_SYNC;
import static info.martinmarinov.drivers.DvbStatus.FE_HAS_VITERBI;
class Mn88472 extends Mn8847X {
private final static int DVBT2_STREAM_ID = 0;
private final static long XTAL = 20_500_000L;
private DvbTuner tuner;
private DeliverySystem currentDeliverySystem = null;
Mn88472(Rtl28xxDvbDevice.Rtl28xxI2cAdapter i2cAdapter, Resources resources) {
super(i2cAdapter, resources, 0x02);
}
@Override
public synchronized void release() {
/* Power down */
try {
writeReg(2, 0x0c, 0x30);
writeReg(2, 0x0b, 0x30);
writeReg(2, 0x05, 0x3e);
} catch (DvbException e) {
e.printStackTrace();
}
}
@Override
public synchronized void init(DvbTuner tuner) throws DvbException {
this.tuner = tuner;
/* Power up */
writeReg(2, 0x05, 0x00);
writeReg(2, 0x0b, 0x00);
writeReg(2, 0x0c, 0x00);
loadFirmware(R.raw.mn8847202fw);
/* TS config */
writeReg(2, 0x08, 0x1d);
writeReg(0, 0xd9, 0xe3);
}
@Override
public synchronized void setParams(long frequency, long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException {
int delivery_system_val, reg_bank0_b4_val,
reg_bank0_cd_val, reg_bank0_d4_val, reg_bank0_d6_val;
switch (deliverySystem) {
case DVBT:
delivery_system_val = 0x02;
reg_bank0_b4_val = 0x00;
reg_bank0_cd_val = 0x1f;
reg_bank0_d4_val = 0x0a;
reg_bank0_d6_val = 0x48;
break;
case DVBT2:
delivery_system_val = 0x03;
reg_bank0_b4_val = 0xf6;
reg_bank0_cd_val = 0x01;
reg_bank0_d4_val = 0x09;
reg_bank0_d6_val = 0x46;
break;
case DVBC:
delivery_system_val = 0x04;
reg_bank0_b4_val = 0x00;
reg_bank0_cd_val = 0x17;
reg_bank0_d4_val = 0x09;
reg_bank0_d6_val = 0x48;
break;
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
byte[] bandwidth_vals_ptr;
int bandwidth_val;
switch (deliverySystem) {
case DVBT:
case DVBT2:
switch ((int) bandwidthHz) {
case 5000000:
bandwidth_vals_ptr = new byte[] {(byte) 0xe5, (byte) 0x99, (byte) 0x9a, (byte) 0x1b, (byte) 0xa9, (byte) 0x1b, (byte) 0xa9};
bandwidth_val = 0x03;
break;
case 6000000:
bandwidth_vals_ptr = new byte[] {(byte) 0xbf, (byte) 0x55, (byte) 0x55, (byte) 0x15, (byte) 0x6b, (byte) 0x15, (byte) 0x6b};
bandwidth_val = 0x02;
break;
case 7000000:
bandwidth_vals_ptr = new byte[] {(byte) 0xa4, (byte) 0x00, (byte) 0x00, (byte) 0x0f, (byte) 0x2c, (byte) 0x0f, (byte) 0x2c};
bandwidth_val = 0x01;
break;
case 8000000:
bandwidth_vals_ptr = new byte[] {(byte) 0x8f, (byte) 0x80, (byte) 0x00, (byte) 0x08, (byte) 0xee, (byte) 0x08, (byte) 0xee};
bandwidth_val = 0x00;
break;
default:
throw new DvbException(UNSUPPORTED_BANDWIDTH, resources.getString(R.string.invalid_bw));
}
break;
case DVBC:
bandwidth_vals_ptr = null;
bandwidth_val = 0x00;
break;
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
/* Program tuner */
tuner.setParams(frequency, bandwidthHz, deliverySystem);
long ifFrequency = tuner.getIfFrequency();
writeReg(2, 0x00, 0x66);
writeReg(2, 0x01, 0x00);
writeReg(2, 0x02, 0x01);
writeReg(2, 0x03, delivery_system_val);
writeReg(2, 0x04, bandwidth_val);
/* IF */
long itmp = DvbMath.divRoundClosest(ifFrequency * 0x1000000L, XTAL);
writeReg(2, 0x10, (int) ((itmp >> 16) & 0xff));
writeReg(2, 0x11, (int) ((itmp >> 8) & 0xff));
writeReg(2, 0x12, (int) (itmp & 0xff));
/* Bandwidth */
if (bandwidth_vals_ptr != null) {
for (int i = 0; i < 7; i++) {
writeReg(2, 0x13 + i, bandwidth_vals_ptr[i] & 0xFF);
}
}
writeReg(0, 0xb4, reg_bank0_b4_val);
writeReg(0, 0xcd, reg_bank0_cd_val);
writeReg(0, 0xd4, reg_bank0_d4_val);
writeReg(0, 0xd6, reg_bank0_d6_val);
switch (deliverySystem) {
case DVBT:
writeReg(0, 0x07, 0x26);
writeReg(0, 0x00, 0xba);
writeReg(0, 0x01, 0x13);
break;
case DVBT2:
writeReg(2, 0x2b, 0x13);
writeReg(2, 0x4f, 0x05);
writeReg(1, 0xf6, 0x05);
writeReg(2, 0x32, DVBT2_STREAM_ID);
break;
case DVBC:
break;
default:
break;
}
/* Reset FSM */
writeReg(2, 0xf8, 0x9f);
this.currentDeliverySystem = deliverySystem;
}
@Override
public int readSnr() throws DvbException {
return -1;
}
@Override
public int readRfStrengthPercentage() throws DvbException {
Set<DvbStatus> cachedStatus = getStatus();
if (!cachedStatus.contains(FE_HAS_SIGNAL)) return 0;
return 100;
}
@Override
public int readBer() throws DvbException {
Set<DvbStatus> cachedStatus = getStatus();
if (!cachedStatus.contains(FE_HAS_VITERBI)) return 0xFFFF;
return 0;
}
@Override
public synchronized Set<DvbStatus> getStatus() throws DvbException {
if (currentDeliverySystem == null) return SetUtils.setOf();
int tmp;
switch (currentDeliverySystem) {
case DVBT:
tmp = readReg(0, 0x7f);
if ((tmp & 0x0f) >= 0x09) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER,
FE_HAS_VITERBI, FE_HAS_SYNC,
FE_HAS_LOCK);
} else {
return SetUtils.setOf();
}
case DVBT2:
tmp = readReg(2, 0x92);
if ((tmp & 0x0f) >= 0x0d) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER,
FE_HAS_VITERBI, FE_HAS_SYNC,
FE_HAS_LOCK);
} else if ((tmp & 0x0f) >= 0x0a) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER,
FE_HAS_VITERBI);
} else if ((tmp & 0x0f) >= 0x07) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER);
} else {
return SetUtils.setOf();
}
case DVBC:
tmp = readReg(1, 0x84);
if ((tmp & 0x0f) >= 0x08) {
return SetUtils.setOf(FE_HAS_SIGNAL, FE_HAS_CARRIER,
FE_HAS_VITERBI, FE_HAS_SYNC,
FE_HAS_LOCK);
} else {
return SetUtils.setOf();
}
default:
throw new DvbException(CANNOT_TUNE_TO_FREQ, resources.getString(R.string.unsupported_delivery_system));
}
}
}
| 9,657 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Rtl2832FrontendData.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/rtl28xx/Rtl2832FrontendData.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.usb.rtl28xx;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.tools.SetUtils;
import info.martinmarinov.drivers.DeliverySystem;
class Rtl2832FrontendData {
final static DvbCapabilities CAPABILITIES = new DvbCapabilities(
174000000L,
862000000L,
166667L,
SetUtils.setOf(DeliverySystem.DVBT));
final static byte[][] BW_PARAMS = {
/* 6 MHz bandwidth */
new byte[] {
(byte) 0xf5, (byte) 0xff, (byte) 0x15, (byte) 0x38, (byte) 0x5d, (byte) 0x6d, (byte) 0x52, (byte) 0x07, (byte) 0xfa, (byte) 0x2f,
(byte) 0x53, (byte) 0xf5, (byte) 0x3f, (byte) 0xca, (byte) 0x0b, (byte) 0x91, (byte) 0xea, (byte) 0x30, (byte) 0x63, (byte) 0xb2,
(byte) 0x13, (byte) 0xda, (byte) 0x0b, (byte) 0xc4, (byte) 0x18, (byte) 0x7e, (byte) 0x16, (byte) 0x66, (byte) 0x08, (byte) 0x67,
(byte) 0x19, (byte) 0xe0,
},
/* 7 MHz bandwidth */
new byte[] {
(byte) 0xe7, (byte) 0xcc, (byte) 0xb5, (byte) 0xba, (byte) 0xe8, (byte) 0x2f, (byte) 0x67, (byte) 0x61, (byte) 0x00, (byte) 0xaf,
(byte) 0x86, (byte) 0xf2, (byte) 0xbf, (byte) 0x59, (byte) 0x04, (byte) 0x11, (byte) 0xb6, (byte) 0x33, (byte) 0xa4, (byte) 0x30,
(byte) 0x15, (byte) 0x10, (byte) 0x0a, (byte) 0x42, (byte) 0x18, (byte) 0xf8, (byte) 0x17, (byte) 0xd9, (byte) 0x07, (byte) 0x22,
(byte) 0x19, (byte) 0x10,
},
/* 8 MHz bandwidth */
new byte[] {
(byte) 0x09, (byte) 0xf6, (byte) 0xd2, (byte) 0xa7, (byte) 0x9a, (byte) 0xc9, (byte) 0x27, (byte) 0x77, (byte) 0x06, (byte) 0xbf,
(byte) 0xec, (byte) 0xf4, (byte) 0x4f, (byte) 0x0b, (byte) 0xfc, (byte) 0x01, (byte) 0x63, (byte) 0x35, (byte) 0x54, (byte) 0xa7,
(byte) 0x16, (byte) 0x66, (byte) 0x08, (byte) 0xb4, (byte) 0x19, (byte) 0x6e, (byte) 0x19, (byte) 0x65, (byte) 0x05, (byte) 0xc8,
(byte) 0x19, (byte) 0xe0,
},
};
final static int[][] SNR_CONSTANTS = new int[][] {
new int[] { 85387325, 85387325, 85387325, 85387325 },
new int[] { 86676178, 86676178, 87167949, 87795660 },
new int[] { 87659938, 87659938, 87885178, 88241743 },
};
final static int CONSTELLATION_NUM = SNR_CONSTANTS.length;
final static int HIERARCHY_NUM = SNR_CONSTANTS[0].length;
enum DvbtRegBitName {
DVBT_SOFT_RST(0x1, 0x1, 2, 2),
DVBT_IIC_REPEAT(0x1, 0x1, 3, 3),
DVBT_TR_WAIT_MIN_8K(0x1, 0x88, 11, 2),
DVBT_RSD_BER_FAIL_VAL(0x1, 0x8f, 15, 0),
DVBT_EN_BK_TRK(0x1, 0xa6, 7, 7),
DVBT_AD_EN_REG(0x0, 0x8, 7, 7),
DVBT_AD_EN_REG1(0x0, 0x8, 6, 6),
DVBT_EN_BBIN(0x1, 0xb1, 0, 0),
DVBT_MGD_THD0(0x1, 0x95, 7, 0),
DVBT_MGD_THD1(0x1, 0x96, 7, 0),
DVBT_MGD_THD2(0x1, 0x97, 7, 0),
DVBT_MGD_THD3(0x1, 0x98, 7, 0),
DVBT_MGD_THD4(0x1, 0x99, 7, 0),
DVBT_MGD_THD5(0x1, 0x9a, 7, 0),
DVBT_MGD_THD6(0x1, 0x9b, 7, 0),
DVBT_MGD_THD7(0x1, 0x9c, 7, 0),
DVBT_EN_CACQ_NOTCH(0x1, 0x61, 4, 4),
DVBT_AD_AV_REF(0x0, 0x9, 6, 0),
DVBT_REG_PI(0x0, 0xa, 2, 0),
DVBT_PIP_ON(0x0, 0x21, 3, 3),
DVBT_SCALE1_B92(0x2, 0x92, 7, 0),
DVBT_SCALE1_B93(0x2, 0x93, 7, 0),
DVBT_SCALE1_BA7(0x2, 0xa7, 7, 0),
DVBT_SCALE1_BA9(0x2, 0xa9, 7, 0),
DVBT_SCALE1_BAA(0x2, 0xaa, 7, 0),
DVBT_SCALE1_BAB(0x2, 0xab, 7, 0),
DVBT_SCALE1_BAC(0x2, 0xac, 7, 0),
DVBT_SCALE1_BB0(0x2, 0xb0, 7, 0),
DVBT_SCALE1_BB1(0x2, 0xb1, 7, 0),
DVBT_KB_P1(0x1, 0x64, 3, 1),
DVBT_KB_P2(0x1, 0x64, 6, 4),
DVBT_KB_P3(0x1, 0x65, 2, 0),
DVBT_OPT_ADC_IQ(0x0, 0x6, 5, 4),
DVBT_AD_AVI(0x0, 0x9, 1, 0),
DVBT_AD_AVQ(0x0, 0x9, 3, 2),
DVBT_K1_CR_STEP12(0x2, 0xad, 9, 4),
DVBT_TRK_KS_P2(0x1, 0x6f, 2, 0),
DVBT_TRK_KS_I2(0x1, 0x70, 5, 3),
DVBT_TR_THD_SET2(0x1, 0x72, 3, 0),
DVBT_TRK_KC_P2(0x1, 0x73, 5, 3),
DVBT_TRK_KC_I2(0x1, 0x75, 2, 0),
DVBT_CR_THD_SET2(0x1, 0x76, 7, 6),
DVBT_PSET_IFFREQ(0x1, 0x19, 21, 0),
DVBT_SPEC_INV(0x1, 0x15, 0, 0),
DVBT_RSAMP_RATIO(0x1, 0x9f, 27, 2),
DVBT_CFREQ_OFF_RATIO(0x1, 0x9d, 23, 4),
DVBT_FSM_STAGE(0x3, 0x51, 6, 3),
DVBT_RX_CONSTEL(0x3, 0x3c, 3, 2),
DVBT_RX_HIER(0x3, 0x3c, 6, 4),
DVBT_RX_C_RATE_LP(0x3, 0x3d, 2, 0),
DVBT_RX_C_RATE_HP(0x3, 0x3d, 5, 3),
DVBT_GI_IDX(0x3, 0x51, 1, 0),
DVBT_FFT_MODE_IDX(0x3, 0x51, 2, 2),
DVBT_RSD_BER_EST(0x3, 0x4e, 15, 0),
DVBT_CE_EST_EVM(0x4, 0xc, 15, 0),
DVBT_RF_AGC_VAL(0x3, 0x5b, 13, 0),
DVBT_IF_AGC_VAL(0x3, 0x59, 13, 0),
DVBT_DAGC_VAL(0x3, 0x5, 7, 0),
DVBT_SFREQ_OFF(0x3, 0x18, 13, 0),
DVBT_CFREQ_OFF(0x3, 0x5f, 17, 0),
DVBT_POLAR_RF_AGC(0x0, 0xe, 1, 1),
DVBT_POLAR_IF_AGC(0x0, 0xe, 0, 0),
DVBT_AAGC_HOLD(0x1, 0x4, 5, 5),
DVBT_EN_RF_AGC(0x1, 0x4, 6, 6),
DVBT_EN_IF_AGC(0x1, 0x4, 7, 7),
DVBT_IF_AGC_MIN(0x1, 0x8, 7, 0),
DVBT_IF_AGC_MAX(0x1, 0x9, 7, 0),
DVBT_RF_AGC_MIN(0x1, 0xa, 7, 0),
DVBT_RF_AGC_MAX(0x1, 0xb, 7, 0),
DVBT_IF_AGC_MAN(0x1, 0xc, 6, 6),
DVBT_IF_AGC_MAN_VAL(0x1, 0xc, 13, 0),
DVBT_RF_AGC_MAN(0x1, 0xe, 6, 6),
DVBT_RF_AGC_MAN_VAL(0x1, 0xe, 13, 0),
DVBT_DAGC_TRG_VAL(0x1, 0x12, 7, 0),
DVBT_AGC_TARG_VAL_0(0x1, 0x2, 0, 0),
DVBT_AGC_TARG_VAL_8_1(0x1, 0x3, 7, 0),
DVBT_AAGC_LOOP_GAIN(0x1, 0xc7, 5, 1),
DVBT_LOOP_GAIN2_3_0(0x1, 0x4, 4, 1),
DVBT_LOOP_GAIN2_4(0x1, 0x5, 7, 7),
DVBT_LOOP_GAIN3(0x1, 0xc8, 4, 0),
DVBT_VTOP1(0x1, 0x6, 5, 0),
DVBT_VTOP2(0x1, 0xc9, 5, 0),
DVBT_VTOP3(0x1, 0xca, 5, 0),
DVBT_KRF1(0x1, 0xcb, 7, 0),
DVBT_KRF2(0x1, 0x7, 7, 0),
DVBT_KRF3(0x1, 0xcd, 7, 0),
DVBT_KRF4(0x1, 0xce, 7, 0),
DVBT_EN_GI_PGA(0x1, 0xe5, 0, 0),
DVBT_THD_LOCK_UP(0x1, 0xd9, 8, 0),
DVBT_THD_LOCK_DW(0x1, 0xdb, 8, 0),
DVBT_THD_UP1(0x1, 0xdd, 7, 0),
DVBT_THD_DW1(0x1, 0xde, 7, 0),
DVBT_INTER_CNT_LEN(0x1, 0xd8, 3, 0),
DVBT_GI_PGA_STATE(0x1, 0xe6, 3, 3),
DVBT_EN_AGC_PGA(0x1, 0xd7, 0, 0),
DVBT_CKOUTPAR(0x1, 0x7b, 5, 5),
DVBT_CKOUT_PWR(0x1, 0x7b, 6, 6),
DVBT_SYNC_DUR(0x1, 0x7b, 7, 7),
DVBT_ERR_DUR(0x1, 0x7c, 0, 0),
DVBT_SYNC_LVL(0x1, 0x7c, 1, 1),
DVBT_ERR_LVL(0x1, 0x7c, 2, 2),
DVBT_VAL_LVL(0x1, 0x7c, 3, 3),
DVBT_SERIAL(0x1, 0x7c, 4, 4),
DVBT_SER_LSB(0x1, 0x7c, 5, 5),
DVBT_CDIV_PH0(0x1, 0x7d, 3, 0),
DVBT_CDIV_PH1(0x1, 0x7d, 7, 4),
DVBT_MPEG_IO_OPT_2_2(0x0, 0x6, 7, 7),
DVBT_MPEG_IO_OPT_1_0(0x0, 0x7, 7, 6),
DVBT_CKOUTPAR_PIP(0x0, 0xb7, 4, 4),
DVBT_CKOUT_PWR_PIP(0x0, 0xb7, 3, 3),
DVBT_SYNC_LVL_PIP(0x0, 0xb7, 2, 2),
DVBT_ERR_LVL_PIP(0x0, 0xb7, 1, 1),
DVBT_VAL_LVL_PIP(0x0, 0xb7, 0, 0),
DVBT_CKOUTPAR_PID(0x0, 0xb9, 4, 4),
DVBT_CKOUT_PWR_PID(0x0, 0xb9, 3, 3),
DVBT_SYNC_LVL_PID(0x0, 0xb9, 2, 2),
DVBT_ERR_LVL_PID(0x0, 0xb9, 1, 1),
DVBT_VAL_LVL_PID(0x0, 0xb9, 0, 0),
DVBT_SM_PASS(0x1, 0x93, 11, 0),
DVBT_AD7_SETTING(0x0, 0x11, 15, 0),
DVBT_RSSI_R(0x3, 0x1, 6, 0),
DVBT_ACI_DET_IND(0x3, 0x12, 0, 0),
DVBT_REG_MON(0x0, 0xd, 1, 0),
DVBT_REG_MONSEL(0x0, 0xd, 2, 2),
DVBT_REG_GPE(0x0, 0xd, 7, 7),
DVBT_REG_GPO(0x0, 0x10, 0, 0),
DVBT_REG_4MSEL(0x0, 0x13, 0, 0);
final int page;
final int startAddress;
final int msb;
final int lsb;
DvbtRegBitName(int page, int startAddress, int msb, int lsb) {
this.page = page;
this.startAddress = startAddress;
this.msb = msb;
this.lsb = lsb;
}
}
static final RegValue[] INITIAL_REGS = new RegValue[] {
new RegValue(DvbtRegBitName.DVBT_AD_EN_REG, 0x1),
new RegValue(DvbtRegBitName.DVBT_AD_EN_REG1, 0x1),
new RegValue(DvbtRegBitName.DVBT_RSD_BER_FAIL_VAL, 0x2800),
new RegValue(DvbtRegBitName.DVBT_MGD_THD0, 0x10),
new RegValue(DvbtRegBitName.DVBT_MGD_THD1, 0x20),
new RegValue(DvbtRegBitName.DVBT_MGD_THD2, 0x20),
new RegValue(DvbtRegBitName.DVBT_MGD_THD3, 0x40),
new RegValue(DvbtRegBitName.DVBT_MGD_THD4, 0x22),
new RegValue(DvbtRegBitName.DVBT_MGD_THD5, 0x32),
new RegValue(DvbtRegBitName.DVBT_MGD_THD6, 0x37),
new RegValue(DvbtRegBitName.DVBT_MGD_THD7, 0x39),
new RegValue(DvbtRegBitName.DVBT_EN_BK_TRK, 0x0),
new RegValue(DvbtRegBitName.DVBT_EN_CACQ_NOTCH, 0x0),
new RegValue(DvbtRegBitName.DVBT_AD_AV_REF, 0x2a),
new RegValue(DvbtRegBitName.DVBT_REG_PI, 0x6),
new RegValue(DvbtRegBitName.DVBT_PIP_ON, 0x0),
new RegValue(DvbtRegBitName.DVBT_CDIV_PH0, 0x8),
new RegValue(DvbtRegBitName.DVBT_CDIV_PH1, 0x8),
new RegValue(DvbtRegBitName.DVBT_SCALE1_B92, 0x4),
new RegValue(DvbtRegBitName.DVBT_SCALE1_B93, 0xb0),
new RegValue(DvbtRegBitName.DVBT_SCALE1_BA7, 0x78),
new RegValue(DvbtRegBitName.DVBT_SCALE1_BA9, 0x28),
new RegValue(DvbtRegBitName.DVBT_SCALE1_BAA, 0x59),
new RegValue(DvbtRegBitName.DVBT_SCALE1_BAB, 0x83),
new RegValue(DvbtRegBitName.DVBT_SCALE1_BAC, 0xd4),
new RegValue(DvbtRegBitName.DVBT_SCALE1_BB0, 0x65),
new RegValue(DvbtRegBitName.DVBT_SCALE1_BB1, 0x43),
new RegValue(DvbtRegBitName.DVBT_KB_P1, 0x1),
new RegValue(DvbtRegBitName.DVBT_KB_P2, 0x4),
new RegValue(DvbtRegBitName.DVBT_KB_P3, 0x7),
new RegValue(DvbtRegBitName.DVBT_K1_CR_STEP12, 0xa),
new RegValue(DvbtRegBitName.DVBT_REG_GPE, 0x1),
new RegValue(DvbtRegBitName.DVBT_SERIAL, 0x0),
new RegValue(DvbtRegBitName.DVBT_CDIV_PH0, 0x9),
new RegValue(DvbtRegBitName.DVBT_CDIV_PH1, 0x9),
new RegValue(DvbtRegBitName.DVBT_MPEG_IO_OPT_2_2, 0x0),
new RegValue(DvbtRegBitName.DVBT_MPEG_IO_OPT_1_0, 0x0),
new RegValue(DvbtRegBitName.DVBT_TRK_KS_P2, 0x4),
new RegValue(DvbtRegBitName.DVBT_TRK_KS_I2, 0x7),
new RegValue(DvbtRegBitName.DVBT_TR_THD_SET2, 0x6),
new RegValue(DvbtRegBitName.DVBT_TRK_KC_I2, 0x5),
new RegValue(DvbtRegBitName.DVBT_CR_THD_SET2, 0x1)
};
static final RegValue[] TUNER_INIT_E4000 = new RegValue[] {
new RegValue(DvbtRegBitName.DVBT_DAGC_TRG_VAL, 0x5a),
new RegValue(DvbtRegBitName.DVBT_AGC_TARG_VAL_0, 0x0),
new RegValue(DvbtRegBitName.DVBT_AGC_TARG_VAL_8_1, 0x5a),
new RegValue(DvbtRegBitName.DVBT_AAGC_LOOP_GAIN, 0x18),
new RegValue(DvbtRegBitName.DVBT_LOOP_GAIN2_3_0, 0x8),
new RegValue(DvbtRegBitName.DVBT_LOOP_GAIN2_4, 0x1),
new RegValue(DvbtRegBitName.DVBT_LOOP_GAIN3, 0x18),
new RegValue(DvbtRegBitName.DVBT_VTOP1, 0x35),
new RegValue(DvbtRegBitName.DVBT_VTOP2, 0x21),
new RegValue(DvbtRegBitName.DVBT_VTOP3, 0x21),
new RegValue(DvbtRegBitName.DVBT_KRF1, 0x0),
new RegValue(DvbtRegBitName.DVBT_KRF2, 0x40),
new RegValue(DvbtRegBitName.DVBT_KRF3, 0x10),
new RegValue(DvbtRegBitName.DVBT_KRF4, 0x10),
new RegValue(DvbtRegBitName.DVBT_IF_AGC_MIN, 0x80),
new RegValue(DvbtRegBitName.DVBT_IF_AGC_MAX, 0x7f),
new RegValue(DvbtRegBitName.DVBT_RF_AGC_MIN, 0x80),
new RegValue(DvbtRegBitName.DVBT_RF_AGC_MAX, 0x7f),
new RegValue(DvbtRegBitName.DVBT_POLAR_RF_AGC, 0x0),
new RegValue(DvbtRegBitName.DVBT_POLAR_IF_AGC, 0x0),
new RegValue(DvbtRegBitName.DVBT_AD7_SETTING, 0xe9d4),
new RegValue(DvbtRegBitName.DVBT_EN_GI_PGA, 0x0),
new RegValue(DvbtRegBitName.DVBT_THD_LOCK_UP, 0x0),
new RegValue(DvbtRegBitName.DVBT_THD_LOCK_DW, 0x0),
new RegValue(DvbtRegBitName.DVBT_THD_UP1, 0x14),
new RegValue(DvbtRegBitName.DVBT_THD_DW1, 0xec),
new RegValue(DvbtRegBitName.DVBT_INTER_CNT_LEN, 0xc),
new RegValue(DvbtRegBitName.DVBT_GI_PGA_STATE, 0x0),
new RegValue(DvbtRegBitName.DVBT_EN_AGC_PGA, 0x1),
new RegValue(DvbtRegBitName.DVBT_REG_GPE, 0x1),
new RegValue(DvbtRegBitName.DVBT_REG_GPO, 0x1),
new RegValue(DvbtRegBitName.DVBT_REG_MONSEL, 0x1),
new RegValue(DvbtRegBitName.DVBT_REG_MON, 0x1),
new RegValue(DvbtRegBitName.DVBT_REG_4MSEL, 0x0),
new RegValue(DvbtRegBitName.DVBT_SPEC_INV, 0x0)
};
static final RegValue[] TUNER_INIT_R820T = new RegValue[] {
new RegValue(DvbtRegBitName.DVBT_DAGC_TRG_VAL, 0x39),
new RegValue(DvbtRegBitName.DVBT_AGC_TARG_VAL_0, 0x0),
new RegValue(DvbtRegBitName.DVBT_AGC_TARG_VAL_8_1, 0x40),
new RegValue(DvbtRegBitName.DVBT_AAGC_LOOP_GAIN, 0x16),
new RegValue(DvbtRegBitName.DVBT_LOOP_GAIN2_3_0, 0x8),
new RegValue(DvbtRegBitName.DVBT_LOOP_GAIN2_4, 0x1),
new RegValue(DvbtRegBitName.DVBT_LOOP_GAIN3, 0x18),
new RegValue(DvbtRegBitName.DVBT_VTOP1, 0x35),
new RegValue(DvbtRegBitName.DVBT_VTOP2, 0x21),
new RegValue(DvbtRegBitName.DVBT_VTOP3, 0x21),
new RegValue(DvbtRegBitName.DVBT_KRF1, 0x0),
new RegValue(DvbtRegBitName.DVBT_KRF2, 0x40),
new RegValue(DvbtRegBitName.DVBT_KRF3, 0x10),
new RegValue(DvbtRegBitName.DVBT_KRF4, 0x10),
new RegValue(DvbtRegBitName.DVBT_IF_AGC_MIN, 0x80),
new RegValue(DvbtRegBitName.DVBT_IF_AGC_MAX, 0x7f),
new RegValue(DvbtRegBitName.DVBT_RF_AGC_MIN, 0x80),
new RegValue(DvbtRegBitName.DVBT_RF_AGC_MAX, 0x7f),
new RegValue(DvbtRegBitName.DVBT_POLAR_RF_AGC, 0x0),
new RegValue(DvbtRegBitName.DVBT_POLAR_IF_AGC, 0x0),
new RegValue(DvbtRegBitName.DVBT_AD7_SETTING, 0xe9f4),
new RegValue(DvbtRegBitName.DVBT_SPEC_INV, 0x1)
};
static final RegValue[] TUNER_INIT_FC0012 = new RegValue[] {
new RegValue(DvbtRegBitName.DVBT_DAGC_TRG_VAL, 0x5a),
new RegValue(DvbtRegBitName.DVBT_AGC_TARG_VAL_0, 0x0),
new RegValue(DvbtRegBitName.DVBT_AGC_TARG_VAL_8_1, 0x5a),
new RegValue(DvbtRegBitName.DVBT_AAGC_LOOP_GAIN, 0x16),
new RegValue(DvbtRegBitName.DVBT_LOOP_GAIN2_3_0, 0x6),
new RegValue(DvbtRegBitName.DVBT_LOOP_GAIN2_4, 0x1),
new RegValue(DvbtRegBitName.DVBT_LOOP_GAIN3, 0x16),
new RegValue(DvbtRegBitName.DVBT_VTOP1, 0x35),
new RegValue(DvbtRegBitName.DVBT_VTOP2, 0x21),
new RegValue(DvbtRegBitName.DVBT_VTOP3, 0x21),
new RegValue(DvbtRegBitName.DVBT_KRF1, 0x0),
new RegValue(DvbtRegBitName.DVBT_KRF2, 0x40),
new RegValue(DvbtRegBitName.DVBT_KRF3, 0x10),
new RegValue(DvbtRegBitName.DVBT_KRF4, 0x10),
new RegValue(DvbtRegBitName.DVBT_IF_AGC_MIN, 0x80),
new RegValue(DvbtRegBitName.DVBT_IF_AGC_MAX, 0x7f),
new RegValue(DvbtRegBitName.DVBT_RF_AGC_MIN, 0x80),
new RegValue(DvbtRegBitName.DVBT_RF_AGC_MAX, 0x7f),
new RegValue(DvbtRegBitName.DVBT_POLAR_RF_AGC, 0x0),
new RegValue(DvbtRegBitName.DVBT_POLAR_IF_AGC, 0x0),
new RegValue(DvbtRegBitName.DVBT_AD7_SETTING, 0xe9bf),
new RegValue(DvbtRegBitName.DVBT_EN_GI_PGA, 0x0),
new RegValue(DvbtRegBitName.DVBT_THD_LOCK_UP, 0x0),
new RegValue(DvbtRegBitName.DVBT_THD_LOCK_DW, 0x0),
new RegValue(DvbtRegBitName.DVBT_THD_UP1, 0x11),
new RegValue(DvbtRegBitName.DVBT_THD_DW1, 0xef),
new RegValue(DvbtRegBitName.DVBT_INTER_CNT_LEN, 0xc),
new RegValue(DvbtRegBitName.DVBT_GI_PGA_STATE, 0x0),
new RegValue(DvbtRegBitName.DVBT_EN_AGC_PGA, 0x1),
new RegValue(DvbtRegBitName.DVBT_IF_AGC_MAN, 0x0),
new RegValue(DvbtRegBitName.DVBT_SPEC_INV, 0x0)
};
static class RegValue {
final DvbtRegBitName reg;
final long val;
RegValue(DvbtRegBitName reg, long val) {
this.reg = reg;
this.val = val;
}
}
}
| 17,682 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
AbstractGenericDvbUsbDevice.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/usb/generic/AbstractGenericDvbUsbDevice.java | package info.martinmarinov.drivers.usb.generic;
import static android.hardware.usb.UsbConstants.USB_DIR_OUT;
import static info.martinmarinov.drivers.DvbException.ErrorCode.HARDWARE_EXCEPTION;
import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbEndpoint;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.concurrent.locks.ReentrantLock;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbDemux;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.usb.DvbUsbDevice;
public abstract class AbstractGenericDvbUsbDevice extends DvbUsbDevice {
private final static int DEFAULT_USB_COMM_TIMEOUT_MS = 100;
private final static long DEFAULT_READ_OR_WRITE_TIMEOUT_MS = 700L;
private final ReentrantLock usbReentrantLock = new ReentrantLock();
protected final UsbEndpoint controlEndpointIn;
protected final UsbEndpoint controlEndpointOut;
protected AbstractGenericDvbUsbDevice(
UsbDevice usbDevice,
Context context,
DeviceFilter deviceFilter,
DvbDemux dvbDemux,
UsbEndpoint controlEndpointIn,
UsbEndpoint controlEndpointOut
) throws DvbException {
super(usbDevice, context, deviceFilter, dvbDemux);
this.controlEndpointIn = controlEndpointIn;
this.controlEndpointOut = controlEndpointOut;
}
private int bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int offset, int length) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
return usbDeviceConnection.bulkTransfer(endpoint, buffer, offset, length, DEFAULT_USB_COMM_TIMEOUT_MS);
} else if (offset == 0) {
return usbDeviceConnection.bulkTransfer(endpoint, buffer, length, DEFAULT_USB_COMM_TIMEOUT_MS);
} else {
byte[] tempbuff = new byte[length - offset];
if (endpoint.getDirection() == USB_DIR_OUT) {
System.arraycopy(buffer, offset, tempbuff, 0, length - offset);
return usbDeviceConnection.bulkTransfer(endpoint, tempbuff, tempbuff.length, DEFAULT_USB_COMM_TIMEOUT_MS);
} else {
int read = usbDeviceConnection.bulkTransfer(endpoint, tempbuff, tempbuff.length, DEFAULT_USB_COMM_TIMEOUT_MS);
if (read <= 0) {
return read;
}
System.arraycopy(tempbuff, 0, buffer, offset, read);
return read;
}
}
}
protected void dvb_usb_generic_rw(@NonNull byte[] wbuf, int wlen, @Nullable byte[] rbuf, int rlen) throws DvbException {
long startTime = System.currentTimeMillis();
usbReentrantLock.lock();
try {
int bytesTransferred = 0;
while (bytesTransferred < wlen) {
int actlen = bulkTransfer(controlEndpointOut, wbuf, bytesTransferred, wlen - bytesTransferred);
if (System.currentTimeMillis() - startTime > DEFAULT_READ_OR_WRITE_TIMEOUT_MS) {
actlen = -99999999;
}
if (actlen < 0) {
throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.cannot_send_control_message, actlen));
}
bytesTransferred += actlen;
}
if (rbuf != null && rlen >= 0) {
bytesTransferred = 0;
while (bytesTransferred < rlen) {
int actlen = bulkTransfer(controlEndpointIn, rbuf, bytesTransferred, rlen - bytesTransferred);
if (System.currentTimeMillis() - startTime > 2*DEFAULT_READ_OR_WRITE_TIMEOUT_MS) {
actlen = -99999999;
}
if (actlen < 0) {
throw new DvbException(HARDWARE_EXCEPTION, resources.getString(R.string.cannot_send_control_message, actlen));
}
bytesTransferred += actlen;
}
}
} finally {
usbReentrantLock.unlock();
}
}
}
| 4,242 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
BitReverse.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/BitReverse.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
public class BitReverse {
private final static byte[] BYTE_REV_TABLE = {
(byte) 0x00, (byte) 0x80, (byte) 0x40, (byte) 0xc0, (byte) 0x20, (byte) 0xa0, (byte) 0x60, (byte) 0xe0,
(byte) 0x10, (byte) 0x90, (byte) 0x50, (byte) 0xd0, (byte) 0x30, (byte) 0xb0, (byte) 0x70, (byte) 0xf0,
(byte) 0x08, (byte) 0x88, (byte) 0x48, (byte) 0xc8, (byte) 0x28, (byte) 0xa8, (byte) 0x68, (byte) 0xe8,
(byte) 0x18, (byte) 0x98, (byte) 0x58, (byte) 0xd8, (byte) 0x38, (byte) 0xb8, (byte) 0x78, (byte) 0xf8,
(byte) 0x04, (byte) 0x84, (byte) 0x44, (byte) 0xc4, (byte) 0x24, (byte) 0xa4, (byte) 0x64, (byte) 0xe4,
(byte) 0x14, (byte) 0x94, (byte) 0x54, (byte) 0xd4, (byte) 0x34, (byte) 0xb4, (byte) 0x74, (byte) 0xf4,
(byte) 0x0c, (byte) 0x8c, (byte) 0x4c, (byte) 0xcc, (byte) 0x2c, (byte) 0xac, (byte) 0x6c, (byte) 0xec,
(byte) 0x1c, (byte) 0x9c, (byte) 0x5c, (byte) 0xdc, (byte) 0x3c, (byte) 0xbc, (byte) 0x7c, (byte) 0xfc,
(byte) 0x02, (byte) 0x82, (byte) 0x42, (byte) 0xc2, (byte) 0x22, (byte) 0xa2, (byte) 0x62, (byte) 0xe2,
(byte) 0x12, (byte) 0x92, (byte) 0x52, (byte) 0xd2, (byte) 0x32, (byte) 0xb2, (byte) 0x72, (byte) 0xf2,
(byte) 0x0a, (byte) 0x8a, (byte) 0x4a, (byte) 0xca, (byte) 0x2a, (byte) 0xaa, (byte) 0x6a, (byte) 0xea,
(byte) 0x1a, (byte) 0x9a, (byte) 0x5a, (byte) 0xda, (byte) 0x3a, (byte) 0xba, (byte) 0x7a, (byte) 0xfa,
(byte) 0x06, (byte) 0x86, (byte) 0x46, (byte) 0xc6, (byte) 0x26, (byte) 0xa6, (byte) 0x66, (byte) 0xe6,
(byte) 0x16, (byte) 0x96, (byte) 0x56, (byte) 0xd6, (byte) 0x36, (byte) 0xb6, (byte) 0x76, (byte) 0xf6,
(byte) 0x0e, (byte) 0x8e, (byte) 0x4e, (byte) 0xce, (byte) 0x2e, (byte) 0xae, (byte) 0x6e, (byte) 0xee,
(byte) 0x1e, (byte) 0x9e, (byte) 0x5e, (byte) 0xde, (byte) 0x3e, (byte) 0xbe, (byte) 0x7e, (byte) 0xfe,
(byte) 0x01, (byte) 0x81, (byte) 0x41, (byte) 0xc1, (byte) 0x21, (byte) 0xa1, (byte) 0x61, (byte) 0xe1,
(byte) 0x11, (byte) 0x91, (byte) 0x51, (byte) 0xd1, (byte) 0x31, (byte) 0xb1, (byte) 0x71, (byte) 0xf1,
(byte) 0x09, (byte) 0x89, (byte) 0x49, (byte) 0xc9, (byte) 0x29, (byte) 0xa9, (byte) 0x69, (byte) 0xe9,
(byte) 0x19, (byte) 0x99, (byte) 0x59, (byte) 0xd9, (byte) 0x39, (byte) 0xb9, (byte) 0x79, (byte) 0xf9,
(byte) 0x05, (byte) 0x85, (byte) 0x45, (byte) 0xc5, (byte) 0x25, (byte) 0xa5, (byte) 0x65, (byte) 0xe5,
(byte) 0x15, (byte) 0x95, (byte) 0x55, (byte) 0xd5, (byte) 0x35, (byte) 0xb5, (byte) 0x75, (byte) 0xf5,
(byte) 0x0d, (byte) 0x8d, (byte) 0x4d, (byte) 0xcd, (byte) 0x2d, (byte) 0xad, (byte) 0x6d, (byte) 0xed,
(byte) 0x1d, (byte) 0x9d, (byte) 0x5d, (byte) 0xdd, (byte) 0x3d, (byte) 0xbd, (byte) 0x7d, (byte) 0xfd,
(byte) 0x03, (byte) 0x83, (byte) 0x43, (byte) 0xc3, (byte) 0x23, (byte) 0xa3, (byte) 0x63, (byte) 0xe3,
(byte) 0x13, (byte) 0x93, (byte) 0x53, (byte) 0xd3, (byte) 0x33, (byte) 0xb3, (byte) 0x73, (byte) 0xf3,
(byte) 0x0b, (byte) 0x8b, (byte) 0x4b, (byte) 0xcb, (byte) 0x2b, (byte) 0xab, (byte) 0x6b, (byte) 0xeb,
(byte) 0x1b, (byte) 0x9b, (byte) 0x5b, (byte) 0xdb, (byte) 0x3b, (byte) 0xbb, (byte) 0x7b, (byte) 0xfb,
(byte) 0x07, (byte) 0x87, (byte) 0x47, (byte) 0xc7, (byte) 0x27, (byte) 0xa7, (byte) 0x67, (byte) 0xe7,
(byte) 0x17, (byte) 0x97, (byte) 0x57, (byte) 0xd7, (byte) 0x37, (byte) 0xb7, (byte) 0x77, (byte) 0xf7,
(byte) 0x0f, (byte) 0x8f, (byte) 0x4f, (byte) 0xcf, (byte) 0x2f, (byte) 0xaf, (byte) 0x6f, (byte) 0xef,
(byte) 0x1f, (byte) 0x9f, (byte) 0x5f, (byte) 0xdf, (byte) 0x3f, (byte) 0xbf, (byte) 0x7f, (byte) 0xff,
};
public static byte bitRev8(byte b) {
return BYTE_REV_TABLE[b & 0xFF];
}
public static short bitRev16(short b) {
return (short) (((bitRev8((byte) b) & 0xFF) << 8) | (bitRev8((byte) (b >> 8)) & 0xFF));
}
public static int bitRev32(int b) {
return ((bitRev16((short) b) & 0xFFFF) << 16) | (bitRev16((short) (b >> 16)) & 0xFFFF);
}
}
| 5,081 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
I2cAdapter.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/I2cAdapter.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import info.martinmarinov.drivers.DvbException;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_TEN;
public abstract class I2cAdapter {
private final Object lock = new Object();
private final static int RETRIES = 10;
public void transfer(int addr, int flags, byte[] buf) throws DvbException {
transfer(addr, flags, buf, buf.length);
}
public void transfer(int addr, int flags, byte[] buf, int len) throws DvbException {
transfer(new I2cMessage(addr, flags, buf, len));
}
public void transfer(int addr1, int flags1, byte[] buf1,
int addr2, int flags2, byte[] buf2) throws DvbException {
transfer(addr1, flags1, buf1, buf1.length,
addr2, flags2, buf2, buf2.length);
}
public void transfer(int addr1, int flags1, byte[] buf1, int len1,
int addr2, int flags2, byte[] buf2, int len2) throws DvbException {
transfer(new I2cMessage(addr1, flags1, buf1, len1),
new I2cMessage(addr2, flags2, buf2, len2));
}
public void send(int addr, byte[] buf, int count) throws DvbException {
transfer(addr, I2C_M_TEN, buf, count);
}
public void recv(int addr, byte[] buf, int count) throws DvbException {
transfer(addr, I2C_M_TEN | I2C_M_RD, buf, count);
}
private void transfer(I2cMessage ... messages) throws DvbException {
synchronized (lock) {
for (int i = 0; i < RETRIES; i++) {
try {
if (masterXfer(messages) == messages.length) {
return;
}
} catch (DvbException e) {
if (i == RETRIES - 1) throw e;
}
}
}
}
protected abstract int masterXfer(I2cMessage[] messages) throws DvbException;
public class I2cMessage {
public static final int I2C_M_TEN = 0x0010 /* this is a ten bit chip address */;
public static final int I2C_M_RD = 0x0001 /* read data, from slave to master */;
public static final int I2C_M_STOP = 0x8000 /* if I2C_FUNC_PROTOCOL_MANGLING */;
public static final int I2C_M_NOSTART = 0x4000 /* if I2C_FUNC_NOSTART */;
public static final int I2C_M_REV_DIR_ADDR = 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */;
public static final int I2C_M_IGNORE_NAK = 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */;
public static final int I2C_M_NO_RD_ACK = 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */;
public static final int I2C_M_RECV_LEN = 0x0400 /* length will be first received byte */;
// These are 16 bit integers, however using int in Java
// since Java doesn't have 16 bit unsigned type
public final int addr;
public final int flags;
public final byte[] buf;
public final int len;
I2cMessage(int addr, int flags, byte[] buf, int len) {
this.addr = addr;
this.flags = flags;
this.buf = buf;
this.len = len;
}
}
public static abstract class I2GateControl {
protected abstract void i2cGateCtrl(boolean enable) throws DvbException;
public synchronized void runInOpenGate(ThrowingRunnable<DvbException> r) throws DvbException {
try {
i2cGateCtrl(true);
r.run();
} finally {
i2cGateCtrl(false);
}
}
}
}
| 4,479 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
SleepUtils.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/SleepUtils.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
public class SleepUtils {
public static void mdelay(long millis) {
safeSleep(millis * 1_000_000L);
}
public static void usleep(long micros) {
safeSleep(micros * 1_000L);
}
private static void safeSleep(long toSleepNs) {
long toSleepMs = (toSleepNs + 999_999L) / 1_000_000L;
if (toSleepMs > 0) {
try {
Thread.sleep(toSleepMs);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
| 1,429 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
SetUtils.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/SetUtils.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class SetUtils {
public static <T> Set<T> union(Set<T> a, Set<T> b) {
Set<T> result = new HashSet<>();
result.addAll(a);
result.addAll(b);
return result;
}
@SafeVarargs
public static <T> Set<T> setOf(T ... data) {
Set<T> result = new HashSet<>();
Collections.addAll(result, data);
return result;
}
}
| 1,367 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DeviceFilterMatcher.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/DeviceFilterMatcher.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import android.annotation.SuppressLint;
import android.hardware.usb.UsbDevice;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import info.martinmarinov.drivers.DeviceFilter;
public class DeviceFilterMatcher {
@SuppressLint("UseSparseArrays") // Use SparseArrays and unit testing is impossible
private final Map<Integer, DeviceFilter> filterMap = new HashMap<>();
public DeviceFilterMatcher(Set<DeviceFilter> filters) {
for (DeviceFilter deviceFilter : filters) {
filterMap.put(hash(deviceFilter), deviceFilter);
}
}
public DeviceFilter getFilter(UsbDevice usbDevice) {
return filterMap.get(hash(usbDevice));
}
private static int hash(DeviceFilter deviceFilter) {
return hash(deviceFilter.getVendorId(), deviceFilter.getProductId());
}
private static int hash(UsbDevice usbDevice) {
return hash(usbDevice.getVendorId(), usbDevice.getProductId());
}
private static int hash(int vendorId, int productId) {
return (vendorId << 16) | (productId & 0xFFFF);
}
}
| 1,999 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
RegMap.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/RegMap.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import androidx.annotation.VisibleForTesting;
import info.martinmarinov.drivers.DvbException;
import static info.martinmarinov.drivers.tools.I2cAdapter.I2cMessage.I2C_M_RD;
public class RegMap {
private final int address;
private final int reg_bytes;
private final I2cAdapter i2CAdapter;
private final Object locker = new Object();
private final byte[] regbuff;
private byte[] tmpbuff = new byte[0];
public RegMap(int address, int reg_bits, I2cAdapter i2CAdapter) {
this.address = address;
this.reg_bytes = reg_bits >> 3;
if (reg_bytes > 8) {
throw new IllegalArgumentException("Only up to 64 bit register supported");
}
this.regbuff = new byte[reg_bytes];
this.i2CAdapter = i2CAdapter;
}
public void read_regs(long reg, byte[] vals, int offset, int length) throws DvbException {
synchronized (locker) {
writeValue(regbuff, reg);
byte[] buf = offset == 0 ? vals : getTmpBuffer(length);
i2CAdapter.transfer(
address, 0, regbuff, regbuff.length,
address, I2C_M_RD, buf, length
);
if (offset != 0) {
System.arraycopy(buf, 0, vals, offset, length);
}
}
}
public int read_reg(long reg) throws DvbException {
byte[] ans = new byte[1];
read_regs(reg, ans, 0, 1);
return ans[0] & 0xFF;
}
public void write_reg(long reg, int val) throws DvbException {
if ((val & 0xFF) != val) throw new IllegalArgumentException();
bulk_write(reg, new byte[] { (byte) val });
}
public void bulk_write(long reg, byte[] vals) throws DvbException {
bulk_write(reg, vals, vals.length);
}
public void bulk_write(long reg, byte[] vals, int len) throws DvbException {
synchronized (locker) {
writeValue(regbuff, reg);
byte[] buf = getTmpBuffer(regbuff.length + len);
System.arraycopy(regbuff, 0, buf, 0, regbuff.length);
System.arraycopy(vals, 0, buf, regbuff.length, len);
i2CAdapter.transfer(address, 0, buf, regbuff.length + len);
}
}
@VisibleForTesting
static long readValue(byte[] buff) {
long res = 0;
for (int i = 0; i < buff.length; i++) {
res |= ((long) (buff[i] & 0xFF)) << ((buff.length - i - 1) * 8);
}
return res;
}
@VisibleForTesting
static void writeValue(byte[] buff, long value) {
for (int i = 0; i < buff.length; i++) {
buff[i] = (byte) (value >> ((buff.length - i - 1) * 8));
}
}
private byte[] getTmpBuffer(int size) {
if (tmpbuff.length < size) {
tmpbuff = new byte[size];
}
return tmpbuff;
}
public void update_bits(int reg, int mask, int val) throws DvbException {
synchronized (locker) {
/* no need for read if whole reg is written */
if (mask != 0xff) {
int tmp = read_reg(reg);
val &= mask;
tmp &= ~mask;
val |= tmp;
}
write_reg(reg, val);
}
}
}
| 4,138 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
CompletedFuture.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/CompletedFuture.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class CompletedFuture<T> implements Future<T> {
private final T result;
public CompletedFuture(T result) {
this.result = result;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public T get() throws InterruptedException, ExecutionException {
return result;
}
@Override
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return result;
}
}
| 1,758 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
FastIntFilter.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/FastIntFilter.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
public class FastIntFilter {
private final byte[] bitmap;
private int[] filter = new int[0];
public FastIntFilter(int size) {
int bitmapSize = (size + 7) >> 3;
this.bitmap = new byte[bitmapSize];
}
public void setFilter(int ... ids) {
synchronized (bitmap) {
for (int aFilter : filter) setFilterOff(aFilter);
this.filter = ids;
for (int aFilter : filter) setFilterOn(aFilter);
}
}
public boolean isFiltered(int id) {
int bid = id >> 3;
int rem = id - (bid << 3);
int mask = 1 << rem;
return (bitmap[bid] & mask) != 0;
}
private void setFilterOn(int id) {
int bid = id >> 3;
int rem = id - (bid << 3);
int mask = 1 << rem;
bitmap[bid] |= mask;
}
private void setFilterOff(int id) {
int bid = id >> 3;
int rem = id - (bid << 3);
int mask = 1 << rem;
bitmap[bid] &= ~mask;
}
}
| 1,898 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Check.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/Check.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
public class Check {
public static <T> T notNull(T o) {
return notNull(o, null);
}
public static <T> T notNull(T o, String msg) {
if (o == null) exception(msg);
return o;
}
private static void exception(String s) {
if (s == null) throw new RuntimeException();
throw new RuntimeException(s);
}
}
| 1,266 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
AsyncFuture.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/AsyncFuture.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import androidx.annotation.NonNull;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class AsyncFuture<V> implements Future<V> {
private final Object locker = new Object();
private V object;
private boolean ready = false;
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
synchronized (locker) {
return ready;
}
}
@Override
public V get() throws InterruptedException, ExecutionException {
synchronized (locker) {
if (ready) return object;
locker.wait();
return object;
}
}
@Override
public V get(long timeout, @NonNull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
synchronized (locker) {
if (ready) return object;
locker.wait(unit.toMillis(timeout));
return object;
}
}
public void setDone(V object) {
synchronized (locker) {
this.object = object;
this.ready = true;
locker.notify();
}
}
}
| 2,271 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
Retry.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/Retry.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import android.util.Log;
public class Retry {
private final static String TAG = Retry.class.getSimpleName();
public static <T extends Throwable> void retry(int times, final ThrowingRunnable<T> throwingRunnable) throws T {
retry(times, new ThrowingCallable<Void, T>() {
@Override
public Void call() throws T {
throwingRunnable.run();
return null;
}
});
}
public static <R, T extends Throwable> R retry(int times, ThrowingCallable<R, T> throwingCallable) throws T {
long sleep = 100;
while (true) {
try {
return throwingCallable.call();
} catch (RuntimeException e) {
throw e;
} catch (Throwable e) {
if (times-- <= 0) {
throw e;
} else {
Log.d(TAG, "Retries left: "+times+", exception "+e);
try {
Thread.sleep(sleep);
} catch (InterruptedException e1) {
return throwingCallable.call();
}
sleep *= 3;
}
}
}
}
}
| 2,140 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
UsbPermissionObtainer.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/UsbPermissionObtainer.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import android.os.Build;
import android.util.Log;
import java.util.concurrent.Future;
public class UsbPermissionObtainer {
private static final String TAG = UsbPermissionObtainer.class.getSimpleName();
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
public static Future<UsbDeviceConnection> obtainFdFor(Context context, UsbDevice usbDevice) {
int flags = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
flags = PendingIntent.FLAG_MUTABLE;
}
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
if (!manager.hasPermission(usbDevice)) {
AsyncFuture<UsbDeviceConnection> task = new AsyncFuture<>();
registerNewBroadcastReceiver(context, usbDevice, task);
manager.requestPermission(usbDevice, PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), flags));
return task;
} else {
return new CompletedFuture<>(manager.openDevice(usbDevice));
}
}
private static void registerNewBroadcastReceiver(final Context context, final UsbDevice usbDevice, final AsyncFuture<UsbDeviceConnection> task) {
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
if (task.isDone()) {
Log.d(TAG, "Permission already should be processed, ignoring.");
return;
}
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (device.equals(usbDevice)) {
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (!manager.hasPermission(device)) {
Log.d(TAG, "Permissions were granted but can't access the device");
task.setDone(null);
} else {
Log.d(TAG, "Permissions granted and device is accessible");
task.setDone(manager.openDevice(device));
}
} else {
Log.d(TAG, "Extra permission was not granted");
task.setDone(null);
}
context.unregisterReceiver(this);
} else {
Log.d(TAG, "Got a permission for an unexpected device");
task.setDone(null);
}
}
} else {
Log.d(TAG, "Unexpected action");
task.setDone(null);
}
}
}, new IntentFilter(ACTION_USB_PERMISSION));
}
private UsbPermissionObtainer() {}
}
| 4,511 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
ThrowingRunnable.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/ThrowingRunnable.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
public interface ThrowingRunnable<T extends Throwable> {
void run() throws T;
}
| 988 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbMath.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/DvbMath.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
/**
* Adapted from dvb_math.c
*/
public class DvbMath {
private static final int[] LOG_TABLE = new int[]{
0x0000, 0x0171, 0x02e0, 0x044e, 0x05ba, 0x0725, 0x088e, 0x09f7,
0x0b5d, 0x0cc3, 0x0e27, 0x0f8a, 0x10eb, 0x124b, 0x13aa, 0x1508,
0x1664, 0x17bf, 0x1919, 0x1a71, 0x1bc8, 0x1d1e, 0x1e73, 0x1fc6,
0x2119, 0x226a, 0x23ba, 0x2508, 0x2656, 0x27a2, 0x28ed, 0x2a37,
0x2b80, 0x2cc8, 0x2e0f, 0x2f54, 0x3098, 0x31dc, 0x331e, 0x345f,
0x359f, 0x36de, 0x381b, 0x3958, 0x3a94, 0x3bce, 0x3d08, 0x3e41,
0x3f78, 0x40af, 0x41e4, 0x4319, 0x444c, 0x457f, 0x46b0, 0x47e1,
0x4910, 0x4a3f, 0x4b6c, 0x4c99, 0x4dc5, 0x4eef, 0x5019, 0x5142,
0x526a, 0x5391, 0x54b7, 0x55dc, 0x5700, 0x5824, 0x5946, 0x5a68,
0x5b89, 0x5ca8, 0x5dc7, 0x5ee5, 0x6003, 0x611f, 0x623a, 0x6355,
0x646f, 0x6588, 0x66a0, 0x67b7, 0x68ce, 0x69e4, 0x6af8, 0x6c0c,
0x6d20, 0x6e32, 0x6f44, 0x7055, 0x7165, 0x7274, 0x7383, 0x7490,
0x759d, 0x76aa, 0x77b5, 0x78c0, 0x79ca, 0x7ad3, 0x7bdb, 0x7ce3,
0x7dea, 0x7ef0, 0x7ff6, 0x80fb, 0x81ff, 0x8302, 0x8405, 0x8507,
0x8608, 0x8709, 0x8809, 0x8908, 0x8a06, 0x8b04, 0x8c01, 0x8cfe,
0x8dfa, 0x8ef5, 0x8fef, 0x90e9, 0x91e2, 0x92db, 0x93d2, 0x94ca,
0x95c0, 0x96b6, 0x97ab, 0x98a0, 0x9994, 0x9a87, 0x9b7a, 0x9c6c,
0x9d5e, 0x9e4f, 0x9f3f, 0xa02e, 0xa11e, 0xa20c, 0xa2fa, 0xa3e7,
0xa4d4, 0xa5c0, 0xa6ab, 0xa796, 0xa881, 0xa96a, 0xaa53, 0xab3c,
0xac24, 0xad0c, 0xadf2, 0xaed9, 0xafbe, 0xb0a4, 0xb188, 0xb26c,
0xb350, 0xb433, 0xb515, 0xb5f7, 0xb6d9, 0xb7ba, 0xb89a, 0xb97a,
0xba59, 0xbb38, 0xbc16, 0xbcf4, 0xbdd1, 0xbead, 0xbf8a, 0xc065,
0xc140, 0xc21b, 0xc2f5, 0xc3cf, 0xc4a8, 0xc580, 0xc658, 0xc730,
0xc807, 0xc8de, 0xc9b4, 0xca8a, 0xcb5f, 0xcc34, 0xcd08, 0xcddc,
0xceaf, 0xcf82, 0xd054, 0xd126, 0xd1f7, 0xd2c8, 0xd399, 0xd469,
0xd538, 0xd607, 0xd6d6, 0xd7a4, 0xd872, 0xd93f, 0xda0c, 0xdad9,
0xdba5, 0xdc70, 0xdd3b, 0xde06, 0xded0, 0xdf9a, 0xe063, 0xe12c,
0xe1f5, 0xe2bd, 0xe385, 0xe44c, 0xe513, 0xe5d9, 0xe69f, 0xe765,
0xe82a, 0xe8ef, 0xe9b3, 0xea77, 0xeb3b, 0xebfe, 0xecc1, 0xed83,
0xee45, 0xef06, 0xefc8, 0xf088, 0xf149, 0xf209, 0xf2c8, 0xf387,
0xf446, 0xf505, 0xf5c3, 0xf680, 0xf73e, 0xf7fb, 0xf8b7, 0xf973,
0xfa2f, 0xfaea, 0xfba5, 0xfc60, 0xfd1a, 0xfdd4, 0xfe8e, 0xff47
};
/**
* fls - find last (most-significant) bit set
* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
*/
static int fls(int x) {
if (x == 0) return 0;
int r = 32;
if ((x & 0xffff0000L) == 0) {
x <<= 16;
r -= 16;
}
if ((x & 0xff000000L) == 0) {
x <<= 8;
r -= 8;
}
if ((x & 0xf0000000L) == 0) {
x <<= 4;
r -= 4;
}
if ((x & 0xc0000000L) == 0) {
x <<= 2;
r -= 2;
}
if ((x & 0x80000000L) == 0) {
r -= 1;
}
return r;
}
static int intlog2(int value) {
int msb = fls(value) - 1;
int significand = value << (31 - msb);
int logentry = (significand >> 23) & 0xff;
int interpolation = ((significand & 0x7fffff) *
((LOG_TABLE[(logentry + 1) & 0xff] -
LOG_TABLE[logentry]) & 0xffff)) >> 15;
return (msb << 24) + (LOG_TABLE[logentry] << 8) + interpolation;
}
public static int intlog10(int value) {
return (int) ((intlog2(value) * 646456993L) >> 31);
}
public static long divU64(long dividend, long divisor) {
long ret = 0;
while (dividend >= divisor) {
dividend -= divisor;
ret++;
}
return ret;
}
public static long divRoundClosest(long x, long divisor) {
return (x + (divisor >> 1)) / divisor;
}
}
| 4,968 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
ThrowingCallable.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/ThrowingCallable.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools;
public interface ThrowingCallable<R, T extends Throwable> {
R call() throws T;
}
| 989 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
NativePipe.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/io/NativePipe.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools.io;
import android.os.ParcelFileDescriptor;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class NativePipe implements Closeable {
private final InputStream inputStream;
private final OutputStream outputStream;
public NativePipe() {
try {
ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
inputStream = new ParcelFileDescriptor.AutoCloseInputStream(pipe[0]) {
private boolean closed = false;
@Override
public void close() throws IOException {
if (closed) return;
closed = true;
super.close();
outputStream.close();
}
};
outputStream = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]) {
private boolean closed = false;
@Override
public void close() throws IOException {
if (closed) return;
closed = true;
super.close();
inputStream.close();
}
};
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public InputStream getInputStream() {
return inputStream;
}
public OutputStream getOutputStream() {
return outputStream;
}
@Override
public void close() throws IOException {
inputStream.close();
outputStream.close();
}
}
| 2,491 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
ThrottledTsSource.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/tools/io/ThrottledTsSource.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.tools.io;
import android.util.SparseArray;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import info.martinmarinov.usbxfer.ByteSink;
import info.martinmarinov.usbxfer.ByteSource;
public class ThrottledTsSource implements ByteSource {
private final File file;
private final byte[] frame = new byte[188];
private SparseArray<PrevInfo> timeKeeping = new SparseArray<>();
private double streamPacketsPerMicroS = -1.0;
private double packetsAvailable = 0.0;
private long lastRead;
private long packetCount;
private FileInputStream in;
public ThrottledTsSource(File file) {
this.file = file;
}
@Override
public void open() throws IOException {
in = new FileInputStream(file);
}
@Override
public void readNext(ByteSink sink) throws IOException, InterruptedException {
boolean packetAvailable = false;
if (streamPacketsPerMicroS < 0.0) {
packetAvailable = true;
lastRead = System.nanoTime();
} else {
long now = System.nanoTime();
packetsAvailable += ((now - lastRead) * streamPacketsPerMicroS) / 1_000.0;
lastRead = now;
if (packetsAvailable >= 1.0) {
packetAvailable = true;
packetsAvailable -= 1.0;
}
}
if (packetAvailable) {
readWithRewind();
sink.consume(frame, frame.length);
} else {
// Packet not available, wait for a second
Thread.sleep(10);
}
packetCount++;
Long tsTimestamp = readTimestampMicroSec();
if (tsTimestamp != null) {
int pid = getPid();
PrevInfo prevInfo = timeKeeping.get(pid);
if (prevInfo == null) {
timeKeeping.put(pid, new PrevInfo(tsTimestamp, packetCount));
} else {
long elapsedTsMicroS = tsTimestamp - prevInfo.prevTsTimestamp;
if (elapsedTsMicroS != 0) {
double currentPacketsPerMicroS = (packetCount - prevInfo.packetCount) / (double) elapsedTsMicroS;
if (streamPacketsPerMicroS < 0.0) {
streamPacketsPerMicroS = currentPacketsPerMicroS;
} else {
// Low pass
streamPacketsPerMicroS = streamPacketsPerMicroS * 0.5 + 0.5 * currentPacketsPerMicroS;
}
}
prevInfo.prevTsTimestamp = tsTimestamp;
prevInfo.packetCount = packetCount;
}
}
}
@Override
public void close() throws IOException {
in.close();
}
private int getPid() {
return ((frame[1] & 0x1F) << 8) | (frame[2] & 0xFF);
}
private Long readTimestampMicroSec() throws IOException {
if (frame[0] != 0x47) throw new IOException("Broken packet");
boolean adaptationFieldPresent = (frame[3] & 0x20) != 0;
if (!adaptationFieldPresent) return null;
byte adaptationFieldLength = frame[4];
if (adaptationFieldLength == 0) return null;
boolean pcrPresent = (frame[5] & 0x10) != 0;
if (!pcrPresent) return null;
long programClockReferenceBase = ((long) (frame[6] & 0xFF) << 25) |
((long) (frame[7] & 0xFF) << 17) |
((long) (frame[8] & 0xFF) << 9) |
((long) (frame[9] & 0xFF) << 1) |
((long) (frame[10] & 0x80) >> 7);
long programClockExtensionReference = ((frame[10] & 0x01) << 8) | (frame[11] & 0xFF);
long pcr = programClockReferenceBase * 300L + programClockExtensionReference;
// Convert to ms 1 tick = 1 / 27_000_000 s
return pcr / 27L;
}
private void reset() throws IOException {
timeKeeping.clear();
in.close();
in = new FileInputStream(file);
}
private void readWithRewind() throws IOException {
if (!readFrame()) {
reset();
if (!readFrame()) throw new IOException("File too short");
}
}
private boolean readFrame() throws IOException {
int header;
while ((header = in.read()) != 0x47) {
if (header == -1) return false; // EOF
}
frame[0] = 0x47;
int rem = frame.length - 1;
int pos = 1;
while (rem > 0) {
int read = in.read(frame, pos, rem);
pos += read;
rem -= read;
if (read <= 0) {
return false;
}
}
return true;
}
private static class PrevInfo {
private long prevTsTimestamp;
private long packetCount;
private PrevInfo(long prevTsTimestamp, long packetCount) {
this.prevTsTimestamp = prevTsTimestamp;
this.packetCount = packetCount;
}
}
}
| 5,838 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
DvbFileDevice.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/file/DvbFileDevice.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.file;
import android.content.res.Resources;
import androidx.annotation.NonNull;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import info.martinmarinov.drivers.DeviceFilter;
import info.martinmarinov.drivers.DvbCapabilities;
import info.martinmarinov.drivers.DvbDemux;
import info.martinmarinov.drivers.DvbDevice;
import info.martinmarinov.drivers.DvbException;
import info.martinmarinov.drivers.DvbStatus;
import info.martinmarinov.drivers.R;
import info.martinmarinov.drivers.tools.SetUtils;
import info.martinmarinov.usbxfer.ByteSource;
import info.martinmarinov.drivers.tools.io.ThrottledTsSource;
import info.martinmarinov.drivers.DeliverySystem;
import static info.martinmarinov.drivers.DvbException.ErrorCode.CANNOT_OPEN_USB;
/**
* This is a DvbDevice that can be used for debugging purposes.
* It takes a file and streams it as if it is a stream coming from a real USB device.
*/
public class DvbFileDevice extends DvbDevice {
private final static DvbCapabilities CAPABILITIES = new DvbCapabilities(174000000L, 862000000L, 166667L, SetUtils.setOf(DeliverySystem.values()));
private final Resources resources;
private final File file;
private final long freq;
private final long bandwidth;
private boolean isTuned = false;
public DvbFileDevice(Resources resources, File file, long freq, long bandwidth) {
super(DvbDemux.DvbDmxSwfilter());
this.resources = resources;
this.file = file;
this.freq = freq;
this.bandwidth = bandwidth;
}
@Override
public void open() throws DvbException {
if (!file.canRead()) throw new DvbException(CANNOT_OPEN_USB, new IOException());
}
@Override
public DeviceFilter getDeviceFilter() {
return new FileDeviceFilter(resources.getString(R.string.rec_name, freq / 1_000_000.0, bandwidth / 1_000_000.0), file);
}
@Override
protected void tuneTo(long freqHz, long bandwidthHz, @NonNull DeliverySystem deliverySystem) throws DvbException {
this.isTuned = freqHz == this.freq && bandwidthHz == this.bandwidth;
}
@Override
public DvbCapabilities readCapabilities() throws DvbException {
return CAPABILITIES;
}
@Override
public int readSnr() throws DvbException {
return isTuned ? 400 : 0;
}
@Override
public int readRfStrengthPercentage() throws DvbException {
return isTuned ? 100 : 0;
}
@Override
public int readBitErrorRate() throws DvbException {
return isTuned ? 0 : 0xFFFF;
}
@Override
public Set<DvbStatus> getStatus() throws DvbException {
if (isTuned) return SetUtils.setOf(DvbStatus.FE_HAS_SIGNAL, DvbStatus.FE_HAS_CARRIER, DvbStatus.FE_HAS_VITERBI, DvbStatus.FE_HAS_SYNC, DvbStatus.FE_HAS_LOCK);
return SetUtils.setOf();
}
@Override
protected ByteSource createTsSource() {
return new ThrottledTsSource(file);
}
@Override
public String getDebugString() {
return "File - "+file.getAbsolutePath();
}
}
| 3,961 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
FileDeviceFilter.java | /FileExtraction/Java_unseen/signalwareltd_AndroidDvbDriver/drivers/src/main/java/info/martinmarinov/drivers/file/FileDeviceFilter.java | /*
* This is an Android user space port of DVB-T Linux kernel modules.
*
* Copyright (C) 2022 by Signalware Ltd <driver at aerialtv.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package info.martinmarinov.drivers.file;
import java.io.File;
import java.util.Objects;
import info.martinmarinov.drivers.DeviceFilter;
class FileDeviceFilter extends DeviceFilter {
private final File file;
FileDeviceFilter(String name, File file) {
super(-1, -1, name);
this.file = file;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
FileDeviceFilter that = (FileDeviceFilter) o;
return Objects.equals(file, that.file);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (file != null ? file.hashCode() : 0);
return result;
}
}
| 1,677 | Java | .java | signalwareltd/AndroidDvbDriver | 183 | 65 | 39 | 2017-02-22T15:41:19Z | 2023-04-29T01:10:41Z |
TppApplication.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/test/java/de/adorsys/xs2a/tpp/TppApplication.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.tpp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableFeignClients(basePackages = "de.adorsys.xs2a.adapter.remote.client", defaultConfiguration = ErrorResponseDecoder.class)
@SpringBootApplication
public class TppApplication {
public static void main(String[] args) {
SpringApplication.run(TppApplication.class, args);
}
}
| 1,336 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
ErrorResponseDecoder.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/test/java/de/adorsys/xs2a/tpp/ErrorResponseDecoder.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.tpp;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.adorsys.xs2a.adapter.api.ResponseHeaders;
import de.adorsys.xs2a.adapter.api.exception.ErrorResponseException;
import de.adorsys.xs2a.adapter.api.model.ErrorResponse;
import feign.Response;
import feign.Util;
import feign.codec.ErrorDecoder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.io.Reader;
import java.util.Map;
import java.util.stream.Collectors;
@Configuration
public class ErrorResponseDecoder implements ErrorDecoder {
@Autowired
ObjectMapper objectMapper;
@Override
public Exception decode(String methodKey, Response response) {
ResponseHeaders responseHeaders = ResponseHeaders.fromMap(
response.headers().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().iterator().next()))
);
ErrorResponse errorResponse = null;
try (Reader bodyReader = response.body().asReader()) {
String responseBody = Util.toString(bodyReader);
if (StringUtils.isNotBlank(responseBody)) {
errorResponse = objectMapper.readValue(responseBody, ErrorResponse.class);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return new ErrorResponseException(response.status(), responseHeaders, errorResponse);
}
}
| 2,397 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
AppConfiguration.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/test/java/de/adorsys/xs2a/tpp/AppConfiguration.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.tpp;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.adorsys.xs2a.adapter.api.AccountInformationService;
import de.adorsys.xs2a.adapter.api.PaymentInitiationService;
import de.adorsys.xs2a.adapter.mapper.HeadersMapper;
import de.adorsys.xs2a.adapter.remote.RemoteAccountInformationService;
import de.adorsys.xs2a.adapter.remote.RemotePaymentInitiationService;
import de.adorsys.xs2a.adapter.remote.client.AccountInformationClient;
import de.adorsys.xs2a.adapter.remote.client.PaymentInitiationClient;
import de.adorsys.xs2a.adapter.remote.config.FeignConfiguration;
import de.adorsys.xs2a.adapter.rest.impl.config.WebMvcConfig;
import de.adorsys.xs2a.adapter.rest.impl.controller.ConsentController;
import de.adorsys.xs2a.adapter.rest.impl.controller.PaymentController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import java.util.Arrays;
import java.util.List;
@Configuration
@Import({WebMvcConfig.class, FeignConfiguration.class})
public class AppConfiguration {
@Autowired
AccountInformationClient accountInformationClient;
@Autowired
PaymentInitiationClient paymentInitiationClient;
@Bean
HeadersMapper getHeadersMapper() {
return new HeadersMapper();
}
@Bean
PaymentInitiationService paymentInitiationService() {
return new RemotePaymentInitiationService(paymentInitiationClient);
}
@Bean
AccountInformationService accountInformationService() {
return new RemoteAccountInformationService(accountInformationClient);
}
@Bean
HttpMessageConverter<String> objectStringHttpMessageConverter() {
return new StringHttpMessageConverter() {
@Override
public boolean supports(Class<?> clazz) {
return Object.class == clazz;
}
@Override
public List<MediaType> getSupportedMediaTypes() {
return Arrays.asList(MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN);
}
};
}
@Bean
ConsentController consentController(AccountInformationService accountInformationService,
ObjectMapper objectMapper,
HeadersMapper headersMapper) {
return new ConsentController(accountInformationService, objectMapper, headersMapper);
}
@Bean
PaymentController paymentController(PaymentInitiationService paymentInitiationService,
ObjectMapper objectMapper,
HeadersMapper headersMapper) {
return new PaymentController(paymentInitiationService, headersMapper, objectMapper);
}
}
| 3,890 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
AspspController.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/test/java/de/adorsys/xs2a/tpp/controller/AspspController.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.tpp.controller;
import de.adorsys.xs2a.adapter.remote.client.AspspClient;
import de.adorsys.xs2a.adapter.rest.api.model.AspspTO;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class AspspController {
private final AspspClient aspspClient;
public AspspController(AspspClient aspspClient) {
this.aspspClient = aspspClient;
}
@RequestMapping("/v1/aspsps")
ResponseEntity<List<AspspTO>> getAspsps(@RequestParam(required = false) String name,
@RequestParam(required = false) String bic,
@RequestParam(required = false) String bankCode,
@RequestParam(required = false) String iban, // if present - other params ignored
@RequestParam(required = false) String after,
@RequestParam(required = false, defaultValue = "10") int size) {
ResponseEntity<List<AspspTO>> aspsps = aspspClient.getAspsps(name, bic, bankCode, iban, after, size);
return ResponseEntity.ok(aspsps.getBody());
}
}
| 2,237 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
RemoteAccountInformationServiceTest.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/test/java/de/adorsys/xs2a/adapter/remote/RemoteAccountInformationServiceTest.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.adorsys.xs2a.adapter.api.RequestHeaders;
import de.adorsys.xs2a.adapter.api.RequestParams;
import de.adorsys.xs2a.adapter.api.Response;
import de.adorsys.xs2a.adapter.api.ResponseHeaders;
import de.adorsys.xs2a.adapter.api.exception.NotAcceptableException;
import de.adorsys.xs2a.adapter.api.model.*;
import de.adorsys.xs2a.adapter.remote.client.AccountInformationClient;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
class RemoteAccountInformationServiceTest {
public static final String CONSENT_ID = "consentId";
public static final String CONTENT_TYPE = "application/json";
public static final String X_REQUEST_ID = "1234567";
public static final int HTTP_STATUS_OK = 200;
public static final String AUTHORIZATION_ID = "AUTHORIZATION_ID";
public static final String ACCOUNT_ID = "ACCOUNT_ID";
public static final String TRANSACTION_ID = "TRX_ID";
private final ObjectMapper objectMapper = new ObjectMapper();
private RemoteAccountInformationService service;
private AccountInformationClient client;
private final ResponseEntity entity = mock(ResponseEntity.class);
@BeforeEach
public void setUp() {
client = mock(AccountInformationClient.class);
service = new RemoteAccountInformationService(client);
}
@Test
void createConsent() {
ConsentsResponse201 responseBody = new ConsentsResponse201();
doReturn(entity).when(client).createConsent(anyMap(), anyMap(), any());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<ConsentsResponse201> response = service.createConsent(RequestHeaders.empty(),
RequestParams.empty(),
new Consents());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
private static void assertResponseHeaders(ResponseHeaders headers) {
Assertions.assertThat(headers.getHeadersMap()).hasSize(2);
Assertions.assertThat(headers.getHeader(ResponseHeaders.CONTENT_TYPE)).isEqualTo(CONTENT_TYPE);
Assertions.assertThat(headers.getHeader(ResponseHeaders.X_REQUEST_ID)).isEqualTo(X_REQUEST_ID);
}
private HttpHeaders buildHttpHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.put(ResponseHeaders.CONTENT_TYPE, Collections.singletonList(CONTENT_TYPE));
headers.put(ResponseHeaders.X_REQUEST_ID, Collections.singletonList(X_REQUEST_ID));
return headers;
}
@Test
void getConsentInformation() {
ConsentInformationResponse200Json responseBody = new ConsentInformationResponse200Json();
doReturn(entity).when(client).getConsentInformation(CONSENT_ID, Collections.emptyMap(), Collections.emptyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<ConsentInformationResponse200Json> response = service.getConsentInformation(CONSENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void getConsentStatus() {
ConsentStatusResponse200 responseBody = new ConsentStatusResponse200();
doReturn(entity).when(client).getConsentStatus(CONSENT_ID, Collections.emptyMap(), Collections.emptyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<ConsentStatusResponse200> response = service.getConsentStatus(CONSENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void deleteConsent() {
doReturn(entity).when(client).deleteConsent(CONSENT_ID, Collections.emptyMap(), Collections.emptyMap());
doReturn(202).when(entity).getStatusCodeValue();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<Void> response = service.deleteConsent(CONSENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertResponseHeaders(response.getHeaders());
}
@Test
void getConsentAuthorisation() {
Authorisations responseBody = new Authorisations();
doReturn(entity).when(client).getConsentAuthorisation(CONSENT_ID, Collections.emptyMap(), Collections.emptyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<Authorisations> response = service.getConsentAuthorisation(CONSENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void startConsentAuthorisation() {
StartScaprocessResponse responseBody = new StartScaprocessResponse();
doReturn(entity).when(client).startConsentAuthorisation(CONSENT_ID,
Collections.emptyMap(),
Collections.emptyMap(),
objectMapper.createObjectNode());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<StartScaprocessResponse> response = service.startConsentAuthorisation(CONSENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void startConsentAuthorisation_PsuAuthentication() {
StartScaprocessResponse responseBody = new StartScaprocessResponse();
doReturn(entity).when(client).startConsentAuthorisation(eq(CONSENT_ID),
anyMap(),
anyMap(),
any());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<StartScaprocessResponse> response = service.startConsentAuthorisation(CONSENT_ID,
RequestHeaders.empty(),
RequestParams.empty(),
new UpdatePsuAuthentication());
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void updateConsentsPsuData_SelectMethod() {
SelectPsuAuthenticationMethodResponse responseBody = new SelectPsuAuthenticationMethodResponse();
SelectPsuAuthenticationMethod requestBody = new SelectPsuAuthenticationMethod();
doReturn(entity).when(client).updateConsentsPsuData(eq(CONSENT_ID),
eq(AUTHORIZATION_ID),
anyMap(),
anyMap(),
any());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<SelectPsuAuthenticationMethodResponse> response = service.updateConsentsPsuData(CONSENT_ID,
AUTHORIZATION_ID,
RequestHeaders.empty(),
RequestParams.empty(),
requestBody);
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void updateConsentsPsuData_SendOTP() {
ScaStatusResponse responseBody = new ScaStatusResponse();
TransactionAuthorisation requestBody = new TransactionAuthorisation();
doReturn(entity).when(client).updateConsentsPsuData(eq(CONSENT_ID),
eq(AUTHORIZATION_ID),
anyMap(),
anyMap(),
any());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<ScaStatusResponse> response = service.updateConsentsPsuData(CONSENT_ID,
AUTHORIZATION_ID,
RequestHeaders.empty(),
RequestParams.empty(),
requestBody);
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void updateConsentsPsuData_PsuAuthentication() {
UpdatePsuAuthenticationResponse responseBody = new UpdatePsuAuthenticationResponse();
UpdatePsuAuthentication requestBody = new UpdatePsuAuthentication();
doReturn(entity).when(client).updateConsentsPsuData(eq(CONSENT_ID),
eq(AUTHORIZATION_ID),
anyMap(),
anyMap(),
any());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<UpdatePsuAuthenticationResponse> response = service.updateConsentsPsuData(CONSENT_ID,
AUTHORIZATION_ID,
RequestHeaders.empty(),
RequestParams.empty(),
requestBody);
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void getAccountList() {
AccountList responseBody = new AccountList();
doReturn(responseBody).when(entity).getBody();
doReturn(entity).when(client).getAccountList(false, Collections.emptyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<AccountList> response = service.getAccountList(RequestHeaders.empty(), RequestParams.empty());
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void readAccountDetails() {
OK200AccountDetails responseBody = new OK200AccountDetails();
String accountId = "accountId";
doReturn(responseBody).when(entity).getBody();
doReturn(entity).when(client).readAccountDetails(accountId, false, Collections.emptyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<OK200AccountDetails> response = service.readAccountDetails(accountId, RequestHeaders.empty(),
RequestParams.empty());
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void getTransactionList_NotAJsonContentType() {
Map<String, String> headersMap = new HashMap<>();
headersMap.put(RequestHeaders.CONTENT_TYPE, "application/xml");
RequestHeaders headers = RequestHeaders.fromMap(headersMap);
assertThrows(NotAcceptableException.class, () -> service.getTransactionList(ACCOUNT_ID,
headers,
RequestParams.empty()));
}
@Test
void getTransactionDetails() {
OK200TransactionDetails responseBody = new OK200TransactionDetails();
doReturn(responseBody).when(entity).getBody();
doReturn(entity).when(client).getTransactionDetails(eq(ACCOUNT_ID), eq(TRANSACTION_ID), anyMap(), anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<OK200TransactionDetails> response = service.getTransactionDetails(ACCOUNT_ID,
TRANSACTION_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void getConsentScaStatus() {
ScaStatusResponse responseBody = new ScaStatusResponse();
doReturn(responseBody).when(entity).getBody();
doReturn(entity).when(client).getConsentScaStatus(eq(CONSENT_ID), eq(AUTHORIZATION_ID), anyMap(), anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<ScaStatusResponse> response = service.getConsentScaStatus(CONSENT_ID,
AUTHORIZATION_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void getBalances() {
ReadAccountBalanceResponse200 responseBody = new ReadAccountBalanceResponse200();
doReturn(responseBody).when(entity).getBody();
doReturn(entity).when(client).getBalances(eq(ACCOUNT_ID), anyMap(), anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<ReadAccountBalanceResponse200> response = service.getBalances(ACCOUNT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void getCardAccountList() {
CardAccountList responseBody = new CardAccountList();
doReturn(responseBody).when(entity).getBody();
doReturn(entity).when(client).getCardAccount(anyMap(), anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<CardAccountList> response = service.getCardAccountList(RequestHeaders.empty(),
RequestParams.empty());
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void getCardAccountDetails() {
OK200CardAccountDetails responseBody = new OK200CardAccountDetails();
doReturn(responseBody).when(entity).getBody();
doReturn(entity).when(client).ReadCardAccount(eq(ACCOUNT_ID), anyMap(), anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<OK200CardAccountDetails> response = service.getCardAccountDetails(ACCOUNT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void getCardAccountBalances() {
ReadCardAccountBalanceResponse200 responseBody = new ReadCardAccountBalanceResponse200();
doReturn(responseBody).when(entity).getBody();
doReturn(entity).when(client).getCardAccountBalances(eq(ACCOUNT_ID), anyMap(), anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<ReadCardAccountBalanceResponse200> response = service.getCardAccountBalances(ACCOUNT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void getCardAccountTransactionList() {
String dateFrom = "2020-07-20";
String dateTo = "2020-07-21";
String entryReferenceFrom = "entryReferenceFrom";
String bookingStatus = "both";
CardAccountsTransactionsResponse200 responseBody = new CardAccountsTransactionsResponse200();
Map<String, String> paramsMap = new HashMap<>();
paramsMap.put(RequestParams.DATE_FROM, dateFrom);
paramsMap.put(RequestParams.DATE_TO, dateTo);
paramsMap.put(RequestParams.ENTRY_REFERENCE_FROM, entryReferenceFrom);
paramsMap.put(RequestParams.BOOKING_STATUS, bookingStatus);
paramsMap.put(RequestParams.DELTA_LIST, "true");
paramsMap.put(RequestParams.WITH_BALANCE, "false");
RequestParams requestParams = RequestParams.fromMap(paramsMap);
doReturn(responseBody).when(entity).getBody();
doReturn(entity).when(client).getCardAccountTransactionList(eq(ACCOUNT_ID),
eq(requestParams.dateFrom()),
eq(requestParams.dateTo()),
eq(entryReferenceFrom),
eq(BookingStatusCard.BOTH),
eq(requestParams.deltaList()),
eq(requestParams.withBalance()),
anyMap(),
anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<CardAccountsTransactionsResponse200> response = service.getCardAccountTransactionList(ACCOUNT_ID,
RequestHeaders.empty(),
requestParams);
assertResponseHeaders(response.getHeaders());
Assertions.assertThat(response.getBody()).isEqualTo(responseBody);
}
@Test
void getTransactionListAsString() throws JsonProcessingException {
TransactionsResponse200Json report = buildTransactionReport();
when(client.getTransactionListAsString(
any(), any(), any(), any(), any(), any(), any(), any())
).thenReturn(buildResponseEntity(report));
Response<String> response = service.getTransactionListAsString(
"accountId",
RequestHeaders.fromMap(buildHeaders()),
RequestParams.fromMap(buildRequestParams())
);
assertThat(service.objectMapper.writeValueAsString(report)).isEqualTo(response.getBody());
}
@Test
void getTransactionList() {
AccountInformationClient client = mock(AccountInformationClient.class);
RemoteAccountInformationService service = new RemoteAccountInformationService(client);
TransactionsResponse200Json report = buildTransactionReport();
ResponseEntity<String> responseEntity = buildResponseEntity(report);
when(client.getTransactionListAsString(
any(), any(), any(), any(), any(), any(), any(), any())
).thenReturn(responseEntity);
Response<TransactionsResponse200Json> response = service.getTransactionList(
"accountId",
RequestHeaders.fromMap(buildHeaders()),
RequestParams.fromMap(buildRequestParams())
);
assertThat(response.getBody()).isEqualTo(report);
}
private ResponseEntity<String> buildResponseEntity(TransactionsResponse200Json report) {
try {
String body = service.objectMapper.writeValueAsString(report);
return new ResponseEntity<>(body, HttpStatus.OK);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
private TransactionsResponse200Json buildTransactionReport() {
TransactionsResponse200Json report = new TransactionsResponse200Json();
AccountReference accountReference = new AccountReference();
accountReference.setIban("iban");
accountReference.setCurrency("EUR");
report.setAccount(accountReference);
return report;
}
private HashMap<String, String> buildRequestParams() {
HashMap<String, String> params = new HashMap<>();
params.put(RequestParams.BOOKING_STATUS, BookingStatusGeneric.BOOKED.toString());
return params;
}
private Map<String, String> buildHeaders() {
Map<String, String> headers = new HashMap<>();
headers.put("Accept", "application/json");
return headers;
}
}
| 26,532 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
RemotePaymentInitiationServiceTest.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/test/java/de/adorsys/xs2a/adapter/remote/RemotePaymentInitiationServiceTest.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import de.adorsys.xs2a.adapter.api.RequestHeaders;
import de.adorsys.xs2a.adapter.api.RequestParams;
import de.adorsys.xs2a.adapter.api.Response;
import de.adorsys.xs2a.adapter.api.ResponseHeaders;
import de.adorsys.xs2a.adapter.api.model.*;
import de.adorsys.xs2a.adapter.remote.client.PaymentInitiationClient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import java.util.Collection;
import java.util.Collections;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
class RemotePaymentInitiationServiceTest {
public static final String CONSENT_ID = "consentId";
public static final String CONTENT_TYPE = "application/json";
public static final String X_REQUEST_ID = "1234567";
public static final int HTTP_STATUS_CREATED = 201;
public static final int HTTP_STATUS_OK = 200;
public static final String AUTHORIZATION_ID = "AUTHORIZATION_ID";
public static final String PAYMENT_ID = "payment-id";
private RemotePaymentInitiationService service;
private PaymentInitiationClient client;
private final ObjectMapper objectMapper = new ObjectMapper();
private final ResponseEntity entity = mock(ResponseEntity.class);
@BeforeEach
public void setUp() {
client = mock(PaymentInitiationClient.class);
service = new RemotePaymentInitiationService(client);
}
@Test
void initiatePayment_ObjectNode() {
PaymentInitationRequestResponse201 responseBody = new PaymentInitationRequestResponse201();
doReturn(entity).when(client).initiatePayment(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
anyMap(),
anyMap(),
any(ObjectNode.class));
doReturn(HTTP_STATUS_CREATED).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<PaymentInitationRequestResponse201> response = service.initiatePayment(PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
RequestHeaders.empty(),
RequestParams.empty(),
new PaymentInitiationJson());
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void initiatePayment_Periodic() {
PaymentInitationRequestResponse201 responseBody = new PaymentInitationRequestResponse201();
doReturn(entity).when(client).initiatePayment(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
anyMap(),
anyMap(),
any(PeriodicPaymentInitiationMultipartBody.class));
doReturn(HTTP_STATUS_CREATED).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<PaymentInitationRequestResponse201> response = service.initiatePayment(PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
RequestHeaders.empty(),
RequestParams.empty(),
new PeriodicPaymentInitiationMultipartBody());
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void initiatePayment_Xml() {
PaymentInitationRequestResponse201 responseBody = new PaymentInitationRequestResponse201();
doReturn(entity).when(client).initiatePayment(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
anyMap(),
anyMap(),
any(String.class));
doReturn(HTTP_STATUS_CREATED).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<PaymentInitationRequestResponse201> response =
service.initiatePayment(PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
RequestHeaders.empty(),
RequestParams.empty(),
"<xml/>");
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void getSinglePaymentInformation() {
PaymentInitiationWithStatusResponse responseBody = new PaymentInitiationWithStatusResponse();
doReturn(entity).when(client).getPaymentInformation(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
anyMap(),
anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<PaymentInitiationWithStatusResponse> response =
service.getSinglePaymentInformation(PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void getPeriodicPaymentInformation() {
PeriodicPaymentInitiationWithStatusResponse responseBody = new PeriodicPaymentInitiationWithStatusResponse();
doReturn(entity).when(client).getPaymentInformation(eq(PaymentService.PERIODIC_PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
anyMap(),
anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<PeriodicPaymentInitiationWithStatusResponse> response =
service.getPeriodicPaymentInformation(PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void getPeriodicPain001PaymentInformation() {
PeriodicPaymentInitiationMultipartBody responseBody = new PeriodicPaymentInitiationMultipartBody();
doReturn(entity).when(client).getPaymentInformation(eq(PaymentService.PERIODIC_PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
anyMap(),
anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<PeriodicPaymentInitiationMultipartBody> response =
service.getPeriodicPain001PaymentInformation(PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void getPaymentInformationAsString() {
String responseBody = "response in string format";
doReturn(entity).when(client).getPaymentInformation(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
anyMap(),
anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<String> response =
service.getPaymentInformationAsString(
PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void getPaymentInitiationScaStatus() {
ScaStatusResponse responseBody = new ScaStatusResponse();
doReturn(entity).when(client).getPaymentInitiationScaStatus(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
eq(AUTHORIZATION_ID),
anyMap(),
anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<ScaStatusResponse> response =
service.getPaymentInitiationScaStatus(
PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
AUTHORIZATION_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void getPaymentInitiationStatus() {
PaymentInitiationStatusResponse200Json responseBody = new PaymentInitiationStatusResponse200Json();
doReturn(entity).when(client).getPaymentInitiationStatus(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
anyMap(),
anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<PaymentInitiationStatusResponse200Json> response =
service.getPaymentInitiationStatus(
PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void getPaymentInitiationStatusAsString() throws JsonProcessingException {
Collection<String> responseBody = Collections.singletonList("payment initiation status in string format");
doReturn(entity).when(client).getPaymentInitiationStatus(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
anyMap(),
anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<String> response =
service.getPaymentInitiationStatusAsString(
PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertThat(response.getBody()).isEqualTo(objectMapper.writeValueAsString(responseBody));
assertResponseHeaders(response.getHeaders());
}
@Test
void getPaymentInitiationAuthorisation() {
Authorisations responseBody = new Authorisations();
doReturn(entity).when(client).getPaymentInitiationAuthorisation(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
anyMap(),
anyMap());
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<Authorisations> response =
service.getPaymentInitiationAuthorisation(
PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void startPaymentAuthorisation() {
StartScaprocessResponse responseBody = new StartScaprocessResponse();
doReturn(entity).when(client).startPaymentAuthorisation(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
anyMap(),
anyMap(),
any(ObjectNode.class));
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<StartScaprocessResponse> response =
service.startPaymentAuthorisation(
PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
RequestHeaders.empty(),
RequestParams.empty());
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void startPaymentAuthorisation_UpdatePsuAuthentication() {
StartScaprocessResponse responseBody = new StartScaprocessResponse();
UpdatePsuAuthentication requestBody = new UpdatePsuAuthentication();
doReturn(entity).when(client).startPaymentAuthorisation(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
anyMap(),
anyMap(),
any(ObjectNode.class));
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<StartScaprocessResponse> response =
service.startPaymentAuthorisation(
PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
RequestHeaders.empty(),
RequestParams.empty(),
requestBody);
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void updatePaymentPsuData_UpdatePsuAuthentication() {
UpdatePsuAuthenticationResponse responseBody = new UpdatePsuAuthenticationResponse();
UpdatePsuAuthentication requestBody = new UpdatePsuAuthentication();
doReturn(entity).when(client).updatePaymentPsuData(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
eq(AUTHORIZATION_ID),
anyMap(),
anyMap(),
any(ObjectNode.class));
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<UpdatePsuAuthenticationResponse> response =
service.updatePaymentPsuData(
PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
AUTHORIZATION_ID,
RequestHeaders.empty(),
RequestParams.empty(),
requestBody);
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void updatePaymentPsuData_SelectPsuAuthenticationMethod() {
SelectPsuAuthenticationMethodResponse responseBody = new SelectPsuAuthenticationMethodResponse();
SelectPsuAuthenticationMethod requestBody = new SelectPsuAuthenticationMethod();
doReturn(entity).when(client).updatePaymentPsuData(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
eq(AUTHORIZATION_ID),
anyMap(),
anyMap(),
any(ObjectNode.class));
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<SelectPsuAuthenticationMethodResponse> response =
service.updatePaymentPsuData(
PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
AUTHORIZATION_ID,
RequestHeaders.empty(),
RequestParams.empty(),
requestBody);
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
@Test
void updatePaymentPsuData_TransactionAuthorisation() {
ScaStatusResponse responseBody = new ScaStatusResponse();
TransactionAuthorisation requestBody = new TransactionAuthorisation();
doReturn(entity).when(client).updatePaymentPsuData(eq(PaymentService.PAYMENTS),
eq(PaymentProduct.SEPA_CREDIT_TRANSFERS),
eq(PAYMENT_ID),
eq(AUTHORIZATION_ID),
anyMap(),
anyMap(),
any(ObjectNode.class));
doReturn(HTTP_STATUS_OK).when(entity).getStatusCodeValue();
doReturn(responseBody).when(entity).getBody();
doReturn(buildHttpHeaders()).when(entity).getHeaders();
Response<ScaStatusResponse> response =
service.updatePaymentPsuData(
PaymentService.PAYMENTS,
PaymentProduct.SEPA_CREDIT_TRANSFERS,
PAYMENT_ID,
AUTHORIZATION_ID,
RequestHeaders.empty(),
RequestParams.empty(),
requestBody);
assertThat(response.getBody()).isEqualTo(responseBody);
assertResponseHeaders(response.getHeaders());
}
private HttpHeaders buildHttpHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.put(ResponseHeaders.CONTENT_TYPE, Collections.singletonList(CONTENT_TYPE));
headers.put(ResponseHeaders.X_REQUEST_ID, Collections.singletonList(X_REQUEST_ID));
return headers;
}
private static void assertResponseHeaders(ResponseHeaders headers) {
assertThat(headers.getHeadersMap()).hasSize(2);
assertThat(headers.getHeader(ResponseHeaders.CONTENT_TYPE)).isEqualTo(CONTENT_TYPE);
assertThat(headers.getHeader(ResponseHeaders.X_REQUEST_ID)).isEqualTo(X_REQUEST_ID);
}
}
| 24,509 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
RemoteEmbeddedPreAuthorisationServiceTest.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/test/java/de/adorsys/xs2a/adapter/remote/RemoteEmbeddedPreAuthorisationServiceTest.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote;
import de.adorsys.xs2a.adapter.api.RequestHeaders;
import de.adorsys.xs2a.adapter.api.model.EmbeddedPreAuthorisationRequest;
import de.adorsys.xs2a.adapter.api.model.TokenResponse;
import de.adorsys.xs2a.adapter.remote.client.EmbeddedPreAuthorisationClient;
import de.adorsys.xs2a.adapter.rest.api.model.EmbeddedPreAuthorisationRequestTO;
import de.adorsys.xs2a.adapter.rest.api.model.TokenResponseTO;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
class RemoteEmbeddedPreAuthorisationServiceTest {
private static final String ACCESS_TOKEN = "94A2776E7BD6F611462BC4344E17773C65FC4C486401643B724D102A8936DFF4";
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
private final EmbeddedPreAuthorisationClient client = mock(EmbeddedPreAuthorisationClient.class);
private final RemoteEmbeddedPreAuthorisationService service = new RemoteEmbeddedPreAuthorisationService(client);
private final ArgumentCaptor<EmbeddedPreAuthorisationRequestTO> argumentCaptor
= ArgumentCaptor.forClass(EmbeddedPreAuthorisationRequestTO.class);
@Test
void getToken() {
when(client.getToken(any(), any())).thenReturn(getTokenTO());
TokenResponse actualResponse = service.getToken(getAuthorisationRequest(), RequestHeaders.empty());
verify(client, times(1)).getToken(anyMap(), argumentCaptor.capture());
assertThat(actualResponse)
.isNotNull()
.extracting("accessToken")
.isEqualTo(ACCESS_TOKEN);
assertThat(argumentCaptor.getValue())
.isNotNull()
.matches(request -> request.getPassword().equals(PASSWORD))
.matches(request -> request.getUsername().equals(USERNAME));
}
private TokenResponseTO getTokenTO() {
TokenResponseTO token = new TokenResponseTO();
token.setAccessToken(ACCESS_TOKEN);
return token;
}
private EmbeddedPreAuthorisationRequest getAuthorisationRequest() {
EmbeddedPreAuthorisationRequest request = new EmbeddedPreAuthorisationRequest();
request.setPassword(PASSWORD);
request.setUsername(USERNAME);
return request;
}
}
| 3,239 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
RemoteOauth2ServiceTest.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/test/java/de/adorsys/xs2a/adapter/remote/RemoteOauth2ServiceTest.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote;
import de.adorsys.xs2a.adapter.api.Oauth2Service;
import de.adorsys.xs2a.adapter.api.model.HrefType;
import de.adorsys.xs2a.adapter.api.model.TokenResponse;
import de.adorsys.xs2a.adapter.remote.client.Oauth2Client;
import de.adorsys.xs2a.adapter.rest.api.model.TokenResponseTO;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.doReturn;
class RemoteOauth2ServiceTest {
private Oauth2Client oauth2Client = Mockito.mock(Oauth2Client.class);
private final RemoteOauth2Service service = new RemoteOauth2Service(oauth2Client);
@Test
void getAuthorizationRequestUri() throws IOException {
Oauth2Service.Parameters parameters = new Oauth2Service.Parameters();
String authUrl = "http://localhost:8080/auth";
doReturn(buildHref(authUrl)).when(oauth2Client).getAuthorizationUrl(anyMap(), any());
URI uri = service.getAuthorizationRequestUri(new HashMap<>(), parameters);
assertThat(uri).isEqualTo(URI.create(authUrl));
}
@Test
void getAuthorizationRequestUriWithException() throws IOException {
HashMap<String, String> headers = new HashMap<>();
Oauth2Service.Parameters parameters = new Oauth2Service.Parameters();
doReturn(buildHref("blablabla_unexisting_uri@2#^"))
.when(oauth2Client)
.getAuthorizationUrl(anyMap(), any());
assertThrows(IOException.class, () -> service.getAuthorizationRequestUri(headers, parameters));
}
private HrefType buildHref(String authUrl) {
HrefType hrefType = new HrefType();
hrefType.setHref(authUrl);
return hrefType;
}
@Test
void getToken() throws IOException {
Oauth2Service.Parameters parameters = new Oauth2Service.Parameters();
String accessToken = "access-token";
String tokenType = "token-type";
long expires = 60L;
String scope = "test-scope";
String refreshToken = "refresh-token";
TokenResponseTO tokenTO = new TokenResponseTO();
tokenTO.setAccessToken(accessToken);
tokenTO.setTokenType(tokenType);
tokenTO.setExpiresInSeconds(expires);
tokenTO.setRefreshToken(refreshToken);
tokenTO.setScope(scope);
doReturn(tokenTO).when(oauth2Client).getToken(anyMap(), any());
TokenResponse token = service.getToken(new HashMap<>(), parameters);
assertThat(token.getAccessToken()).isEqualTo(accessToken);
assertThat(token.getRefreshToken()).isEqualTo(refreshToken);
assertThat(token.getTokenType()).isEqualTo(tokenType);
assertThat(token.getExpiresInSeconds()).isEqualTo(expires);
assertThat(token.getScope()).isEqualTo(scope);
}
}
| 3,910 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
RemotePaymentInitiationServiceWireMockTest.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/test/java/de/adorsys/xs2a/adapter/remote/RemotePaymentInitiationServiceWireMockTest.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote;
import com.github.tomakehurst.wiremock.WireMockServer;
import de.adorsys.xs2a.adapter.api.RequestHeaders;
import de.adorsys.xs2a.adapter.api.RequestParams;
import de.adorsys.xs2a.adapter.api.Response;
import de.adorsys.xs2a.adapter.api.model.ExecutionRule;
import de.adorsys.xs2a.adapter.api.model.PaymentProduct;
import de.adorsys.xs2a.adapter.api.model.PeriodicPaymentInitiationMultipartBody;
import de.adorsys.xs2a.adapter.api.model.PeriodicPaymentInitiationXmlPart2StandingorderTypeJson;
import de.adorsys.xs2a.adapter.impl.http.wiremock.WiremockHttpClient;
import de.adorsys.xs2a.tpp.TppApplication;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
@SpringBootTest(classes = {TppApplication.class}, webEnvironment = NONE)
class RemotePaymentInitiationServiceWireMockTest {
@Autowired
RemotePaymentInitiationService remotePaymentInitiationService;
private static WireMockServer wireMockServer;
@BeforeAll
static void beforeAll() {
int port = WiremockHttpClient.randomPort();
System.setProperty("xs2a-adapter.url", "http://localhost:" + port);
wireMockServer = new WireMockServer(wireMockConfig().port(port));
wireMockServer.start();
configureFor(wireMockServer.port());
stubFor(get(urlEqualTo("/v1/periodic-payments/pain.001-sepa-credit-transfers/payment-id"))
.willReturn(aResponse().withStatus(200)
.withHeader("Content-Type", "multipart/form-data; boundary=-")
.withBody("---\r\n" +
"Content-Disposition: form-data; name=\"json_standingorderType\"\r\n" +
"Content-Type: application/json\r\n\r\n" +
"{\"executionRule\":\"following\"}\r\n" +
"---\r\n" +
"Content-Disposition: form-data; name=\"xml_sct\"\r\n" +
"Content-Type: application/xml\r\n\r\n" +
"<xml>\r\n" +
"-----\r\n")));
}
@AfterAll
static void afterAll() {
wireMockServer.stop();
}
@Test
void getPeriodicPain001PaymentInformation() {
Response<PeriodicPaymentInitiationMultipartBody> response =
remotePaymentInitiationService.getPeriodicPain001PaymentInformation(
PaymentProduct.PAIN_001_SEPA_CREDIT_TRANSFERS,
"payment-id",
RequestHeaders.empty(),
RequestParams.empty());
PeriodicPaymentInitiationMultipartBody expected = new PeriodicPaymentInitiationMultipartBody();
expected.setXml_sct("<xml>");
PeriodicPaymentInitiationXmlPart2StandingorderTypeJson json =
new PeriodicPaymentInitiationXmlPart2StandingorderTypeJson();
json.setExecutionRule(ExecutionRule.FOLLOWING);
expected.setJson_standingorderType(json);
assertThat(response.getBody()).isEqualTo(expected);
}
}
| 4,257 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
ResponseHeadersMapperTest.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/test/java/de/adorsys/xs2a/adapter/remote/mapper/ResponseHeadersMapperTest.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote.mapper;
import de.adorsys.xs2a.adapter.api.ResponseHeaders;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import org.springframework.http.HttpHeaders;
import java.util.Collections;
import static de.adorsys.xs2a.adapter.api.ResponseHeaders.*;
import static org.assertj.core.api.Assertions.assertThat;
class ResponseHeadersMapperTest {
@Test
void getHeaders() {
ResponseHeadersMapper mapper = Mappers.getMapper(ResponseHeadersMapper.class);
String json = "application/json";
String location = "/v1/consents/123456";
String xRequestId = "1234567";
String scaApproach = "embedded";
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.put(CONTENT_TYPE, Collections.singletonList(json));
httpHeaders.put(LOCATION, Collections.singletonList(location));
httpHeaders.put(X_REQUEST_ID, Collections.singletonList(xRequestId));
httpHeaders.put(ASPSP_SCA_APPROACH, Collections.singletonList(scaApproach));
ResponseHeaders headers = mapper.getHeaders(httpHeaders);
assertThat(headers.getHeadersMap()).hasSize(4);
assertThat(headers.getHeader(CONTENT_TYPE)).isEqualTo(json);
assertThat(headers.getHeader(LOCATION)).isEqualTo(location);
assertThat(headers.getHeader(X_REQUEST_ID)).isEqualTo(xRequestId);
assertThat(headers.getHeader(ASPSP_SCA_APPROACH)).isEqualTo(scaApproach);
}
}
| 2,316 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
RemoteEmbeddedPreAuthorisationService.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/RemoteEmbeddedPreAuthorisationService.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote;
import de.adorsys.xs2a.adapter.api.EmbeddedPreAuthorisationService;
import de.adorsys.xs2a.adapter.api.RequestHeaders;
import de.adorsys.xs2a.adapter.api.model.EmbeddedPreAuthorisationRequest;
import de.adorsys.xs2a.adapter.api.model.TokenResponse;
import de.adorsys.xs2a.adapter.mapper.EmbeddedPreAuthorisationMapper;
import de.adorsys.xs2a.adapter.mapper.Oauth2Mapper;
import de.adorsys.xs2a.adapter.remote.client.EmbeddedPreAuthorisationClient;
import de.adorsys.xs2a.adapter.rest.api.model.TokenResponseTO;
import org.mapstruct.factory.Mappers;
public class RemoteEmbeddedPreAuthorisationService implements EmbeddedPreAuthorisationService {
private final EmbeddedPreAuthorisationClient client;
private final Oauth2Mapper oauth2Mapper = Mappers.getMapper(Oauth2Mapper.class);
private final EmbeddedPreAuthorisationMapper embeddedPreAuthorisationMapper = Mappers.getMapper(EmbeddedPreAuthorisationMapper.class);
public RemoteEmbeddedPreAuthorisationService(EmbeddedPreAuthorisationClient client) {
this.client = client;
}
@Override
public TokenResponse getToken(EmbeddedPreAuthorisationRequest request, RequestHeaders requestHeaders) {
TokenResponseTO responseTO
= client.getToken(requestHeaders.toMap(), embeddedPreAuthorisationMapper.toEmbeddedPreAuthorisationRequestTO(request));
return oauth2Mapper.toTokenResponse(responseTO);
}
}
| 2,281 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
RemoteAccountInformationService.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/RemoteAccountInformationService.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import de.adorsys.xs2a.adapter.api.AccountInformationService;
import de.adorsys.xs2a.adapter.api.RequestHeaders;
import de.adorsys.xs2a.adapter.api.RequestParams;
import de.adorsys.xs2a.adapter.api.Response;
import de.adorsys.xs2a.adapter.api.exception.NotAcceptableException;
import de.adorsys.xs2a.adapter.api.model.*;
import de.adorsys.xs2a.adapter.remote.client.AccountInformationClient;
import de.adorsys.xs2a.adapter.remote.mapper.ResponseHeadersMapper;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.factory.Mappers;
import org.springframework.http.ResponseEntity;
import java.io.IOException;
import java.time.LocalDate;
import java.util.Map;
public class RemoteAccountInformationService implements AccountInformationService {
private final AccountInformationClient client;
private final ResponseHeadersMapper responseHeadersMapper =
Mappers.getMapper(ResponseHeadersMapper.class);
final ObjectMapper objectMapper;
public RemoteAccountInformationService(
AccountInformationClient client, ObjectMapper objectMapper
) {
this.client = client;
this.objectMapper = objectMapper;
}
public RemoteAccountInformationService(AccountInformationClient client) {
this.client = client;
this.objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
@Override
public Response<ConsentsResponse201> createConsent(RequestHeaders requestHeaders,
RequestParams requestParams,
Consents consents) {
ResponseEntity<ConsentsResponse201> responseEntity = client.createConsent(requestParams.toMap(),
requestHeaders.toMap(),
consents);
return new Response<>(
responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<ConsentInformationResponse200Json> getConsentInformation(String consentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<ConsentInformationResponse200Json> responseEntity =
client.getConsentInformation(consentId, requestParams.toMap(), requestHeaders.toMap());
return new Response<>(
responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<Void> deleteConsent(String consentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<Void> responseEntity =
client.deleteConsent(consentId, requestParams.toMap(), requestHeaders.toMap());
return new Response<>(
responseEntity.getStatusCodeValue(),
null,
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<ConsentStatusResponse200> getConsentStatus(String consentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<ConsentStatusResponse200> responseEntity =
client.getConsentStatus(consentId, requestParams.toMap(), requestHeaders.toMap());
return new Response<>(
responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<Authorisations> getConsentAuthorisation(String consentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<Authorisations> responseEntity =
client.getConsentAuthorisation(consentId,
requestParams.toMap(),
requestHeaders.toMap());
return new Response<>(
responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<StartScaprocessResponse> startConsentAuthorisation(String consentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<StartScaprocessResponse> responseEntity =
client.startConsentAuthorisation(consentId,
requestParams.toMap(),
requestHeaders.toMap(),
createEmptyBody());
return new Response<>(
responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
private ObjectNode createEmptyBody() {
return new ObjectNode(JsonNodeFactory.instance);
}
@Override
public Response<StartScaprocessResponse> startConsentAuthorisation(String consentId,
RequestHeaders requestHeaders,
RequestParams requestParams,
UpdatePsuAuthentication updatePsuAuthentication) {
ResponseEntity<StartScaprocessResponse> responseEntity =
client.startConsentAuthorisation(consentId,
requestParams.toMap(),
requestHeaders.toMap(),
objectMapper.valueToTree(updatePsuAuthentication));
return new Response<>(
responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<SelectPsuAuthenticationMethodResponse> updateConsentsPsuData(String consentId,
String authorisationId,
RequestHeaders requestHeaders,
RequestParams requestParams,
SelectPsuAuthenticationMethod selectPsuAuthenticationMethod) {
ResponseEntity<Object> responseEntity = client.updateConsentsPsuData(
consentId,
authorisationId,
requestParams.toMap(),
requestHeaders.toMap(),
objectMapper.valueToTree(selectPsuAuthenticationMethod)
);
SelectPsuAuthenticationMethodResponse selectPsuAuthenticationMethodResponse =
objectMapper.convertValue(
responseEntity.getBody(),
SelectPsuAuthenticationMethodResponse.class
);
return new Response<>(
responseEntity.getStatusCodeValue(),
selectPsuAuthenticationMethodResponse,
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<ScaStatusResponse> updateConsentsPsuData(
String consentId,
String authorisationId,
RequestHeaders requestHeaders,
RequestParams requestParams,
TransactionAuthorisation transactionAuthorisation
) {
ResponseEntity<Object> responseEntity = client.updateConsentsPsuData(
consentId,
authorisationId,
requestParams.toMap(),
requestHeaders.toMap(),
objectMapper.valueToTree(transactionAuthorisation)
);
ScaStatusResponse scaStatusResponse =
objectMapper.convertValue(responseEntity.getBody(), ScaStatusResponse.class);
return new Response<>(
responseEntity.getStatusCodeValue(),
scaStatusResponse,
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<UpdatePsuAuthenticationResponse> updateConsentsPsuData(
String consentId,
String authorisationId,
RequestHeaders requestHeaders,
RequestParams requestParams,
UpdatePsuAuthentication updatePsuAuthentication
) {
ResponseEntity<Object> responseEntity = client.updateConsentsPsuData(
consentId,
authorisationId,
requestParams.toMap(),
requestHeaders.toMap(),
objectMapper.valueToTree(updatePsuAuthentication)
);
UpdatePsuAuthenticationResponse updatePsuAuthenticationResponse = objectMapper.convertValue(
responseEntity.getBody(),
UpdatePsuAuthenticationResponse.class
);
return new Response<>(
responseEntity.getStatusCodeValue(),
updatePsuAuthenticationResponse,
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<AccountList> getAccountList(
RequestHeaders requestHeaders,
RequestParams requestParams
) {
String withBalance = requestParams.toMap().getOrDefault(
RequestParams.WITH_BALANCE,
Boolean.FALSE.toString()
);
ResponseEntity<AccountList> responseEntity = client.getAccountList(
Boolean.valueOf(withBalance),
requestHeaders.toMap()
);
return new Response<>(
responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<OK200AccountDetails> readAccountDetails(
String accountId,
RequestHeaders requestHeaders,
RequestParams requestParams
) {
String withBalance = requestParams.toMap().getOrDefault(
RequestParams.WITH_BALANCE,
Boolean.FALSE.toString()
);
ResponseEntity<OK200AccountDetails> responseEntity = client.readAccountDetails(
accountId,
Boolean.valueOf(withBalance),
requestHeaders.toMap()
);
return new Response<>(
responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<TransactionsResponse200Json> getTransactionList(
String accountId,
RequestHeaders requestHeaders,
RequestParams requestParams
) {
if (!requestHeaders.isAcceptJson()) {
throw new NotAcceptableException(
"Unsupported accept type: " + requestHeaders.get(RequestHeaders.ACCEPT)
);
}
ResponseEntity<String> responseEntity = getTransactionListFromClient(
accountId,
requestParams,
requestHeaders
);
TransactionsResponse200Json transactionsResponse = null;
try {
transactionsResponse = objectMapper.readValue(
responseEntity.getBody(),
TransactionsResponse200Json.class
);
} catch (IOException e) {
throw new Xs2aAdapterClientParseException(e);
}
return new Response<>(
responseEntity.getStatusCodeValue(),
transactionsResponse,
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<OK200TransactionDetails> getTransactionDetails(String accountId,
String transactionId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<OK200TransactionDetails> response = client.getTransactionDetails(accountId,
transactionId,
requestParams.toMap(),
requestHeaders.toMap());
return new Response<>(response.getStatusCodeValue(),
response.getBody(),
responseHeadersMapper.getHeaders(response.getHeaders()));
}
private ResponseEntity<String> getTransactionListFromClient(
String accountId,
RequestParams requestParams,
RequestHeaders requestHeaders
) {
Map<String, String> requestParamMap = requestParams.toMap();
LocalDate dateFrom = strToLocalDate(requestParamMap.get(RequestParams.DATE_FROM));
LocalDate dateTo = strToLocalDate(requestParamMap.get(RequestParams.DATE_TO));
String entryReferenceFrom = requestParamMap.get(RequestParams.ENTRY_REFERENCE_FROM);
BookingStatusGeneric bookingStatus = BookingStatusGeneric.fromValue(
requestParamMap.get(RequestParams.BOOKING_STATUS)
);
Boolean deltaList = Boolean.valueOf(requestParamMap.get(RequestParams.DELTA_LIST));
Boolean withBalance = Boolean.valueOf(requestParamMap.get(RequestParams.WITH_BALANCE));
return client.getTransactionListAsString(
accountId,
dateFrom,
dateTo,
entryReferenceFrom,
bookingStatus,
deltaList,
withBalance,
requestHeaders.toMap()
);
}
@Override
public Response<String> getTransactionListAsString(
String accountId, RequestHeaders requestHeaders, RequestParams requestParams
) {
ResponseEntity<String> responseEntity = getTransactionListFromClient(
accountId, requestParams, requestHeaders
);
String body = responseEntity.getBody();
if (requestHeaders.isAcceptJson()) {
TransactionsResponse200Json json = null;
try {
json = objectMapper.readValue(body, TransactionsResponse200Json.class);
body = objectMapper.writeValueAsString(json);
} catch (IOException e) {
throw new Xs2aAdapterClientParseException(e);
}
}
return new Response<>(
responseEntity.getStatusCodeValue(),
body,
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<ScaStatusResponse> getConsentScaStatus(String consentId,
String authorisationId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<ScaStatusResponse> responseEntity =
client.getConsentScaStatus(consentId, authorisationId, requestParams.toMap(), requestHeaders.toMap());
return new Response<>(
responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<ReadAccountBalanceResponse200> getBalances(String accountId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<ReadAccountBalanceResponse200> responseEntity =
client.getBalances(accountId, requestParams.toMap(), requestHeaders.toMap());
return new Response<>(
responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders())
);
}
@Override
public Response<CardAccountList> getCardAccountList(RequestHeaders requestHeaders, RequestParams requestParams) {
ResponseEntity<CardAccountList> responseEntity =
client.getCardAccount(requestParams.toMap(), requestHeaders.toMap());
return new Response<>(responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<OK200CardAccountDetails> getCardAccountDetails(String accountId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<OK200CardAccountDetails> responseEntity =
client.ReadCardAccount(accountId, requestParams.toMap(), requestHeaders.toMap());
return new Response<>(responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<ReadCardAccountBalanceResponse200> getCardAccountBalances(String accountId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<ReadCardAccountBalanceResponse200> responseEntity =
client.getCardAccountBalances(accountId, requestParams.toMap(), requestHeaders.toMap());
return new Response<>(responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<CardAccountsTransactionsResponse200> getCardAccountTransactionList(String accountId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<CardAccountsTransactionsResponse200> responseEntity =
client.getCardAccountTransactionList(accountId,
requestParams.dateFrom(),
requestParams.dateTo(),
requestParams.entryReferenceFrom(),
requestParams.bookingStatus() != null ? BookingStatusCard.fromValue(requestParams.bookingStatus()) : null,
requestParams.deltaList(),
requestParams.withBalance(),
requestParams.toMap(),
requestHeaders.toMap());
return new Response<>(responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
private LocalDate strToLocalDate(String date) {
if (StringUtils.isNotBlank(date)) {
try {
return LocalDate.parse(date);
} catch (Exception e) {
throw new Xs2aAdapterClientParseException(e);
}
}
return null;
}
}
| 21,042 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
RemotePaymentInitiationService.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/RemotePaymentInitiationService.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import de.adorsys.xs2a.adapter.api.PaymentInitiationService;
import de.adorsys.xs2a.adapter.api.RequestHeaders;
import de.adorsys.xs2a.adapter.api.RequestParams;
import de.adorsys.xs2a.adapter.api.Response;
import de.adorsys.xs2a.adapter.api.model.*;
import de.adorsys.xs2a.adapter.remote.client.PaymentInitiationClient;
import de.adorsys.xs2a.adapter.remote.mapper.ResponseHeadersMapper;
import org.mapstruct.factory.Mappers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
public class RemotePaymentInitiationService implements PaymentInitiationService {
private static final Logger log = LoggerFactory.getLogger(RemotePaymentInitiationService.class);
private final PaymentInitiationClient client;
private final ObjectMapper objectMapper;
private final ResponseHeadersMapper responseHeadersMapper = Mappers.getMapper(ResponseHeadersMapper.class);
public RemotePaymentInitiationService(PaymentInitiationClient paymentInitiationClient) {
this(paymentInitiationClient, new ObjectMapper());
}
public RemotePaymentInitiationService(PaymentInitiationClient paymentInitiationClient, ObjectMapper objectMapper) {
this.client = paymentInitiationClient;
this.objectMapper = objectMapper;
}
@Override
public Response<PaymentInitationRequestResponse201> initiatePayment(PaymentService paymentService,
PaymentProduct paymentProduct,
RequestHeaders requestHeaders,
RequestParams requestParams,
Object o) {
ResponseEntity<PaymentInitationRequestResponse201> responseEntity;
if (o instanceof String) {
responseEntity = client.initiatePayment(
paymentService,
paymentProduct,
requestParams.toMap(),
requestHeaders.toMap(),
(String) o
);
} else if (o instanceof PeriodicPaymentInitiationMultipartBody) {
PeriodicPaymentInitiationMultipartBody body = (PeriodicPaymentInitiationMultipartBody) o;
responseEntity = client.initiatePayment(
paymentService,
paymentProduct,
requestParams.toMap(),
requestHeaders.toMap(),
body
);
} else {
responseEntity = client.initiatePayment(
paymentService,
paymentProduct,
requestParams.toMap(),
requestHeaders.toMap(),
objectMapper.valueToTree(o)
);
}
return new Response<>(responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<PaymentInitiationWithStatusResponse> getSinglePaymentInformation(PaymentProduct paymentProduct,
String paymentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<Object> responseEntity = client.getPaymentInformation(
PaymentService.PAYMENTS,
paymentProduct,
paymentId,
requestParams.toMap(),
requestHeaders.toMap()
);
PaymentInitiationWithStatusResponse response =
objectMapper.convertValue(responseEntity.getBody(), PaymentInitiationWithStatusResponse.class);
return new Response<>(responseEntity.getStatusCodeValue(),
response,
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<PeriodicPaymentInitiationWithStatusResponse> getPeriodicPaymentInformation(PaymentProduct paymentProduct,
String paymentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<Object> responseEntity = client.getPaymentInformation(
PaymentService.PERIODIC_PAYMENTS,
paymentProduct,
paymentId,
requestParams.toMap(),
requestHeaders.toMap()
);
PeriodicPaymentInitiationWithStatusResponse response = objectMapper.convertValue(responseEntity.getBody(),
PeriodicPaymentInitiationWithStatusResponse.class);
return new Response<>(responseEntity.getStatusCodeValue(), response,
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<PeriodicPaymentInitiationMultipartBody> getPeriodicPain001PaymentInformation(PaymentProduct paymentProduct,
String paymentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<Object> responseEntity = client.getPaymentInformation(
PaymentService.PERIODIC_PAYMENTS,
paymentProduct,
paymentId,
requestParams.toMap(),
requestHeaders.toMap()
);
return new Response<>(responseEntity.getStatusCodeValue(),
(PeriodicPaymentInitiationMultipartBody) responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<String> getPaymentInformationAsString(PaymentService paymentService,
PaymentProduct paymentProduct,
String paymentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<Object> responseEntity = client.getPaymentInformation(
paymentService,
paymentProduct,
paymentId,
requestParams.toMap(),
requestHeaders.toMap());
return new Response<>(responseEntity.getStatusCodeValue(),
(String) responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<ScaStatusResponse> getPaymentInitiationScaStatus(PaymentService paymentService,
PaymentProduct spaymentProduct,
String paymentId,
String authorisationId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<ScaStatusResponse> responseEntity = client.getPaymentInitiationScaStatus(
paymentService,
spaymentProduct,
paymentId,
authorisationId,
requestParams.toMap(),
requestHeaders.toMap());
return new Response<>(responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<PaymentInitiationStatusResponse200Json> getPaymentInitiationStatus(PaymentService paymentService,
PaymentProduct paymentProduct,
String paymentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<Object> responseEntity = client.getPaymentInitiationStatus(
paymentService,
paymentProduct,
paymentId,
requestParams.toMap(),
requestHeaders.toMap());
PaymentInitiationStatusResponse200Json response =
objectMapper.convertValue(responseEntity.getBody(), PaymentInitiationStatusResponse200Json.class);
return new Response<>(responseEntity.getStatusCodeValue(),
response,
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<String> getPaymentInitiationStatusAsString(PaymentService paymentService,
PaymentProduct paymentProduct,
String paymentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<Object> responseEntity = client.getPaymentInitiationStatus(
paymentService,
paymentProduct,
paymentId,
requestParams.toMap(),
requestHeaders.toMap());
try {
String responseObject = objectMapper.writeValueAsString(responseEntity.getBody());
return new Response<>(responseEntity.getStatusCodeValue(), responseObject, responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
} catch (JsonProcessingException e) {
log.error("Failed to convert the response body into a string", e);
}
return new Response<>(responseEntity.getStatusCodeValue(), "{}", responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<Authorisations> getPaymentInitiationAuthorisation(PaymentService paymentService,
PaymentProduct paymentProduct,
String paymentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<Authorisations> responseEntity = client.getPaymentInitiationAuthorisation(
paymentService,
paymentProduct,
paymentId,
requestParams.toMap(),
requestHeaders.toMap());
return new Response<>(responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<StartScaprocessResponse> startPaymentAuthorisation(PaymentService paymentService,
PaymentProduct paymentProduct,
String paymentId,
RequestHeaders requestHeaders,
RequestParams requestParams) {
ResponseEntity<StartScaprocessResponse> responseEntity = client.startPaymentAuthorisation(
paymentService,
paymentProduct,
paymentId,
requestParams.toMap(),
requestHeaders.toMap(),
new ObjectNode(JsonNodeFactory.instance));
return new Response<>(responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<StartScaprocessResponse> startPaymentAuthorisation(PaymentService paymentService,
PaymentProduct paymentProduct,
String paymentId,
RequestHeaders requestHeaders,
RequestParams requestParams,
UpdatePsuAuthentication updatePsuAuthentication) {
ResponseEntity<StartScaprocessResponse> responseEntity = client.startPaymentAuthorisation(
paymentService,
paymentProduct,
paymentId,
requestParams.toMap(),
requestHeaders.toMap(),
objectMapper.valueToTree(updatePsuAuthentication)
);
return new Response<>(responseEntity.getStatusCodeValue(),
responseEntity.getBody(),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<SelectPsuAuthenticationMethodResponse> updatePaymentPsuData(PaymentService paymentService,
PaymentProduct paymentProduct,
String paymentId,
String authorisationId,
RequestHeaders requestHeaders,
RequestParams requestParams,
SelectPsuAuthenticationMethod selectPsuAuthenticationMethod) {
ResponseEntity<Object> responseEntity = client.updatePaymentPsuData(
paymentService,
paymentProduct,
paymentId,
authorisationId,
requestParams.toMap(),
requestHeaders.toMap(),
objectMapper.valueToTree(selectPsuAuthenticationMethod));
return new Response<>(responseEntity.getStatusCodeValue(),
objectMapper.convertValue(responseEntity.getBody(), SelectPsuAuthenticationMethodResponse.class),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<ScaStatusResponse> updatePaymentPsuData(PaymentService paymentService,
PaymentProduct paymentProduct,
String paymentId,
String authorisationId,
RequestHeaders requestHeaders,
RequestParams requestParams,
TransactionAuthorisation transactionAuthorisation) {
ResponseEntity<Object> responseEntity = client.updatePaymentPsuData(
paymentService,
paymentProduct,
paymentId, authorisationId,
requestParams.toMap(),
requestHeaders.toMap(),
objectMapper.valueToTree(transactionAuthorisation));
return new Response<>(responseEntity.getStatusCodeValue(),
objectMapper.convertValue(responseEntity.getBody(), ScaStatusResponse.class),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
@Override
public Response<UpdatePsuAuthenticationResponse> updatePaymentPsuData(PaymentService paymentService,
PaymentProduct paymentProduct,
String paymentId,
String authorisationId,
RequestHeaders requestHeaders,
RequestParams requestParams,
UpdatePsuAuthentication updatePsuAuthentication) {
ResponseEntity<Object> responseEntity = client.updatePaymentPsuData(
paymentService,
paymentProduct,
paymentId, authorisationId,
requestParams.toMap(),
requestHeaders.toMap(),
objectMapper.valueToTree(updatePsuAuthentication));
return new Response<>(responseEntity.getStatusCodeValue(),
objectMapper.convertValue(responseEntity.getBody(), UpdatePsuAuthenticationResponse.class),
responseHeadersMapper.getHeaders(responseEntity.getHeaders()));
}
}
| 18,608 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
RemoteOauth2Service.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/RemoteOauth2Service.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote;
import de.adorsys.xs2a.adapter.api.Oauth2Service;
import de.adorsys.xs2a.adapter.api.model.TokenResponse;
import de.adorsys.xs2a.adapter.mapper.Oauth2Mapper;
import de.adorsys.xs2a.adapter.remote.client.Oauth2Client;
import org.mapstruct.factory.Mappers;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
public class RemoteOauth2Service implements Oauth2Service {
private final Oauth2Client oauth2Client;
private final Oauth2Mapper oauth2Mapper = Mappers.getMapper(Oauth2Mapper.class);
public RemoteOauth2Service(Oauth2Client oauth2Client) {
this.oauth2Client = oauth2Client;
}
@Override
public URI getAuthorizationRequestUri(Map<String, String> headers, Parameters parameters) throws IOException {
try {
return new URI(this.oauth2Client.getAuthorizationUrl(headers, parameters.asMap()).getHref());
} catch (URISyntaxException e) {
throw new IOException(e);
}
}
@Override
public TokenResponse getToken(Map<String, String> headers, Parameters parameters) throws IOException {
return this.oauth2Mapper.toTokenResponse(this.oauth2Client.getToken(headers, parameters.asMap()));
}
}
| 2,118 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
Xs2aAdapterClientParseException.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/Xs2aAdapterClientParseException.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote;
public class Xs2aAdapterClientParseException extends RuntimeException {
public Xs2aAdapterClientParseException(Throwable cause) {
super(cause);
}
}
| 1,035 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
ResponseHeadersMapper.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/mapper/ResponseHeadersMapper.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote.mapper;
import de.adorsys.xs2a.adapter.api.ResponseHeaders;
import org.mapstruct.Mapper;
import org.springframework.http.HttpHeaders;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Mapper
public interface ResponseHeadersMapper {
default ResponseHeaders getHeaders(HttpHeaders httpHeaders) {
Set<Map.Entry<String, List<String>>> entrySet = httpHeaders.entrySet();
Map<String, String> headers = new HashMap<>(entrySet.size());
for (Map.Entry<String, List<String>> entry : entrySet) {
List<String> value = entry.getValue();
if (value != null && !value.isEmpty()) {
headers.put(entry.getKey(), value.get(0));
}
}
return ResponseHeaders.fromMap(headers);
}
}
| 1,674 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
FeignConfiguration.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/config/FeignConfiguration.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.adorsys.xs2a.adapter.api.ResponseHeaders;
import de.adorsys.xs2a.adapter.api.http.ContentType;
import de.adorsys.xs2a.adapter.api.http.HttpLogSanitizer;
import de.adorsys.xs2a.adapter.api.model.BookingStatusCard;
import de.adorsys.xs2a.adapter.api.model.BookingStatusGeneric;
import de.adorsys.xs2a.adapter.api.model.PaymentProduct;
import de.adorsys.xs2a.adapter.api.model.PaymentService;
import de.adorsys.xs2a.adapter.api.model.PeriodicPaymentInitiationMultipartBody;
import de.adorsys.xs2a.adapter.impl.http.ResponseHandlers;
import de.adorsys.xs2a.adapter.impl.http.Xs2aHttpLogSanitizer;
import de.adorsys.xs2a.adapter.rest.impl.config.PeriodicPaymentInitiationMultipartBodyHttpMessageConverter;
import feign.Contract;
import feign.RequestTemplate;
import feign.Response;
import feign.codec.Decoder;
import feign.codec.EncodeException;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import feign.optionals.OptionalDecoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.ResponseEntityDecoder;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static de.adorsys.xs2a.adapter.api.RequestHeaders.CONTENT_TYPE;
@Configuration
public class FeignConfiguration {
@Value("${xs2a-adapter.sanitizer.whitelist:recurringIndicator,validUntil,frequencyPerDay,combinedServiceIndicator}")
private List<String> whitelist;
@Bean
HttpLogSanitizer httpLogSanitizer() {
return new Xs2aHttpLogSanitizer(whitelist);
}
@Bean
public Contract feignContract() {
return new SpringMvcContract(Collections.emptyList(), new CustomConversionService());
}
public static class CustomConversionService extends DefaultConversionService {
public CustomConversionService() {
addConverter(new Converter<BookingStatusGeneric, String>() {
@Override
public String convert(BookingStatusGeneric source) {
return source.toString();
}
});
addConverter(new Converter<BookingStatusCard, String>() {
@Override
public String convert(BookingStatusCard source) {
return source.toString();
}
});
addConverter(new Converter<PaymentProduct, String>() {
@Override
public String convert(PaymentProduct source) {
return source.toString();
}
});
addConverter(new Converter<PaymentService, String>() {
@Override
public String convert(PaymentService source) {
return source.toString();
}
});
}
}
@Bean
Encoder encoder(ObjectFactory<HttpMessageConverters> messageConverters, ObjectMapper objectMapper) {
PeriodicPaymentInitiationMultipartBodyHttpMessageConverter httpMessageConverter =
new PeriodicPaymentInitiationMultipartBodyHttpMessageConverter(objectMapper);
return new SpringEncoder(new SpringFormEncoder() {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
if (!(object instanceof PeriodicPaymentInitiationMultipartBody)) {
super.encode(object, bodyType, template);
return;
}
BufferingOutputMessage outputMessage = new BufferingOutputMessage();
try {
httpMessageConverter.write((PeriodicPaymentInitiationMultipartBody) object,
MediaType.MULTIPART_FORM_DATA,
outputMessage);
} catch (IOException e) {
throw new EncodeException(e.getMessage(), e);
}
template.body(outputMessage.getOutputStream().toByteArray(), StandardCharsets.UTF_8);
template.removeHeader(HttpHeaders.CONTENT_TYPE);
template.header(HttpHeaders.CONTENT_TYPE, outputMessage.getHeaders().getContentType().toString());
}
}, messageConverters);
}
private static final class BufferingOutputMessage implements HttpOutputMessage {
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
private final HttpHeaders httpHeaders = new HttpHeaders();
@Override
public OutputStream getBody() throws IOException {
return this.outputStream;
}
@Override
public HttpHeaders getHeaders() {
return this.httpHeaders;
}
public ByteArrayOutputStream getOutputStream() {
return this.outputStream;
}
}
@Bean
public Decoder decoder(ObjectFactory<HttpMessageConverters> messageConverters, HttpLogSanitizer logSanitizer) {
return new OptionalDecoder(
new ResponseEntityDecoder(new SpringDecoder(messageConverters) {
@Override
public Object decode(Response response, Type type) throws IOException {
Collection<String> contentTypeValues = response.headers().get(CONTENT_TYPE);
String contentType = null;
if (contentTypeValues != null) {
contentType = contentTypeValues.stream().findFirst().orElse(null);
}
if (contentType != null && contentType.startsWith(ContentType.MULTIPART_FORM_DATA)) {
return new ResponseHandlers(logSanitizer).multipartFormDataResponseHandler(PeriodicPaymentInitiationMultipartBody.class)
.apply(response.status(),
response.body().asInputStream(),
ResponseHeaders.fromMap(Collections.singletonMap(CONTENT_TYPE, contentType)));
}
return super.decode(response, type);
}
}));
}
}
| 7,918 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
AspspClient.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/client/AspspClient.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote.client;
import de.adorsys.xs2a.adapter.rest.api.AspspSearchApi;
import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(value = "aspsp-client", url = "${xs2a-adapter.url}")
public interface AspspClient extends AspspSearchApi {
}
| 1,113 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
PaymentInitiationClient.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/client/PaymentInitiationClient.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote.client;
import de.adorsys.xs2a.adapter.rest.api.PaymentApi;
import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(value = "payment-initiation-client", url = "${xs2a-adapter.url}")
public interface PaymentInitiationClient extends PaymentApi {
}
| 1,130 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
AccountInformationClient.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/client/AccountInformationClient.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote.client;
import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(value = "account-information-client", url = "${xs2a-adapter.url}")
public interface AccountInformationClient extends AccountApi {
}
| 1,080 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
AccountApi.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/client/AccountApi.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote.client;
import com.fasterxml.jackson.databind.node.ObjectNode;
import de.adorsys.xs2a.adapter.api.model.*;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.Map;
//todo: remove it after the task https://git.adorsys.de/xs2a-gateway/xs2a-gateway/issues/325 will be completed
interface AccountApi {
@RequestMapping(
value = "/v1/consents",
method = RequestMethod.POST,
consumes = "application/json"
)
ResponseEntity<ConsentsResponse201> createConsent(
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers,
@RequestBody Consents body);
@RequestMapping(
value = "/v1/consents/{consentId}",
method = RequestMethod.GET
)
ResponseEntity<ConsentInformationResponse200Json> getConsentInformation(
@PathVariable("consentId") String consentId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/consents/{consentId}",
method = RequestMethod.DELETE
)
ResponseEntity<Void> deleteConsent(
@PathVariable("consentId") String consentId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/consents/{consentId}/status",
method = RequestMethod.GET
)
ResponseEntity<ConsentStatusResponse200> getConsentStatus(
@PathVariable("consentId") String consentId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/consents/{consentId}/authorisations",
method = RequestMethod.GET
)
ResponseEntity<Authorisations> getConsentAuthorisation(
@PathVariable("consentId") String consentId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/consents/{consentId}/authorisations",
method = RequestMethod.POST,
consumes = "application/json"
)
ResponseEntity<StartScaprocessResponse> startConsentAuthorisation(
@PathVariable("consentId") String consentId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers,
@RequestBody ObjectNode body);
@RequestMapping(
value = "/v1/consents/{consentId}/authorisations/{authorisationId}",
method = RequestMethod.GET
)
ResponseEntity<ScaStatusResponse> getConsentScaStatus(
@PathVariable("consentId") String consentId,
@PathVariable("authorisationId") String authorisationId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/consents/{consentId}/authorisations/{authorisationId}",
method = RequestMethod.PUT,
consumes = "application/json"
)
ResponseEntity<Object> updateConsentsPsuData(
@PathVariable("consentId") String consentId,
@PathVariable("authorisationId") String authorisationId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers,
@RequestBody ObjectNode body);
@RequestMapping(
value = "/v1/accounts",
method = RequestMethod.GET
)
ResponseEntity<AccountList> getAccountList(
@RequestParam(value = "withBalance", required = false) Boolean withBalance,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/accounts/{account-id}",
method = RequestMethod.GET
)
ResponseEntity<OK200AccountDetails> readAccountDetails(
@PathVariable("account-id") String accountId,
@RequestParam(value = "withBalance", required = false) Boolean withBalance,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/accounts/{account-id}/balances",
method = RequestMethod.GET
)
ResponseEntity<ReadAccountBalanceResponse200> getBalances(
@PathVariable("account-id") String accountId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/accounts/{account-id}/transactions",
method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE}
)
ResponseEntity<TransactionsResponse200Json> getTransactionList(
@PathVariable("account-id") String accountId,
@RequestParam(value = "dateFrom", required = false) LocalDate dateFrom,
@RequestParam(value = "dateTo", required = false) LocalDate dateTo,
@RequestParam(value = "entryReferenceFrom", required = false) String entryReferenceFrom,
@RequestParam(value = "bookingStatus", required = true) BookingStatusGeneric bookingStatus,
@RequestParam(value = "deltaList", required = false) Boolean deltaList,
@RequestParam(value = "withBalance", required = false) Boolean withBalance,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/accounts/{account-id}/transactions",
method = RequestMethod.GET
)
ResponseEntity<String> getTransactionListAsString(
@PathVariable("account-id") String accountId,
@RequestParam(value = "dateFrom", required = false) LocalDate dateFrom,
@RequestParam(value = "dateTo", required = false) LocalDate dateTo,
@RequestParam(value = "entryReferenceFrom", required = false) String entryReferenceFrom,
@RequestParam(value = "bookingStatus", required = true) BookingStatusGeneric bookingStatus,
@RequestParam(value = "deltaList", required = false) Boolean deltaList,
@RequestParam(value = "withBalance", required = false) Boolean withBalance,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/accounts/{account-id}/transactions/{transactionId}",
method = RequestMethod.GET
)
ResponseEntity<OK200TransactionDetails> getTransactionDetails(
@PathVariable("account-id") String accountId,
@PathVariable("transactionId") String transactionId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/card-accounts",
method = RequestMethod.GET
)
ResponseEntity<CardAccountList> getCardAccount(
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/card-accounts/{account-id}",
method = RequestMethod.GET
)
ResponseEntity<OK200CardAccountDetails> ReadCardAccount(
@PathVariable("account-id") String accountId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/card-accounts/{account-id}/balances",
method = RequestMethod.GET
)
ResponseEntity<ReadCardAccountBalanceResponse200> getCardAccountBalances(
@PathVariable("account-id") String accountId,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
@RequestMapping(
value = "/v1/card-accounts/{account-id}/transactions",
method = RequestMethod.GET
)
ResponseEntity<CardAccountsTransactionsResponse200> getCardAccountTransactionList(
@PathVariable("account-id") String accountId,
@RequestParam(value = "dateFrom", required = false) LocalDate dateFrom,
@RequestParam(value = "dateTo", required = false) LocalDate dateTo,
@RequestParam(value = "entryReferenceFrom", required = false) String entryReferenceFrom,
@RequestParam(value = "bookingStatus", required = true) BookingStatusCard bookingStatus,
@RequestParam(value = "deltaList", required = false) Boolean deltaList,
@RequestParam(value = "withBalance", required = false) Boolean withBalance,
@RequestParam Map<String, String> parameters,
@RequestHeader Map<String, String> headers);
}
| 9,227 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
Oauth2Client.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/client/Oauth2Client.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote.client;
import de.adorsys.xs2a.adapter.rest.api.Oauth2Api;
import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(value = "oauth2-client", url = "${xs2a-adapter.url}")
public interface Oauth2Client extends Oauth2Api {
}
| 1,105 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
EmbeddedPreAuthorisationClient.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-service-remote/src/main/java/de/adorsys/xs2a/adapter/remote/client/EmbeddedPreAuthorisationClient.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.remote.client;
import de.adorsys.xs2a.adapter.rest.api.EmbeddedPreAuthorisationApi;
import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(value = "embedded-pre-authorisation-client", url = "${xs2a-adapter.url}")
public interface EmbeddedPreAuthorisationClient extends EmbeddedPreAuthorisationApi {
}
| 1,179 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
LuceneAspspRepositoryFactoryTest.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-aspsp-registry/src/test/java/de/adorsys/xs2a/adapter/registry/LuceneAspspRepositoryFactoryTest.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.registry;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class LuceneAspspRepositoryFactoryTest {
@Test
void newLuceneAspspRepository() {
LuceneAspspRepositoryFactory factory = new LuceneAspspRepositoryFactory();
LuceneAspspRepository repository = factory.newLuceneAspspRepository();
assertNotNull(repository);
}
}
| 1,270 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |
LuceneAspspRepositoryTest.java | /FileExtraction/Java_unseen/adorsys_xs2a-adapter/xs2a-adapter-aspsp-registry/src/test/java/de/adorsys/xs2a/adapter/registry/LuceneAspspRepositoryTest.java | /*
* Copyright 2018-2022 adorsys GmbH & Co KG
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*
* This project is also available under a separate commercial license. You can
* contact us at [email protected].
*/
package de.adorsys.xs2a.adapter.registry;
import de.adorsys.xs2a.adapter.api.AspspReadOnlyRepository;
import de.adorsys.xs2a.adapter.api.exception.IbanException;
import de.adorsys.xs2a.adapter.api.model.Aspsp;
import de.adorsys.xs2a.adapter.api.model.AspspScaApproach;
import org.apache.lucene.store.ByteBuffersDirectory;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.*;
class LuceneAspspRepositoryTest {
private static final String ASPSP_ID = "1";
private static final Integer SIZE = Integer.MAX_VALUE;
private static final String AFTER = "0";
private LuceneAspspRepository luceneAspspRepository = new LuceneAspspRepository(new ByteBuffersDirectory());
@Test
void deleteById() {
Aspsp aspsp = new Aspsp();
aspsp.setId(ASPSP_ID);
luceneAspspRepository.save(aspsp);
List<Aspsp> all = luceneAspspRepository.findAll(AspspReadOnlyRepository.DEFAULT_SIZE);
assertThat(all).hasSize(1);
luceneAspspRepository.deleteById(ASPSP_ID);
Optional<Aspsp> aspsp1 = luceneAspspRepository.findById(ASPSP_ID);
assertThat(aspsp1).isNotPresent();
}
@Test
void deleteAll() {
Aspsp aspsp1 = new Aspsp();
luceneAspspRepository.save(aspsp1);
Aspsp aspsp2 = new Aspsp();
luceneAspspRepository.save(aspsp2);
List<Aspsp> found = luceneAspspRepository.findAll();
assertThat(found).hasSize(2);
luceneAspspRepository.deleteAll();
found = luceneAspspRepository.findAll();
assertThat(found).isEmpty();
}
@Test
void saveCanHandleNullProperties() {
try {
luceneAspspRepository.save(new Aspsp());
} catch (Throwable e) {
fail("expect no exceptions");
}
}
@Test
void findByIdReturnsEmptyWhenIndexDoesntExist() {
Optional<Aspsp> found = new LuceneAspspRepository(new ByteBuffersDirectory()).findById("id");
assertThat(found).isEmpty();
}
@Test
void findById_NotFound() {
Optional<Aspsp> found = luceneAspspRepository.findById("id");
assertThat(found).isEmpty();
}
@Test
void findById_Found() {
Aspsp aspsp = new Aspsp();
aspsp.setId(ASPSP_ID);
luceneAspspRepository.save(aspsp);
Optional<Aspsp> found = luceneAspspRepository.findById(ASPSP_ID);
assertThat(found).get().hasFieldOrPropertyWithValue("id", ASPSP_ID);
}
@Test
void findByBic_NotFound() {
List<Aspsp> found = luceneAspspRepository.findByBic("bic");
assertThat(found).isEmpty();
}
@Test
void findByBic_Found() {
Aspsp aspsp1 = new Aspsp();
aspsp1.setBic("BIC1");
luceneAspspRepository.save(aspsp1);
Aspsp aspsp2 = new Aspsp();
aspsp2.setBic("BIC2");
luceneAspspRepository.save(aspsp2);
List<Aspsp> found = luceneAspspRepository.findByBic("BIC1");
assertThat(found).hasSize(1);
assertThat(found.get(0)).hasFieldOrPropertyWithValue("bic", "BIC1");
}
@Test
void findByBicUsesPrefixSearch() {
Aspsp aspsp1 = new Aspsp();
aspsp1.setBic("BIC1");
luceneAspspRepository.save(aspsp1);
Aspsp aspsp2 = new Aspsp();
aspsp2.setBic("BIC2");
luceneAspspRepository.save(aspsp2);
List<Aspsp> found = luceneAspspRepository.findByBic("BIC");
assertThat(found).hasSize(2);
}
@Test
void findByNameUsesPrefixSearch() {
Aspsp aspsp1 = new Aspsp();
aspsp1.setName("Sparkasse Nürnberg - Geschäftsstelle");
luceneAspspRepository.save(aspsp1);
Aspsp aspsp2 = new Aspsp();
aspsp2.setName("VR Bank Nürnberg");
luceneAspspRepository.save(aspsp2);
Aspsp aspsp3 = new Aspsp();
aspsp3.setName("Commerzbank");
luceneAspspRepository.save(aspsp3);
Iterable<Aspsp> found = luceneAspspRepository.findByName("nurnberg");
assertThat(found).hasSize(2);
}
@Test
void findAll() {
Aspsp aspsp1 = new Aspsp();
luceneAspspRepository.save(aspsp1);
Aspsp aspsp2 = new Aspsp();
luceneAspspRepository.save(aspsp2);
Aspsp aspsp3 = new Aspsp();
luceneAspspRepository.save(aspsp3);
Iterable<Aspsp> found = luceneAspspRepository.findAll();
assertThat(found).hasSize(3);
}
@Test
void findAllWithPageSize() {
Aspsp aspsp1 = new Aspsp();
luceneAspspRepository.save(aspsp1);
Aspsp aspsp2 = new Aspsp();
luceneAspspRepository.save(aspsp2);
Aspsp aspsp3 = new Aspsp();
luceneAspspRepository.save(aspsp3);
Iterable<Aspsp> found = luceneAspspRepository.findAll(2);
assertThat(found).hasSize(2);
}
@Test
void findAllWithPagination() {
Aspsp aspsp1 = new Aspsp();
luceneAspspRepository.save(aspsp1);
Aspsp aspsp2 = new Aspsp();
luceneAspspRepository.save(aspsp2);
Aspsp aspsp3 = new Aspsp();
luceneAspspRepository.save(aspsp3);
List<Aspsp> firstPage = luceneAspspRepository.findAll(2);
assertThat(firstPage).hasSize(2);
List<Aspsp> secondPage = luceneAspspRepository.findAll(firstPage.get(1).getPaginationId(), 2);
assertThat(secondPage).hasSize(1);
}
@Test
void findLike() {
Aspsp aspsp1 = new Aspsp();
aspsp1.setBic("ABCDEF");
luceneAspspRepository.save(aspsp1);
Aspsp aspsp2 = new Aspsp();
aspsp2.setBankCode("123446");
luceneAspspRepository.save(aspsp2);
Aspsp aspsp3 = new Aspsp();
aspsp3.setBic("ABC");
aspsp3.setBankCode("123");
List<Aspsp> found = luceneAspspRepository.findLike(aspsp3);
assertThat(found).hasSize(2);
}
@Test
void findLikeShouldBeOrderedByPriorities_BicBankCodeName_BicBankCode_Bic_BankCode_Name() {
List<Aspsp> expected = Arrays.asList(
buildAspsp("TESTBICA", "111111", "SomeBank"),
buildAspsp("TESTBICA", "111111"),
buildAspsp("TESTBICA", "111111"),
buildAspsp("TESTBICA", "111111"),
buildAspsp("TESTBICA", "111111"),
buildAspsp("TESTBICA", "111111"),
buildAspsp("TESTBICA", null),
buildAspsp("TESTBICA", null),
buildAspsp(null, "111111"),
buildAspsp(null, "111111")
);
luceneAspspRepository.save(buildAspsp("TESTBICA", "111111"));
luceneAspspRepository.save(buildAspsp("TESTBICA", "111111"));
luceneAspspRepository.save(buildAspsp("TESTBICA", "111111"));
luceneAspspRepository.save(buildAspsp("TESTBICA", "111111"));
luceneAspspRepository.save(buildAspsp("TESTBICA", "111111"));
luceneAspspRepository.save(buildAspsp("TESTBICB", "222222"));
luceneAspspRepository.save(buildAspsp("TESTBICC", "333333"));
luceneAspspRepository.save(buildAspsp("TESTBICD", "444444"));
luceneAspspRepository.save(buildAspsp("TESTBICE", "555555"));
luceneAspspRepository.save(buildAspsp(null, "111111"));
luceneAspspRepository.save(buildAspsp(null, "111111"));
luceneAspspRepository.save(buildAspsp(null, "111111"));
luceneAspspRepository.save(buildAspsp(null, "111111"));
luceneAspspRepository.save(buildAspsp("TESTBICA", null));
luceneAspspRepository.save(buildAspsp("TESTBICA", null));
luceneAspspRepository.save(buildAspsp("TESTBICA", "111111", "SomeBank"));
List<Aspsp> actual = luceneAspspRepository.findLike(buildAspsp("TESTBICA", "111111", "SomeBank"));
assertThat(actual).hasSize(10)
.isEqualTo(expected);
}
private Aspsp buildAspsp(String bic, String bankCode) {
Aspsp aspsp = new Aspsp();
aspsp.setBic(bic);
aspsp.setBankCode(bankCode);
return aspsp;
}
private Aspsp buildAspsp(String bic, String bankCode, String name) {
Aspsp aspsp = new Aspsp();
aspsp.setBic(bic);
aspsp.setBankCode(bankCode);
aspsp.setName(name);
return aspsp;
}
@Test
void saveAllTreatsEmptyFieldsAsNull() {
Aspsp aspsp = new Aspsp();
aspsp.setId(ASPSP_ID);
aspsp.setIdpUrl("");
luceneAspspRepository.saveAll(singletonList(aspsp));
Optional<Aspsp> found = luceneAspspRepository.findById(ASPSP_ID);
assertThat(found).get().extracting(Aspsp::getIdpUrl).isNull();
}
@Test
void saveTreatsEmptyIdAsNull() {
Aspsp aspsp = new Aspsp();
aspsp.setId("");
Aspsp saved = luceneAspspRepository.save(aspsp);
assertThat(saved.getId()).isNotEmpty();
}
@Test
void findByBankCode() {
String bankCode = "00000000";
Aspsp aspsp = buildAspsp(null, bankCode);
aspsp.setScaApproaches(singletonList(AspspScaApproach.EMBEDDED));
luceneAspspRepository.save(aspsp);
List<Aspsp> actual = luceneAspspRepository.findByBankCode(bankCode, AFTER, SIZE);
assertThat(actual.isEmpty()).isFalse();
assertThat(actual.size()).isEqualTo(1);
assertThat(actual.get(0).getBankCode()).isEqualTo(bankCode);
}
@Test
void findByIban() {
String iban = "DE86999999990000001000";
String bankCode = "99999999";
Aspsp aspsp = buildAspsp("", bankCode);
luceneAspspRepository.save(aspsp);
List<Aspsp> actual = luceneAspspRepository.findByIban(iban, AFTER, SIZE);
assertThat(actual.isEmpty()).isFalse();
assertThat(actual.size()).isEqualTo(1);
assertThat(actual.get(0).getBankCode()).isEqualTo(bankCode);
}
@Test
void findByIban_invalidIban() {
String iban = "DE123123123123123123123";
Aspsp aspsp = new Aspsp();
luceneAspspRepository.save(aspsp);
Throwable actual = catchThrowable(() -> {
luceneAspspRepository.findByIban(iban, AFTER, SIZE);
});
assertThat(actual).isInstanceOf(IbanException.class);
}
@Test
void findLike_bicOnlyAndBankCodeOnly() {
String bic = "ABABAB";
String bankCode = "00000000";
Aspsp bicOnly = buildAspsp(bic, null);
Aspsp bankCodeOnly = buildAspsp(null, bankCode);
luceneAspspRepository.saveAll(Arrays.asList(bicOnly, bankCodeOnly));
List<Aspsp> bicOnlyActual = luceneAspspRepository.findLike(bicOnly, AFTER, SIZE);
List<Aspsp> bankCodeOnlyActual = luceneAspspRepository.findLike(bankCodeOnly, AFTER, SIZE);
assertThat(bicOnlyActual.isEmpty()).isFalse();
assertThat(bicOnlyActual.size()).isEqualTo(1);
assertThat(bicOnlyActual.get(0).getBic()).isEqualTo(bic);
assertThat(bankCodeOnlyActual.isEmpty()).isFalse();
assertThat(bankCodeOnlyActual.size()).isEqualTo(1);
assertThat(bankCodeOnlyActual.get(0).getBankCode()).isEqualTo(bankCode);
}
}
| 11,942 | Java | .java | adorsys/xs2a-adapter | 37 | 25 | 5 | 2019-04-01T09:31:44Z | 2024-03-09T08:27:14Z |