Android Open Source - p1keyboard Data Dump Reader






From Project

Back to project page p1keyboard.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project p1keyboard listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/* Copyright (C) 2011, Kenneth Skovhede
 * http://www.hexad.dk, opensource@hexad.dk
 * //from   w ww. ja va2  s .  c om
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
package mobi.omegacentauri.p1keyboard;

import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.util.Log;

public class DataDumpReader extends RfcommReader {

  private static final String LOG_NAME = "BluezIME:DataDumpReader";
  public static final String DRIVER_NAME = "dump";
  public static final String DISPLAY_NAME = "Data Dump Reader";
  
  public DataDumpReader(String address, String sessionId, Context context, boolean startnotification) throws Exception {
    super(address, sessionId, context, startnotification);
  }

  @Override
  public String getDriverName() {
    return DRIVER_NAME;
  }

  @Override
  protected int setupConnection(ImprovedBluetoothDevice device, byte[] readBuffer) throws Exception {
    String connectionType = "?";
    
    for(int port = 0; port < 31; port++) {
      Log.d(LOG_NAME, "Connecting with port: " + port);
    
      try {
        connectionType = "Secure";
        Log.d(LOG_NAME, "Attempting createRfcommSocket");
    
          BluetoothSocket s = device.createRfcommSocket(port);
            s.connect();
            
            m_socket = s;
      } catch (Exception ex) {
        Log.e(LOG_NAME, ex.toString());
        m_socket = null;
        try {
          connectionType = "Insecure";
          Log.d(LOG_NAME, "Attempting createInsecureRfcommSocket");
            
            BluetoothSocket s = device.createInsecureRfcommSocket(port);
              s.connect();
              
              m_socket = s;
        } catch (Exception ex2) {
          Log.e(LOG_NAME, ex2.toString());
          m_socket = null;
        }
      }
      
      if (m_socket != null) {
        Log.d(LOG_NAME, "Connection succeeded with " + connectionType + " connection on port " + port);
        break;
      }
    }
    
    if (m_socket == null) {
        m_socket = device.createRfcommSocket(1);
          m_socket.connect();
    }
      
        Log.d(LOG_NAME, "Connected to " + m_address);
      
      m_input = m_socket.getInputStream();
      return m_input.read(readBuffer);    
  }

  @Override
  protected int parseInputData(byte[] data, int read) {
    Log.d(LOG_NAME, "Read data: " + getHexString(data, 0, read));
    return 0;
  }

  @Override
  protected void validateWelcomeMessage(byte[] data, int read) {
    Log.d(LOG_NAME, "Welcome message is: " + getHexString(data, 0, read));
  }

}




Java Source Code List

mobi.omegacentauri.p1keyboard.BGP100Reader.java
mobi.omegacentauri.p1keyboard.BluezDriverInterface.java
mobi.omegacentauri.p1keyboard.BluezForegroundService.java
mobi.omegacentauri.p1keyboard.BluezIMESettings.java
mobi.omegacentauri.p1keyboard.BluezIME.java
mobi.omegacentauri.p1keyboard.BluezService.java
mobi.omegacentauri.p1keyboard.ButtonConfiguration.java
mobi.omegacentauri.p1keyboard.DataDumpReader.java
mobi.omegacentauri.p1keyboard.DeviceScanActivity.java
mobi.omegacentauri.p1keyboard.FutureKeyCodes.java
mobi.omegacentauri.p1keyboard.GameStopReader.java
mobi.omegacentauri.p1keyboard.HIDKeyboard.java
mobi.omegacentauri.p1keyboard.HIDReaderBase.java
mobi.omegacentauri.p1keyboard.HIDipega.java
mobi.omegacentauri.p1keyboard.ImprovedBluetoothDevice.java
mobi.omegacentauri.p1keyboard.PalmOneWirelessKeyboardReader.java
mobi.omegacentauri.p1keyboard.PhonejoyReader.java
mobi.omegacentauri.p1keyboard.Preferences.java
mobi.omegacentauri.p1keyboard.RfcommReader.java
mobi.omegacentauri.p1keyboard.WiimoteReader.java
mobi.omegacentauri.p1keyboard.ZeemoteReader.java
mobi.omegacentauri.p1keyboard.iCadeReader.java
mobi.omegacentauri.p1keyboard.iControlPadReader.java