sdk_parse.dart 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'dart:ffi';
  2. import 'dart:io';
  3. import 'dart:typed_data';
  4. import 'package:ffi/ffi.dart';
  5. import 'package:shoes_sdk/generated_bindings.dart';
  6. import 'package:shoes_sdk/shoes_sdk.dart';
  7. class SDKApi {
  8. late NativeLibrary sdk;
  9. SDKApi() {
  10. sdk = NativeLibrary(Platform.isAndroid ? DynamicLibrary.open("libnative-lib.so") : DynamicLibrary.process());
  11. }
  12. void gameInit(int type) {
  13. sdk.gameInit(type, 1);
  14. }
  15. Pointer<Int32> result = int32ListToArrayPointer([-1, -1, -1, -1,-1, -1, -1, -1,-1, -1]);
  16. static const _shoe_id = 0;
  17. void gameProcess(Uint8List byteArray) {
  18. int length = byteArray.length;
  19. Pointer<Uint8> ptr = calloc<Uint8>(length);
  20. ptr.asTypedList(length).setAll(0, byteArray);
  21. sdk.gameProcess(_shoe_id, ptr, length, result);
  22. }
  23. List<int> getMotion() {
  24. // sdk.getGameResult(_shoe_id, result);
  25. return result.asTypedList(10);
  26. }
  27. int getInteractionCMD() {
  28. return sdk.getInteractionCMD();
  29. }
  30. int getStepFreq() {
  31. return sdk.getStepFreq(_shoe_id);
  32. }
  33. int getStepCount() {
  34. return sdk.getStepCount(_shoe_id);
  35. }
  36. int getMotionCount(int type) {
  37. return sdk.getMotionCount(_shoe_id, type);
  38. }
  39. int getGameStepVel() {
  40. return sdk.getGameStepVel(_shoe_id);
  41. }
  42. int getAttX() {
  43. return sdk.NativeGetAttX(_shoe_id);
  44. }
  45. String getVersion() {
  46. Pointer<Int8> ptr = calloc<Int8>(32);
  47. sdk.getGameVersion(ptr);
  48. var utf8 = ptr.cast<Utf8>();
  49. print("getVersion ${utf8} ${utf8.length}");
  50. return utf8.toDartString();
  51. }
  52. Pointer<Int8> getGameDataStrPointer = calloc<Int8>(2048);
  53. String getGameDataStr() {
  54. sdk.getGameDataStr(_shoe_id, getGameDataStrPointer);
  55. var utf8 = getGameDataStrPointer.cast<Utf8>();
  56. String result = utf8.toDartString();
  57. return result;
  58. }
  59. }