Commit 90a71f4735f26c24813b46124039c8f15ee4fefe

Authored by 郑军
0 parents

first commit

Showing 51 changed files with 1496 additions and 0 deletions   Show diff stats
.classpath 0 → 100644
  1 +++ a/.classpath
... ... @@ -0,0 +1,6 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<classpath>
  3 + <classpathentry kind="src" path="src"/>
  4 + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  5 + <classpathentry kind="output" path="bin"/>
  6 +</classpath>
... ...
.idea/.gitignore 0 → 100644
  1 +++ a/.idea/.gitignore
... ... @@ -0,0 +1,8 @@
  1 +# Default ignored files
  2 +/shelf/
  3 +/workspace.xml
  4 +# Datasource local storage ignored files
  5 +/dataSources/
  6 +/dataSources.local.xml
  7 +# Editor-based HTTP Client requests
  8 +/httpRequests/
... ...
.idea/artifacts/Demo_jar.xml 0 → 100644
  1 +++ a/.idea/artifacts/Demo_jar.xml
... ... @@ -0,0 +1,8 @@
  1 +<component name="ArtifactManager">
  2 + <artifact type="jar" name="Demo:jar">
  3 + <output-path>$PROJECT_DIR$/classes/artifacts/Demo_jar</output-path>
  4 + <root id="archive" name="Demo.jar">
  5 + <element id="module-output" name="Demo" />
  6 + </root>
  7 + </artifact>
  8 +</component>
0 9 \ No newline at end of file
... ...
.idea/encodings.xml 0 → 100644
  1 +++ a/.idea/encodings.xml
... ... @@ -0,0 +1,7 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="Encoding">
  4 + <file url="file://$PROJECT_DIR$/src/mydemo/MainFrame.java" charset="GBK" />
  5 + <file url="PROJECT" charset="GBK" />
  6 + </component>
  7 +</project>
0 8 \ No newline at end of file
... ...
.idea/inspectionProfiles/Project_Default.xml 0 → 100644
  1 +++ a/.idea/inspectionProfiles/Project_Default.xml
... ... @@ -0,0 +1,36 @@
  1 +<component name="InspectionProjectProfileManager">
  2 + <profile version="1.0">
  3 + <option name="myName" value="Project Default" />
  4 + <inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
  5 + <option name="TOP_LEVEL_CLASS_OPTIONS">
  6 + <value>
  7 + <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
  8 + <option name="REQUIRED_TAGS" value="" />
  9 + </value>
  10 + </option>
  11 + <option name="INNER_CLASS_OPTIONS">
  12 + <value>
  13 + <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
  14 + <option name="REQUIRED_TAGS" value="" />
  15 + </value>
  16 + </option>
  17 + <option name="METHOD_OPTIONS">
  18 + <value>
  19 + <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
  20 + <option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
  21 + </value>
  22 + </option>
  23 + <option name="FIELD_OPTIONS">
  24 + <value>
  25 + <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
  26 + <option name="REQUIRED_TAGS" value="" />
  27 + </value>
  28 + </option>
  29 + <option name="IGNORE_DEPRECATED" value="false" />
  30 + <option name="IGNORE_JAVADOC_PERIOD" value="true" />
  31 + <option name="IGNORE_DUPLICATED_THROWS" value="false" />
  32 + <option name="IGNORE_POINT_TO_ITSELF" value="false" />
  33 + <option name="myAdditionalJavadocTags" value="date" />
  34 + </inspection_tool>
  35 + </profile>
  36 +</component>
0 37 \ No newline at end of file
... ...
.idea/misc.xml 0 → 100644
  1 +++ a/.idea/misc.xml
... ... @@ -0,0 +1,6 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
  4 + <output url="file://$PROJECT_DIR$/classes" />
  5 + </component>
  6 +</project>
0 7 \ No newline at end of file
... ...
.idea/modules.xml 0 → 100644
  1 +++ a/.idea/modules.xml
... ... @@ -0,0 +1,8 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ProjectModuleManager">
  4 + <modules>
  5 + <module fileurl="file://$PROJECT_DIR$/Demo.iml" filepath="$PROJECT_DIR$/Demo.iml" />
  6 + </modules>
  7 + </component>
  8 +</project>
0 9 \ No newline at end of file
... ...
.project 0 → 100644
  1 +++ a/.project
... ... @@ -0,0 +1,17 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<projectDescription>
  3 + <name>Demo</name>
  4 + <comment></comment>
  5 + <projects>
  6 + </projects>
  7 + <buildSpec>
  8 + <buildCommand>
  9 + <name>org.eclipse.jdt.core.javabuilder</name>
  10 + <arguments>
  11 + </arguments>
  12 + </buildCommand>
  13 + </buildSpec>
  14 + <natures>
  15 + <nature>org.eclipse.jdt.core.javanature</nature>
  16 + </natures>
  17 +</projectDescription>
... ...
Demo.iml 0 → 100644
  1 +++ a/Demo.iml
... ... @@ -0,0 +1,12 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<module type="JAVA_MODULE" version="4">
  3 + <component name="NewModuleRootManager">
  4 + <output url="file://$MODULE_DIR$/bin" />
  5 + <exclude-output />
  6 + <content url="file://$MODULE_DIR$">
  7 + <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
  8 + </content>
  9 + <orderEntry type="sourceFolder" forTests="false" />
  10 + <orderEntry type="inheritedJdk" />
  11 + </component>
  12 +</module>
0 13 \ No newline at end of file
... ...
bin/META-INF/MANIFEST.MF 0 → 100644
  1 +++ a/bin/META-INF/MANIFEST.MF
... ... @@ -0,0 +1,3 @@
  1 +Manifest-Version: 1.0
  2 +Main-Class: mydemo.MainFrame
  3 +
... ...
bin/mydemo/HttpURLConnectionUtil.class 0 → 100644
No preview for this file type
bin/mydemo/MainFrame$1.class 0 → 100644
No preview for this file type
bin/mydemo/MainFrame$2.class 0 → 100644
No preview for this file type
bin/mydemo/MainFrame$3.class 0 → 100644
No preview for this file type
bin/mydemo/MainFrame$4.class 0 → 100644
No preview for this file type
bin/mydemo/MainFrame$5.class 0 → 100644
No preview for this file type
bin/mydemo/MainFrame.class 0 → 100644
No preview for this file type
bin/phonicapi/PhonicConst.class 0 → 100644
No preview for this file type
bin/phonicapi/PhonicHandler.class 0 → 100644
No preview for this file type
bin/phonicapi/PhonicNative.class 0 → 100644
No preview for this file type
bin/x64/phonic_native.dll 0 → 100644
No preview for this file type
bin/x64/phonic_ubox.dll 0 → 100644
No preview for this file type
bin/x64/phonic_utool.dll 0 → 100644
No preview for this file type
bin/x64/phonic_utoolI.dll 0 → 100644
No preview for this file type
bin/x64/phonic_utoolII.dll 0 → 100644
No preview for this file type
bin/x64/phonic_utoolIIEx.dll 0 → 100644
No preview for this file type
bin/x86/phonic_native.dll 0 → 100644
No preview for this file type
bin/x86/phonic_ubox.dll 0 → 100644
No preview for this file type
bin/x86/phonic_utool.dll 0 → 100644
No preview for this file type
bin/x86/phonic_utoolI.dll 0 → 100644
No preview for this file type
bin/x86/phonic_utoolII.dll 0 → 100644
No preview for this file type
bin/x86/phonic_utoolIIEx.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/Demo.jar 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x64/phonic_native.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x64/phonic_ubox.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x64/phonic_utool.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x64/phonic_utoolI.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x64/phonic_utoolII.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x64/phonic_utoolIIEx.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x86/phonic_native.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x86/phonic_ubox.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x86/phonic_utool.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x86/phonic_utoolI.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x86/phonic_utoolII.dll 0 → 100644
No preview for this file type
classes/artifacts/Demo_jar/bin/x86/phonic_utoolIIEx.dll 0 → 100644
No preview for this file type
src/META-INF/MANIFEST.MF 0 → 100644
  1 +++ a/src/META-INF/MANIFEST.MF
... ... @@ -0,0 +1,3 @@
  1 +Manifest-Version: 1.0
  2 +Main-Class: mydemo.MainFrame
  3 +
... ...
src/mydemo/HttpURLConnectionUtil.java 0 → 100644
  1 +++ a/src/mydemo/HttpURLConnectionUtil.java
