Android Open Source - BT-Connection-Template Transaction Receiver






From Project

Back to project page BT-Connection-Template.

License

The source code is released under:

Apache License

If you think the Android project BT-Connection-Template 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) 2014 Bluetooth Connection Template
 */* www . j a va 2  s.c o m*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hardcopy.btctemplate.bluetooth;

import java.util.ArrayList;

import android.os.Handler;

/**
 * Parse stream and extract accel data
 * @author Administrator
 */
public class TransactionReceiver {
  private static final String TAG = "TransactionReceiver";
  
  private static final int PARSE_MODE_ERROR = 0;
  private static final int PARSE_MODE_WAIT_START_BYTE = 1;
  private static final int PARSE_MODE_WAIT_COMMAND = 2;
  private static final int PARSE_MODE_WAIT_DATA = 3;
  private static final int PARSE_MODE_WAIT_END_BYTE = 4;
  private static final int PARSE_MODE_COMPLETED = 101;
  
  private Handler mHandler = null;
  
  
  
  public TransactionReceiver(Handler h) {
    mHandler = h;
    reset();
  }
  
  
  /**
   * Reset transaction receiver.
   */
  public void reset() {
  }
  
  /**
   * Set bytes to parse
   * This method automatically calls parseStream()
   * @param buffer  
   * @param count
   */
  public void setByteArray(byte[] buffer, int count) {
    parseStream(buffer, count);
  }
  
  /**
   * After parsing bytes received, transaction receiver makes object instance.
   * This method returns parsed results
   * @return  Object    parsed object
   */
  public Object getObject() {
    // TODO: return what you want
    return null;
  }

  /**
   * Caching received stream and parse byte array
   * @param buffer    byte array to parse
   * @param count      byte array size
   */
  public void parseStream(byte[] buffer, int count) {
    if(buffer != null && buffer.length > 0 && count > 0) {
      for(int i=0; i < buffer.length && i < count; i++) {
        
        // Parse received data
        // Protocol description -----------------------------------------------------------
        // Describe brief info about protocol
        
        // TODO: parse buffer
        
        
      }  // End of for loop
    }  // End of if()
  }  // End of parseStream()

  
}




Java Source Code List

com.hardcopy.btctemplate.DeviceListActivity.java
com.hardcopy.btctemplate.MainActivity.java
com.hardcopy.btctemplate.bluetooth.BluetoothManager.java
com.hardcopy.btctemplate.bluetooth.ConnectionInfo.java
com.hardcopy.btctemplate.bluetooth.TransactionBuilder.java
com.hardcopy.btctemplate.bluetooth.TransactionReceiver.java
com.hardcopy.btctemplate.contents.DBHelper.java
com.hardcopy.btctemplate.fragments.ExampleFragment.java
com.hardcopy.btctemplate.fragments.FragmentAdapter.java
com.hardcopy.btctemplate.fragments.IFragmentListener.java
com.hardcopy.btctemplate.fragments.LLSettingsFragment.java
com.hardcopy.btctemplate.service.BTCTemplateService.java
com.hardcopy.btctemplate.service.ServiceMonitoring.java
com.hardcopy.btctemplate.utils.AppSettings.java
com.hardcopy.btctemplate.utils.Constants.java
com.hardcopy.btctemplate.utils.Logs.java
com.hardcopy.btctemplate.utils.RecycleUtils.java