1 #include
2 #include
3 #include
4 #include "Provider.h"
5 #include "libCold_chain.h"
6
7 JNIEnv*jniEnv;8
9 jint10 Java_com_panasonic_communicationtest_StateConfirmFragment_openSerialDevice( JNIEnv*env, jobject thiz, jstring devName )11 {12 const char* devName_id = (*env)->GetStringUTFChars(env, devName, NULL);13 if(jniEnv ==NULL) {14 jniEnv =env;15 }16
17 returnopenSerialDevice(devName_id);18 }19
20 jint21 Java_com_panasonic_communicationtest_StateConfirmFragment_readSerialData( JNIEnv*env, jobject thiz )22 {23 long dataTest = 0;24
25 if(jniEnv ==NULL) {26 jniEnv =env;27 }28
29 jclass class;30 jfieldID send_instruction_record;31 jfieldID receive_instruction_record;32 class = (*env)->GetObjectClass(env, thiz);33 if (class ==NULL)34 {35 return -1;36 }37 send_instruction_record = (*env)->GetFieldID(env, class, "send_instruction_str", "Ljava/lang/String;");38 receive_instruction_record = (*env)->GetFieldID(env, class, "receive_instruction_str", "Ljava/lang/String;");39 if (send_instruction_record == NULL || receive_instruction_record ==NULL)40 {41 return -1;42 }43
44 unsigned char* rcmdReq = malloc(9*sizeof(jchar));45 unsigned char* rcmdRes = malloc(10*sizeof(jchar));46
47 if(readSerialData(1, 1, 80, &dataTest, 500, rcmdReq, rcmdRes) == 0){48
49 unsigned char* str1 = "hello fan sen!";50 unsigned char* str2 =rcmdReq;51
52 jstring jstr1 = (*env)->NewStringUTF(env, str1);53 jstring jstr2 = (*env)->NewStringUTF(env, str2);54 __android_log_print(ANDROID_LOG_INFO, "ComTest", rcmdReq);55 if(jstr1 == NULL || jstr2 ==NULL){56 return 2;57 }58 (*env)->SetObjectField(env, thiz, send_instruction_record, jstr1);59 (*env)->SetObjectField(env, thiz, receive_instruction_record, jstr2);60
61 returndataTest;62 }63
64 return -1;65 }66
67 jint68 Java_com_panasonic_communicationtest_StateConfirmFragment_closeSerialDevice( JNIEnv*env, jobject thiz, jint devFd )69 {70 if(jniEnv ==NULL) {71 jniEnv =env;72 }73
74 returncloseSerialDevice(devFd);75 }76
77 //===========================================
78 jint79 Java_com_panasonic_communicationtest_ParameterSettingFragment_openSerialDevice( JNIEnv*env, jobject thiz, jstring devName )80 {81 const char* devName_id = (*env)->GetStringUTFChars(env, devName, NULL);82 if(jniEnv ==NULL) {83 jniEnv =env;84 }85
86 returnopenSerialDevice(devName_id);87 }88
89 jint90 Java_com_panasonic_communicationtest_ParameterSettingFragment_readSerialData( JNIEnv*env, jobject thiz, jint devFd, jchar unitno, jshort addr, jlong data )91 {92 if(jniEnv ==NULL) {93 jniEnv =env;94 }95
96 unsigned char rcmdReq[10];97 unsigned char rcmdRes[10];98
99 return readSerialData(devFd, unitno, addr, data, 500, rcmdReq[10], rcmdRes[10]);100 }101
102 jint103 Java_com_panasonic_communicationtest_ParameterSettingFragment_writeSerialData( JNIEnv*env, jobject thiz, jint devFd, jchar unitno, jshort addr, jlong data )104 {105 if(jniEnv ==NULL) {106 jniEnv =env;107 }108
109 unsigned char rcmdReq[10];110 unsigned char rcmdRes[10];111
112 return writeSerialData(devFd, unitno, addr, data, 500, rcmdReq[10], rcmdRes[10]);113 }114
115 jint116 Java_com_panasonic_communicationtest_ParameterSettingFragment_closeSerialDevice( JNIEnv*env, jobject thiz, jint devFd )117 {118 if(jniEnv ==NULL) {119 jniEnv =env;120 }121
122 returncloseSerialDevice(devFd);123 }124
125
126
127 //--------------------------------------
128 jstring129 Java_com_panasonic_communicationtest_StateConfirmFragment_getStringFromJNI( JNIEnv*env, jobject thiz, jstring address )130 {131 const char* address_id = (*env)->GetStringUTFChars(env, address, NULL);132 if(jniEnv ==NULL) {133 jniEnv =env;134 }135
136 //return getString(address_id);
137 return (*env)->NewStringUTF(env, address_id);138 }139
140 jstring141 Java_com_panasonic_communicationtest_ParameterSettingFragment_getStringFromJNI( JNIEnv*env, jobject thiz, jstring address )142 {143 const char* address_id = (*env)->GetStringUTFChars(env, address, NULL);144 if(jniEnv ==NULL) {145 jniEnv =env;146 }147 returngetString(address_id);148 }149
150 jstring151 Java_com_panasonic_communicationtest_ParameterSettingFragment_setStringIntoJNI( JNIEnv*env, jobject thiz, jstring address )152 {153 const char* address_id = (*env)->GetStringUTFChars(env, address, NULL);154 if(jniEnv ==NULL) {155 jniEnv =env;156 }157 returnsetString(address_id);158 }