This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

NIRScan nano BLE data deserialization on Android

Hello,

I have begun writing an android application to interface with the NIRScan nano and have run into issues deserializing the scan configurations and scan data structures. I am writing the application with the Ionic framework (Based on Cordova) which allows the use of plugins to develop using native android (java). How can I use the Spectrum library (written in C) with Android? Could someone give me a high level explaination as to how this can be done. Keeping in mind that this is my first time developing on Android. I have heard suggestions saying I should use NVM? Anything would be helpful, because I'm pretty lost.

Thank you

  • Hi Miguel,

    To use native code like the DLP Spectrum Library in Android apps, Android provides the NDK (Native Development Kit):
    developer.android.com/.../index.html

    I don't have experience building Android apps or using the NDK, but hopefully this will help you get started.
  • Thanks for the response Eric, I've added NDK functionality to my application (I have a c function that returns Hello world). I'm looking into the spectrum library and It looks like I need to use the following
    DLPSPEC_ERR_CODE dlpspec_scan_interpret
    DLPSPEC_ERR_CODE dlpspec_scan_read_configuration

    I see there is a bat file used to build the library, what exactly does building the library achieve? or do you recommend I ignore that and instead try to copy over the functionality I need over to a NDK friendly format.
  • ok I went ahead and built the spectrum library with the ndk as .c and .h files which I included in my jni c files. Problem is that I have the following code:

    // get jbyte array from array and it's length
    jbyte* configPtr = (*env)->GetByteArrayElements(env, array, NULL);
    jsize lengthOfArray = (*env)->GetArrayLength(env, array);

    size_t bufSize = lengthOfArray;

    dlpspec_scan_read_configuration (configPtr, bufSize );
    union uScanConfig2 *config = (union uScanConfig2 *)configPtr;
    char* config_name = config->scanCfg.config_name;

    // release array
    (*env)->ReleaseByteArrayElements(env, array, configPtr, 0);

    return (*env)->NewStringUTF(env, config_name);

    I had to redefine uScanConfig because I kept getting incomplete type errors during the cast from void* to uScanConfig.

    typedef union uScanConfig2
    {
    scanConfig scanCfg;
    slewScanConfig slewScanCfg;
    };

    This approach seems like a total hack on my part, and the config_name string is returning values like "c#c/c#x" definitely not the scan config name. Also should the buffer being passed to dlpspec_scan_read_configuration always be 124bytes? the bluetooth is always returning a 124 byte payload.

    Thanks

  • The scanConfig buffer translated over BLE from Tiva firmware 2.x (which uses DLP Spectrum Library 2.x), and the associated uScanConfig struct when interpreted with dlpspec_scan_read_configuration() will always be the same size. Prior to the 2.x release, the scanConfig structure was transmitted which may be a slightly different size.

    From the string returned in config_name, it looks like the scan configuration may not be getting deserialized correctly. Can you try checking the return code of the call to dlpspec_scan_read_configuration()?

    Also, please ensure that you are using a compatible Spectrum Library version in your Android code as what the NIRscan Nano Tiva firmware is currently using. The Spectrum Library version used in the NIRscan Nano can be read using the device information service, Spectrum Library revision characteristic (0x180A, 0x2A28) explained in table J-1 of the NIRscan Nano User's Guide.