Quellcode durchsuchen

1.增加通过web端修改Android板IP地址,增加显示设备调试信息
2.修改点阵屏循环显示,语音播报循环播报

weizhengliang vor 2 Jahren
Ursprung
Commit
f58c1da53d

+ 56 - 9
app/src/main/java/com/wdkl/ncs/s433/receiver/MainActivity.java

@@ -64,8 +64,6 @@ public class MainActivity extends SerialPortActivity  {
     String callbackString = "";
 
     private SmdtManager smdtManager;
-    private String defaultIP = "172.28.100.10";
-    private String ledIp = "172.28.100.210";
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -150,6 +148,7 @@ public class MainActivity extends SerialPortActivity  {
         smdtManager = SmdtManager.create(this);
 
         //获取当前IP地址,如果IP不对则设置一下默认IP
+        String defaultIP = SettingConfig.getHostIp(getApplicationContext());
         if (!defaultIP.equals(localIP)) {
             Log.e(TAG, "set default ip: " + defaultIP);
             try {
@@ -161,10 +160,10 @@ public class MainActivity extends SerialPortActivity  {
 
         SpeechUtil.getInstance().init(this, null);
 
-        setLedParams(SettingConfig.getLedResolution(this), SettingConfig.getLedFontSize(this));
+        setLedParams(SettingConfig.getLedIp(this), SettingConfig.getLedResolution(this), SettingConfig.getLedFontSize(this));
     }
 
-    private void setLedParams(String resolution, int fontSize) {
+    private void setLedParams(String ledIp, String resolution, int fontSize) {
         LedItem ledItem = new LedItem(resolution, ledIp, false, fontSize);
         ArrayList<LedItem> list = new ArrayList<>();
         list.add(ledItem);
@@ -279,12 +278,42 @@ public class MainActivity extends SerialPortActivity  {
 
                 if (!TextUtils.isEmpty(text)) {
                     if ("reboot".equals(text)) {
-                        //重启
+                        //重启点阵屏
                         LedManagerUtils.getInstance().removeAllProgram(true);
                         SpeechUtil.getInstance().stopSpeak();
 
-                        if (smdtManager != null) {
-                            smdtManager.smdtReboot("reboot");
+                        //延迟5s重启Android板
+                        new Thread(new Runnable() {
+                            @Override
+                            public void run() {
+                                try {
+                                    Thread.sleep(5000);
+
+                                    if (smdtManager != null) {
+                                        smdtManager.smdtReboot("reboot");
+                                    }
+                                } catch (Exception e) {
+                                    e.printStackTrace();
+                                }
+                            }
+                        }).start();
+                    } else if (text.startsWith("led")) {
+                        //修改点阵屏IP
+                        int sepIndex = text.indexOf("@");
+                        String ledIP = text.substring(sepIndex+1);
+                        Log.e(TAG, "set led ip: " + ledIP);
+                        SettingConfig.setLedIp(getApplicationContext(), ledIP);
+                        setLedParams(ledIP, SettingConfig.getLedResolution(getApplicationContext()), SettingConfig.getLedFontSize(getApplicationContext()));
+                    } else if (text.startsWith("host")) {
+                        //修改Android控制板IP
+                        int sepIndex = text.indexOf("@");
+                        String hostIP = text.substring(sepIndex+1);
+                        Log.e(TAG, "set host ip: " + hostIP);
+                        try {
+                            smdtManager.smdtSetEthIPAddress(hostIP, "255.255.0.0", "172.28.100.1", "8.8.8.8");
+                            SettingConfig.setHostIp(getApplicationContext(), hostIP);
+                        } catch (Exception e) {
+                            e.printStackTrace();
                         }
                     } else {
                         //点阵屏显示
@@ -300,7 +329,7 @@ public class MainActivity extends SerialPortActivity  {
 
                 if (TextUtils.isEmpty(text)) {
                     //清除所有信息
-                    LedManagerUtils.getInstance().removeAllProgram(true);
+                    LedManagerUtils.getInstance().updateProgram("clearAll", 3);
                     SpeechUtil.getInstance().stopSpeak();
                 } else {
                     //清除对应呼叫
@@ -320,7 +349,7 @@ public class MainActivity extends SerialPortActivity  {
                 SettingConfig.setLedVoiceVolume(getApplicationContext(), volume);
                 SettingConfig.setLedResolution(getApplicationContext(), ledType);
                 SettingConfig.setLedFontSize(getApplicationContext(), ledSize);
-                setLedParams(ledType, ledSize);
+                setLedParams(SettingConfig.getLedIp(this), ledType, ledSize);
 
                 if (volume > 0 && volume <= 10) {
                     VoiceManagerUtil.setMusicVoice(getApplicationContext(), volume * 10);
@@ -335,6 +364,24 @@ public class MainActivity extends SerialPortActivity  {
                 setSysTime(time, timezone);
             } else if (TcpAction.S433Action.EXIST == tcpModel.getAction()) {
                 //显示调试信息
+                final String debugInfo = "host IP: " + localIP
+                        + "\nhost mac: " + macAddress
+                        + "\nled IP: " + SettingConfig.getLedIp(getApplicationContext())
+                        + "\napp version: " + BuildConfig.VERSION_NAME;
+                LedManagerUtils.getInstance().updateProgram(debugInfo, 1);
+                //1分钟后清除调试信息
+                new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            Thread.sleep(60000);
+
+                            LedManagerUtils.getInstance().updateProgram(debugInfo, 2);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }).start();
             }
         } catch (Exception ex) {
             ex.printStackTrace();

+ 5 - 1
app/src/main/java/com/wdkl/ncs/s433/receiver/led/LedC2MManager.java

@@ -56,7 +56,7 @@ public class LedC2MManager extends LedManager {
             copyFont();
         }
 
-        initScheduledExecutor();
+        //initScheduledExecutor();
     }
 
     @Override
@@ -451,6 +451,10 @@ public class LedC2MManager extends LedManager {
                         return;
                     }
                     break;
+                case 3:
+                    //清屏
+                    programTextList.clear();
+                    break;
             }
 
             sendProgramStart();

+ 19 - 0
app/src/main/java/com/wdkl/ncs/s433/receiver/settingconfig/SettingConfig.java

@@ -19,6 +19,9 @@ public class SettingConfig {
     private static final String KEY_SP_LED_RESOLUTION = "KEY_SP_LED_RESOLUTION";
     private static final String KEY_SP_LED_FONT_SIZE = "KEY_SP_LED_FONT_SIZE";
 
+    private static final String KEY_SP_HOST_IP = "KEY_SP_HOST_IP";
+    private static final String KEY_SP_LED_IP = "KEY_SP_LED_IP";
+
     /**
      * 获取点阵屏节目显示时间
      *
@@ -127,6 +130,22 @@ public class SettingConfig {
         getEditor(context).putInt(KEY_SP_LED_FONT_SIZE, value).apply();
     }
 
+    public static String getHostIp(Context context) {
+        return getSP(context).getString(KEY_SP_HOST_IP, "172.28.100.10");
+    }
+
+    public static void setHostIp(Context context, String value) {
+        getEditor(context).putString(KEY_SP_HOST_IP, value).apply();
+    }
+
+    public static String getLedIp(Context context) {
+        return getSP(context).getString(KEY_SP_LED_IP, "172.28.100.210");
+    }
+
+    public static void setLedIp(Context context, String value) {
+        getEditor(context).putString(KEY_SP_LED_IP, value).apply();
+    }
+
 
 
     private static SharedPreferences getSP(Context context) {

+ 14 - 3
app/src/main/java/com/wdkl/ncs/s433/receiver/utils/SpeechUtil.java

@@ -22,6 +22,7 @@ public class SpeechUtil {
 
     private TextToSpeech textToSpeech;
     private static SpeechUtil speech;
+    private int loopIndex = 0;
     private int speakIndex = 0;
     private int loopCount = 5;
     private boolean isStop = true;
@@ -213,6 +214,7 @@ public class SpeechUtil {
             textToSpeech.stop();
             isStop = true;
             speakIndex = 0;
+            loopIndex = 0;
 
             Log.d(TAG, "stop speak");
         }
@@ -264,16 +266,25 @@ public class SpeechUtil {
         public void run() {
             while (isSpeechLoop) {
                 if (speechTextList.size() > 0 && isStop) {
-                    speakSpeech = speechTextList.get(0);
+                    /*speakSpeech = speechTextList.get(0);
                     Log.d(TAG, "speakSpeech: " + speakSpeech);
+                    speak(speakSpeech);
+                    speechTextList.remove(speakSpeech);*/
+
+                    //循环播报
+                    if (loopIndex >= speechTextList.size()) {
+                        loopIndex = 0;
+                    }
+                    speakSpeech = speechTextList.get(loopIndex);
 
+                    Log.d(TAG, "speakSpeech: " + speakSpeech + ", speak loopIndex: " + loopIndex + ", speech size: " + speechTextList.size());
                     speak(speakSpeech);
 
-                    speechTextList.remove(speakSpeech);
+                    loopIndex++;
                 }
 
                 try {
-                    Thread.sleep(100);
+                    Thread.sleep(500);
                 } catch (Exception e) {
                     e.printStackTrace();
                 }