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