tempEncrypt function

Future<List<int>> tempEncrypt(
  1. int cmd,
  2. List<int> subData
)

去加密 包含指令和长度的数据:cmdData,有效数据:subData

Implementation

Future<List<int>> tempEncrypt(int cmd, List<int> subData) async {
  // 包含指令和数据长度的数组
  List<int> cmdData = [0xfe, cmd, subData.length];

  //有效数据
  if (subData.length > 16) {
    print('有效数据长度大于16,请检查数据');
    return [];
  }
  int len = subData.length;

  //有效数据不足16位,补全
  for (int i = 0; i < 16 - len; i++) {
//不足16位就补ff
    subData = [...subData, 0xff];
  }

//获取mac地址
//   final List<int> macAddressList = await getMacAdressList();
// // 获取加密的key
//   List<int> keyList = await createKey(macAddressList);
//
// //去加密
//   List<int> encryptData = encryptWithBytes(subData, keyList);
  List<int> encryptData = await myEncryptWithBytes(subData);

  List<int> data = [...cmdData, ...encryptData];
  data = [...data, getChecksum(data)];

  return data;
}