1 /* JNtpTimeToStringUs.c */
3 * This code provides conversion between JAVA a C environments.
4 * The C functions are calling here and results are send to JAVA
5 * native functions. It uses the header pregenerated by JAVA
6 * (by command 'javah -jni class_with_native_function')
8 * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
9 * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
10 * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
11 * @author dedication to Kj
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
28 // origin orte headers
30 // pregenerated header
31 #include "jorte/org_ocera_orte_types_NtpTime.h"
35 /* native function - prototype declared in pregenerated header */
36 JNIEXPORT jstring JNICALL
37 Java_org_ocera_orte_types_JORTENtpTime_NtpTimeToStringUs
38 (JNIEnv *env, jclass class, jobject j_ntpTime)
40 char buff[65]; // 32 + 32 + 1 end char
46 // NtpTime - get object's class
47 ntpTimeClass = (*env)->GetObjectClass(env, j_ntpTime);
49 // seconds - get object field ID
50 fieldID = (*env)->GetFieldID(env,ntpTimeClass,"seconds","I");
52 return((*env)->NewStringUTF(env, "error when reading Java NtpTime"));
54 time.seconds = (int32_t) (*env)->GetIntField(env,j_ntpTime,fieldID);
59 // fraction - get object field ID
60 fieldID = (*env)->GetFieldID(env,ntpTimeClass,"fraction","J");
62 return((*env)->NewStringUTF(env, "error when reading Java NtpTime"));
64 time.fraction = (uint32_t) (*env)->GetIntField(env,j_ntpTime,fieldID);
66 // calling an orte's function
67 NtpTimeToStringUs(time,buff);
68 // return result of the conversion
69 return((*env)->NewStringUTF(env, buff));