Browse Source

修改会议助手自动连接ftp服务

weicu
tanlongsheng 1 year ago
parent
commit
3af61b41b7
  1. 40
      lib/core/utils/ftpconnect/src/ftp_entry.dart
  2. 37
      lib/modules/meeting/controllers/meeting_connect_controller.dart

40
lib/core/utils/ftpconnect/src/ftp_entry.dart

@ -27,11 +27,8 @@ class FTPEntry {
r"(.+)$" //file/dir name[8] r"(.+)$" //file/dir name[8]
); );
static final regexpLISTSiiServers = RegExp(r"^(.{8}\s+.{7})\s+" //date[1] static final regexpLISTSiiServers = RegExp(
r"(.{0,5})\s+" //type file or dir [2] r"^(\d{2}-\d{2}-\d{4}\s+\d{2}:\d{2}[AP]M)\s+(\<DIR\>)?\s*(\d*)\s+(.+)$");
r"(\d{0,24})\s+" //size [3]
r"(.+)$" //file/ dir name [4]
);
// Hide constructor // Hide constructor
FTPEntry._( FTPEntry._(
@ -218,35 +215,22 @@ class FTPEntry {
int _uid = -1; int _uid = -1;
Iterable<Match> matches = regexpLISTSiiServers.allMatches(responseLine); Iterable<Match> matches = regexpLISTSiiServers.allMatches(responseLine);
for (Match match in matches) { for (Match match in matches) {
//date // 日期,合并多余空格
String date = String date = match.group(1)!.replaceAll(RegExp(r'\s+'), ' ');
match.group(1)!.split(" ").fold('', (previousValue, element) {
//keep only one space and add fullyear if only last 2 digits in year
if (element.isEmpty) return previousValue;
if (previousValue.isEmpty) {
return element.length <= 8
? element.substring(0, 6) +
DateTime.now().year.toString().substring(0, 2) +
element.substring(6, 8)
: element;
}
return '$previousValue $element';
});
_modifyTime = DateFormat('MM-dd-yyyy hh:mma').parse(date); _modifyTime = DateFormat('MM-dd-yyyy hh:mma').parse(date);
//type // 类型
if (match.group(2)!.trim().isEmpty) { if ((match.group(2) ?? '').trim().isNotEmpty) {
_type = FTPEntryType.FILE;
} else if (match.group(2)!.toLowerCase().contains("dir")) {
_type = FTPEntryType.DIR; _type = FTPEntryType.DIR;
} else { } else {
_type = FTPEntryType.LINK; _type = FTPEntryType.FILE;
} }
//size
_size = int.tryParse(match.group(3)!) ?? 0;
//file/dir name // 大小
_name = match.group(4)!; _size = int.tryParse(match.group(3) ?? '') ?? 0;
// 文件/目录名
_name = match.group(4)!.trim();
} }
return FTPEntry._(_name, _modifyTime, _persmission, _type, _size, _unique, return FTPEntry._(_name, _modifyTime, _persmission, _type, _size, _unique,
_group, _gid, _mode, _owner, _uid, {}); _group, _gid, _mode, _owner, _uid, {});

37
lib/modules/meeting/controllers/meeting_connect_controller.dart

@ -4,6 +4,8 @@ import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:wifi_iot/wifi_iot.dart'; import 'package:wifi_iot/wifi_iot.dart';
import '../../../core/utils/ftpconnect/ftpconnect.dart';
class MeetingConnectController extends GetxController { class MeetingConnectController extends GetxController {
RxString stateStr = '搜索中...'.obs; RxString stateStr = '搜索中...'.obs;
RxBool isRescan = false.obs; RxBool isRescan = false.obs;
@ -16,8 +18,8 @@ class MeetingConnectController extends GetxController {
bool isScanFailed = false; bool isScanFailed = false;
late BluetoothCharacteristic? _writeCharacteristic; BluetoothCharacteristic? _writeCharacteristic;
late StreamSubscription<List<int>>? _valueReceivedSubscription; StreamSubscription<List<int>>? _valueReceivedSubscription;
String _wifiSSID = ''; String _wifiSSID = '';
String _wifiPassword = ''; String _wifiPassword = '';
@ -26,6 +28,8 @@ class MeetingConnectController extends GetxController {
String _ftpAccount = ''; String _ftpAccount = '';
String _ftpPassword = ''; String _ftpPassword = '';
FTPConnect? _ftpConnect;
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
@ -56,6 +60,7 @@ class MeetingConnectController extends GetxController {
_scanResultsSubscription.cancel(); _scanResultsSubscription.cancel();
_isScanningSubscription.cancel(); _isScanningSubscription.cancel();
_valueReceivedSubscription?.cancel(); _valueReceivedSubscription?.cancel();
_ftpConnect?.disconnect();
_stopScan(); _stopScan();
_disconnect(); _disconnect();
super.onClose(); super.onClose();
@ -86,6 +91,7 @@ class MeetingConnectController extends GetxController {
} }
Future<void> _disconnect() async { Future<void> _disconnect() async {
await WiFiForIoTPlugin.forceWifiUsage(false);
await WiFiForIoTPlugin.disconnect(); await WiFiForIoTPlugin.disconnect();
await _device?.disconnect(); await _device?.disconnect();
} }
@ -131,7 +137,6 @@ class MeetingConnectController extends GetxController {
} }
void _listenData(List<int> value) { void _listenData(List<int> value) {
print('----$value--------');
int command = value[2]; int command = value[2];
switch (command) { switch (command) {
case 0x0d: // 是否有导入文件 case 0x0d: // 是否有导入文件
@ -145,12 +150,12 @@ class MeetingConnectController extends GetxController {
break; break;
case 0x87: // Wi-Fi 开启/关闭 case 0x87: // Wi-Fi 开启/关闭
if (value[3] == 0x01 && value[4] == 0x01) { if (value[3] == 0x01 && value[4] == 0x01) {
_getWifi(); sendData([0x5a, 0x01, 0x0b]);
} }
break; break;
case 0x0b: // WiFi 热点 SSID case 0x0b: // WiFi 热点 SSID
_wifiSSID = String.fromCharCodes(value.sublist(3, value.length - 2)); _wifiSSID = String.fromCharCodes(value.sublist(3, value.length - 2));
_connectWifi(); sendData([0x5a, 0x01, 0x0c]);
break; break;
case 0x0c: // WiFi 热点密码 case 0x0c: // WiFi 热点密码
_wifiPassword = _decodePassword(value); _wifiPassword = _decodePassword(value);
@ -176,11 +181,6 @@ class MeetingConnectController extends GetxController {
} }
} }
void _getWifi() async {
await sendData([0x5a, 0x01, 0x0b]);
await sendData([0x5a, 0x01, 0x0c]);
}
void _connectWifi() async { void _connectWifi() async {
if (_wifiSSID.isNotEmpty && _wifiPassword.isNotEmpty) { if (_wifiSSID.isNotEmpty && _wifiPassword.isNotEmpty) {
stateStr.value = '正在连接 Wi-Fi...'; stateStr.value = '正在连接 Wi-Fi...';
@ -189,16 +189,29 @@ class MeetingConnectController extends GetxController {
password: _wifiPassword, password: _wifiPassword,
security: NetworkSecurity.WPA, security: NetworkSecurity.WPA,
); );
await WiFiForIoTPlugin.forceWifiUsage(true);
stateStr.value = 'Wi-Fi 连接成功'; stateStr.value = 'Wi-Fi 连接成功';
sendData([0x5a, 0x01, 0x03]); sendData([0x5a, 0x01, 0x03]);
} }
} }
void _connectFtp() { void _connectFtp() async {
if (_ftpAddress.isNotEmpty && if (_ftpAddress.isNotEmpty &&
_ftpPort.isNotEmpty && _ftpPort.isNotEmpty &&
_ftpAccount.isNotEmpty && _ftpAccount.isNotEmpty &&
_ftpPassword.isNotEmpty) {} _ftpPassword.isNotEmpty) {
_ftpConnect = FTPConnect(
_ftpAddress,
port: int.tryParse(_ftpPort) ?? 21,
user: _ftpAccount,
pass: _ftpPassword,
);
await _ftpConnect?.connect();
_ftpConnect?.listCommand = ListCommand.LIST;
List<FTPEntry>? _listDirectory =
await _ftpConnect?.listDirectoryContent();
print(_listDirectory);
}
} }
String _decodePassword(List<int> data) { String _decodePassword(List<int> data) {

Loading…
Cancel
Save