极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 21299|回复: 9

MobBob 3D打印机器人 表示蓝牙连不上

[复制链接]
发表于 2015-4-14 18:19:47 | 显示全部楼层 |阅读模式
本帖最后由 bobst 于 2015-4-15 10:17 编辑



MobBob:用智能手机做身体的3D打印机器人
http://letsmakerobots.com/robot/project/mobbob-mobile-phone-bob



蓝牙 HC-05
爪机android 5.0
连不上原作的app
求解、、


apk打包 http://pan.baidu.com/s/1sjyotEP

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2015-4-14 23:52:28 | 显示全部楼层
先看看手机能不能能不能扫描到蓝牙模块,用蓝牙助手之类的app传数据看看,可行的话再看mobbob的app
回复 支持 反对

使用道具 举报

发表于 2015-4-15 09:50:01 | 显示全部楼层
手机开启蓝牙     解决了吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-15 10:15:15 | 显示全部楼层
本帖最后由 bobst 于 2015-4-15 10:37 编辑
nick_zm 发表于 2015-4-14 23:52
先看看手机能不能能不能扫描到蓝牙模块,用蓝牙助手之类的app传数据看看,可行的话再看mobbob的app


1.安卓系统上已连接HC05
2.PC串口AT 可用
vcc---3v
txo--rx0
rx0-tx0
GND--GND
3.蓝牙助手app 这样发AT是不对的吧? hc05要设置成AT模式?
蓝牙助手这样发木反应、、

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-15 10:24:42 | 显示全部楼层
本帖最后由 bobst 于 2015-4-15 10:31 编辑
suoma 发表于 2015-4-15 09:50
手机开启蓝牙     解决了吗?


打开了 安卓系统里连上HC05了 原作app连不上

问下蓝牙AT、、
按住按钮,然后上电。看到灯慢闪就是at模式了。
楼上图是这样发AT的么? 表示也没反应、、 PC 发AT可以、、
回复 支持 反对

使用道具 举报

发表于 2015-4-15 10:45:16 | 显示全部楼层
蓝牙模块要配置成slave模式
回复 支持 反对

使用道具 举报

