Showing posts with label libRFID. Show all posts
Showing posts with label libRFID. Show all posts

Make file Sample Code for Porting libRFID from Linux to Anroid


MY_PATH := $(call my-dir)/librfid-0.2.0

LOCAL_PATH := $(MY_PATH)/src/ \
  $(MY_PATH)/src/ccid

include $(CLEAR_VARS)

# path for Header files
LOCAL_C_INCLUDES := $(MY_PATH)/include

#C files added from the src/ path
LOCAL_SRC_FILES := usleep.c rfid.c rfid_scan.c rfid_reader.c rfid_reader_spidev.c rfid_reader_rc632_common.c \
rfid_reader_openpcd.c rfid_reader_cm5121.c rfid_reader_cm5121_openct.c rfid_protocol.c \
rfid_proto_tcl.c rfid_proto_tagit.c rfid_proto_mifare_ul.c rfid_proto_mifare_classic.c rfid_proto_icode.c \
rfid_layer2.c rfid_layer2_iso15693.c rfid_layer2_iso14443b.c rfid_layer2_iso14443a.c rfid_iso14443_common.c \
rfid_asic_rc632.c rfid_access_mifare_classic.c libusb_dyn.c

#C files added from utils
LOCAL_SRC_FILES := utils/common.c utils/librfid-tool.c utils/mifare-tool.c utils/send_script.c

#C files added from the src/ccid path
#here we are not using the file rfid_reader_cm5121_ccid_direct.c because it is used by rfid_reader_cm5121.c as 
#reference
LOCAL_SRC_FILES := ccid-driver.c 

#Module path of the library
LOCAL_MODULE := test_rfid_integration_RfidLib
LOCAL_LDLIBS := -llog


include $(BUILD_SHARED_LIBRARY)

Write to ADB Log terminal from Java and native code

Usually when we deal with High level programming we should maintain the log information something line debugging because we may have bunch of log data when the system is compiling. Therefore in Android native programming most of the time we deal with c and java.

To track the log in Android native project.

  1. run the android virtual machine using eclipse 
  2. open terminal 
  3. go to the specific folder
  4. command adt logcat to view the log information (This will only run while your android virtual machine is running ,if not it will giving a message like bellow)
Dhanushanths-MacBook-Pro:RFIDIntegration dhanus$ adb logcat
- waiting for device -


From Java
First we see how to pass log information form Java,
Pass the log data information from Java to adb log cat is pretty simple


package test.rfid.integration;
import android.util.Log;------------------------(1)
public class RfidLib {
//Write a own lines in Log using terminal 
public static final String TAG = "Test"; ------------(2)
public static int addValueJ(int x,int y){
Log.d(TAG,"*********The log data from the Java Method************");-----(3)
int sum = x+y;
return sum;
}
public native static int addValueN(int x,int y);
static{
System.loadLibrary("test_rfid_integration_RfidLib");
}
}

you have to add that 3 mentioned lines in your code. Also don't forget to add the LOCAL_LDLIBS line in make file 


LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := test_rfid_integration_RfidLib.c
LOCAL_MODULE := test_rfid_integration_RfidLib
LOCAL_LDLIBS := -llog ---------------(make line)
include $(BUILD_SHARED_LIBRARY)


From Native
Here we can call the log from native code,

#include "test_rfid_integration_RfidLib.h"
#include <android/log.h> ----------------(1)

/*
 * Class:     test_rfid_integration_RfidLib
 * Method:    addValueN
 * Signature: (II)I
 */

JNIEXPORT jint JNICALL Java_test_rfid_integration_RfidLib_addValueN
  (JNIEnv *env, jclass cla, jint x, jint y)
{
//pass the log data in to terminal using
__android_log_print(ANDROID_LOG_DEBUG, "test_rfid_integration_Rfidlib.c", "*********Log data from Native code***********"); ----------(2)
jint sum = x * y;
return sum;

}

Add the two lines which are mentioned in bellow as 1 and 2.

Finally to build the file use ,
  • ndk-build clean
  • ndk-build all
great you are in business





RFID Library for projects

If any one deal with RFID related project for android or linux. Here you can get the open source librfid for your development. The file can be downloadable here. To conform that the source file is working perfectly on your machine follow the instruction.

image reference
  1. Extract the file to your specific location.
  2. Change the folder permission (This should be done if now the ./configure will not process) to change the user permission ->go to folder using terminal and type chmod -R 700 *.
  3. after change the permission type sudo ./configure
  4. Then type sudo make and finally sudo make install .
  5. Done. Now you can start with your code implementation if the source was successfully build.
For Android Developers,
You guys can port this to native library.