I work with Flutter and want to log and store the collected Data of the Sensor Model: OP174. I'm using the Accelorometer, Gyroscope, Magnetometer and Temperatur.
I see in the Movesense.swift that there is a Logbook_path and a Datalogger_config_path but I can't figure out how to get it to save the collected Data, it tried another soloution that i post below.
How can i store this Data in a CSV File and will be the Timestamp automaticly included?
Getting the Gyroscope Data
int _gyroSubscription;
String _gyroscopeData = "";
String get gyroscopeData => _gyroscopeData;
bool get gyroscopeSubscribed => _gyroSubscription != null;
void subscribeToGyroscope() {
_gyroscopeData = "";
_gyroSubscription = Mds.subscribe(
Mds.createSubscriptionUri(_serial, "/Meas/Gyro/104"),
"{}",
(d, c) => {},
(e, c) => {},
(data) => _onNewGyroscopeData(data),
(e, c) => {});
notifyListeners();
}
void _onNewGyroscopeData(String data) {
Map<String, dynamic> gyroData = jsonDecode(data);
Map<String, dynamic> body = gyroData["Body"];
List<dynamic> gyroArry = body["ArrayGyro"];
dynamic gyro = gyroArry.last;
_gyroscopeData = "x: " +
gyro["x"].toStringAsFixed(2) +
"
y: " +
gyro["y"].toStringAsFixed(2) +
"
z: " +
gyro["z"].toStringAsFixed(2);
notifyListeners();
}
Trying to save the Data
Future<String> getFilePath() async {
Directory appDocumentsDirectory = await getExternalStorageDirectory();
List<FileSystemEntity> directory = appDocumentsDirectory.listSync();
directory.forEach((x) => debugPrint(x.path));
String appDocumentsPath = appDocumentsDirectory.path;
String filePath = '$appDocumentsPath/recording.csv';
return filePath;
}
void saveFile(DeviceModel deviceModel) async {
File file = File(await getFilePath());
file.writeAsString(deviceModel.gyroscopeData);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…