发表于 2015-4-15 13:03:28 | 显示全部楼层
从原作者网页信息看需要蓝牙4.0的模块才能支持,HC-05才蓝牙2.0
The current app is setup to work with DFRobot Bluno boards. It should work with any of them (there are a bunch of different ones...). The app connects using the Bluno's Bluetooth LE GATT profile
我反编译了一下其中一个Android的apk,从释出的源代码看确实是用BLE协议,而且会抓固定uuid的设备
  1. package com.shatalmic.unityandroidbluetoothlelib;

  2. import android.app.Activity;
  3. import android.bluetooth.BluetoothAdapter;
  4. import android.bluetooth.BluetoothAdapter.LeScanCallback;
  5. import android.bluetooth.BluetoothDevice;
  6. import android.bluetooth.BluetoothGatt;
  7. import android.bluetooth.BluetoothGattCallback;
  8. import android.bluetooth.BluetoothGattCharacteristic;
  9. import android.bluetooth.BluetoothGattDescriptor;
  10. import android.bluetooth.BluetoothGattService;
  11. import android.bluetooth.BluetoothManager;
  12. import android.content.BroadcastReceiver;
  13. import android.content.Context;
  14. import android.content.Intent;
  15. import android.content.IntentFilter;
  16. import android.content.pm.PackageManager;
  17. import android.os.Parcelable;
  18. import android.util.Base64;
  19. import android.util.Log;
  20. import com.unity3d.player.UnityPlayer;
  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.HashMap;
  24. import java.util.Iterator;
  25. import java.util.List;
  26. import java.util.Map;
  27. import java.util.Set;
  28. import java.util.UUID;
  29. import java.util.concurrent.atomic.AtomicBoolean;

  30. public class UnityBluetoothLE
  31. {
  32.   protected static final UUID CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
  33.   public static final String TAG = "UnityBluetoothLE";
  34.   public static UnityBluetoothLE _instance;
  35.   private final BroadcastReceiver ActionFoundReceiver = new BroadcastReceiver()
  36.   {
  37.     public void onReceive(Context paramContext, Intent paramIntent)
  38.     {
  39.       BluetoothDevice localBluetoothDevice;
  40.       Parcelable[] arrayOfParcelable;
  41.       int i;
  42.       if ("android.bluetooth.device.action.UUID".equals(paramIntent.getAction()))
  43.       {
  44.         UnityBluetoothLE.this.androidBluetoothLog("got action_uuid");
  45.         if (UnityBluetoothLE.this.uuidList != null)
  46.         {
  47.           localBluetoothDevice = (BluetoothDevice)paramIntent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
  48.           arrayOfParcelable = paramIntent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID");
  49.           if ((localBluetoothDevice == null) || (arrayOfParcelable == null))
  50.             break label144;
  51.           i = arrayOfParcelable.length;
  52.         }
  53.       }
  54.       for (int j = 0; ; j++)
  55.       {
  56.         if (j >= i)
  57.           return;
  58.         String str = arrayOfParcelable[j].toString();
  59.         UnityBluetoothLE.this.androidBluetoothLog("checking uuid " + str);
  60.         if (!UnityBluetoothLE.this.uuidList.contains(UnityBluetoothLE.this.getFullBluetoothLEUUID(str)))
  61.           continue;
  62.         UnityBluetoothLE.this.sendDiscoveredDevice(localBluetoothDevice);
  63.       }
  64.       label144: if (localBluetoothDevice != null)
  65.         UnityBluetoothLE.this.androidBluetoothLog("device: " + localBluetoothDevice.getAddress());
  66.       while (arrayOfParcelable != null)
  67.       {
  68.         UnityBluetoothLE.this.androidBluetoothLog("uuid count: " + arrayOfParcelable.length);
  69.         return;
  70.         UnityBluetoothLE.this.androidBluetoothLog("device is null");
  71.       }
  72.       UnityBluetoothLE.this.androidBluetoothLog("uuidExtra is null");
  73.     }
  74.   };
  75.   private Map<String, BluetoothGatt> deviceGattMap = null;
  76.   private Map<String, BluetoothDevice> deviceMap = null;
  77.   private BluetoothAdapter mBluetoothAdapter;
  78.   private Context mContext = null;
  79.   private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback()
  80.   {
  81.     public void onCharacteristicChanged(BluetoothGatt paramBluetoothGatt, BluetoothGattCharacteristic paramBluetoothGattCharacteristic)
  82.     {
  83.       byte[] arrayOfByte = paramBluetoothGattCharacteristic.getValue();
  84.       if (arrayOfByte != null)
  85.       {
  86.         String str = Base64.encodeToString(arrayOfByte, 0);
  87.         UnityBluetoothLE.UnitySend("DidUpdateValueForCharacteristic~" + paramBluetoothGattCharacteristic.getUuid() + "~" + str);
  88.       }
  89.     }

  90.     public void onCharacteristicRead(BluetoothGatt paramBluetoothGatt, BluetoothGattCharacteristic paramBluetoothGattCharacteristic, int paramInt)
  91.     {
  92.       if (paramInt == 0)
  93.       {
  94.         byte[] arrayOfByte = paramBluetoothGattCharacteristic.getValue();
  95.         if (arrayOfByte != null)
  96.         {
  97.           String str = Base64.encodeToString(arrayOfByte, 0);
  98.           UnityBluetoothLE.UnitySend("DidUpdateValueForCharacteristic~" + paramBluetoothGattCharacteristic.getUuid() + "~" + str);
  99.         }
  100.       }
  101.     }

  102.     public void onCharacteristicWrite(BluetoothGatt paramBluetoothGatt, BluetoothGattCharacteristic paramBluetoothGattCharacteristic, int paramInt)
  103.     {
  104.       if (paramInt == 0)
  105.       {
  106.         UnityBluetoothLE.UnitySend("DidWriteCharacteristic~" + paramBluetoothGattCharacteristic.getUuid());
  107.         return;
  108.       }
  109.       UnityBluetoothLE.UnitySend("Error~Response - failed to write characteristic: " + paramInt);
  110.     }

  111.     public void onConnectionStateChange(BluetoothGatt paramBluetoothGatt, int paramInt1, int paramInt2)
  112.     {
  113.       UnityBluetoothLE.this.androidBluetoothLog("onConnectionStateChange");
  114.       String str = paramBluetoothGatt.getDevice().getAddress();
  115.       if (paramInt2 == 2)
  116.       {
  117.         if (UnityBluetoothLE.this.deviceGattMap == null)
  118.           UnityBluetoothLE.this.deviceGattMap = new HashMap();
  119.         UnityBluetoothLE.this.deviceGattMap.put(str, paramBluetoothGatt);
  120.         UnityBluetoothLE.UnitySend("ConnectedPeripheral~" + str);
  121.         paramBluetoothGatt.discoverServices();
  122.       }
  123.       do
  124.         return;
  125.       while (paramInt2 != 0);
  126.       UnityBluetoothLE.UnitySend("DisconnectedPeripheral~" + str);
  127.     }

  128.     public void onDescriptorWrite(BluetoothGatt paramBluetoothGatt, BluetoothGattDescriptor paramBluetoothGattDescriptor, int paramInt)
  129.     {
  130.       if (paramInt == 0)
  131.       {
  132.         UnityBluetoothLE.this.androidBluetoothLog("onDescriptorWrite Success");
  133.         if ((paramBluetoothGattDescriptor != null) && (paramBluetoothGattDescriptor.getCharacteristic() != null) && (paramBluetoothGattDescriptor.getCharacteristic().getUuid() != null))
  134.         {
  135.           UnityBluetoothLE.UnitySend("DidUpdateNotificationStateForCharacteristic~" + paramBluetoothGattDescriptor.getCharacteristic().getUuid());
  136.           return;
  137.         }
  138.         UnityBluetoothLE.UnitySend("Error~Descriptor Write Failed: characterstic or uuid blank");
  139.         return;
  140.       }
  141.       UnityBluetoothLE.UnitySend("Error~Descriptor Write Failed: " + paramInt);
  142.     }

  143.     public void onServicesDiscovered(BluetoothGatt paramBluetoothGatt, int paramInt)
  144.     {
  145.       if (paramInt == 0)
  146.       {
  147.         UnityBluetoothLE.this.androidBluetoothLog("Services Discovered");
  148.         List localList = paramBluetoothGatt.getServices();
  149.         String str;
  150.         Iterator localIterator1;
  151.         if (localList != null)
  152.         {
  153.           str = paramBluetoothGatt.getDevice().getAddress();
  154.           localIterator1 = localList.iterator();
  155.         }
  156.         while (true)
  157.         {
  158.           if (!localIterator1.hasNext())
  159.             return;
  160.           BluetoothGattService localBluetoothGattService = (BluetoothGattService)localIterator1.next();
  161.           UnityBluetoothLE.UnitySend("DiscoveredService~" + str + "~" + localBluetoothGattService.getUuid());
  162.           Iterator localIterator2 = localBluetoothGattService.getCharacteristics().iterator();
  163.           while (localIterator2.hasNext())
  164.           {
  165.             BluetoothGattCharacteristic localBluetoothGattCharacteristic = (BluetoothGattCharacteristic)localIterator2.next();
  166.             UnityBluetoothLE.UnitySend("DiscoveredCharacteristic~" + str + "~" + localBluetoothGattService.getUuid() + "~" + localBluetoothGattCharacteristic.getUuid());
  167.           }
  168.         }
  169.       }
  170.       UnityBluetoothLE.this.androidBluetoothLog("Error~Service Discovery " + paramInt);
  171.     }
  172.   };
  173.   private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback()
  174.   {
  175.     public void onLeScan(BluetoothDevice paramBluetoothDevice, int paramInt, byte[] paramArrayOfByte)
  176.     {
  177.       UnityBluetoothLE.this.sendDiscoveredDevice(paramBluetoothDevice);
  178.     }
  179.   };
  180.   public AtomicBoolean mRunning = new AtomicBoolean();
  181.   private ArrayList<UUID> uuidList = null;

  182.   public static void UnitySend(String paramString)
  183.   {
  184.     UnityPlayer.UnitySendMessage("BluetoothLEReceiver", "OnBluetoothMessage", paramString);
  185.   }

  186.   public static void UnitySend(byte[] paramArrayOfByte, int paramInt)
  187.   {
  188.     UnityPlayer.UnitySendMessage("BluetoothLEReceiver", "OnBluetoothData", Base64.encodeToString(Arrays.copyOfRange(paramArrayOfByte, 0, paramInt), 0));
  189.   }

  190.   private UUID getFullBluetoothLEUUID(String paramString)
  191.   {
  192.     if (paramString.length() == 4)
  193.       return UUID.fromString("0000" + paramString + "-0000-1000-8000-00805F9B34FB");
  194.     return UUID.fromString(paramString);
  195.   }

  196.   public static UnityBluetoothLE getInstance()
  197.   {
  198.     if (_instance == null)
  199.       _instance = new UnityBluetoothLE();
  200.     return _instance;
  201.   }

  202.   private void sendDiscoveredDevice(BluetoothDevice paramBluetoothDevice)
  203.   {
  204.     String str = "No Name";
  205.     if (paramBluetoothDevice.getName() != null)
  206.       str = paramBluetoothDevice.getName();
  207.     if (this.deviceMap == null)
  208.       this.deviceMap = new HashMap();
  209.     this.deviceMap.put(paramBluetoothDevice.getAddress(), paramBluetoothDevice);
  210.     UnitySend("DiscoveredPeripheral~" + paramBluetoothDevice.getAddress() + "~" + str);
  211.   }

  212.   public void androidBluetoothConnectToPeripheral(String paramString)
  213.   {
  214.     if ((this.mBluetoothAdapter != null) && (this.deviceMap != null) && (this.mContext != null))
  215.     {
  216.       BluetoothDevice localBluetoothDevice = (BluetoothDevice)this.deviceMap.get(paramString);
  217.       if (localBluetoothDevice != null)
  218.         UnityPlayer.currentActivity.runOnUiThread(new Runnable(localBluetoothDevice)
  219.         {
  220.           public void run()
  221.           {
  222.             this.val$device.connectGatt(UnityBluetoothLE.this.mContext, false, UnityBluetoothLE.this.mGattCallback);
  223.           }
  224.         });
  225.     }
  226.   }

  227.   public void androidBluetoothDeInitialize()
  228.   {
  229.     Log.d("UnityBluetoothLE", "androidBluetoothDeInitialize");
  230.     onDestroy();
  231.     UnitySend("DeInitialized");
  232.   }

  233.   public void androidBluetoothDisconnectPeripheral(String paramString)
  234.   {
  235.     if ((this.mBluetoothAdapter != null) && (this.deviceGattMap != null) && (this.mContext != null))
  236.     {
  237.       BluetoothGatt localBluetoothGatt = (BluetoothGatt)this.deviceGattMap.get(paramString);
  238.       if (localBluetoothGatt != null)
  239.         localBluetoothGatt.disconnect();
  240.     }
  241.   }

  242.   public void androidBluetoothInitialize(boolean paramBoolean1, boolean paramBoolean2)
  243.   {
  244.     Log.d("UnityBluetoothLE", "androidBluetoothInitialize");
  245.     this.mContext = UnityPlayer.currentActivity.getApplicationContext();
  246.     if (!this.mContext.getPackageManager().hasSystemFeature("android.hardware.bluetooth_le"))
  247.     {
  248.       UnitySend("Error~Bluetooth Low Energy Not Available");
  249.       return;
  250.     }
  251.     this.uuidList = null;
  252.     this.deviceMap = null;
  253.     this.deviceGattMap = null;
  254.     IntentFilter localIntentFilter = new IntentFilter("android.bluetooth.device.action.FOUND");
  255.     localIntentFilter.addAction("android.bluetooth.device.action.UUID");
  256.     localIntentFilter.addAction("android.bluetooth.adapter.action.DISCOVERY_STARTED");
  257.     localIntentFilter.addAction("android.bluetooth.adapter.action.DISCOVERY_FINISHED");
  258.     this.mContext.registerReceiver(this.ActionFoundReceiver, localIntentFilter);
  259.     this.mBluetoothAdapter = ((BluetoothManager)this.mContext.getSystemService("bluetooth")).getAdapter();
  260.     UnitySend("Initialized");
  261.   }

  262.   public void androidBluetoothLog(String paramString)
  263.   {
  264.     Log.i("UnityBluetoothLE", paramString);
  265.   }

  266.   public void androidBluetoothPause(boolean paramBoolean)
  267.   {
  268.   }

  269.   public void androidBluetoothRetrieveListOfPeripheralsWithServices(String paramString)
  270.   {
  271.     String[] arrayOfString;
  272.     int i;
  273.     if (this.mBluetoothAdapter != null)
  274.     {
  275.       this.uuidList = new ArrayList();
  276.       if (!paramString.contains("|"))
  277.         break label99;
  278.       arrayOfString = paramString.split("|");
  279.       if ((arrayOfString != null) && (arrayOfString.length > 0))
  280.       {
  281.         i = 0;
  282.         if (i < arrayOfString.length)
  283.           break label77;
  284.       }
  285.     }
  286.     while (true)
  287.     {
  288.       androidBluetoothLog("getting bonded devices");
  289.       UnityPlayer.currentActivity.runOnUiThread(new Runnable()
  290.       {
  291.         public void run()
  292.         {
  293.           Set localSet = UnityBluetoothLE.this.mBluetoothAdapter.getBondedDevices();
  294.           Iterator localIterator;
  295.           if ((localSet != null) && (localSet.size() > 0))
  296.             localIterator = localSet.iterator();
  297.           while (true)
  298.           {
  299.             if (!localIterator.hasNext())
  300.               return;
  301.             BluetoothDevice localBluetoothDevice = (BluetoothDevice)localIterator.next();
  302.             if (localBluetoothDevice == null)
  303.               continue;
  304.             UnityBluetoothLE.this.androidBluetoothLog("got device " + localBluetoothDevice.getAddress());
  305.             if (UnityBluetoothLE.this.uuidList.size() > 0)
  306.             {
  307.               localBluetoothDevice.fetchUuidsWithSdp();
  308.               continue;
  309.             }
  310.             UnityBluetoothLE.this.sendDiscoveredDevice(localBluetoothDevice);
  311.           }
  312.         }
  313.       });
  314.       return;
  315.       label77: this.uuidList.add(getFullBluetoothLEUUID(arrayOfString[i]));
  316.       i++;
  317.       break;
  318.       label99: if (paramString.length() <= 0)
  319.         continue;
  320.       this.uuidList.add(getFullBluetoothLEUUID(paramString));
  321.     }
  322.   }

  323.   public void androidBluetoothScanForPeripheralsWithServices(String paramString)
  324.   {
  325.     ArrayList localArrayList;
  326.     String[] arrayOfString;
  327.     int i;
  328.     if (this.mBluetoothAdapter != null)
  329.     {
  330.       localArrayList = new ArrayList();
  331.       if (paramString != null)
  332.       {
  333.         if (!paramString.contains("|"))
  334.           break label118;
  335.         arrayOfString = paramString.split("|");
  336.         if ((arrayOfString != null) && (arrayOfString.length > 0))
  337.         {
  338.           i = 0;
  339.           if (i < arrayOfString.length)
  340.             break label98;
  341.         }
  342.       }
  343.     }
  344.     while (true)
  345.     {
  346.       if (localArrayList.size() <= 0)
  347.         break label138;
  348.       UUID[] arrayOfUUID = (UUID[])localArrayList.toArray(new UUID[localArrayList.size()]);
  349.       this.mBluetoothAdapter.startLeScan(arrayOfUUID, this.mLeScanCallback);
  350.       return;
  351.       label98: localArrayList.add(getFullBluetoothLEUUID(arrayOfString[i]));
  352.       i++;
  353.       break;
  354.       label118: if (paramString.length() <= 0)
  355.         continue;
  356.       localArrayList.add(getFullBluetoothLEUUID(paramString));
  357.     }
  358.     label138: this.mBluetoothAdapter.startLeScan(this.mLeScanCallback);
  359.   }

  360.   public void androidBluetoothStopScan()
  361.   {
  362.     if (this.mBluetoothAdapter != null)
  363.       this.mBluetoothAdapter.stopLeScan(this.mLeScanCallback);
  364.   }

  365.   public void androidReadCharacteristic(String paramString1, String paramString2, String paramString3)
  366.   {
  367.     if ((this.mBluetoothAdapter != null) && (this.deviceGattMap != null) && (this.mContext != null))
  368.     {
  369.       BluetoothGatt localBluetoothGatt = (BluetoothGatt)this.deviceGattMap.get(paramString1);
  370.       if (localBluetoothGatt != null)
  371.       {
  372.         UUID localUUID1 = getUUID(paramString2);
  373.         if (localUUID1 == null)
  374.           break label131;
  375.         BluetoothGattService localBluetoothGattService = localBluetoothGatt.getService(localUUID1);
  376.         if (localBluetoothGattService == null)
  377.           break label124;
  378.         UUID localUUID2 = getUUID(paramString3);
  379.         if (localUUID2 == null)
  380.           break label117;
  381.         BluetoothGattCharacteristic localBluetoothGattCharacteristic = localBluetoothGattService.getCharacteristic(localUUID2);
  382.         if (localBluetoothGattCharacteristic == null)
  383.           break label110;
  384.         if (!localBluetoothGatt.readCharacteristic(localBluetoothGattCharacteristic))
  385.           UnitySend("Error~Failed to read characteristic");
  386.       }
  387.     }
  388.     return;
  389.     label110: UnitySend("Error~Characteristic not found for Read");
  390.     return;
  391.     label117: UnitySend("Error~Not a Valid Characteristic UUID for Read");
  392.     return;
  393.     label124: UnitySend("Error~Service not found for Read");
  394.     return;
  395.     label131: UnitySend("Error~Not a Valid Service UUID for Read");
  396.   }

  397.   protected void androidSetCharacteristicNotification(String paramString1, String paramString2, String paramString3, boolean paramBoolean)
  398.   {
  399.     androidBluetoothLog("1");
  400.     BluetoothGatt localBluetoothGatt;
  401.     BluetoothGattDescriptor localBluetoothGattDescriptor;
  402.     if ((this.mBluetoothAdapter != null) && (this.deviceGattMap != null) && (this.mContext != null))
  403.     {
  404.       androidBluetoothLog("2");
  405.       localBluetoothGatt = (BluetoothGatt)this.deviceGattMap.get(paramString1);
  406.       if (localBluetoothGatt != null)
  407.       {
  408.         androidBluetoothLog("3");
  409.         UUID localUUID1 = getUUID(paramString2);
  410.         if (localUUID1 == null)
  411.           break label268;
  412.         androidBluetoothLog("4");
  413.         BluetoothGattService localBluetoothGattService = localBluetoothGatt.getService(localUUID1);
  414.         if (localBluetoothGattService == null)
  415.           break label261;
  416.         androidBluetoothLog("5");
  417.         UUID localUUID2 = getUUID(paramString3);
  418.         if (localUUID2 == null)
  419.           break label254;
  420.         androidBluetoothLog("6");
  421.         BluetoothGattCharacteristic localBluetoothGattCharacteristic = localBluetoothGattService.getCharacteristic(localUUID2);
  422.         if (localBluetoothGattCharacteristic == null)
  423.           break label247;
  424.         androidBluetoothLog("7");
  425.         if (!localBluetoothGatt.setCharacteristicNotification(localBluetoothGattCharacteristic, true))
  426.           break label240;
  427.         androidBluetoothLog("8");
  428.         localBluetoothGattDescriptor = localBluetoothGattCharacteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID);
  429.         if (localBluetoothGattDescriptor == null)
  430.           break label233;
  431.         androidBluetoothLog("9");
  432.         if (!paramBoolean)
  433.           break label217;
  434.       }
  435.     }
  436.     label217: for (byte[] arrayOfByte = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE; ; arrayOfByte = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE)
  437.     {
  438.       localBluetoothGattDescriptor.setValue(arrayOfByte);
  439.       if (localBluetoothGatt.writeDescriptor(localBluetoothGattDescriptor))
  440.         break;
  441.       UnitySend("Error~Failed to write characteristic descriptor");
  442.       return;
  443.     }
  444.     androidBluetoothLog("10");
  445.     return;
  446.     label233: UnitySend("Error~Failed to get notification descriptor");
  447.     return;
  448.     label240: UnitySend("Error~Failed to set characteristic notification");
  449.     return;
  450.     label247: UnitySend("Error~Characteristic not found for Subscribe");
  451.     return;
  452.     label254: UnitySend("Error~Not a Valid Characteristic UUID for Subscribe");
  453.     return;
  454.     label261: UnitySend("Error~Service not found for Subscribe");
  455.     return;
  456.     label268: UnitySend("Error~Not a Valid Service UUID for Subscribe");
  457.   }

  458.   public void androidSubscribeCharacteristic(String paramString1, String paramString2, String paramString3)
  459.   {
  460.     androidBluetoothLog("subscribe characteristic");
  461.     androidSetCharacteristicNotification(paramString1, paramString2, paramString3, true);
  462.   }

  463.   public void androidUnsubscribeCharacteristic(String paramString1, String paramString2, String paramString3)
  464.   {
  465.     androidBluetoothLog("unsubscribe characteristic");
  466.     androidSetCharacteristicNotification(paramString1, paramString2, paramString3, false);
  467.   }

  468.   public void androidWriteCharacteristic(String paramString1, String paramString2, String paramString3, byte[] paramArrayOfByte, int paramInt, boolean paramBoolean)
  469.   {
  470.     BluetoothGatt localBluetoothGatt;
  471.     BluetoothGattCharacteristic localBluetoothGattCharacteristic;
  472.     if ((this.mBluetoothAdapter != null) && (this.deviceGattMap != null) && (this.mContext != null))
  473.     {
  474.       localBluetoothGatt = (BluetoothGatt)this.deviceGattMap.get(paramString1);
  475.       if (localBluetoothGatt != null)
  476.       {
  477.         UUID localUUID1 = getUUID(paramString2);
  478.         if (localUUID1 == null)
  479.           break label167;
  480.         BluetoothGattService localBluetoothGattService = localBluetoothGatt.getService(localUUID1);
  481.         if (localBluetoothGattService == null)
  482.           break label160;
  483.         UUID localUUID2 = getUUID(paramString3);
  484.         if (localUUID2 == null)
  485.           break label153;
  486.         localBluetoothGattCharacteristic = localBluetoothGattService.getCharacteristic(localUUID2);
  487.         if (localBluetoothGattCharacteristic == null)
  488.           break label146;
  489.         androidBluetoothLog("write characteristic");
  490.         localBluetoothGattCharacteristic.setValue(paramArrayOfByte);
  491.         if (!paramBoolean)
  492.           break label140;
  493.       }
  494.     }
  495.     label140: for (int i = 2; ; i = 1)
  496.     {
  497.       localBluetoothGattCharacteristic.setWriteType(i);
  498.       if (!localBluetoothGatt.writeCharacteristic(localBluetoothGattCharacteristic))
  499.         UnitySend("Error~Failed to write characteristic");
  500.       return;
  501.     }
  502.     label146: UnitySend("Error~Characteristic not found for Write");
  503.     return;
  504.     label153: UnitySend("Error~Not a Valid Characteristic UUID for Write");
  505.     return;
  506.     label160: UnitySend("Error~Service not found for Write");
  507.     return;
  508.     label167: UnitySend("Error~Not a Valid Service UUID for Write");
  509.   }

  510.   protected UUID getUUID(String paramString)
  511.   {
  512.     UUID localUUID;
  513.     if (paramString.length() == 36)
  514.       localUUID = UUID.fromString(paramString);
  515.     int i;
  516.     do
  517.     {
  518.       return localUUID;
  519.       i = paramString.length();
  520.       localUUID = null;
  521.     }
  522.     while (i > 8);
  523.     StringBuilder localStringBuilder = new StringBuilder();
  524.     localStringBuilder.append("00000000", 0, 8 - paramString.length());
  525.     localStringBuilder.append(paramString);
  526.     localStringBuilder.append("-0000-1000-8000-00805f9b34fb");
  527.     return UUID.fromString(localStringBuilder.toString());
  528.   }

  529.   public void onDestroy()
  530.   {
  531.     if (this.mContext != null)
  532.     {
  533.       this.mContext.unregisterReceiver(this.ActionFoundReceiver);
  534.       this.uuidList = null;
  535.       this.deviceMap = null;
  536.       this.deviceGattMap = null;
  537.     }
  538.   }
  539. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2015-4-15 15:56:05 | 显示全部楼层
高手,逆向工程好强大
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-15 20:02:22 | 显示全部楼层
本帖最后由 bobst 于 2015-4-15 20:06 编辑
HuaShine2015 发表于 2015-4-15 13:03
从原作者网页信息看需要蓝牙4.0的模块才能支持,HC-05才蓝牙2.0
The current app is setup to work with D ...


膜拜、、
1.unity3 用什么反编译的?

2.uuid是每个蓝牙独有的么,
用原作的app  UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
这个UUID 要和蓝牙上的匹配才可以么?(app 蓝牙 uuid要一致?==)

3.CC2540 CC2541 RF-BM-S02  这只4.0可以么、、//
回复 支持 反对

使用道具 举报

发表于 2015-4-16 11:23:43 | 显示全部楼层
bobst 发表于 2015-4-15 20:02
膜拜、、
1.unity3 用什么反编译的?

买一个4.0的蓝牙从模块就可以了,很便宜的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-7 22:28 , Processed in 0.043176 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表