Skip to content

Android Developer SDK

Rémy edited this page Nov 13, 2023 · 25 revisions

At last, PandwaRF has an Android SDK. The library is called gollum. You can include this library module to your Android project and develop your own application to drive your PandwaRF.

Complete PandwaRF API documentation can be found here.

Getting started

Gradle setup

In your project build.gradle, add the Repo Read URL for PandwaRF Gollum Android Lib:

allprojects {
    repositories {
        ...
        maven {
            // Repo Read URL for PandwaRF Gollum Android Lib
            url "https://mymavenrepo.com/repo/l8uzsKQuWwYGByPmlbZ4/"
        }
    }
}

In your application Module build.gradle, provide the gradle dependency: Maven Version nrftoolbox

Maven Version gollum

dependencies {
    ...
    // Gollum Lib components
    implementation 'de.greenrobot:eventbus:2.4.1'
    implementation 'com.comthings.pandwarf:nrftoolbox:{x.y.z}'
    implementation 'com.comthings.pandwarf:gollum:{x.y.z}'
    ...
}

Using the library

Connection

All PandwaRF methods are accessible using a singleton instance of GollumDongle class.

BLE connection

Register for BLE callbacks

GollumDongle.getInstance(getActivity()).setBleManagerAppCallbacks(bleManagerCallbacks);

BLE scan for PandwaRF devices

GollumDongle.getInstance(getActivity()).searchDevice(new ScannerListener() {
	@Override
	public void onSignalNewDevice(final ExtendedBluetoothDevice device) {
...
          GollumDongle.getInstance(getActivity()).openDevice(device, true, false, bleManagerCallbacks);
...
	}

	@Override
	public void onSignalUpdateDevice(ExtendedBluetoothDevice device) {
	}

	@Override
	public void onSignalEndScan(Exception e) {     
	}
});

Stop BLE scanning for PandwaRF devices

GollumDongle.getInstance(getActivity()).stopSearchDevice();

Open PandwaRF connection

GollumDongle.getInstance(getActivity()).openDevice(device, true, false, bleManagerCallbacks);

Close PandwaRF connection

GollumDongle.getInstance(getActivity()).closeDevice();

Pause PandwaRF connection

in your activity onPause() method

