我的第一个内部类是“ getPosition” ,该类更新设备的位置并将信息写入csv文件中。 我的第二个内部类是“ ConnectedThread” ,该类连续监听蓝牙obd设备并将信息写入csv文件中。
如何将两者信息合并到一个 CSV文件?
private inner class ConnectedThread() : Thread() {
init {
rpmCommand = RPMCommand ()
}
override fun run() {
while (!Thread.currentThread().isInterrupted) {
val rpm = rpmCommand.run(mmInStream,mmOutStream)
val row = listOf(
rpm
)
csvWriter().open(Environment.getExternalStorageDirectory().absolutePath + File.separator + csvFilename) {
writeRow(row)
}
}
private inner class getPosition(
googleMap: GoogleMap,
filename: String
) : Thread() {
init {
mMap = googleMap
mMap.uiSettings.isZoomControlsEnabled = true
}
override fun run() {
val currentLatLng = LatLng(location.latitude, location.longitude)
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLatLng, 12f))
val timeStamp: String = SimpleDateFormat("ddMMyyyy_HHmmss").format(Date())
locationData.timeStamp = timeStamp
locationData.lat = location.latitude
locationData.lon = location.longitude
val row = listOf(
timeStamp,
locationData.lon,
locationData.lat
)
csvWriter().open(Environment.getExternalStorageDirectory().absolutePath + File.separator + csvFilename) {
writeRow(row)
println("position data is added")
}
}
}
}