#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include"windows.h"
#include <string>
#include <io.h>
#include<cstring>
/* DO NOT EDIT THIS FILE - it is machine generated */
#include "jni.h"
using namespace std;
/* Header for class test_Test */
char to_search1[] = "d:\\GPSTrack\\";
char to_search[] = "d:\\GPSTrack\\*";
char to_all[50000] = {0};
int offset = 0;
int the_replace1(char pp[])
{
int i = 0;
while(pp[i] != '\0')
{
if(pp[i] == '*')
{
pp[i] = '\0';
return 0;
}
i++;
}
return 0;
}
int the_start_time(char pp[])
{
int i = 0;
while(pp[i] != '\0')
{
if(pp[i] == ' ')
{
pp[i] = '\0';
return 0;
}
i++;
}
return 0;
}
#ifndef _Included_util_GPSUtil
#define _Included_util_GPSUtil
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: util_GPSUtil
* Method: selectGPSInfo
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_util_GPSUtil_selectGPSInfo
(JNIEnv * env, jobject, jstring the_id, jstring the_start, jstring the_end, jstring the_jump)
{
char The_id[100] = {0};
char* str_condition=(char*)env->GetStringUTFChars(the_id,JNI_FALSE);
strncpy(The_id,str_condition,strlen(str_condition)+1);
//printf("the_id = %s,sizeof = %d;The_id = %s,strlen = %d\n",the_id,sizeof(the_id),The_id,strlen(The_id));
char The_start[100] = {0};
char* str_start=(char*)env->GetStringUTFChars(the_start,JNI_FALSE);
strncpy(The_start,str_start,strlen(str_start)+1);
char The_end[100] = {0};
char* str_end=(char*)env->GetStringUTFChars(the_end,JNI_FALSE);
strncpy(The_end,str_end,strlen(str_end)+1);
char The_jump[100] = {0};
char* str_jump=(char*)env->GetStringUTFChars(the_jump,JNI_FALSE);
strncpy(The_jump,str_jump,strlen(str_jump)+1);
char the_time[100] = {0};
strncpy(the_time,The_start,strlen(The_start)+1);
//strcpy(the_time,The_start);
the_start_time(the_time);
int time_ok = atoi(The_jump);
printf("the_time = %s;;;;;time_ok = %d\n",The_jump,time_ok);
int number = 0;
// printf("处理后起始时间的年月日 = %s,strlen = %d\n",the_time,strlen(the_time));
// printf("开始处理\n");
long handle; //用于查找的句柄
struct _finddata_t fileinfo; //文件信息的结构体
handle=_findfirst(to_search,&fileinfo); //第一次查找
if(-1==handle)
{
printf("打开错误\n");
return 0;
}
printf("%s,ok\n",fileinfo.name); //打印出找到的文件的文件名
while(!_findnext(handle,&fileinfo)) //循环查找其他符合的文件,知道找不到其他的为止
{
printf("fileinfo.name = %s,strlen = %d\n",fileinfo.name,strlen(fileinfo.name));
if(!strncmp(fileinfo.name,the_time,strlen(fileinfo.name)))
{
strcat(to_search1,fileinfo.name);
strcat(to_search1,"\\");
strcat(to_search1,The_id);
strcat(to_search1,"\\*");
printf("找到文件,开始读 %s\n",to_search1);
break;
}
}
_findclose(handle); //别忘了关闭句柄
int num = 0;
handle=_findfirst(to_search1,&fileinfo); //第一次查找
if(-1==handle)return 0;
printf("%s,ok\n",fileinfo.name); //打印出找到的文件的文件名
while(!_findnext(handle,&fileinfo)) //循环查找其他符合的文件,知道找不到其他的为止
{
printf("%s\n",fileinfo.name);
if(num == 0)
{
num++;
continue;
}
the_replace1(to_search1);
strcat(to_search1,fileinfo.name);
// printf("找到了%s\n",to_search1);
FILE* file1;
int ret;
s_NV_GPS_FILEHEAD first;
s_NV_GPS_All second;
file1 = fopen(to_search1,"r");
fread(&first,sizeof(first),1,file1);
printf("%s\n",first.szDeviceID);
char *to_all1;
while(1)
{
ret = fread(&second,sizeof(second),1,file1);
if(ret == 0)
{
break;
}
// printf("%lf %lf %f %f %d %s %s\n",second.stBaseInfo.dbLongitude,second.stBaseInfo.dbLatitude,second.stBaseInfo.fDirect,second.stBaseInfo.fSpeed,second.stExternInfo.sHigh,second.stExternInfo.cSatelliteNumber,second.szTime);
if(strncmp(The_start,second.szTime,strlen(second.szTime)) >= 0 && strncmp(The_end,second.szTime,strlen(second.szTime)) >= 0)
{
if(number == time_ok)
{
offset += sprintf(to_all + offset, "%lf,", second.stBaseInfo.dbLongitude);
offset += sprintf(to_all + offset, "%lf,", second.stBaseInfo.dbLatitude);
offset += sprintf(to_all + offset, "%f,", second.stBaseInfo.fDirect);
offset += sprintf(to_all + offset, "%f,", second.stBaseInfo.fSpeed);
offset += sprintf(to_all + offset, "%d,", second.stExternInfo.sHigh);
offset += sprintf(to_all + offset, "%x,", second.stExternInfo.cSatelliteNumber);
offset += sprintf(to_all + offset, "%s;", second.szTime);
// printf("%lf %lf %f %f %d %s %s\n",second.stBaseInfo.dbLongitude,second.stBaseInfo.dbLatitude,second.stBaseInfo.fDirect,second.stBaseInfo.fSpeed,second.stExternInfo.sHigh,second.stExternInfo.cSatelliteNumber,second.szTime);
number = 0;
printf("111111111111111111111111111\n%s\n",to_all);
}
number++;
}
fflush(NULL);
}
fclose(file1);
if(num == 1)
{
break;
}
}
/*释放资源*/
env->ReleaseStringUTFChars(the_id,str_condition);
env->ReleaseStringUTFChars(the_start,str_start);
env->ReleaseStringUTFChars(the_end,str_end);
env->ReleaseStringUTFChars(the_jump,str_jump);
_findclose(handle);
// printf(to_all);
printf("%s\n",to_all);
//加载string类
jclass strClass = env->FindClass("Ljava/lang/String;");
//获得方法id
jmethodID ctorID = env->GetMethodID(strClass, "<init>", "([BLjava/lang/String;)V");
//将字符串转换为jstring
jbyteArray bytes_time = env->NewByteArray(strlen(to_all));
env->SetByteArrayRegion(bytes_time, 0, strlen(to_all), (jbyte*)to_all);
jstring js_time = env->NewStringUTF("utf-8");
js_time=(jstring)env->NewObject(strClass, ctorID, bytes_time, js_time);
// system("pause");
return js_time;
};
#ifdef __cplusplus
}
#endif
#endif