package com.hxzkoa.udp;
|
import com.hxzkoa.util.Config;
|
import com.hxzkoa.util.HttpUtil;
|
import com.hxzkoa.util.ModifyConfig;
|
import com.sun.jna.Library;
|
import com.sun.jna.Native;
|
|
import net.sf.json.JSONObject;
|
|
public class DellJAN {
|
|
static boolean start=true;
|
static int youxiao=0;
|
static int suanfaversion=0;
|
|
|
|
|
/**
|
* 动态链接库编译时选择的平台。如果通过x86平台编译,那么只能使用32位jdk环境加载,如果要使用64位jdk,必须使用x64平台编译。
|
*
|
* 接口内部需要一个公共静态常量:INSTANCE,通过这个常量,就可以获得这个接口的实例,从而使用接口的方法,也就是调用外部dll/so的函数。
|
* 该常量通过Native.loadLibrary()这个API函数获得,该函数有2个参数:
|
*
|
* 第一个参数是动态链接库dll/so的名称,但不带.dll或.so这样的后缀,这符合JNI的规范,因为带了后缀名就不可以跨操作系统平台了。
|
* 搜索动态链接库路径的顺序是:先从当前类的当前文件夹找,如果没有找到,再在工程当前文件夹下面找win32/win64文件夹,
|
* 找到后搜索对应的dll文件,如果 找不到再到WINDOWS下面去搜索,再找不到就会抛异常了。
|
* 第二个参数是本接口的Class类型。JNA通过这个Class类型,根据指定的.dll/.so文件,动态创建接口的实例。
|
* 该实例由JNA通过反射自动生成。
|
*
|
* 接口中只需要定义你要用到的函数或者公共变量,不需要的可以不定义,注意参数和返回值的类型,应该和链接库中的函数类型保持一致。
|
* 定义好接口后,就可以使用接口中的函数即相应dll/so中的函数了
|
*/
|
|
public interface DLibrary extends Library {
|
//此处我的jdk版本为64位,故加载64位的Dll
|
DLibrary INSTANCE = (DLibrary) Native.loadLibrary("JNA",DLibrary.class);
|
//JNA.dll 中定义的函数
|
|
/**初始化
|
* @param anchornum 系统基站总数*/
|
public int SuanFa_Init(int anchornum);
|
|
|
/**添加基站*/
|
public int anchor_register(
|
int an_id,
|
int an_px,
|
int an_py,
|
int an_pz,
|
int group, //基站所属的组
|
int range, //基站的量程
|
int dimension,//基站的维度
|
int nearby_anchor_number, // 临近基站id数目
|
int[] nearby_anchor_id_list); // 临近基站id数组
|
|
|
/**添加区域*/
|
public int add_area(
|
int id, //区域编号
|
int num, // 顶点数目
|
int[] px, //x顶点集合
|
int[] py, //y顶点集合
|
int[] entrance, // 可入
|
int[] exit); // 可出
|
|
/**删除区域*/
|
public int delete_area( // 如果不成功返回-1
|
int id); // 要删除的基站id
|
|
/** 返回区域内基站*/
|
public int get_anchor_in_area( // 返回区域内基站数目
|
int area_id, // 输入区域id
|
int[] an_id); // 返回基站id
|
|
|
/**返回时间片函数
|
* @param timestamp时间戳
|
* @param 标签id
|
* @param 标签的频率*/
|
public int slotted_aloha(int timestamp, int tagid, int tag_freq);
|
|
/**
|
* @param timestamp时间戳 (小时*3600+分钟*60)*1000
|
* @param an_x基站X坐标
|
* @param an_y基站y坐标
|
* @param an_z基站z坐标
|
* @param dis 标签到基站距离
|
* @param anchor_num 基站数量
|
* @param anchor_id基站id
|
* @param tag_id 标签id
|
* @param tag_heigt 标签高度 s
|
* @param tag_hz标签频率
|
* @param tagspeed_limit速度限制
|
* @param anchour_distance基站的量程
|
* @param dimension 算法选择1是1维2是二维
|
* @param stationary_flag静止状态
|
* @param tag_pos 返回的标签坐标
|
* @param power第一路径信号强度集合
|
* @param power_diff第二路信号强度集合*/
|
|
public int get_position(
|
int timestamp,
|
int[] an_x,
|
int[] an_y,
|
int[] an_z,
|
int[] dis,
|
int anchor_num,
|
int[] anchor_id,
|
int tag_id,
|
int tag_height,
|
int tag_hz,
|
int tagspeed_limit,
|
int[] anchour_distance,
|
int[] dimension ,
|
int stationary_flag,
|
int[] power,
|
int[] power_diff,
|
int[] zu,
|
int[] tag_pos_out
|
);
|
|
/**删除时间片接口函数,返回值0正常成功删除,其他异常。
|
* @param 参数为tagid(标签id)和
|
* @param tag_freq(标签频率)*/
|
public int delete_tag_from_slotted_aloha(int tagid, int tag_freq);
|
|
|
|
|
}
|
|
/**删除时间片函数*
|
* @param 参数为tagid(标签id)和
|
*@param tag_freq(标签频率)*/
|
|
public static int delete_tag_from_slotted_aloha(int tagid, int tag_freq) {
|
|
int succ=DLibrary.INSTANCE.delete_tag_from_slotted_aloha(tagid, tag_freq);
|
String filePath = Config.getBaowenConfig();
|
String baowenSwitch = ModifyConfig.readData(filePath,"baowenSwitch").toString(); //进入查看报文页面打开开关
|
String debugSwitch = ModifyConfig.readData(filePath,"debugSwitch").toString();;//调试页面打开
|
if(baowenSwitch.contentEquals("1")&& debugSwitch.contentEquals("1")) {
|
StringBuffer text_str=new StringBuffer();
|
text_str.append("delete_tag_from_slotted_aloha:"+tagid+","+tag_freq+",return:"+succ);
|
// String postUrl = Config.getPostUrl();
|
// String debugUrl=postUrl+"debugMessage.do";
|
String messageJson = "{\"result\":\""+ text_str + "\"}";
|
JSONObject json = JSONObject.fromObject(messageJson);
|
// HttpUtil.doPost(debugUrl, json, "UTF-8");
|
text_str=new StringBuffer();
|
}
|
|
return succ;
|
}
|
|
/**返回时间片函数
|
* @param timestamp时间戳
|
* @param 标签id
|
* @param 标签的频率*/
|
public static int get_slotted_aloha(int timestamp, int tagid, int tag_freq) {
|
|
int slotted_aloha=DLibrary.INSTANCE.slotted_aloha(timestamp, tagid, tag_freq);
|
String filePath = Config.getBaowenConfig();
|
String baowenSwitch = ModifyConfig.readData(filePath,"baowenSwitch").toString(); //进入查看报文页面打开开关
|
String debugSwitch = ModifyConfig.readData(filePath,"debugSwitch").toString();;//调试页面打开
|
if(baowenSwitch.contentEquals("1")&& debugSwitch.contentEquals("1")) {
|
StringBuffer text_str=new StringBuffer();
|
text_str.append("get_slotted_aloha:"+timestamp+", "+tagid+", "+tag_freq+",return:"+slotted_aloha);
|
String postUrl = Config.getPostUrl();
|
// String debugUrl=postUrl+"debugMessage.do";
|
String messageJson = "{\"result\":\""+ text_str + "\"}";
|
JSONObject json = JSONObject.fromObject(messageJson);
|
// HttpUtil.doPost(debugUrl, json, "UTF-8");
|
text_str=new StringBuffer();
|
}
|
|
return slotted_aloha;
|
}
|
|
/**算法库初始化*/
|
public static void suanfa_chushi(int anchornum) {
|
if(start) {
|
suanfaversion=DLibrary.INSTANCE.SuanFa_Init(anchornum);
|
start=false;
|
}
|
}
|
|
|
/**告诉算法库基站的相关信息*/
|
public static int anchor_register(
|
int an_id,
|
int an_px,
|
int an_py,
|
int an_pz,
|
int group, //基站所属的组
|
int range, //基站的量程
|
int dimension,//基站的维度
|
int nearby_anchor_number, // 临近基站id数目
|
int[] nearby_anchor_id_list) {// 临近基站id数组
|
// Open_soft_dialog.getJt_are().append(GetNowTime.now()+":初始化算法库...\n");
|
|
int num=DLibrary.INSTANCE.anchor_register(an_id,
|
an_px,
|
an_py,
|
an_pz,
|
group,
|
range,
|
dimension,
|
nearby_anchor_number,
|
nearby_anchor_id_list);
|
|
if(true) {
|
|
StringBuffer near_anchorid=new StringBuffer();
|
for(int i=0;i<nearby_anchor_id_list.length;i++) {
|
|
if(i==(nearby_anchor_id_list.length-1)) {
|
near_anchorid.append(nearby_anchor_id_list[i]);
|
}else {
|
near_anchorid.append(nearby_anchor_id_list[i]+",");
|
}
|
}
|
|
|
|
StringBuffer text_str=new StringBuffer();
|
text_str.append("anchor_register: "+an_id+", "+an_px+", "
|
+an_pz+", "+group+", "+range+", "+dimension+", "
|
+nearby_anchor_number+", ("+near_anchorid+"), result:"+num);
|
|
String postUrl = Config.getPostUrl();
|
// String debugUrl=postUrl+"debugMessage.do";
|
String messageJson = "{\"result\":\""+ text_str + "\"}";
|
JSONObject json = JSONObject.fromObject(messageJson);
|
// HttpUtil.doPost(debugUrl, json, "UTF-8");
|
|
text_str=null;
|
near_anchorid=null;
|
}
|
|
return num;
|
}
|
|
|
/**添加区域*/
|
public static int add_area(
|
int id, //区域编号
|
int num, // 顶点数目
|
int[] px, //x顶点集合
|
int[] py, //y顶点集合
|
int[] entrance, // 可入
|
int[] exit) {// 可出
|
|
int add_area=DLibrary.INSTANCE.add_area(id, num, px, py, entrance, exit);
|
// Open_soft_dialog.getJt_are().append(GetNowTime.now()+":初始化算法库区域...\n");
|
|
if(true) {
|
StringBuffer px1=new StringBuffer();
|
StringBuffer py1=new StringBuffer();
|
StringBuffer entrance1=new StringBuffer();
|
StringBuffer exit1=new StringBuffer();
|
for(int i=0;i<px.length;i++) {
|
|
if(i==(px.length-1)) {
|
px1.append(px[i]);
|
}else {
|
px1.append(px[i]+",");
|
}
|
}
|
|
for(int i=0;i<py.length;i++) {
|
|
if(i==(py.length-1)) {
|
py1.append(py[i]);
|
}else {
|
py1.append(py[i]+",");
|
}
|
}
|
|
for(int i=0;i<entrance.length;i++) {
|
|
if(i==(entrance.length-1)) {
|
entrance1.append(entrance[i]);
|
}else {
|
entrance1.append(entrance[i]+",");
|
}
|
}
|
|
for(int i=0;i<exit.length;i++) {
|
|
if(i==(exit.length-1)) {
|
exit1.append(exit[i]);
|
}else {
|
exit1.append(exit[i]+",");
|
}
|
}
|
|
|
StringBuffer text_str=new StringBuffer();
|
text_str.append("add_area: "+id+num+", ("+px1+"), ("+py1+"), ("+entrance1+"), ("+exit1+"), result:"+add_area);
|
|
String postUrl = Config.getPostUrl();
|
// String debugUrl=postUrl+"debugMessage.do";
|
String messageJson = "{\"result\":\""+ text_str + "\"}";
|
JSONObject json = JSONObject.fromObject(messageJson);
|
// HttpUtil.doPost(debugUrl, json, "UTF-8");
|
|
text_str=null;
|
px1=null;
|
py1=null;
|
entrance1=null;
|
exit1=null;
|
}
|
|
return add_area;
|
}
|
|
/**删除区域*/
|
public static int delete_area( // 如果不成功返回-1
|
int id) {
|
|
int delete_area=DLibrary.INSTANCE.delete_area(id);
|
|
return delete_area;
|
}
|
|
/** 返回区域内基站*/
|
public int get_anchor_in_area( // 返回区域内基站数目
|
int area_id, // 输入区域id
|
int[] an_id) {// 返回基站id
|
int get_anchor_in_area=DLibrary.INSTANCE.get_anchor_in_area(area_id, an_id);
|
|
return get_anchor_in_area;
|
};
|
|
|
|
|
|
/**
|
* @param timestamp时间戳 (小时*3600+分钟*60)*1000
|
* @param an_x基站X坐标
|
* @param an_y基站y坐标
|
* @param an_z基站z坐标
|
* @param dis 标签到基站距离
|
* @param anchor_num 基站数量
|
* @param anchor_id基站id
|
* @param tag_id 标签id
|
* @param tag_heigt 标签高度 s
|
* @param tag_hz标签频率
|
* @param tagspeed_limit速度限制
|
* @param anchour_distance基站的量程
|
* @param dimension 算法选择1是1维2是二维
|
* @param stationary_flag静止状态
|
* @param tag_pos 返回的标签坐标
|
* @param power第一路径信号强度集合
|
* @param power_diff第二路信号强度集合
|
* @param zu基站所在的组*/
|
public static int[] get_tag_pos(
|
int timestamp,
|
int[] an_x,
|
int[] an_y,
|
int[] an_z,
|
int[] dis,
|
int anchor_num,
|
int[] anchor_id,
|
int tag_id,
|
int tag_height,
|
int tag_hz,
|
int tagspeed_limit,
|
int[] anchour_distance,
|
int[] dimension,
|
int stationary_flag,
|
int[] power,
|
int[] power_diff,
|
int[] zu
|
) {
|
|
|
/**经过DNS计算后输出的结果*/
|
int[] tag_pos_out= {0,0};
|
|
youxiao=DLibrary.INSTANCE.get_position(
|
timestamp,
|
an_x,
|
an_y,
|
an_z,
|
dis,
|
anchor_num,
|
anchor_id,
|
tag_id,
|
tag_height,
|
tag_hz,
|
tagspeed_limit,
|
anchour_distance,
|
dimension,
|
stationary_flag,
|
power,
|
power_diff,
|
zu,
|
tag_pos_out);
|
|
|
// System.out.println("输出位置结果"+tag_pos_out[0]+";"+tag_pos_out[1]);
|
|
return tag_pos_out;
|
}
|
|
|
|
public static int getYouxiao() {
|
return youxiao;
|
}
|
|
|
|
public static String getSuanfaversion() {
|
|
int v=suanfaversion/1000;
|
int banben=suanfaversion % 1000;
|
String version="V"+v+"."+banben;
|
// System.out.println(suanfaversion);
|
|
return version;
|
}
|
|
|
}
|