... ... @@ -0,0 +1,165 @@
  1 +package mydemo;
  2 +
  3 +
  4 +import com.sun.istack.internal.Nullable;
  5 +
  6 +import java.io.*;
  7 +import java.net.HttpURLConnection;
  8 +import java.net.MalformedURLException;
  9 +import java.net.URL;
  10 +
  11 +
  12 +public class HttpURLConnectionUtil {
  13 +
  14 + /**
  15 + * Http get请求
  16 + * @param httpUrl 连接
  17 + * @return 响应数据
  18 + */
  19 + public static String doGet(String httpUrl){
  20 + //链接
  21 + HttpURLConnection connection = null;
  22 + InputStream is = null;
  23 + BufferedReader br = null;
  24 + StringBuffer result = new StringBuffer();
  25 + try {
  26 + //创建连接
  27 + URL url = new URL(httpUrl);
  28 + connection = (HttpURLConnection) url.openConnection();
  29 + //设置请求方式
  30 + connection.setRequestMethod("GET");
  31 + //设置连接超时时间
  32 + connection.setReadTimeout(15000);
  33 + //开始连接
  34 + connection.connect();
  35 + //获取响应数据
  36 + if (connection.getResponseCode() == 200) {
  37 + //获取返回的数据
  38 + is = connection.getInputStream();
  39 + if (null != is) {
  40 + br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
  41 + String temp = null;
  42 + while (null != (temp = br.readLine())) {
  43 + result.append(temp);
  44 + }
  45 + }
  46 + }
  47 + } catch (IOException e) {
  48 + e.printStackTrace();
  49 + } finally {
  50 + if (null != br) {
  51 + try {
  52 + br.close();
  53 + } catch (IOException e) {
  54 + e.printStackTrace();
  55 + }
  56 + }
  57 + if (null != is) {
  58 + try {
  59 + is.close();
  60 + } catch (IOException e) {
  61 + e.printStackTrace();
  62 + }
  63 + }
  64 + //关闭远程连接
  65 + connection.disconnect();
  66 + }
  67 + return result.toString();
  68 + }
  69 +
  70 + /**
  71 + * Http post请求
  72 + * @param httpUrl 连接
  73 + * @param param 参数
  74 + * @return
  75 + */
  76 + public static String doPost(String httpUrl, @Nullable String param) {
  77 + StringBuffer result = new StringBuffer();
  78 + //连接
  79 + HttpURLConnection connection = null;
  80 + OutputStream os = null;
  81 + InputStream is = null;
  82 + BufferedReader br = null;
  83 + try {
  84 + //创建连接对象
  85 + URL url = new URL(httpUrl);
  86 + //创建连接
  87 + connection = (HttpURLConnection) url.openConnection();
  88 + //设置请求方法
  89 + connection.setRequestMethod("POST");
  90 + //设置连接超时时间
  91 + connection.setConnectTimeout(15000);
  92 + //设置读取超时时间
  93 + connection.setReadTimeout(15000);
  94 + //DoOutput设置是否向httpUrlConnection输出,DoInput设置是否从httpUrlConnection读入,此外发送post请求必须设置这两个
  95 + //设置是否可读取
  96 + connection.setDoOutput(true);
  97 + connection.setDoInput(true);
  98 + //设置通用的请求属性
  99 + connection.setRequestProperty("accept", "*/*");
  100 + connection.setRequestProperty("connection", "Keep-Alive");
  101 + connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
  102 + connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
  103 +
  104 + //拼装参数
  105 + if (null != param && param.equals("")) {
  106 + //设置参数
  107 + os = connection.getOutputStream();
  108 + //拼装参数
  109 + os.write(param.getBytes("UTF-8"));
  110 + }
  111 + //设置权限
  112 + //设置请求头等
  113 + //开启连接
  114 + //connection.connect();
  115 + //读取响应
  116 + if (connection.getResponseCode() == 200) {
  117 + is = connection.getInputStream();
  118 + if (null != is) {
  119 + br = new BufferedReader(new InputStreamReader(is, "GBK"));
  120 + String temp = null;
  121 + while (null != (temp = br.readLine())) {
  122 + result.append(temp);
  123 + result.append("\r\n");
  124 + }
  125 + }
  126 + }
  127 +
  128 + } catch (MalformedURLException e) {
  129 + e.printStackTrace();
  130 + } catch (IOException e) {
  131 + e.printStackTrace();
  132 + } finally {
  133 + //关闭连接
  134 + if(br!=null){
  135 + try {
  136 + br.close();
  137 + } catch (IOException e) {
  138 + e.printStackTrace();
  139 + }
  140 + }
  141 + if(os!=null){
  142 + try {
  143 + os.close();
  144 + } catch (IOException e) {
  145 + e.printStackTrace();
  146 + }
  147 + }
  148 + if(is!=null){
  149 + try {
  150 + is.close();
  151 + } catch (IOException e) {
  152 + e.printStackTrace();
  153 + }
  154 + }
  155 + //关闭连接
  156 + connection.disconnect();
  157 + }
  158 + return result.toString();
  159 + }
  160 +
  161 + public static void main(String[] args) {
  162 + String message = doPost("https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=13026194071", "");
  163 + System.out.println(message);
  164 + }
  165 +}
... ...
src/mydemo/MainFrame.java 0 → 100644
  1 +++ a/src/mydemo/MainFrame.java
