80 lines
2.2 KiB
Dart
80 lines
2.2 KiB
Dart
// 网关配网
|
|
import 'dart:convert';
|
|
|
|
import '../io_reply.dart';
|
|
import '../io_sender.dart';
|
|
import '../io_tool/io_tool.dart';
|
|
import '../io_type.dart';
|
|
|
|
class GatewayConfiguringWifiCommand extends SenderProtocol {
|
|
GatewayConfiguringWifiCommand({
|
|
this.ssid,
|
|
this.password,
|
|
this.gatewayConfigurationStr,
|
|
}) : super(CommandType.gatewayConfiguringWifi);
|
|
|
|
String? ssid;
|
|
String? password;
|
|
String? gatewayConfigurationStr;
|
|
|
|
@override
|
|
String toString() {
|
|
return 'SenderConfiguringWifiCommand{ssid: $ssid, password: $password, gatewayConfigurationStr:$gatewayConfigurationStr}';
|
|
}
|
|
|
|
@override
|
|
List<int> messageDetail() {
|
|
final List<int> data = <int>[];
|
|
List<int> subData = <int>[];
|
|
|
|
// 指令类型
|
|
final int type = commandType!.typeValue;
|
|
final double typeDouble = type / 256;
|
|
final int type1 = typeDouble.toInt();
|
|
final int type2 = type % 256;
|
|
data.add(type1);
|
|
data.add(type2);
|
|
|
|
//SSID 30
|
|
final int ssidLength = utf8.encode(ssid!).length;
|
|
subData.addAll(utf8.encode(ssid!));
|
|
subData = getFixedLengthList(subData, 30 - ssidLength);
|
|
|
|
//Password 20
|
|
final int passwordLength = utf8.encode(password!).length;
|
|
subData.addAll(utf8.encode(password!));
|
|
subData = getFixedLengthList(subData, 20 - passwordLength);
|
|
|
|
//gatewayConfigurationStr
|
|
final int clientIdLength = utf8.encode(gatewayConfigurationStr!).length;
|
|
subData.add(clientIdLength);
|
|
subData.addAll(utf8.encode(gatewayConfigurationStr!));
|
|
// subData = getFixedLengthList(subData, 20 - clientIdLength);
|
|
|
|
data.addAll(subData);
|
|
|
|
printLog(data);
|
|
return data;
|
|
}
|
|
}
|
|
|
|
class GatewayConfiguringWifiReply extends Reply {
|
|
GatewayConfiguringWifiReply.parseData(
|
|
CommandType commandType, List<int> dataDetail)
|
|
: super.parseData(commandType, dataDetail) {
|
|
data = dataDetail;
|
|
final int status = data[2];
|
|
errorWithStstus(status);
|
|
}
|
|
}
|
|
|
|
class GatewayConfiguringWifiResultReply extends Reply {
|
|
GatewayConfiguringWifiResultReply.parseData(
|
|
CommandType commandType, List<int> dataDetail)
|
|
: super.parseData(commandType, dataDetail) {
|
|
data = dataDetail;
|
|
final int status = data[2];
|
|
errorWithStstus(status);
|
|
}
|
|
}
|