diff --git a/doc/“哨兵”软件系统软件设计规格说明书.doc b/doc/“哨兵”软件系统软件设计规格说明书.doc index 648bda4..dd3692b 100644 Binary files a/doc/“哨兵”软件系统软件设计规格说明书.doc and b/doc/“哨兵”软件系统软件设计规格说明书.doc differ diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/2/a/2ab0711d9aa5839cecbb6cf0ed96f5a3f6470de5 b/src/sixaunyi/.idea/sonarlint/issuestore/2/a/2ab0711d9aa5839cecbb6cf0ed96f5a3f6470de5 deleted file mode 100644 index e69de29..0000000 diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/7/1/71fd1993763df2214bbdad8cfee650733993fe44 b/src/sixaunyi/.idea/sonarlint/issuestore/7/1/71fd1993763df2214bbdad8cfee650733993fe44 deleted file mode 100644 index 7233058..0000000 --- a/src/sixaunyi/.idea/sonarlint/issuestore/7/1/71fd1993763df2214bbdad8cfee650733993fe44 +++ /dev/null @@ -1,133 +0,0 @@ - -` java:S112h"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -a java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂ -h java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂8̇1 -h java:S112"FDefine and throw a dedicated exception instead of using a generic one.(҂8̇1 -s java:S117"QRename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ᮾ8̇1 -> -java:S1604b"(Make this anonymous inner class a lambda(Ʒ -> -java:S1604m"(Make this anonymous inner class a lambda( -> -java:S1604z"(Make this anonymous inner class a lambda( -K -java:S1604"(Make this anonymous inner class a lambda(ݳ8̇1 -D -java:S1604"(Make this anonymous inner class a lambda( -D -java:S1604"(Make this anonymous inner class a lambda( -D -java:S1604"(Make this anonymous inner class a lambda( -? -java:S1604"(Make this anonymous inner class a lambda( -? -java:S1604"(Make this anonymous inner class a lambda(ڊ -? -java:S1604"(Make this anonymous inner class a lambda( -F -java:S1604"(Make this anonymous inner class a lambda(8̇1 -] -java:S2184"@Cast one of the operands of this integer division to a "double".([8͇1 -_ -java:S2184"ACast one of the operands of this division operation to a "float".(ϓ8͇1 -d -java:S2184"ACast one of the operands of this division operation to a "float".(8͇1 -b -java:S2184"DCast one of the operands of this subtraction operation to a "float".(8͇1 -d -java:S2184"ACast one of the operands of this division operation to a "float".(8͇1 -b -java:S2184"DCast one of the operands of this subtraction operation to a "float".(8͇1 -b -java:S2184"DCast one of the operands of this subtraction operation to a "float".(8͇1 -d -java:S2184"ACast one of the operands of this addition operation to a "float".(8͇1 -g -java:S2184"DCast one of the operands of this subtraction operation to a "float".(8͇1 -d -java:S2184"ACast one of the operands of this division operation to a "float".(Ҍ8͇1 -c -java:S2184"@Cast one of the operands of this integer division to a "double".(8͇1 -j -java:S2095"LUse try-with-resources or close this "DatagramSocket" in a "finally" clause.(8͇1 -o java:S115/"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(ƴư -t java:S1150"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(ܶ -k java:S1163"WRename this field "TimeInterval" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(n -t java:S116<"ZRename this field "Trans_to_Detect" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -k java:S116?"VRename this field "Forward_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ѕ -m java:S116@"SRename this field "Back_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -h java:S116A"SRename this field "Left_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -i java:S116B"TRename this field "Right_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(Ο -m java:S116C"SRename this field "Down_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(缎 -k java:S116D"QRename this field "Up_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ф -q java:S116E"WRename this field "TurnLeft_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ݎ -l java:S116F"XRename this field "TurnRight_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(p -k java:S116G"VRename this field "Setting_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -p java:S116H"VRename this field "TakeOff_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -p java:S116I"VRename this field "Landing_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -u -java:S1450I"ZRemove the "Landing_btn" field and declare it as a local variable in the relevant methods.( -u -java:S1450H"ZRemove the "TakeOff_btn" field and declare it as a local variable in the relevant methods.( -o -java:S1450J"TRemove the "angle" field and declare it as a local variable in the relevant methods.( -r -java:S1450K"WRemove the "distance" field and declare it as a local variable in the relevant methods.(׾ -[ -java:S1124/"EReorder the modifiers to comply with the Java Language Specification.(ƴư -` -java:S11240"EReorder the modifiers to comply with the Java Language Specification.(ܶ -[ -java:S11241"EReorder the modifiers to comply with the Java Language Specification.(ß -[ -java:S11242"EReorder the modifiers to comply with the Java Language Specification.(Ӿ -o java:S100y"NRename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(8͇1 -t -java:S3776y"RRefactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.(8͇1 -K -java:S1185"(Remove this method to simply inherit it.(8·1 -S -java:S2696"6Make the enclosing method "static" or remove this set.(è8·1 -^ java:S125""'Remove this unused "btn" private field.(ȧ -D -java:S1068J")Remove this unused "angle" private field.( -G -java:S1068K",Remove this unused "distance" private field.(׾ -J -java:S1068M"/Remove this unused "mThreadPool" private field.( -G -java:S1068")Remove this unused "mPath" private field.(䓍8·1 -M -java:S1068"/Remove this unused "mIsUnlocked" private field.(8·1 \ No newline at end of file diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/7/c/7c120b7216f76ce98d1573d90803ab36f481640c b/src/sixaunyi/.idea/sonarlint/issuestore/7/c/7c120b7216f76ce98d1573d90803ab36f481640c deleted file mode 100644 index 01d0bae..0000000 --- a/src/sixaunyi/.idea/sonarlint/issuestore/7/c/7c120b7216f76ce98d1573d90803ab36f481640c +++ /dev/null @@ -1,84 +0,0 @@ - -l java:S117"QRename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -p -java:S1104D"[Make mLocationClient a static final constant or non-public and provide accessors if needed.(L -q -java:S1104F"[Make mLocationOption a static final constant or non-public and provide accessors if needed.( -d -java:S2259"MA "NullPointerException" could be thrown; "mLocationClient" is nullable here.(Թ -c -java:S2095"LUse try-with-resources or close this "DatagramSocket" in a "finally" clause.( -o java:S115d"ZRename this constant name to match the regular expression '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.(뿧 -s java:S116I"YRename this field "Current_latlng" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -o java:S116["ZRename this field "ClearMarker_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -r java:S116]"XRename this field "ChangeAct_btn" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( -d java:S116i"PRename this field "Angle" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(D -q java:S116j"WRename this field "MonitorAngle" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(Ԁ -o java:S116l"ZRename this field "MonitorDistance" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( - -java:S1186"Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.( -i -java:S1450i"TRemove the "Angle" field and declare it as a local variable in the relevant methods.(D -w -java:S1450]"\Remove the "ChangeAct_btn" field and declare it as a local variable in the relevant methods.( -i -java:S1450H"SRemove the "city" field and declare it as a local variable in the relevant methods.( -m -java:S1450W"WRemove the "cityCode" field and declare it as a local variable in the relevant methods.( -r -java:S1450k"WRemove the "distance" field and declare it as a local variable in the relevant methods.(׾ -G -java:S1874S"1Remove this use of "PoiSearch"; it is deprecated.( -L -java:S1874U"1Remove this use of "PoiSearch"; it is deprecated.( -[ -java:S1124d"EReorder the modifiers to comply with the Java Language Specification.(뿧 -` -java:S1124e"EReorder the modifiers to comply with the Java Language Specification.( -Q java:S125h"Use isEmpty() to check whether the collection is empty or not.( -G -java:S1172"+Remove this unused method parameter "view".(ɑ -Q java:S125" -java:S1068H"(Remove this unused "city" private field.( -? -java:S1068S")Remove this unused "query" private field.( -H -java:S1068U"-Remove this unused "poiSearch" private field.( -B -java:S1068W",Remove this unused "cityCode" private field.( -I -java:S1068c".Remove this unused "reveSocket" private field.( -K -java:S1068e"0Remove this unused "RECEIVE_PORT" private field.( -K -java:S1068f"0Remove this unused "listenStatus" private field.(㋸ -I -java:S1068g".Remove this unused "serverAddr" private field.( -E -java:S1068".Remove this unused "mReceiveIp" private field.( \ No newline at end of file diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e b/src/sixaunyi/.idea/sonarlint/issuestore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e deleted file mode 100644 index 48e3a42..0000000 --- a/src/sixaunyi/.idea/sonarlint/issuestore/8/c/8c55c3ccc257e5907959013f99656e4c8ec3903e +++ /dev/null @@ -1,2 +0,0 @@ - -R xml:S55943"1Implement permissions on this exported component.(81 \ No newline at end of file diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/f/7/f7730cde41931660f06cfc32899edf44acf4d104 b/src/sixaunyi/.idea/sonarlint/issuestore/f/7/f7730cde41931660f06cfc32899edf44acf4d104 deleted file mode 100644 index 77f57c1..0000000 --- a/src/sixaunyi/.idea/sonarlint/issuestore/f/7/f7730cde41931660f06cfc32899edf44acf4d104 +++ /dev/null @@ -1,10 +0,0 @@ - -k java:S117'"QRename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.(ߏ -q -java:S1450"[Remove the "mLoginButton" field and declare it as a local variable in the relevant methods.(Ձ -t -java:S1171"YMove the contents of this initializer to a standard constructor or to field initializers.( -G -java:S1602 ",Remove useless curly braces around statement( -V -java:S11263"AReplace this if-then-else statement by a single return statement.(ցz \ No newline at end of file diff --git a/src/sixaunyi/.idea/sonarlint/issuestore/index.pb b/src/sixaunyi/.idea/sonarlint/issuestore/index.pb index a42e3f3..bd69223 100644 --- a/src/sixaunyi/.idea/sonarlint/issuestore/index.pb +++ b/src/sixaunyi/.idea/sonarlint/issuestore/index.pb @@ -22,14 +22,4 @@ j j :app/src/main/java/com/example/sixaunyi/DetectActivity.java,9\6\9668392b13e33166876f2a7d3f10eb5405e757ad k -;app/src/main/java/com/example/sixaunyi/ControlActivity.java,c\9\c99a584c2117ed2df42496451bb97ac1147f5ea0 -P - app/src/main/AndroidManifest.xml,8\c\8c55c3ccc257e5907959013f99656e4c8ec3903e -k -;app/src/main/java/com/example/sixaunyi/SettingActivity.java,2\a\2ab0711d9aa5839cecbb6cf0ed96f5a3f6470de5 -i -9app/src/main/java/com/example/sixaunyi/LoginActivity.java,f\7\f7730cde41931660f06cfc32899edf44acf4d104 -h -8app/src/main/java/com/example/sixaunyi/MainActivity.java,7\c\7c120b7216f76ce98d1573d90803ab36f481640c -i -9app/src/main/java/com/example/sixaunyi/VideoActivity.java,7\1\71fd1993763df2214bbdad8cfee650733993fe44 \ No newline at end of file +;app/src/main/java/com/example/sixaunyi/ControlActivity.java,c\9\c99a584c2117ed2df42496451bb97ac1147f5ea0 \ No newline at end of file diff --git a/src/sixaunyi/app/src/main/java/com/example/sixaunyi/SettingActivity.java b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/SettingActivity.java index 1be7ece..8ec28ba 100644 --- a/src/sixaunyi/app/src/main/java/com/example/sixaunyi/SettingActivity.java +++ b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/SettingActivity.java @@ -5,7 +5,7 @@ import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; public class SettingActivity extends AppCompatActivity { - + private boolean if_jiankong; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/src/sixaunyi/app/src/main/java/com/example/sixaunyi/VideoActivity.java b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/VideoActivity.java index 3edfe37..a10e82f 100644 --- a/src/sixaunyi/app/src/main/java/com/example/sixaunyi/VideoActivity.java +++ b/src/sixaunyi/app/src/main/java/com/example/sixaunyi/VideoActivity.java @@ -20,6 +20,7 @@ import android.graphics.RectF; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.provider.ContactsContract; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; @@ -48,7 +49,6 @@ public class VideoActivity extends AppCompatActivity { private final static String Recieve_IP = "192.168.39.47";//填服务器IP,与send_to_IP为同一个 private final static int SEND_PORT = 8888; //发送端口号 private final static int RECEIVE_PORT = 9999; //接收端口号 - int TimeInterval = 5; private static boolean listenStatus = true; //接收线程的循环标识 private byte[] buf; static Bitmap bp; @@ -71,8 +71,8 @@ public class VideoActivity extends AppCompatActivity { private ImageButton Setting_btn; private ImageButton TakeOff_btn; private ImageButton Landing_btn; - private String angle; - private float distance; + private String mangle; + private float mdistance; // 创建一个可缓存的线程池 private ExecutorService mThreadPool = Executors.newCachedThreadPool(); //ReceiveData()显示到imageView @@ -99,31 +99,40 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - sendOrder("TAKEOFF"); + sendCommand("TAKEOFF"); } catch (UnknownHostException e) { throw new RuntimeException(e); } - Log.i(TAG, "onClick: BBBBBBBBackward"); + Log.i(TAG, "onClick: TTTTTTTTTTTTTTakeoff"); } }); Landing_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - new UdpReceiveThread().start(); + ReceiveHandler receiveHandler = new ReceiveHandler(); + UdpReceiveThread StreamThread = new UdpReceiveThread(Recieve_IP,RECEIVE_PORT,receiveHandler); + + + try { + StreamThread.startListen(); + StreamThread.start(); + } catch (SocketException | UnknownHostException e) { + e.printStackTrace(); + } } }); Setting_btn = findViewById(R.id.setting_button); Button_Init(); Intent i = getIntent(); - distance = i.getFloatExtra("Distance",0); - angle = i.getStringExtra("Angle"); + mdistance = i.getFloatExtra("Distance",0); + mangle = i.getStringExtra("Angle"); } private void Button_Init(){ Forward_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { - sendOrder("FORWARD"); + sendCommand("FORWARD"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -134,7 +143,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - sendOrder("BACKWORD"); + sendCommand("BACKWORD"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -145,7 +154,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - sendOrder("LEFT"); + sendCommand("LEFT"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -156,7 +165,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - sendOrder("RIGHT"); + sendCommand("RIGHT"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -167,7 +176,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - sendOrder("DOWN"); + sendCommand("DOWN"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -178,7 +187,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - sendOrder("UP"); + sendCommand("UP"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -189,7 +198,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - sendOrder("TURN_LEFT"); + sendCommand("TURN_LEFT"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -200,7 +209,7 @@ public class VideoActivity extends AppCompatActivity { @Override public void onClick(View v) { try { - sendOrder("TURN_RIGHT"); + sendCommand("TURN_RIGHT"); } catch (UnknownHostException e) { throw new RuntimeException(e); } @@ -218,8 +227,14 @@ public class VideoActivity extends AppCompatActivity { class ReceiveHandler extends Handler{ @Override public void handleMessage(Message msg) { - super.handleMessage(msg); - imgShow.setImageBitmap(bp); + if (msg.what == 1) { + runOnUiThread(new Runnable() { + @Override + public void run() { + imgShow.setImageBitmap(bp); + } + }); + } } } @@ -233,38 +248,91 @@ public class VideoActivity extends AppCompatActivity { /* * UDP数据接受线程 * */ - public class UdpReceiveThread extends Thread - { + public class UdpReceiveThread extends Thread { + private DatagramSocket reveSocket; + private String Recieve_IP; + private int RECEIVE_PORT; + private Handler receiveHandler; + + public UdpReceiveThread(String ip, int port, Handler handler) { + this.Recieve_IP = ip; + this.RECEIVE_PORT = port; + this.receiveHandler = handler; + } + + public void startListen() throws SocketException, UnknownHostException { + reveSocket = new DatagramSocket(RECEIVE_PORT); + } + + public void stopListen() { + if (reveSocket != null && !reveSocket.isClosed()) { + listenStatus = false; + //reveSocket.close(); + } + } + @Override - public void run() - { - try - { - reveSocket = new DatagramSocket(RECEIVE_PORT); - serverAddr = InetAddress.getByName(Recieve_IP); - //ByteArrayOutputStream out = new ByteArrayOutputStream(); - while(listenStatus) - { - byte[] inBuf= new byte[1024*1024]; - DatagramPacket inPacket=new DatagramPacket(inBuf,inBuf.length); - //out.write(inPacket.getData()); + public void run() { + try { + InetAddress serverAddr = InetAddress.getByName(Recieve_IP); + + while (listenStatus) { + byte[] inBuf = new byte[1024 * 1024]; + DatagramPacket inPacket = new DatagramPacket(inBuf, inBuf.length); reveSocket.receive(inPacket); - if(!inPacket.getAddress().equals(serverAddr)){ + + if (!inPacket.getAddress().equals(serverAddr)) { throw new IOException("未知名的报文"); } + ByteArrayInputStream in = new ByteArrayInputStream(inPacket.getData()); receiveHandler.sendEmptyMessage(1); bp = BitmapFactory.decodeStream(in); } - } catch (Exception e) - { + } catch (IOException e) { e.printStackTrace(); - }finally { - reveSocket.close(); } } } + /* + * UDP数据发送线程,Runnable方法 + * */ + class SendRunnable implements Runnable { + byte[] mData; + InetAddress mAddress; + int mPort; + + public SendRunnable(byte[] data, InetAddress address, int port) { + mData = data; + mAddress = address; + mPort = port; + } + + @Override + public void run() { + try { + // 创建发送数据报文 + DatagramPacket packet = new DatagramPacket(mData, mData.length, mAddress, mPort); + // 创建 DatagramSocket 对象并发送数据报文 + DatagramSocket socket = new DatagramSocket(); + socket.send(packet); + + // 关闭 DatagramSocket 对象 + socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /*封装函数*/ + private void sendCommand(String str) throws UnknownHostException { + byte[] sendData = str.getBytes(); + InetAddress address = InetAddress.getByName(SEND_to_IP); + SendRunnable sendRunnable1 = new SendRunnable(sendData, address, SEND_PORT); + mThreadPool.execute(sendRunnable1); + } /* * UDP数据发送线程 * */ @@ -294,13 +362,13 @@ public class VideoActivity extends AppCompatActivity { } //初始化UDP发送线程 - private static void sendOrder(String Sendstr) throws UnknownHostException { - InetAddress sendIP = InetAddress.getByName(SEND_to_IP); // 目标 IP 地址 - int sendPort = 8888; // 目标端口号 - byte[] sendData = Sendstr.getBytes(); // 要发送的数据 - UdpSendThread sendOrderThread = new UdpSendThread(sendIP, sendPort, sendData); // 创建新的线程对象 - sendOrderThread.start(); // 启动线程发送数据 - } +// private static void sendCommand(String Sendstr) throws UnknownHostException { +// InetAddress sendIP = InetAddress.getByName(SEND_to_IP); // 目标 IP 地址 +// int sendPort = 8888; // 目标端口号 +// byte[] sendData = Sendstr.getBytes(); // 要发送的数据 +// UdpSendThread sendCommandThread = new UdpSendThread(sendIP, sendPort, sendData); // 创建新的线程对象 +// sendCommandThread.start(); // 启动线程发送数据 +// } @@ -317,7 +385,7 @@ public class VideoActivity extends AppCompatActivity { // public void onUnlock() { // // 在用户滑动解锁后执行操作 //// try { -//// sendOrder("TAKEOFF"+"___"+angle+"___"+String.valueOf(distance)); +//// sendCommand("TAKEOFF"+"___"+angle+"___"+String.valueOf(distance)); //// } catch (UnknownHostException e) { //// throw new RuntimeException(e); //// }