... ... @@ -0,0 +1,529 @@
  1 +package mydemo;
  2 +
  3 +import java.awt.Dimension;
  4 +import java.awt.Insets;
  5 +import java.awt.Toolkit;
  6 +import java.awt.event.ActionEvent;
  7 +import java.awt.event.ActionListener;
  8 +import java.awt.event.WindowAdapter;
  9 +import java.awt.event.WindowEvent;
  10 +import java.io.File;
  11 +import java.text.DateFormat;
  12 +import java.text.SimpleDateFormat;
  13 +import java.util.Date;
  14 +
  15 +import javax.swing.JButton;
  16 +import javax.swing.JComboBox;
  17 +import javax.swing.JFrame;
  18 +import javax.swing.JTextField;
  19 +import javax.swing.event.ChangeEvent;
  20 +import javax.swing.event.ChangeListener;
  21 +
  22 +import phonicapi.PhonicConst;
  23 +import phonicapi.PhonicHandler;
  24 +import phonicapi.PhonicNative;
  25 +
  26 +
  27 +
  28 +public class MainFrame extends JFrame implements PhonicHandler{
  29 + private JButton btnHookOff = new JButton("摘机");
  30 + private JButton btnHookOn = new JButton("挂机");
  31 + private JButton btnCall = new JButton("拨号");
  32 +
  33 + private JButton btnSendMsg = new JButton("发送短信");
  34 + private JTextField txtNumb = new JTextField();
  35 + private JComboBox cbxLine = new JComboBox();
  36 + private JTextField txtShortMsgNumber = new JTextField();
  37 + private JTextField txtShortMsg = new JTextField();
  38 + private int uBoxHndOne = 0; //线路1操作句柄
  39 + private int uBoxHndTwo = 0; //线路2操作句柄
  40 + private int uBoxId = 0;// 设备类型
  41 + private boolean bHookOff = false;
  42 + private String strDir = "C:\\";
  43 +
  44 + MainFrame ()
  45 + {
  46 + try{
  47 + File directory = new File("");
  48 + strDir = directory.getAbsolutePath();
  49 + System.out.println(strDir);
  50 + }catch(Exception e){}
  51 +
  52 + //线路
  53 + cbxLine.setBounds(20, 20, 160, 20);
  54 + cbxLine.addItem("线路1");
  55 + cbxLine.addItem("线路2");
  56 + cbxLine.setSelectedItem("线路1");
  57 +
  58 + //摘机
  59 + btnHookOff.setBounds(20, 60, 60, 20);
  60 + btnHookOff.addActionListener(new ActionListener() {
  61 + public void actionPerformed(ActionEvent e) {
  62 + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo;
  63 + int nResult = PhonicNative.ubox_soft_hook_off(uBoxHnd);
  64 + System.out.println(nResult);
  65 + if(0 == nResult)
  66 + {
  67 + bHookOff = true;
  68 + cbxLine.setEnabled(false);
  69 + btnHookOff.setEnabled(false);
  70 + btnHookOn.setEnabled(true);
  71 + btnCall.setEnabled(true);
  72 + txtNumb.setEnabled(true);
  73 +
  74 + //开始录音
  75 + Date nowDate = new Date();
  76 + DateFormat dfDate = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
  77 + String strPath = strDir+"\\"+dfDate.format(nowDate)+".wav";
  78 + System.out.println(strPath);
  79 + PhonicNative.ubox_record_file(uBoxHnd, strPath, CODER_ALAW);
  80 + }
  81 + }
  82 + });
  83 + //挂机
  84 + btnHookOn.setEnabled(false);
  85 + btnHookOn.setBounds(120, 60, 60, 20);
  86 + btnHookOn.addActionListener(new ActionListener() {
  87 + public void actionPerformed(ActionEvent e) {
  88 + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo;
  89 + int nResult = PhonicNative.ubox_soft_hook_on(uBoxHnd);
  90 + System.out.println(nResult);
  91 + if(0 == nResult)
  92 + {
  93 + bHookOff = false;
  94 + cbxLine.setEnabled(true);
  95 + btnHookOff.setEnabled(true);
  96 + btnHookOn.setEnabled(false);
  97 + btnCall.setEnabled(true);
  98 + txtNumb.setEnabled(true);
  99 +
  100 + //停止录音
  101 + PhonicNative.ubox_stop_record(uBoxHnd);
  102 + }
  103 + }
  104 + });
  105 +
  106 + //拨号
  107 + btnCall.setBounds(120, 100, 60, 20);
  108 + btnCall.addActionListener(new ActionListener() {
  109 + public void actionPerformed(ActionEvent e) {
  110 + if(uBoxId == 8)
  111 + {
  112 + if(txtNumb.getText().length() > 0)
  113 + {
  114 + cbxLine.setEnabled(false);
  115 + btnHookOff.setEnabled(false);
  116 + btnHookOn.setEnabled(true);
  117 + btnCall.setEnabled(true);
  118 + txtNumb.setEnabled(true);
  119 + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo;
  120 + int nResult = PhonicNative.ubox_makecall(uBoxHnd, txtNumb.getText());
  121 + System.out.println(nResult);
  122 +
  123 +
  124 + }
  125 + }
  126 + else
  127 + {
  128 + //摘机
  129 + if(!bHookOff)
  130 + {
  131 + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo;
  132 + int nResult = PhonicNative.ubox_soft_hook_off(uBoxHnd);
  133 + System.out.println(nResult);
  134 + if(0 == nResult)
  135 + {
  136 + bHookOff = true;
  137 + cbxLine.setEnabled(false);
  138 + btnHookOff.setEnabled(false);
  139 + btnHookOn.setEnabled(true);
  140 + btnCall.setEnabled(true);
  141 + txtNumb.setEnabled(true);
  142 +
  143 + //开始录音
  144 + Date nowDate = new Date();
  145 + DateFormat dfDate = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
  146 + String strPath = strDir+"\\"+dfDate.format(nowDate)+".wav";
  147 + System.out.println(strPath);
  148 + PhonicNative.ubox_record_file(uBoxHnd, strPath, CODER_ALAW);
  149 + }
  150 + //等待0.5秒再拨号
  151 + try{
  152 + Thread.sleep(500);
  153 + }catch(Exception ee){
  154 + ee.printStackTrace();
  155 + }
  156 + }
  157 +
  158 + if(txtNumb.getText().length() > 0)
  159 + {
  160 + btnCall.setEnabled(false);
  161 + txtNumb.setEnabled(false);
  162 + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo;
  163 + int nResult = PhonicNative.ubox_send_dtmf(uBoxHnd, txtNumb.getText());
  164 + System.out.println(nResult);
  165 + }
  166 + }
  167 + }
  168 + });
  169 +
  170 + btnCall.setEnabled(false);
  171 + btnSendMsg.setEnabled(false);
  172 + //号码输入框
  173 + txtNumb.setBounds(20, 100, 80, 20);
  174 + txtNumb.setText("910000");
  175 +
  176 + txtShortMsgNumber.setBounds(20, 140, 80, 20); //收件号码
  177 + txtShortMsgNumber.setText("8615907558923");//发短信,需要在号码前加国际区号 ,中国"86"
  178 +
  179 + txtShortMsg.setBounds(120, 140, 200, 20); //短信内容
  180 + txtShortMsg.setText("");//发短信,需要在号码前加国际区号 ,中国"86"
  181 +
  182 + //发送短信
  183 + btnSendMsg.setBounds(340, 140, 120, 20);
  184 + btnSendMsg.addActionListener(new ActionListener() {
  185 + public void actionPerformed(ActionEvent e) {
  186 + if(uBoxId == 8)
  187 + {
  188 + if(txtShortMsgNumber.getText().length() > 0 && txtShortMsg.getText().length() > 0)
  189 + {
  190 +
  191 + int uBoxHnd = cbxLine.getSelectedIndex()==0?uBoxHndOne:uBoxHndTwo;
  192 + int nResult = PhonicNative.ubox_send_gsm_msg(uBoxHnd, 1, txtShortMsgNumber.getText(), txtShortMsg.getText(),txtShortMsg.getText().length());
  193 + System.out.println(nResult);
  194 +
  195 +
  196 + }
  197 + }
  198 + }
  199 + });
  200 + //添加控件
  201 + add(cbxLine);
  202 + add(btnHookOff);
  203 + add(btnHookOn);
  204 + add(btnCall);
  205 + add(txtNumb);
  206 +
  207 + add(txtShortMsgNumber);
  208 + add(txtShortMsg);
  209 + add(btnSendMsg);
  210 + //初始化
  211 + openUBox();
  212 + }
  213 +
  214 + //打开设备
  215 + public boolean openUBox()
  216 + {
  217 + PhonicNative.ubox_open_logfile(0);
  218 + int nOpen = PhonicNative.ubox_open(this, PhonicConst.WORK_MODE_RECORD);
  219 + System.out.println("ubox_open="+nOpen);
  220 + if(nOpen == 0)
  221 + {
  222 + return true;
  223 + }
  224 + return false;
  225 + }
  226 +
  227 + //关闭设备
  228 + public boolean closeUBox()
  229 + {
  230 + uBoxHndOne = 0;
  231 + uBoxHndTwo = 0;
  232 + PhonicNative.ubox_close();
  233 + return true;
  234 + }
  235 +
  236 +
  237 + //设备事件
  238 + public void event(int uboxHnd, int eventID, int param1, int param2, int param3, int param4) {
  239 + switch (eventID)
  240 + {
  241 + case UBOX_EVENT_DEVICE_PLUG_IN:
  242 + {
  243 + //检测型号正确
  244 + //if(1 == PhonicNative.ubox_get_product_ID(uboxHnd))
  245 + {
  246 + if(0 == uBoxHndOne)
  247 + {
  248 + uBoxHndOne = uboxHnd;
  249 + uBoxId = PhonicNative.ubox_get_product_ID(uboxHnd);
  250 + System.out.println(PhonicNative.ubox_get_device_versionnum(uboxHnd));
  251 + System.out.println(PhonicNative.ubox_get_product_name(uboxHnd));
  252 + if(uBoxId == 8) //无线设备
  253 + {
  254 + PhonicNative.ubox_set_gsm_work_mode(uboxHnd, 1, 0); //如果不用电话机,关闭电话机模式,否则振铃的时候,戴着耳麦会听到很大的给电话机送来电号码声音,体验效果不好。
  255 + }
  256 + }
  257 + else if(0 == uBoxHndTwo)
  258 + {
  259 + uBoxHndTwo = uboxHnd;
  260 + }
  261 + else
  262 + {
  263 + uBoxHndOne = uboxHnd;
  264 + uBoxHndTwo = 0;
  265 + }
  266 + }
  267 + System.out.println("收到设备插入事件:" + uboxHnd);
  268 + }
  269 + break;
  270 + case UBOX_EVENT_DEVICE_PLUG_OUT:
  271 + {
  272 + System.out.println("收到设备拔出事件:" + uboxHnd);
  273 + }
  274 + break;
  275 + case UBOX_EVENT_LINE_HOOK_UP:
  276 + {
  277 +
  278 + if(uBoxId == 8)
  279 + {
  280 + if(param1 == 1)
  281 + {
  282 + System.out.println("收到GSM模块挂机:" + uboxHnd);
  283 + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 0); //被叫能够听不到耳麦说话的声音
  284 + }
  285 + else if(param1 == 2)
  286 + {
  287 + System.out.println("收到电话机挂机:" + uboxHnd);
  288 + }
  289 + else if(param1 == 3)
  290 + {
  291 + System.out.println("收到耳麦挂机:" + uboxHnd);
  292 + }
  293 + }
  294 + else
  295 + {
  296 + System.out.println("收到设备挂机事件:" + uboxHnd);
  297 + }
  298 + }
  299 + break;
  300 + case UBOX_EVENT_LINE_HOOK_OFF:
  301 + {
  302 + if(uBoxId == 8)
  303 + {
  304 + if(param1 == 0)
  305 + {
  306 + System.out.println("收到电话机摘机:" + uboxHnd);
  307 + }
  308 + else if(param1 == 2)
  309 + {
  310 + System.out.println("收到耳麦摘机:" + uboxHnd);
  311 + }
  312 + else if(param1 == 6)
  313 + {
  314 + System.out.println("收到GSM模块摘机:" + uboxHnd);
  315 + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 1); //被叫能够听到耳麦说话的声音
  316 + }
  317 + }
  318 + else
  319 + {
  320 + System.out.println("收到设备摘机事件:" + uboxHnd);
  321 + }
  322 + }
  323 + break;
  324 + case UBOX_EVENT_LINE_RINGING:
  325 + {
  326 + System.out.println("收到设备检测线路振铃开始事件:" + uboxHnd);
  327 + }
  328 + break;
  329 + case UBOX_EVENT_DEVICE_PLAY_END:
  330 + {
  331 + System.out.println("收到放音结束事件:" + uboxHnd);
  332 + }
  333 + break;
  334 + case UBOX_EVENT_RING_CANCEL:
  335 + {
  336 + System.out.println("收到设备检测线路振铃停止事件:" + uboxHnd);
  337 + }
  338 + break;
  339 + case UBOX_EVENT_DEVICE_BUSY_TONE:
  340 + {
  341 + System.out.println("收到设备检测线路忙音事件:" + uboxHnd);
  342 + }
  343 + break;
  344 + case UBOX_EVENT_ALARM:
  345 + {
  346 + System.out.println("收到设备工作警告事件:" + uboxHnd);
  347 + }
  348 + break;
  349 + case UBOX_EVENT_DEVICE_ERROR:
  350 + {
  351 + System.out.println("收到设备错误事件:" + uboxHnd);
  352 + }
  353 + break;
  354 + case UBOX_EVENT_LINE_RING_STOP:
  355 + {
  356 + System.out.println("收到设备检测线路振铃闪停事件:" + uboxHnd);
  357 + }
  358 + break;
  359 + case UBOX_EVENT_LINE_HANG:
  360 + {
  361 + System.out.println("收到设备悬空事件:" + uboxHnd);
  362 + }
  363 + break;
  364 + case UBOX_EVENT_LINE_VOLTAGE:
  365 + {
  366 + System.out.println("收到设备线路当前电压事件:" + uboxHnd);
  367 + }
  368 + break;
  369 + case UBOX_EVENT_STREAM_VOICE:
  370 + {
  371 + System.out.println("收到流式录音数据包事件:" + uboxHnd);
  372 + }
  373 + break;
  374 + case UBOX_EVENT_DTMF_DOWN:
  375 + {
  376 + //System.out.println("按键事件:" + uboxHnd);
  377 + }
  378 + break;
  379 + case UBOX_EVENT_DTMF_UP:
  380 + {
  381 + System.out.println("收到按键释放事件:" + uboxHnd);
  382 + }
  383 + break;
  384 + case UBOX_EVENT_DEVICE_PLAY_ERROR:
  385 + {
  386 + System.out.println("收到放音错误事件:" + uboxHnd);
  387 + }
  388 + break;
  389 + case UBOX_EVENT_CALLOUTFINISH:
  390 + {
  391 + System.out.println("收到软件拨号完成事件:" + uboxHnd);
  392 + }
  393 + break;
  394 + case UBOX_EVENT_POLARITY:
  395 + {
  396 + System.out.println("收到检测极性反转事件:" + uboxHnd);
  397 + }
  398 + break;
  399 + case UBOX_EVENT_SIM_STATE:
  400 + {
  401 + if(param2 == 1)
  402 + {
  403 + System.out.println("卡状态事件, 当前选择sim卡" + param1);
  404 + }
  405 + else if(param2 == 2)
  406 + {
  407 + System.out.println("卡状态事件, sim卡" + param1 +" GSM 模块检查Sim卡未插入");
  408 + }
  409 + else if(param2 == 3)
  410 + {
  411 + System.out.println("卡状态事件, sim卡" + param1 +" 检测到卡存在,并且是插好的");
  412 + }
  413 + else if(param2 > 3)
  414 + {
  415 + System.out.println("卡状态事件, sim卡" + param1 +" 检测到卡有错误,错误值:"+param2);
  416 + }
  417 + }
  418 + break;
  419 + case UBOX_EVENT_ANSWER:
  420 + {
  421 + System.out.println(" 被叫已经应答了");
  422 +
  423 + PhonicNative.ubox_set_talk_link(uboxHnd, EARPHONE_TO_GSM, 1); //被叫能够听到耳麦说话的声音
  424 + }
  425 + break;
  426 + case UBOX_EVENT_SIGNALE_SIZE:
  427 + {
  428 + System.out.println(" 信号大小:"+param1);
  429 + }
  430 + break;
  431 + case UBOX_EVENT_SHORT_MSG_SIZE:
  432 + {
  433 + System.out.println(" 被叫已经应答了");
  434 + }
  435 + break;
  436 + case UBOX_EVENT_SIM_REG:
  437 + {
  438 + if(param2 == 0)
  439 + {
  440 + System.out.println("sim卡" + param1+1 + " 网络未注册,当前没有搜索到要注册业务的新营运商 ");
  441 + }
  442 + else if(param2 == 1)
  443 + {
  444 + System.out.println("sim卡" + param1+1 + " 网络已注册");
  445 + btnCall.setEnabled(true); //网络已经注册好了,可以拨打电话和发短信
  446 + btnSendMsg.setEnabled(true);
  447 + }
  448 + else if(param2 == 2)
  449 + {
  450 + System.out.println("sim卡" + param1+1 + " 网络未注册,正在搜索要注册业务的新营运商");
  451 + }
  452 + else if(param2 == 3)
  453 + {
  454 + System.out.println("sim卡" + param1+1 + " 注册被拒绝");
  455 + }
  456 + else if(param2 == 4)
  457 + {
  458 + System.out.println("sim卡" + param1+1 + " 未注册, 未知原因");
  459 + }
  460 + else if(param2 == 5)
  461 + {
  462 + System.out.println("sim卡" + param1+1 + " 已注册,漫游");
  463 + }
  464 + }
  465 + break;
  466 + case UBOX_EVENT_SHORT_MSG_SEND_REPORT:
  467 + {
  468 + if(param1 == 0)
  469 + {
  470 + System.out.println("短信发送失败");
  471 + }
  472 + else if(param1 == 1)
  473 + {
  474 + System.out.println("短信发送成功");
  475 + }
  476 + else if(param1 == 2)
  477 + {
  478 + System.out.println("短信发送超时");
  479 + }
  480 + }
  481 + break;
  482 + default:
  483 + {
  484 + System.out.println("未知事件[uboxHnd=" + uboxHnd + "][eventID=" + eventID
  485 + + "][param1=" + param1 + "][param2=" + param2 + "][param3="
  486 + + param3 + "][param4=" + param4 + "]");
  487 + }
  488 + break;
  489 + }
  490 + }
  491 +
  492 + public void callInNumber(int uboxHnd, String number) {
  493 + String usernum = PhonicNative.ubox_get_usernum(uboxHnd, 32);
  494 + System.out.println("收到主叫号码[uboxHnd=" + uboxHnd + "][number=" + number + "]");
  495 + System.out.println("用户号"+"[usernum=" + usernum + "]");
  496 + String get = HttpURLConnectionUtil.doGet("http://xiyangyang.51feijin.com/api/mobile/code?mobile=15179379512");
  497 + System.out.println("请求结果" + get);
  498 + String get2 = HttpURLConnectionUtil.doGet("http://xiyangyang.51feijin.com/company-api/security/popup?code=112233&phone="+number);
  499 + System.out.println("请求结果" + get2);
  500 + }
  501 +
  502 + public void ShortMsg(int uboxHnd, String PhoneNumber, String stTime, String msg, String strDived) {
  503 + System.out.println("收到短信[uboxHnd=" + uboxHnd + "][发件人=" + PhoneNumber + "]" + ", 时间:"+stTime +", 内容:" +msg+ " "+strDived);
  504 + }
  505 +
  506 + public void CmdMsg(int uboxHnd, String cmd) {
  507 + System.out.println("收到消息[uboxHnd=" + uboxHnd + "][内容=" + cmd + "]");
  508 + }
  509 +
  510 + public static void main(String[] args)
  511 + {
  512 + final MainFrame myFrame = new MainFrame();
  513 + myFrame.setTitle("电话示例");
  514 + myFrame.setSize(800, 600);
  515 + myFrame.setLayout(null);
  516 + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  517 + Dimension frameSize = myFrame.getSize();
  518 + myFrame.setLocation((screenSize.width-frameSize.width)/2, (screenSize.height-frameSize.height)/2);
  519 + myFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
  520 + myFrame.addWindowListener(new WindowAdapter(){
  521 + public void windowClosing(WindowEvent e){
  522 + myFrame.closeUBox();
  523 + }
  524 + });
  525 + myFrame.setVisible(true);
  526 + System.out.println("退出");
  527 +
  528 + }
  529 +}