@Override
protected void onPause() {
...
        // If you want to keep BLE background connection
	if (!isKeepConnectionInBackgroundEnabled()) {
		Log.d(TAG, "BLE connection pause, going to background");
                // Warning: Do not call this if connected in USB
		GollumDongle.getInstance(getParent()).pause();
	}	
...

Resume PandwaRF connection

in your activity onResume() method

@Override
protected void onResume() {
...
        // If you want to resume BLE background connection
	if (!isKeepConnectionInBackgroundEnabled()) {
		Log.d(TAG, "Auto reconnect - onResume() - to last BLE mac address");
		GollumDongle.getInstance(this).reconnect("");
	}	
...

USB connection

Register for USB callbacks

GollumDongle.getInstance(getActivity()).setUsbManagerAppCallbacks(usbManagerCallbacks);

React to USB events

When USB is connected/disconnected, the following methods are called

public void onUsbDeviceConnected(String deviceName);
public void onUsbDeviceDisconnected(String deviceName);

Warning about USB Pause

Do not call the pause() method if you are connected in USB.

@Override
protected void onPause() {
...
  // Warning: Do not call pause() if connected in USB
  //GollumDongle.getInstance(getParent()).pause();
...

App closing

in your activity onDestroy() method

@Override
protected void onDestroy() {
...
   GollumDongle.getInstance(this).destroy();
...

Communication with PandwaRF

Send data

GollumDongle.getInstance(getActivity()).txSetup(freq, mod, datarate);

// txSend() takes an ASCII buffer as input
// 1 byte = 2 hex digits ==> Eg. "0xAB0F" is stored in data[] as [0x41, 0x42, 0x30, 0x46, ...]
byte[] data = { 0x41, 0x42, 0x30, 0x46, ... };
GollumDongle.getInstance(getActivity()).txSend(data.getBytes(), data.getBytes().length / 2, true);

Receive data

Receive from background task:

GollumDongle.getInstance(getActivity()).rxSetup(freq, mod, drate, frameLength);
while(true) {
    byte[] bufferHex = new byte[frameLength];    // Hex buffer : range [0x00 to 0xFF]
    rx_size = GollumDongle.getInstance(getActivity()).rxListen(bufferHex , frameLength);

    // Convert buffer to ASCII. Since 1 byte is coded in 2 ASCII digits, bufferAsciiStr size = bufferHex size * 2
    String bufferAsciiStr = Utils.byteArrayToHexString(bufferHex, rx_size);

}

Receive from UI thread:

GollumDongle.getInstance(getActivity()).rxSetup(freq, mod, drate, frameLength, new GollumCallbackGetInteger() {
    @Override
    public void done(int result) {
        Log.d(TAG, "rxSetup finished: " + result);

        while (true) {
            byte[] bufferHex = new byte[frameLength];    // Local Hex buffer : range [0x00 to 0xFF]
            rx_size = GollumDongle.getInstance(getActivity()).rxListen(bufferHex, frameLength, new GollumCallbackGetInteger() {
                @Override
                public void done(int result) {
                    Log.d(TAG, "rxListen finished: " + rx_size);
  
                }
            });
        }
    }
});

Spectrum Analyzer

// Set the delay between each RSSI packet
GollumDongle.getInstance(getActivity()).rfSpecanSetPktDelay(0, progress, new GollumCallbackGetInteger() {
  @Override
  public void done(int integer) {
    Log.d(TAG, "Delay between 2 SpecAn packets set");
  }
});

...

// Kick the SpecAn
GollumDongle.getInstance(getActivity()).rfSpecanStart(0, (int) (basefreqMHz * MHZ_TO_HZ), incHz, specchans, measInterval);

...

// Store data (do this from background thread)
while (true) {
  // Array to store RSSI values
  byte[] rssi_buffer = new byte[specchans];
  
  int numRssiMeas = GollumDongle.getInstance(activity).rfSpecanGetRssi(rssi_buffer, specchans);

  // Now display the data...
  ...
}

...

// Stop the SpecAn
GollumDongle.getInstance(getActivity()).rfSpecanStop(0, new GollumCallbackGetInteger() {
  @Override
  public void done(int integer) {
    Log.d(TAG, "SpecAn successfully stopped");
  }
});

Brute Force

GollumDongle.getInstance(getActivity()).rfBruteForceAttackStart(0, 433000000, 5000, 0x30,
		8, 0, 100,        // CodeWord: 8 bits, starts brute from index 0 to 100
		5, true, 100,     // repeat each frame 5 times, use Little Endian for transmission, 100ms interframe
		0x8E, 0xEE, 0x00, 0x00, // Symbols encoding
		4, "80000000",   // Synchro word
		new GollumCallbackGetInteger() {
			@Override
			public void done(int result) {
				Log.d(TAG, "Brute Force successfully started");   
			}
		});

...

// Get Brute Force status: do this from background thread
GollumDongle.getInstance(activity).rfBruteForceAttackStatusUpdate(0, new GollumCallbackGetInteger() {
  @Override
  public void done(int status) {							
  		Log.d(TAG, "New Brute force Status update: " + status);    
    }
  });   

...

GollumDongle.getInstance(activity).rfBruteForceAttackStop(0, new GollumCallbackGetInteger() {
	@Override
	public void done(int result) {
		Log.d(TAG, "Brute Force finished: " + result);
	}
});

Check the API documentation

PandwaRF API documentation can be found here.

Check our Sample Android Applications

Sample Android Application

  • Spectrum Analyzer sample application
  • RX/TX sample application
  • JavaScript sample application

Project Information

PandwaRF Android Application (Normal Mode)

PandwaRF Android Application (Dev Mode)

Marauder Android Application

iOS Application

Linux

Hardware

For developers

Support

Gimme moar!

Clone this wiki locally