app-starlock/lib/blue/io_gateway/io_gateway_configuringWifi.dart

95 lines
3.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 网关配网
import 'dart:convert';
import 'dart:typed_data';
import 'package:star_lock/app_settings/app_settings.dart';
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;
Uint8List lengthBytes = Uint8List(2);
ByteData byteData = ByteData.view(lengthBytes.buffer);
byteData.setUint16(0, clientIdLength, Endian.little); // 使用大端序big-endian
// 将两个字节添加到 subData
subData.addAll(lengthBytes);
// subData.add(clientIdLength);
// final double clientIdLengthDouble = clientIdLength / 256;
// final int clientIdLengthDoubleType1 = clientIdLengthDouble.toInt();
// final int clientIdLengthDoubleType2 = clientIdLength % 256;
// // AppLog.log('gatewayConfigurationStr!:$gatewayConfigurationStr! clientIdLength:$clientIdLength clientIdLengthDouble:$clientIdLengthDouble clientIdLengthDoubleType1:$clientIdLengthDoubleType1 clientIdLengthDoubleType2:$clientIdLengthDoubleType2');
// data.add(clientIdLengthDoubleType1);
// data.add(clientIdLengthDoubleType2);
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);
}
}