... ...
src/phonicapi/PhonicConst.java 0 → 100644
  1 +++ a/src/phonicapi/PhonicConst.java
... ... @@ -0,0 +1,88 @@
  1 +package phonicapi;
  2 +
  3 +public interface PhonicConst {
  4 + int UBOX_EVENT_DEVICE_PLUG_IN = 1; // 检测到设备插入,回调函数中param1、param2、param3、param4未使用,
  5 + int UBOX_EVENT_DEVICE_PLUG_OUT = 2; // 检测到设备拔出,
  6 +
  7 + int UBOX_EVENT_ALARM = 3; // 报警,param1参照UBOX_ALARM的定义,设备工作不正常,软件退出,检查设备驱动程序是否安装好
  8 +
  9 + int UBOX_EVENT_LINE_RESET = 10; // 复位:摘机->挂机,振铃->停振 硬件LED灭 已经将该事件分为两个挂机和停振事件
  10 + int UBOX_EVENT_LINE_RINGING = 11; // 振铃,硬件LED亮
  11 + int UBOX_EVENT_LINE_HOOK_OFF = 12; // 摘机,硬件LED亮
  12 + int UBOX_EVENT_LINE_HANG = 13; // 检测到线路悬空 ,默认线路电压小于3V,认为线路悬空,硬件LED闪烁
  13 +
  14 + // UBOX_EVENT_LING_FLUSH = 14, //?? 需要吗?
  15 +
  16 + int UBOX_EVENT_RING_CANCEL = 15; // 振铃取消,当末次振铃停止超过6秒,则触发此事件,
  17 +
  18 + int UBOX_EVENT_LINE_VOLTAGE = 16; // 线路电压事件,param1是线路电压值,param1不会出现等于0的电压。
  19 + int UBOX_EVENT_STREAM_VOICE = 20; // 流式录音事件,param1是录音数据地址,需要转换,unsigned
  20 + // char* pvoice= (unsigned char*)param1
  21 + // param2是录音数据长度
  22 +
  23 + int UBOX_EVENT_CALLER_ID = 21; // param1是号码地址 param2是时间地址 param3是姓名地址
  24 + // param4没有用
  25 + // 需要类型转换 char* pszcallId =(char*)param1; char* pszcalltime=(char*)param2;
  26 + // char* pszcallname=(char*) param3
  27 +
  28 + int UBOX_EVENT_DTMF_DOWN = 22; // 按键事件,param1是按键键值
  29 + int UBOX_EVENT_DTMF_UP = 23;
  30 + int UBOX_EVENT_DEVICE_ERROR = 24; // 设备错误;需要软件重新启动,不然接收不到主叫号码
  31 + int UBOX_EVENT_DEVICE_PLAY_END = 25; // 放音完毕
  32 + int UBOX_EVENT_DEVICE_PLAY_ERROR = 26; // 放音异常
  33 + int UBOX_EVENT_DEVICE_BUSY_TONE = 27; // 检测到忙音,对方挂机
  34 + int UBOX_EVENT_CALLOUTFINISH = 28; // 呼出完成,表示拨号结束
  35 + int UBOX_EVENT_POLARITY = 29; // 检测到极性反转
  36 + int UBOX_EVENT_LINE_HOOK_UP = 30; // 挂机
  37 + int UBOX_EVENT_LINE_RING_STOP = 31; // 停振
  38 +
  39 + int UBOX_EVENT_SIM_STATE = 32; //param1: 1 sim卡1 2:sim卡2 param2: 0 未插入(新版本已经不支持了) 1:设备当前工作sim卡序号 2:GSM 模块检查Sim卡未插入 3. 检测到sim卡插入,其它值检测到sim有错误
  40 + int UBOX_EVENT_ANSWER = 33;
  41 + int UBOX_EVENT_GSM_MSG = 34; //收到GSM返回的消息
  42 + int UBOX_EVENT_SHORT_MSG =35; ////短信 param1:发短信电话号码 param2:短信时间 param3:短信内容 param4:"" 为空,短信没有被分割
  43 + int UBOX_EVENT_SIGNALE_SIZE = 36; //信号大小
  44 + int UBOX_EVENT_GSM_VOL_SIZE = 37; //param1: 1 gsm play 2:gsm mic param2: 声音大小
  45 + int UBOX_EVENT_SHORT_MSG_SIZE = 38; //短信数量 param1:SIM卡 短信数目, param2: SIM卡短信存储空间数目
  46 + int UBOX_EVENT_SIM_REG = 39; //SIM 是否注册 param1: sim序号 0:sim1 ,1:sim2 param2: sim卡注册返回值,
  47 + /*
  48 + 0 未注册;ME 当前没有搜索到要注册业务的新营运商
  49 + 1 已注册,本地网
  50 + 2 未注册,但 ME正在搜索要注册业务的新营运商
  51 + 3 注册被拒绝
  52 + 4 未知
  53 + 5 已注册,漫游
  54 + */
  55 + int UBOX_EVENT_SHORT_MSG_SEND_REPORT = 40; //短信发送报告, param1=0,发送失败 param1=1,发送成功 ,param1=3,发送超时,失败
  56 +
  57 + // 工作模式
  58 + int WORK_MODE_RECORD = 0;
  59 + int WORK_MODE_DIAGNOSIS = 1;
  60 + int WORK_MODE_CONFIG = 2;
  61 +
  62 + // 语言编码
  63 + int CODER_ALAW = 0;// 默认使用
  64 + int CODER_PCM = 1;
  65 + int CODER_G729 = 3;
  66 + int CODER_SPEEX = 20;// 8倍压缩
  67 + int CODER_MP3 = 38;
  68 + int CODER_ULAW = 100;
  69 +
  70 + //USB无线设备,通话控制开关,要能够听到通话声音,根据自己的应用打开和关闭相应的开关
  71 + int SLIC_TO_GSM = 0; //SLIC到GSM方向
  72 + int GSM_TO_SLIC = 1; //GSM到SLIC方向
  73 + int EARPHONE_TO_GSM = 2; //耳麦到GSM方向
  74 + int GSM_TO_EARPHONE =3; //GSM到耳麦方向
  75 + int SLIC_TO_EARPHONE = 4; //电话机坐席到耳麦方向
  76 + int EARPHONE_TO_SLIC = 5; //G耳麦到电话机坐席方向
  77 + int USB_TO_EARPHONE = 6; //USB到耳麦方向 用于电脑播放语音
  78 + int USB_TO_GSM = 7; //USB到GSM方向 用于电脑播放语音
  79 + int USB_TO_SLIC = 8; //USB到电话机坐席方向 用于电脑播放语音
  80 +
  81 +
  82 + //USB无线设备, 录音控制开关,可以选择需要那方面的声音
  83 + int SLIC_REC_ = 0; //SLIC(电话机方向)录音
  84 + int GSM_REC = 1; //GSM录音, 对于3101B, 是对外线录音,为了方便兼容,还是叫这个名称
  85 + int EARPHONE_REC = 2; //Earphone(耳麦)录音
  86 + int USB_REC = 3; //录下USB播放的声音
  87 +
  88 +}
