gpt4 book ai didi

java - Android Things 和 Adafruit Ultimate GPS Breakout v3

转载 作者:行者123 更新时间:2023-11-29 23:52:40 24 4
gpt4 key购买 nike

我开始在 Raspberry Pi 3 上使用 Adafruit Ultimate GPS Breakout v3 和 Android Things v1.0.1。我在这里使用代码:Github Contrib Drivers尝试获取 GPS 坐标,但我没有任何运气,所以我希望有人能指出我正确的方向。

GpsModuleCallBack() 没有在日志中显示任何内容。

这是我的代码:

主 Activity .java

public class MainActivity extends Activity {

private static final String UART_DEVICE_NAME = "UART0";

UartDevice mDevice;
NmeaGpsModule mGpsModule;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setTitle("GPS Test");

PeripheralManager gpiolist = PeripheralManager.getInstance();
List<String> portList = gpiolist.getGpioList();
if (portList.isEmpty()) {
Log.w(TAG, "No GPIO port available on this device.");
} else {
Log.i(TAG, "List of available ports: " + portList);
}

PeripheralManager uartlist = PeripheralManager.getInstance();
List<String> deviceList = uartlist.getUartDeviceList();
if (deviceList.isEmpty()) {
Log.w(TAG, "No UART port available on this device.");
} else {
Log.i(TAG, "List of available devices: " + deviceList);
}


// Attempt to access the UART device
try {
PeripheralManager gpsmanager = PeripheralManager.getInstance();
mDevice = gpsmanager.openUartDevice(UART_DEVICE_NAME);
Log.i(TAG, "Accessed " + UART_DEVICE_NAME );
} catch (IOException e) {
Log.w(TAG, "Unable to access UART device", e);
}

try {
mGpsModule = new NmeaGpsModule(
"UART0", 9600, 1.8f);

mGpsModule.setGpsModuleCallback(new GpsModuleCallback() {
@Override
public void onGpsSatelliteStatus(GnssStatus status) {
Log.i(TAG, "Status: " + status.getSatelliteCount());
}

@Override
public void onGpsTimeUpdate(long timestamp) {
Log.i(TAG, "Time: " + timestamp);
}

@Override
public void onGpsLocationUpdate(Location location) {
Log.i(TAG, "Location: " + location.getLatitude() + location.getLongitude());
}

@Override
public void onNmeaMessage(String nmeaMessage) {
Log.i(TAG, "NMEA Message: " + nmeaMessage);
}
});

} catch (IOException e) {
// couldn't configure the gps module...
}

// Close the GPS module when finished:

try {
mGpsModule.close();
} catch (IOException e) {
// error closing gps module
}

}

@Override
protected void onDestroy() {
super.onDestroy();

if (mDevice != null) {
try {
mDevice.close();
mDevice = null;
} catch (IOException e) {
Log.w(TAG, "Unable to close UART device", e); }
}
}

最佳答案

Android Things 驱动程序会为您打开外设端口,因此您不应直接从 PeripheralManager 访问 UART 并使用该驱动程序。删除以下代码块:

try {
PeripheralManager gpsmanager = PeripheralManager.getInstance();
mDevice = gpsmanager.openUartDevice(UART_DEVICE_NAME);
Log.i(TAG, "Accessed " + UART_DEVICE_NAME );
} catch (IOException e) {
Log.w(TAG, "Unable to access UART device", e);
}

最有可能的是,您的示例中的下一个代码块抛出异常,因为它无法打开 UART(它不能打开两次)但空的 catch block 正在吞噬它:

try {
mGpsModule = new NmeaGpsModule(
"UART0", 9600, 1.8f);
...

} catch (IOException e) {
// couldn't configure the gps module...
}

您可能还应该在那里添加一个 Log 语句,以确保没有异常。

关于java - Android Things 和 Adafruit Ultimate GPS Breakout v3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50720319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com