// Path: DeviceService/src/com/ratio/exceptions/DeviceManagerException.java
// public class DeviceManagerException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceManagerException(String s) {
// 		super(s);
// 	}
// 	public DeviceManagerException(String error, String errorValue) {
//     	super(String.format("%s %s", error, errorValue));
// 	}
// }
// 
// Path: DeviceService/src/com/ratio/exceptions/DeviceNameNotFoundException.java
// public class DeviceNameNotFoundException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceNameNotFoundException(String s) {
// 		super(s);
// 	}
// }


import java.util.ArrayList;
import java.util.UUID;
import com.ratio.exceptions.DeviceManagerException;
import com.ratio.exceptions.DeviceNameNotFoundException;
import com.ratio.deviceService.IDeviceCommand;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
    public final static String EXTRA_VALUE = DeviceService.class.getName() + ".EXTRA_VALUE";
    public final static String EXTRA_RSSI = DeviceService.class.getName() + ".EXTRA_RSSI";
    public final static String EXTRA_STATUS = DeviceService.class.getName() + ".EXTRA_STATUS";
    public final static String EXTRA_RETRIES_LEFT = DeviceService.class.getName() + ".EXTRA_RETRIES_LEFT";
       
    protected static BTLEDeviceManager	mDeviceManager;					// device manager actually does device interface
    protected static int 				mPeriodMsec;					// how many msec should we poll for?
    protected static UUID[]				mAdvertisedServices;			// advertised services to scan for
    protected static boolean			mfInitialized = false;
    protected static boolean			mfScanning = false;				// scanning for BTLE devices, don't start another scan
		
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		if ((intent != null) && (intent.getAction() != null)) {
			// this is because we get the message from the broadcast receiver that toggles the bluetooth adapter.
			if (intent.getAction().equals(ACTION_PERFORM_SCAN)) {
				mfScanning = true;
				mDeviceManager.scanLeDevice(mAdvertisedServices, mPeriodMsec);
			}
		}
		return START_STICKY;
	}
   /**
     * Initializes a reference to the local Bluetooth adapter.
     *
     * @return Return true if the initialization is successful.
     */
    public boolean initialize() {
    	try {
    		mDeviceManager = new BTLEDeviceManager(this, this);
// Path: DeviceService/src/com/ratio/exceptions/DeviceManagerException.java
// public class DeviceManagerException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceManagerException(String s) {
// 		super(s);
// 	}
// 	public DeviceManagerException(String error, String errorValue) {
//     	super(String.format("%s %s", error, errorValue));
// 	}
// }
// 
// Path: DeviceService/src/com/ratio/exceptions/DeviceNameNotFoundException.java
// public class DeviceNameNotFoundException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceNameNotFoundException(String s) {
// 		super(s);
// 	}
// }


// Path: DeviceService/src/com/ratio/deviceService/DeviceService.java
import java.util.ArrayList;
import java.util.UUID;
import com.ratio.exceptions.DeviceManagerException;
import com.ratio.exceptions.DeviceNameNotFoundException;
import com.ratio.deviceService.IDeviceCommand;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

    public final static String EXTRA_VALUE = DeviceService.class.getName() + ".EXTRA_VALUE";
    public final static String EXTRA_RSSI = DeviceService.class.getName() + ".EXTRA_RSSI";
    public final static String EXTRA_STATUS = DeviceService.class.getName() + ".EXTRA_STATUS";
    public final static String EXTRA_RETRIES_LEFT = DeviceService.class.getName() + ".EXTRA_RETRIES_LEFT";
       
    protected static BTLEDeviceManager	mDeviceManager;					// device manager actually does device interface
    protected static int 				mPeriodMsec;					// how many msec should we poll for?
    protected static UUID[]				mAdvertisedServices;			// advertised services to scan for
    protected static boolean			mfInitialized = false;
    protected static boolean			mfScanning = false;				// scanning for BTLE devices, don't start another scan
		
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		if ((intent != null) && (intent.getAction() != null)) {
			// this is because we get the message from the broadcast receiver that toggles the bluetooth adapter.
			if (intent.getAction().equals(ACTION_PERFORM_SCAN)) {
				mfScanning = true;
				mDeviceManager.scanLeDevice(mAdvertisedServices, mPeriodMsec);
			}
		}
		return START_STICKY;
	}
   /**
     * Initializes a reference to the local Bluetooth adapter.
     *
     * @return Return true if the initialization is successful.
     */
    public boolean initialize() {
    	try {
    		mDeviceManager = new BTLEDeviceManager(this, this);
    	} catch (DeviceManagerException dmex) {