... ...
src/phonicapi/PhonicHandler.java 0 → 100644
  1 +++ a/src/phonicapi/PhonicHandler.java
... ... @@ -0,0 +1,23 @@
  1 +package phonicapi;
  2 +
  3 +public interface PhonicHandler extends PhonicConst{
  4 + /**
  5 + * @param uboxHnd
  6 + * 设备句柄
  7 + * @param eventID
  8 + * 事件,参考UBOX_EVENT的定义
  9 + * @param param1
  10 + * 不同的事件,其含义不同
  11 + * @param param2
  12 + * 不同的事件,其含义不同
  13 + * @param param3
  14 + * 不同的事件,其含义不同
  15 + * @param param4
  16 + * 不同的事件,其含义不同
  17 + */
  18 + public void event(int uboxHnd, int eventID, int param1, int param2, int param3, int param4);
  19 +
  20 + public void callInNumber(int uboxHnd, String number); //来电号码
  21 + public void ShortMsg(int uboxHnd, String PhoneNumber, String stTime, String msg, String strDived); //短信内容
  22 + public void CmdMsg(int uboxHnd, String cmd); //返回命令消息,比如操作失败等
  23 +}
... ...
src/phonicapi/PhonicNative.java 0 → 100644
  1 +++ a/src/phonicapi/PhonicNative.java
