zyg_flutter_plugin

这个是中裕冠的Ekey Lock的flutter插件。

"中裕冠的插件" version: 0.0.99

Android

 相关权限已在插件内部添加

iOS

The app's Info.plist must contain an NSBluetoothAlwaysUsageDescription key with a string value explaining to the user how the app uses this data.

使用示例

安装

在项目里的pubspec.yaml文件内添加,如:

dependencies:
  zyg_flutter_plugin: ^0.0.99

示例页面

import 'package:zyg_flutter_plugin/zyg_blue_page.dart';
void main() {
  // runApp(const MyApp());
  runApp(const ZygBluePage());
}

ZygBluetoothTool的使用,引入:

import 'package:zyg_flutter_plugin/zyg_bluetooth_tool.dart';

1.搜索蓝牙(具体可在zyg_device_list_page.dart文件内查看)



//result为ScanResult 对象,resulMap格式为 
{
"ble_name":"xxxxx",	//蓝牙名称
"ble_uuid":"xxxxx",	//蓝牙的服务UUID
"ble_mac":"xxxxx",    //iphone 拿不到mac,就返回对应的 identifier
"ble_adv":"xxxxx",    //广播包的内容
}
ZygBluetoothTool blueObj = ZygBluetoothTool();
blueObj.beginScaningWithCallback((result, resulMap)  {
  for (int i = 0; i < deviceList.length; i++) {
    ScanResult rr = deviceList[i];
    BluetoothDevice dd = rr.device;
    if (result.device.remoteId == dd.remoteId) {
      deviceList.remove(rr);
      break;
    }
  }

  deviceList.add(result);
  setState(() {});
}, (flag) {
  isScaning = flag;
  setState(() {});
});

2.连接蓝牙 (具体可在zyg_device_list_page.dart文件内查看)

连接蓝牙的回调方法返回的deviceMap对象的格式为:
{
"ble_name":"xxxxx",	//蓝牙名称
"ble_uuid":"xxxxx",	//蓝牙的服务UUID
"ble_mac":"xxxxx",    //iphone 拿不到mac,就返回对应的 identifier
"ble_adv":"xxxxx",    //广播包的内容
"ble_adv":"xxxxx",    //广播包的内容
'connectde': '1',      //1为已连接,0为未连接
}

await blueObj.stopScan();
ZygBluetoothTool().goToConnet(device, (state,deviceMap) {
  if (state == BluetoothConnectionState.connected) {
  if (ZygState.isEkeyLock) {
    Navigator.push(
        context,
        MaterialPageRoute(
            builder: (context) => OperationListPagePage(
                connectDevice: device)));
  } else {
    Navigator.push(
        context,
        MaterialPageRoute(
            builder: (context) => ZygCustomDataOperation(
                connectDevice: device)));
  }
}});
  

2.1 断开连接

  ZygBluetoothTool().myDisconnect();

2.3 发送数据的通用方法

int one = int.parse('12', radix: 16);
int two = int.parse('34', radix: 16);
int three = int.parse('56', radix: 16);

//获取自动登陆的指令数据 ,此数据需要自行根据需求自定义 数据长度必须是19
List<int> data =
    await getAutoLoginData_bujiami([one, two, three]);
// 是否需要加密
bool isEncryption = true;
//发送指令
ZygBluetoothTool().zyg_senCustomData(
    widget.connectDevice, data, isEncryption, (data) {
  //接收到的data就是接收到的蓝牙数据,此数据已经过解密
  setState(() {
    cmdMsgList.add(data.toString());
  });
});

3.绑定手机(注意:首次发送指令必须先执行本指令成功后才能执行其他指令)

ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.BING_PHONE, _controller.text, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

4.自动登录


ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.AUTO_LOGIN, _controller.text, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

5.创建用户


ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.CREATE_USER, _controller.text, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});


6.查询或编辑用户名


ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.EDIT_QUERY_USER_NAME, contentMap, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

7.添加密码/卡/指纹


ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice,
BluetoothAction.ADD_PWD_CARD_FINGERPRINT,
contentMap, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

8.删除密码、卡、指纹


ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice,
BluetoothAction.DELETE_PWD_CARD_FINGERPRINT_USER,
contentMap, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

9.修改/查询密码类型


ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.EDIT_QURY_PWD_TYPE, contentMap, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

10.密码登录验证


ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice,
BluetoothAction.PWD_LOGIN_VERIFICATION,
_controller.text, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

11.设置/查询 绑定手机之后能否自动生成密码


ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.SET_QUERY_BING_PWD, contentMap, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

12.开门关门


ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.OPEN_CLOSE, contentMap, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

13.修改密码

ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.EDIT_PWD, contentMap, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

14.查询电量

ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.QUERY_ELECTRICITY_LEVEL, null, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

15.查询锁的状态

ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice, BluetoothAction.QUERY_STATE, null,
(data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

16.设置/查询时间

ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.SET_QUERY_TIME, DateTime.now(), (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

17.设置查询锁的名称

设置:
ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice,
BluetoothAction.SET_QUERY_LOCK_NAME,
_controller.text, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});
查询:
ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.SET_QUERY_LOCK_NAME, null, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

18.查询管理员信息

ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice, BluetoothAction.QUERY_ADMIN, null,
(data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

19.绑同步用户、已绑定的手机

ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice,
BluetoothAction.SYNC_USER_BING_PHONE,
SYNC_type.sync_user, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

20.自动锁门时间设置、查询

 自动锁门的时间,单位为秒,数值为0-240,0表示禁用自动关锁功能
ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice,
BluetoothAction.SET_QUERY_AUTO_LOCK_TIME,
_controller.text, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

21.同步日志

ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice, BluetoothAction.SYNC_LOG, null, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

22.查询版本号

ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice, BluetoothAction.QUERY_VERSION, null,
(data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

23.手机设置/查询音量

ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice,
BluetoothAction.SET_QUERY_VOLUME,
typeMap[dropdownValue], (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

24.主动断开蓝牙

ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.DIECONNET_BLUETOOTH, null, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

25.启用/禁用指定的动态密码

Map contentMap = {
'PASSWORD': _controller.text,
'isEable': typeMap[dropdownValue]
};

//发送指令
ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice,
BluetoothAction.Enable_Disable_Dynamic_Password,
contentMap, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

26.等待查询锁端的MAC地址

ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.Query_mac_address, null, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

27.设置/查询超级用户的权限

ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice,
BluetoothAction.Set_Query_Spuer,
typeMap[dropdownValue], (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

28.查询锁是否被锁死

ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.Query_lock_it_up, null, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

29.查询锁的基本信息

ZygBluetoothTool().zyg_sendCMD(widget.connectDevice,
BluetoothAction.Query_basic_message, null, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

30.清空用户、恢复出厂设置

ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice,
BluetoothAction.Clear_user_and_restore_factory_settings,
ZYG_ClearType.clearAllUser, (data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});

31.进入恢复出厂设置

ZygBluetoothTool().zyg_sendCMD(
widget.connectDevice, BluetoothAction.Dfu_patterm, null,
(data,dataMap) {
setState(() {
cmdMsgList.add(data.toString());
});
});