Files
fengshui_compass/lib/utils/recv_parse.dart

23 lines
607 B
Dart
Raw Normal View History

2022-06-27 09:51:30 +08:00
// 处理串口接收字节数组转换
String intToHex(int i, {int pad = 2}) {
return i.toRadixString(16).padLeft(pad, '0').toUpperCase();
}
List<int> hexToUnits(String hexStr, {int combine = 2}) {
hexStr = hexStr.replaceAll(" ", "");
List<int> hexUnits = [];
for (int i = 0; i < hexStr.length; i += combine) {
hexUnits.add(hexToInt(hexStr.substring(i, i + combine)));
}
return hexUnits;
}
int hexToInt(String hex) {
return int.parse(hex, radix: 16);
}
String formatReceivedData(recv) {
return recv
.map((List<int> char) => char.map((c) => intToHex(c)).join())
.join();
}