... ... @@ -0,0 +1,577 @@
  1 +package phonicapi;
  2 +
  3 +public class PhonicNative {
  4 +
  5 + /**
  6 + * 设置事件通知回调函数和工作模式
  7 + *
  8 + * @param eh回调函数
  9 + * @param mode
  10 + * USB盒的工作模式,通常是录音方式,0录音模式,1诊断模式,2配置模式
  11 + * @return 0成功,其实失败
  12 + */
  13 + public static native int ubox_open(PhonicHandler eh, int mode);
  14 +
  15 + /**
  16 + * 设关闭
  17 + */
  18 + public static native void ubox_close();
  19 +
  20 + /**
  21 + * 获取硬件的版本号,
  22 + *
  23 + * @param uboxHnd
  24 + * 设备句柄
  25 + * @return version_num由整数部分和1位小数部分组成,整数部分是主版本号,小数部分是次版本号
  26 + */
  27 + public static native float ubox_get_device_versionnum(int uboxHnd);
  28 +
  29 + /**
  30 + * 获取产品设备号
  31 + *
  32 + * @param uboxHnd
  33 + * 设备句柄
  34 + * @return 产品对应的设备号,1 FI3102A,2 FI3002B,3 FI3001B,4 FI3101A
  35 + */
  36 + public static native int ubox_get_product_ID(int uboxHnd);
  37 +
  38 + /**
  39 + * 获取产品设备名称
  40 + *
  41 + * @param uboxHnd
  42 + * 设备句柄
  43 + * @return 设备名称
  44 + * "FI3102A"两路外线,"FI3002B"两路高阻录音,"FI3001B"一路高阻录音,"FI3101A"带耳麦语音盒
  45 + */
  46 + public static native String ubox_get_product_name(int uboxHnd);
  47 +
  48 + /**
  49 + * 读取用户号
  50 + *
  51 + * @param uboxHnd
  52 + * 设备句柄
  53 + * @param len
  54 + * 返回用户号的长度不能低于16
  55 + * @return 用户号,用户号的长度为16字节,前8个字节为用户编号,后8个字节为出厂日期
  56 + */
  57 + public static native String ubox_get_usernum(int uboxHnd, int len);
  58 +
  59 + /**
  60 + * 获取当前工作模式
  61 + *
  62 + * @return 当前工作的模式有:0录音模式,1诊断模式,2配置模式
  63 + */
  64 + public static native int ubox_get_work_mode();
  65 +
  66 + /**
  67 + * 检查指定的语音编码是否合法
  68 + *
  69 + * @param coder
  70 + * 语音编码支持一下几种编码格式:0 CODER_ALAW,1 CODER_PCM,3 CODER_G729,20
  71 + * CODER_SPEEX(8倍压缩率),38 CODER_MP3,100 CODER_ULAW
  72 + * @return 0合法,UBOX_ERR_INVALID_VOICE_CODER 语音编码不合法
  73 + */
  74 + public static native int ubox_check_coder(int coder);
  75 +
  76 + /**
  77 + * 录音到文件中
  78 + *
  79 + * @param uboxHnd
  80 + * 设备句柄
  81 + * @param filename
  82 + * 录音文件名 如果编码格式选择CODER_MP3,文件名后缀为.mp3,其它格式推荐使用.wav后缀
  83 + * @param coder
  84 + * 语音编码格式:0 CODER_ALAW,1 CODER_PCM,3 CODER_G729,20
  85 + * CODER_SPEEX(8倍压缩率),38 CODER_MP3,100
  86 + * CODER_ULAW,一般推荐用CODER_ALAW, CODER_MP3和CODER_SPEEX编码
  87 + * @return 0成功,<0失败
  88 + */
  89 + public static native int ubox_record_file(int uboxHnd, String filename,
  90 + int coder);
  91 +
  92 + /**
  93 + * 流式录音
  94 + *
  95 + * @param uboxHnd
  96 + * 设备句柄
  97 + * @param coder
  98 + * 语音编码格式:0 CODER_ALAW,1 CODER_PCM,3 CODER_G729,20
  99 + * CODER_SPEEX(8倍压缩率),38 CODER_MP3,100 CODER_ULAW
  100 + * @return 0成功
  101 + * 说明:调用这个函数后,会不停地触发UBOX_EVENT_STREAM_VOICE事件,直到调用ubox_stop_record()
  102 + */
  103 + public static native int ubox_record_stream(int uboxHnd, int coder);
  104 +
  105 + /**
  106 + * 停止文件和流式录音
  107 + *
  108 + * @param uboxHnd
  109 + * 设备句柄
  110 + * @return 0成功
  111 + */
  112 + public static native int ubox_stop_record(int uboxHnd);
  113 +
  114 + /**
  115 + * 读取悬空
  116 + *
  117 + * @param uboxHnd
  118 + * 设备句柄
  119 + * @return >0悬空门限值,<0失败 说明:此函数必需在 UBOX_MODE_CONFIG 模式下使用,否则返回
  120 + * UBOX_ERR_INVALID_WORK_MODE。Fi3001B调用这个函数才有意义
  121 + */
  122 + public static native int ubox_get_hang_threshold(int uboxHnd);
  123 +
  124 + /**
  125 + * 设置悬空门限值,参考ubox_set_hookoff_threshold中的说明
  126 + *
  127 + * @param uboxHnd
  128 + * 设备句柄
  129 + * @param threshold
  130 + * 小于该值,判断线路悬空
  131 + * @return 0成功, 说明:产品Fi3001B调用这个函数才有意义
  132 + */
  133 + public static native int ubox_set_hang_threshold(int uboxHnd, int threshold);
  134 +
  135 + /**
  136 + * 读取摘机门限值
  137 + *
  138 + * @param uboxHnd
  139 + * 设备句柄
  140 + * @return >0摘机门限值,<0失败 说明:产品Fi3001B调用这个函数才有意义
  141 + */
  142 + public static native int ubox_get_hookoff_threshold(int uboxHnd);
  143 +
  144 + /**
  145 + * 设置摘机门限值
  146 + *
  147 + * @param uboxHnd
  148 + * 设备句柄
  149 + * @param threshold
  150 + * 的值是摘机电压和挂机电压的之和的一半,摘机电压和挂机电压测量调用,ubox_start_read_line_voltage,
  151 + * 对于Fi3001B摘机状态是通过电压判断的
  152 + * @return 说明:产品Fi3001B调用这个函数才有意义
  153 + * Fi3001是通过压控方式检测电话状态,通常情况下,挂机时直流电压为48V左右,摘机时直流电压会降到6V左右
  154 + * 。USB录音盒设置默认摘机门限值为18V,
  155 + * 当线路电压大于18V,软件判断为挂机,小于18V软件判断为摘机。由于电话线的所处的环境不同
  156 + * ,线路直流电压值不同,可能摘机后,线路电压依然要大于摘机门限值,这样软件不能正确检测到电话状态,需要重新设置摘机门限值
  157 + */
  158 + public static native int ubox_set_hookoff_threshold(int uboxHnd,
  159 + int threshold);
  160 +
  161 + /**
  162 + * 开始检测线路电压
  163 + *
  164 + * @param uboxHnd
  165 + * 设备句柄
  166 + * @return 0成功
  167 + * 说明:调用这个函数后,会不停触发UBOX_EVENT_LINE_VOLTAGE事件,报告当前线路电压值。产品Fi3001B调用这个函数才有意义
  168 + */
  169 + public static native int ubox_start_read_line_voltage(int uboxHnd);
  170 +
  171 + /**
  172 + * 结束检测线路电压
  173 + *
  174 + * @param uboxHnd
  175 + * 设备句柄
  176 + * @return 0成功 说明:调用这个函数后,会停止触发UBOX_EVENT_LINE_VOLTAGE事件产品Fi3001B调用这个函数才有意义
  177 + */
  178 + public static native int ubox_stop_read_line_voltage(int uboxHnd);
  179 +
  180 + /**
  181 + * 发送号码(DTMF)
  182 + *
  183 + * @param uboxHnd
  184 + * 设备句柄
  185 + * @param dmftfstring
  186 + * 号码串
  187 + * @return 0成功
  188 + * 说明:Fi3101A,FI3102A可以不摘机,软拨号直接拨出号码。对于Fi3101A,如果电话机摘机声音自动切换到电话机里
  189 + * ,底层自动软挂机,耳机无声音
  190 + * 。Fi3001B和Fi3002B,必须要先手动摘机,才可以拨号。对于有软摘机功能的产品,直接软件拨号,
  191 + * 有可能拨号不成功,拨得太快了,
  192 + * 交换机需要时间检测摘机,因此处理方法上层程序需要先软摘机后,延时1-2S钟,然后再调用ubox_send_dtmf函数
  193 + */
  194 + public static native int ubox_send_dtmf(int uboxHnd, String dmftfstring);
  195 +
  196 + /**
  197 + * 播放语音文件
  198 + *
  199 + * @param uboxHnd
  200 + * 设备句柄
  201 + * @param filename
  202 + * 语音文件名
  203 + * @return 0成功 说明:放音格式为: A-law,u-law, 8k * 16 位 pcm文件
  204 + */
  205 + public static native int ubox_play_file(int uboxHnd, String filename);
  206 +
  207 + /**
  208 + * 停止播放
  209 + *
  210 + * @param uboxHnd
  211 + * 设备句柄
  212 + * @return 0成功
  213 + */
  214 + public static native int ubox_stop_play(int uboxHnd);
  215 +
  216 + /**
  217 + * 暂停播放,再调用一次,继续播放
  218 + *
  219 + * @param uboxHnd
  220 + * 设备句柄
  221 + * @return 0成功
  222 + */
  223 + public static native int ubox_play_pause(int uboxHnd);
  224 +
  225 + /**
  226 + * 设置MIC音量,一般设置为0db
  227 + *
  228 + * @param uboxHnd
  229 + * 设备句柄
  230 + * @param volume
  231 + * 设置值,取值范围为0--19
  232 + * @return 0成功
  233 + */
  234 + public static native int ubox_set_volume(int uboxHnd, int volume);
  235 +
  236 + /**
  237 + * 设置放音音量
  238 + *
  239 + * @param uboxHandle
  240 + * 设备句柄
  241 + * @param volume
  242 + * 设置音量,取值范围为-12--6
  243 + * @return 0成功
  244 + */
  245 + public static native int ubox_set_Speakervolume(long uboxHandle,
  246 + short volume);
  247 +
  248 + /**
  249 + * 打开和关闭agc
  250 + *
  251 + * @param uboxHnd
  252 + * 设备句柄
  253 + * @param bclose
  254 + * true关闭agc,false打开agc,默认情况下是打开agc
  255 + * @return 0成功
  256 + */
  257 + public static native int ubox_close_agc(int uboxHnd, boolean bclose);
  258 +
  259 + /**
  260 + * 读取USB录音盒中eeprom内的数据
  261 + *
  262 + * @param uboxHnd
  263 + * 设备句柄
  264 + * @param addr
  265 + * 要读取的数据的起始地址,范围为0x00-0x07
  266 + * @param len
  267 + * 读取的长度
  268 + * @return 读取到的数据 说明:Fi3001B使用该函数必须要在配置模式下才能使用
  269 + * 用法:假如uboxHnd=1,addr=0x0,unsigned char
  270 + * readdata[8],ubox_read_eeprom
  271 + * (1,0x00,&readata[0],8),调用成功后,读取的数据在readdata中
  272 + */
  273 + public static native String ubox_read_eeprom(int uboxHnd, char addr, int len);
  274 +
  275 + /**
  276 + * 往USB录音盒中的eeprom写入数据
  277 + *
  278 + * @param uboxHnd
  279 + * 设备句柄
  280 + * @param addr
  281 + * 开始写入的起始地址,范围为0x00-0x07
  282 + * @return 0成功 用法:假如uboxHnd=1,addr=0x00,unsigned char writedata[8]=
  283 + * {0x01,0x20,0x30,0x31,0x32,0x33,0x40,0x70}
  284 + * ubox_write_eeprom(1,0x0,
  285 + * &writedata[0],8),可以在同一个地址区域调用ubox_read_eeprom验证,读取的数据和写入数据是否相等
  286 + */
  287 + public static native int ubox_write_eeprom(int uboxHnd, char addr,
  288 + byte[] inData);
  289 +
  290 + /**
  291 + * 读取USB录音盒中eeprom内的数据
  292 + *
  293 + * @param uboxHnd
  294 + * 设备句柄
  295 + * @param addr
  296 + * 要读取的数据的起始地址,范围为0x00-0x07
  297 + * @param len
  298 + * 读取的长度
  299 + * @return 读取到的数据
  300 + * 说明:对于Fi3001B,调用ubox_write_eeprom写成功后,读取其正确值,必须在软件重新启动后(关闭后,
  301 + * 再打开),调用ubox_read_eepromEx才能正确读取上次修改的值
  302 + * 。而其它产品调用ReadEepromEx和ReadEeprom功能是一样的
  303 + * 用法:假如uboxHnd=1,addr=0x0,unsigned char
  304 + * readdata[8],ubox_read_eeprom
  305 + * (1,0x00,&readata[0],8),调用成功后,读取的数据在readdata中
  306 + */
  307 + public static native int ubox_read_eepromEx(int uboxHnd, char addr, int len);
  308 +
  309 + /**
  310 + * 软件摘机
  311 + *
  312 + * @param uboxHnd
  313 + * 设备句柄
  314 + * @return 0成功 说明:Fi3101A 和Fi3102A才具有该功能
  315 + */
  316 + public static native int ubox_soft_hook_off(int uboxHnd);
  317 +
  318 + /**
  319 + * 软件挂机
  320 + *
  321 + * @param uboxHnd
  322 + * 设备句柄
  323 + * @return 0成功 说明:Fi3101A 和Fi3102A才具有该功能
  324 + */
  325 + public static native int ubox_soft_hook_on(int uboxHnd);
  326 +
  327 + /**
  328 + * 设置忙音参数
  329 + *
  330 + * @param uboxHnd
  331 + * 设备句柄
  332 + * @param dual_frequency
  333 + * 是否是双音频,默认为0
  334 + * @param frequency0
  335 + * 忙音频率0,默认为450HZ
  336 + * @param frequency1
  337 + * 忙音频率1,默认420HZ
  338 + * @param busy_on
  339 + * 忙音周期的持续时间,默认为35表示350ms
  340 + * @param busy_off
  341 + * 忙音周期的断续时间,默认为35表示350ms
  342 + * @param on_off_error
  343 + * 忙音周期的持续时间和断续时间的误差,默认为5表示50ms
  344 + * @param enery_gate
  345 + * 忙音的能量,默认为12db
  346 + * @param period_count
  347 + * 忙音判断的周期数,默认为3,表示连续检测到三个周期的忙音才报告有忙音UBOX_EVENT_DEVICE_BUSY_TONE事件
  348 + * @return 0成功 说明:Fi3101A 和Fi3102A才具有该功能
  349 + */
  350 + public static native int ubox_set_busy_tone(int uboxHnd,
  351 + int dual_frequency, int frequency0, int frequency1, int busy_on,
  352 + int busy_off, int on_off_error, int enery_gate, int period_count);
  353 +
  354 + /**
  355 + * 设置留言模式参数
  356 + *
  357 + * @param uboxHnd
  358 + * 设备句柄
  359 + * @param bset
  360 + * true打开留言参数,false关闭留言参数
  361 + * @return 0成功 说明:设置留言模式下才需要打开留言参数。要退出留言模式,必须关闭留言参数,否则麦克风不能用Fi3101A才具有该功能
  362 + */
  363 + public static native int ubox_set_message_param(int uboxHnd, boolean bset);
  364 +
  365 + /**
  366 + * 打开/关闭蜂鸣器
  367 + *
  368 + * @param uboxHnd
  369 + * 设备句柄
  370 + * @param bset
  371 + * true 打开蜂鸣器,false 关闭蜂鸣器。该功能的用于没有接电话机只接耳麦时,当振铃时蜂鸣器响,提示用户
  372 + * @return 0成功 说明:Fi3101A才具有该功能
  373 + */
  374 + public static native int ubox_open_buzzer_switch(int uboxHnd, boolean bset);
  375 +
  376 + /**
  377 + * 打开日志文件,记录底层的工作信息
  378 + *
  379 + * @param level
  380 + * 0记录所有日志信息,1记录错误和警告信息,该函数可以在调用ubox_open之前调用
  381 + * 说明:调用这个函数后,在应用程序目录下会产生一个ubox-log目录,在该目录下会生成日志文件
  382 + */
  383 + public static native void ubox_open_logfile(long level);
  384 +
  385 + /**
  386 + * 关闭日志文件
  387 + */
  388 + public static native void ubox_close_logfile();
  389 +
  390 + /**
  391 + *打开日志文件,该函数可以在调用ubox_open之前调用
  392 + *dir:记录日志文件的路径,如果为空,就是当前程序目录下。
  393 + *level=0, 显示所有日志信息
  394 + *level =1, 显示错误和警告信息显示
  395 + *
  396 + * */
  397 + public static native void ubox_open_logfileEx(String strDir, long level);
  398 +
  399 +
  400 + /**
  401 + *
  402 + 功 能:上传录音文件。
  403 + 参 数:uploadUrl: 上传文件使用的URL(形如192.168.1.1)
  404 + paramName: 提交http请求时,上传文件在服务器上名字,可以包括目录,目录必须是存在的。
  405 + uploadFilePath: 待上传的文件全路径(形如D:\\recordFile.wav)
  406 + 返 回:上传成功返回0,失败返回负数。
  407 + *
  408 + * */
  409 + public static native int ubox_uploadFile(String strUploadUrl, String strParamName, String strUploadFilename);
  410 +
  411 +
  412 + /**
  413 + 无线设备发送号码()
  414 + *
  415 + * @param uboxHnd
  416 + * 设备句柄
  417 + * @param phonenumber
  418 + * 电话号码
  419 + * @return 0成功
  420 + * 说明:无线设备外呼拨号
  421 + */
  422 + public static native int ubox_makecall(int uboxHnd, String phonenumber);
  423 +
  424 +
  425 + public static native int ubox_reject_call(int uboxHnd);
  426 +
  427 + public static native int ubox_set_talk_link(int uboxHnd, int mode, int value); //设定通话link 开关
  428 + public static native int ubox_makecallSlic(int uboxHnd, int ringtime, int stopringtime, String phonenumber);
  429 + public static native int ubox_set_record_enable(int uboxHnd, int mode, int value); // 设定录音开关
  430 +
  431 +
  432 + public static native int ubox_gsm_power(int uboxHnd, int value); //0:GSM模块断电, 1:GSM模块上电
  433 + public static native int ubox_gsm_bootkey(int uboxHnd, int value); //1:GSM开机键, 延时按1~2s,在调用释放命令, 0:GSM开机键释放
  434 +
  435 + public static native int ubox_feed_slic_polarity(int uboxHnd, int value); //0:slic正向馈电, 1:slic反向馈电
  436 +
  437 + /*
  438 +
  439 + */
  440 + public static native int ubox_send_gsm_cmd(int uboxHnd, String cmd, int len); //发送GSM命令,供调试GSM模块使用
  441 +
  442 +/*
  443 + *
  444 + *
  445 + uboxHnd 设备句柄
  446 + phonenumber: 手机电话号码,必须要加国家区号,比如8615907550000
  447 + mode: 0: 短信内容已经用unicode转码,
  448 + 1:未转码的数据
  449 + msg: 短信内容
  450 + len: 短信长度
  451 +
  452 + */
  453 + public static native int ubox_send_gsm_msg(int uboxHnd, int mode, String phonenumber, String msg, int len); //发短信
  454 + /*
  455 + 查询GSM设备可存储短信数目和目前有多少条短信
  456 + */
  457 + public static native int ubox_query_gsm_msg_number(int uboxHnd);
  458 +
  459 + /*
  460 + 按照索引值,该数值通过ubox_query_gsm_msg_number获取, index从1开始,查询GSM设备内短信内容
  461 +
  462 +
  463 + */
  464 + public static native int ubox_query_gsm_msg(int uboxHnd, int index); //短信内容是unicode方式,需要应用软件再转换
  465 +
  466 + public static native int ubox_query_gsm_msgEx(int uboxHnd, int index); //短信内容已经转换为多字节方式
  467 +
  468 + /*删除短信数目
  469 + msgtype=0, index是删除单条短信的序号,msgtype为其它值,index设为1
  470 + msgtype=1, 删除所有的已经阅读的短消息
  471 + msgtype=2, 删除所有的已经阅读和发送出去的短消息
  472 + msgtype=3, 删除所有的已经阅读过、已经发送出去的和未发送的短消息
  473 + msgtype=4, 删除所有的短消息
  474 + */
  475 + public static native int ubox_delete_gsm_msg(int uboxHnd, int index, int msgtype);
  476 +
  477 + //设备是单模,支持双卡,0:选择sim卡1, 1:选择sim卡2
  478 + // 选择卡后,需要给GSM模块断电,上电,然后调用GSM开机键 ubox_gsm_bootkey(1),延时2秒,最后开机键释放ubox_gsm_bootkey(0)
  479 + public static native int ubox_select_simcard(int uboxHnd, int simcardno);
  480 +
  481 + /*
  482 + 设置GSM输出和输入音量,
  483 + type:0 输入音量 0-10
  484 + type:1:输出音量 0-100
  485 +
  486 + */
  487 + public static native int ubox_set_gsm_vol(int uboxHnd, int type, int vol);
  488 +
  489 + /*
  490 + type:0 输入音量
  491 + type:1:输出音量
  492 + 获取GSM输出和输入音量,以事件UBOX_EVENT_GSM_VOL_SIZE通知
  493 + */
  494 + public static native int ubox_get_gsm_vol(int uboxHnd, int type);
  495 +
  496 + /*
  497 + type: 0 耳麦模式, 1:电话机模式
  498 + 设置耳麦和slic电话机工作模式
  499 + type mode
  500 + 0 1 耳麦自动模式,有电话呼入,按耳麦线按钮,电话摘机,再按按一次,挂断GSM通话
  501 + 0 0 关闭耳麦自动模式
  502 +
  503 + 1 1 话机自动模式,电话呼入,电话机振铃,电话机挂机,挂断GSM通话
  504 +
  505 + 1 0 关闭话机自动模式
  506 + */
  507 +
  508 + public static native int ubox_set_gsm_work_mode(int uboxHnd, int type, int mode);
  509 +
  510 + /*
  511 + 让GSM模块产生本地定制单音, 用于电话呼入的时候,耳麦里面能够听到声音,提醒有来电
  512 + mode 0 停止播放
  513 + 1 开始播放
  514 + freq 播放单音频率
  515 + periodon 一个周期内播放单音的时长
  516 + periodoff 一个周期内静音的时长
  517 + duration 单音播放总时长,单位为毫秒
  518 + */
  519 +
  520 + public static native int ubox_gsm_generate_tone(int uboxHnd, int mode, int freq, int periodon, int periodoff, int duration);
  521 +
  522 + //加载DLL
  523 + static {
  524 +
  525 + System.out.println(System.getProperty("java.library.path"));
  526 + String property = System.getProperty("user.dir");
  527 + System.out.println("property:"+property.replace("\\","/")+"/bin/");
  528 +// String path = PhonicNative.class.getResource("/").toString();
  529 +// path = path.substring(6).replaceAll("%20", " ");
  530 +// String path =property.replace("\\","/")+"/bin/";
  531 +// System.out.println(path);
  532 + String path = property + "\\bin\\";
  533 + System.out.println(path);
  534 + try {
  535 + // 包含 "64",即可64位 JDK , 否则 32位
  536 + System.out.println(System.getProperty("java.vm.name"));
  537 + System.out.println(System.getProperty("os.arch"));
  538 + System.out.println(System.getProperty("sun.arch.data.model"));
  539 + if(Integer.parseInt(System.getProperty("sun.arch.data.model")) == 32) //32bit Java
  540 + {
  541 + System.out.println("load 32bit dll");
  542 + System.load(path + "x86/phonic_ubox.dll");
  543 + System.load(path + "x86/phonic_native.dll");
  544 + System.load(path + "x86/phonic_utool.dll");
  545 + System.load(path + "x86/phonic_utoolI.dll");
  546 + System.load(path + "x86/phonic_utoolII.dll");
  547 + System.load(path + "x86/phonic_utoolIIEx.dll");
  548 + }
  549 + else
  550 + {
  551 + System.out.println("load 64bit dll");
  552 +// System.load( "E:/workspace/ubox-java/api/Demo/bin/x64/phonic_ubox.dll");
  553 +// System.load("E:/workspace/ubox-java/api/Demo/bin/x64/phonic_native.dll");
  554 +// System.load( "E:/workspace/ubox-java/api/Demo/bin/x64/phonic_utool.dll");
  555 +// System.load("E:/workspace/ubox-java/api/Demo/bin/x64/phonic_utoolI.dll");
  556 +// System.load( "E:/workspace/ubox-java/api/Demo/bin/x64/phonic_utooIIl.dll");
  557 +
  558 + System.load(path + "x64\\phonic_ubox.dll");
  559 + System.load(path + "x64\\phonic_native.dll");
  560 + System.load(path + "x64\\phonic_utool.dll");
  561 + System.load(path + "x64\\phonic_utoolI.dll");
  562 + System.load(path + "x64\\phonic_utoolII.dll");
  563 +
  564 +
  565 +// System.loadLibrary(path + "phonic_ubox.dll");
  566 +// System.loadLibrary(path + "phonic_native.dll");
  567 +// System.loadLibrary(path + "phonic_utool.dll");
  568 +// System.loadLibrary(path + "phonic_utoolI.dll");
  569 +// System.loadLibrary(path + "phonic_utooIIl.dll");
  570 + }
  571 + //System.load(path + "X86/phonic_ubox");
  572 + //System.load(path + "X86/phonic_native");
  573 + } catch (Exception e) {
  574 + e.printStackTrace();
  575 + }
  576 + }
  577 +}
... ...