From 99adb1d513856df80019152df36aeaa123ee5336 Mon Sep 17 00:00:00 2001 From: Ivan Antunes Date: Mon, 15 Jul 2024 14:17:37 -0300 Subject: [PATCH] feat: change login mount package --- lib/actions/actions.dart | 85 +++++++++---------- .../qr_code_page/qr_code_page_widget.dart | 2 +- 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/lib/actions/actions.dart b/lib/actions/actions.dart index e5f67a2a..5cc880ce 100644 --- a/lib/actions/actions.dart +++ b/lib/actions/actions.dart @@ -5,6 +5,7 @@ import 'package:f_r_e_hub/custom_code/actions/get_dev_u_u_i_d.dart'; import 'package:f_r_e_hub/pages/home_page/home_page_widget.dart'; import 'package:flutter/material.dart'; import 'package:qr_flutter/qr_flutter.dart'; +import 'package:sqflite/utils/utils.dart'; import 'dart:developer' as developer; import '/actions/actions.dart' as action_blocks; @@ -508,52 +509,55 @@ Future changeStatusAction( Uint8List assembleQRPacket(int direction, String identifier, String password) { - Uint8List packet = Uint8List(20); - int position = 0; - int check = 0; + List packet = [direction]; - // Direction - packet[position++] = direction; + String paddedBadge = identifier.padLeft(30, '0'); - // Identifier - Uint8List ide = hexStringToByteArray(("000000000000000000000000000000" + identifier).substring(identifier.length)); - for (int i = 0; i < ide.length; i++) { - packet[position++] = ide[i]; + developer.log("Badge: $paddedBadge"); + + for (var i = 0; i < paddedBadge.length; i += 2) { + packet.add(int.parse(paddedBadge.substring(i, i + 2), radix: 16)); } - // Date and time DateTime now = DateTime.now(); - int day = int.parse(DateFormat('dd').format(now)); - int month = int.parse(DateFormat('MM').format(now)); - int year = int.parse(DateFormat('yy').format(now)); - int hour = int.parse(DateFormat('HH').format(now)); - int minute = int.parse(DateFormat('mm').format(now)); + int year = now.year % 100; + int month = now.month; + int day = now.day; + int hour = now.hour; + int minute = now.minute; - int sumDate = year + month + day + hour + minute; - packet[position++] = (sumDate == 0x0D || sumDate == 0x0A) ? 0xFF : sumDate; + int sum = year + month + day + hour + minute; - // Log the sumDate - developer.log("Soma Data: $sumDate", name: "ROTINAS"); - - // Password - Uint8List passBytes = hexStringToByteArray(password); - packet[position++] = passBytes[0]; - packet[position++] = passBytes[1]; - - // Checksum - for (int i = 0; i < packet.length - 1; i++) { - check ^= packet[i]; + if (sum == int.parse('0D', radix: 16) || sum == int.parse('0A', radix: 16)) { + packet.add(int.parse('FF', radix: 16)); + } else { + packet.add(sum); } - packet[position] = (check == 0x0D || check == 0x0A) ? 0xFF : check; - // Log the checksum - developer.log("Checksum: $check", name: "ROTINAS"); + String paddedPassword = password.length != 4 ? 'FFFF' : password; - // Convert packet to hex string and log it - String hexPacket = byteToHexa(packet); - developer.log("Pacote final: $hexPacket", name: "ROTINAS"); + for (var i = 0; i < paddedPassword.length; i += 2) { + packet.add(int.parse(paddedPassword.substring(i, i + 2), radix: 16)); + } - return packet; + int check = 0x00; + + for (var b in packet) { + check ^= b; + } + + if (check == int.parse('0D', radix: 16) || check == int.parse('0A', radix: 16)) { + packet.add(int.parse('FF', radix: 16)); + } else { + packet.add(check); + } + + var bytes = packet.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join((' ')); + + developer.log("Pacote: $packet"); + developer.log("Bytes: $bytes"); + + return Uint8List.fromList(packet); } Uint8List hexStringToByteArray(String s) { @@ -569,12 +573,8 @@ String byteToHexa(List pDados) { return pDados.map((byte) => byte.toRadixString(16).padLeft(2, '0').toUpperCase()).join(); } - - - - String byteToString(Uint8List bytes) { - return utf8.decode(bytes); + return utf8.decode(bytes, allowMalformed: true); } Widget buildQrCode( @@ -590,9 +590,6 @@ Widget buildQrCode( required int direction } ) { - debugPrint('remoteID: ${FFAppState().userDevUUID}'); - debugPrint('androidId: ${FFAppState().devUUID}'); - debugPrint('Serial Number: ${FFAppState().serialNumber}'); try { // Verifica se os dados estão de acordo com as regras de negócio @@ -608,7 +605,7 @@ Widget buildQrCode( data: byteToString(assembleQRPacket(direction, identifier, pass)), version: version, //QrVersions.auto size: dimension, - // errorCorrectionLevel: errorCorrectLevel, + errorCorrectionLevel: errorCorrectLevel, backgroundColor: backgroundColor, foregroundColor: foregroundColor, gapless: false, // Ajuste conforme necessário diff --git a/lib/pages/qr_code_page/qr_code_page_widget.dart b/lib/pages/qr_code_page/qr_code_page_widget.dart index d5a5f0ec..dfaa9694 100644 --- a/lib/pages/qr_code_page/qr_code_page_widget.dart +++ b/lib/pages/qr_code_page/qr_code_page_widget.dart @@ -157,7 +157,7 @@ void dispose() { maskPattern: -1, version: QrVersions.auto, identifier: FFAppState().userDevUUID, - pass: '12313123', + pass: '1234', direction: 5, ), ),