1
zhanghua
2024-09-26 c775c6953d9759e70f08acbfa8f6d7490aaae3d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.netsdk.demo.customize;
 
import com.netsdk.demo.DemoTemplate;
import com.netsdk.demo.util.CaseMenu;
import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.PlaySDKLib;
import com.netsdk.lib.ToolKits;
import com.netsdk.lib.structure.NET_IN_ATTACH_TRAFFIC_FLOW_STAT_REAL_FLOW;
import com.netsdk.lib.structure.NET_OUT_ATTACH_TRAFFIC_FLOW_STAT_REAL_FLOW;
import com.netsdk.lib.structure.NET_VEHICLE_INOUT_ANALYSE_PROC;
import com.netsdk.lib.structure.NET_VEHICLE_OBJECT;
import com.netsdk.lib.utils.Initialization;
import com.sun.jna.Pointer;
 
import java.io.File;
import java.util.Scanner;
 
public class TrafficFlowDemo  extends Initialization {
 
 
    /**变量区**/
    int channel=0;
    NetSDKLib.LLong attachHandle = new NetSDKLib.LLong(0);
    static NetSDKLib netsdkApi = NetSDKLib.NETSDK_INSTANCE;
    static NetSDKLib configApi = NetSDKLib.CONFIG_INSTANCE;
    static PlaySDKLib playsdkApi   = PlaySDKLib.PLAYSDK_INSTANCE;
 
    /**方法区**/
 
    private static class VehicleInOutAnalyseProc implements NetSDKLib.fVehicleInOutAnalyseProc{
 
        private VehicleInOutAnalyseProc() {
        }
 
        private static class VehicleInOutAnalyseHolder {
            private static final VehicleInOutAnalyseProc instance = new VehicleInOutAnalyseProc();
        }
 
        public static VehicleInOutAnalyseProc getInstance() {
 
            return VehicleInOutAnalyseProc.VehicleInOutAnalyseHolder.instance;
        }
        @Override
        public void invoke(NetSDKLib.LLong lAttachHandle, Pointer pstuVehicleInOutAnalyseProc, Pointer dwUser) {
            if (lAttachHandle.longValue() == 0 || pstuVehicleInOutAnalyseProc == null) {
                return;
            }
            NET_VEHICLE_INOUT_ANALYSE_PROC cbMsg = new NET_VEHICLE_INOUT_ANALYSE_PROC();
            ToolKits.GetPointerData(pstuVehicleInOutAnalyseProc, cbMsg);
 
            System.out.println("==========CallBack received==========");
            System.out.println("szName = " + new String(cbMsg.szName).trim());
            System.out.println("dbPTS = " + cbMsg.dbPTS);
            System.out.println("stuUTC = " + cbMsg.stuUTC.toStringTime());
            System.out.println("nEventID = " + cbMsg.nEventID);
            System.out.println("nSequence = " + cbMsg.nSequence);
            System.out.println("nFrameSequence = " + cbMsg.nFrameSequence);
            System.out.println("dbRadarInstallAngle = " + cbMsg.dbRadarInstallAngle);
            System.out.println("nStatNum = " + cbMsg.nStatNum);
            for(int i = 0; i < cbMsg.nStatNum; i ++){
                System.out.println("stuStats[" + i + "] = " + cbMsg.stuStats[i].toString());
            }
            System.out.println("nObjectNum = " + cbMsg.nObjectNum);
            if(cbMsg.nObjectNum > 0){
                NET_VEHICLE_OBJECT[] stuObject = new NET_VEHICLE_OBJECT[cbMsg.nObjectNum];
                for(int i = 0; i < cbMsg.nObjectNum; i ++){
                    stuObject[i] = new NET_VEHICLE_OBJECT();
                }
                ToolKits.GetPointerDataToStructArr(cbMsg.pstuObjets, stuObject);
                for(int i = 0; i < cbMsg.nObjectNum; i ++){
                    System.out.println("pstuObject[" + i + "] = " + stuObject[i].toString());
                }
            }
        }
    }
    
    
    /**
     * 订阅交通流量统计
     */
    public void AttachTrafficFlowStateRealFlow() {
        //先关闭,再开启
        if(attachHandle.intValue() != 0){
            DetachTrafficFlowStateRealFlow();
        }
        NET_IN_ATTACH_TRAFFIC_FLOW_STAT_REAL_FLOW stIn = new NET_IN_ATTACH_TRAFFIC_FLOW_STAT_REAL_FLOW();
        stIn.cbVehicleInOutAnalyseProc = VehicleInOutAnalyseProc.getInstance();
        NET_OUT_ATTACH_TRAFFIC_FLOW_STAT_REAL_FLOW stOut = new NET_OUT_ATTACH_TRAFFIC_FLOW_STAT_REAL_FLOW();
        stIn.write();
        stOut.write();
        attachHandle = netsdkApi.CLIENT_AttachTrafficFlowStatRealFlow(loginHandle, stIn.getPointer(), stOut.getPointer(), 3000);
        if(attachHandle.intValue() != 0){
            System.out.println("AttachTrafficFlowStatRealFlow success");
        } else {
            System.err.println("AttachTrafficFlowStatRealFlow failed" + ToolKits.getLastError());
        }
    }
 
    public void DetachTrafficFlowStateRealFlow() {
        if(netsdkApi.CLIENT_DetachTrafficFlowStatRealFlow(attachHandle)){
            System.out.println("DetachTrafficFlowStatRealFlow success");
        } else {
            System.err.println("DetachTrafficFlowStatRealFlow failed" + ToolKits.getLastError());
        }
    }
 
    public void RunTest()
    {
        System.out.println("Run Test");
        CaseMenu menu = new CaseMenu();;
        menu.addItem((new CaseMenu.Item(this , "AttachTrafficFlowStateRealFlow" , "AttachTrafficFlowStateRealFlow")));
        menu.addItem((new CaseMenu.Item(this , "DetachTrafficFlowStateRealFlow" , "DetachTrafficFlowStateRealFlow")));
        menu.run();
    }
 
    public static void main(String[] args) {
        TrafficFlowDemo demo = new TrafficFlowDemo();
        /**登录信息运行时输入**/
//        Scanner sc = new Scanner(System.in);
//        System.out.print("ip:");
//        String ip = sc.nextLine();
//        System.out.print("port:");
//        String tmp = sc.nextLine();
//        int port = Integer.parseInt(tmp);
//        System.out.print("username:");
//        String username = sc.nextLine();
//        System.out.print("password:");
//        String pwd = sc.nextLine();
//        InitTest(ip,port,username,pwd);
        /**登录信息固定**/
        InitTest("172.9.102.188",37777,"admin","admin123");
        demo.RunTest();
        LoginOut();
 
    }
}