新增门监控控制
ups电池获取单位改成int
This commit is contained in:
parent
6d9ba12cf1
commit
301dc63624
84
src/main/java/com/yutou/nas/Controllers/DoorController.java
Normal file
84
src/main/java/com/yutou/nas/Controllers/DoorController.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package com.yutou.nas.Controllers;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.yutou.nas.utils.RedisTools;
|
||||||
|
import com.yutou.nas.utils.StringUtils;
|
||||||
|
import com.yutou.nas.utils.Tools;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class DoorController {
|
||||||
|
@RequestMapping("/door/data.do")
|
||||||
|
@ResponseBody
|
||||||
|
public JSONObject getData(){
|
||||||
|
JSONObject json=new JSONObject();
|
||||||
|
String zoom=RedisTools.get("door_zoom");
|
||||||
|
if(StringUtils.isEmpty(zoom)){
|
||||||
|
zoom="0";
|
||||||
|
}
|
||||||
|
json.put("zoom", Float.parseFloat(zoom));
|
||||||
|
json.put("audio",RedisTools.get("door_audio"));
|
||||||
|
json.put("restart",RedisTools.get("door_reboot"));
|
||||||
|
json.put("af",RedisTools.get("door_af"));
|
||||||
|
File file=new File("web"+File.separator+"apk"+File.separator+"door");
|
||||||
|
if(file.exists()&& Objects.requireNonNull(file.listFiles()).length!=0){
|
||||||
|
JSONObject update=new JSONObject();
|
||||||
|
update.put("versionName", Objects.requireNonNull(file.listFiles())[0].getName().replace("app-release-","").replace(".apk",""));
|
||||||
|
update.put("url","http://192.168.31.88:803/apk/door/"+ Objects.requireNonNull(file.listFiles())[0].getName());
|
||||||
|
json.put("update",update);
|
||||||
|
}
|
||||||
|
RedisTools.remove("door_audio");
|
||||||
|
RedisTools.remove("door_reboot");
|
||||||
|
RedisTools.remove("door_af");
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
@RequestMapping("/door/zoom.do")
|
||||||
|
@ResponseBody
|
||||||
|
public String setZoom(float zoom){
|
||||||
|
if(zoom>1){
|
||||||
|
zoom=1;
|
||||||
|
}
|
||||||
|
if(zoom<0){
|
||||||
|
zoom=0;
|
||||||
|
}
|
||||||
|
RedisTools.set("door_zoom",zoom+"");
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
@RequestMapping(value="/door/audio.do")
|
||||||
|
@ResponseBody
|
||||||
|
public String setAudio(@RequestParam("audio") MultipartFile audio){
|
||||||
|
System.out.println("收到音频");
|
||||||
|
try {
|
||||||
|
String path=Tools.createFile("audio",audio,System.currentTimeMillis()+".mp3");
|
||||||
|
RedisTools.set("door_audio","http://192.168.31.88:801/"+path);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
@RequestMapping(value="/door/audio_url.do")
|
||||||
|
@ResponseBody
|
||||||
|
public String setAudioUrl(String url){
|
||||||
|
RedisTools.set("door_audio",url);
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
@RequestMapping("/door/reboot.do")
|
||||||
|
@ResponseBody
|
||||||
|
public String reboot(){
|
||||||
|
RedisTools.set("door_reboot","1");
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
@RequestMapping("/door/af.do")
|
||||||
|
@ResponseBody
|
||||||
|
public String af(){
|
||||||
|
RedisTools.set("door_af","1");
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
@Import(BTDownloadManager.class)
|
@Import(BTDownloadManager.class)
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class NasApplication {
|
public class NasApplication {
|
||||||
public static final String version="1.2.6";
|
public static final String version="1.2.7";
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(NasApplication.class, args);
|
SpringApplication.run(NasApplication.class, args);
|
||||||
AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
||||||
|
@ -153,7 +153,7 @@ public class tools {
|
|||||||
}
|
}
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@RequestMapping("/public/getUPSPower.do")
|
@RequestMapping("/public/getUPSPower.do")
|
||||||
public float getUPSPower(){
|
public int getUPSPower(){
|
||||||
return Tools.getSystemUPSPower();
|
return Tools.getSystemUPSPower();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package com.yutou.nas.utils;
|
package com.yutou.nas.utils;
|
||||||
|
|
||||||
import com.iflytek.cloud.speech.*;
|
import com.iflytek.cloud.speech.*;
|
||||||
|
import com.yutou.nas.interfaces.ObjectInterface;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class AudioTools {
|
public class AudioTools {
|
||||||
private static boolean init = false;
|
private static boolean init = false;
|
||||||
@ -19,6 +22,7 @@ public class AudioTools {
|
|||||||
|
|
||||||
public static void playText(String text) {
|
public static void playText(String text) {
|
||||||
SpeechSynthesizer mss = SpeechSynthesizer.createSynthesizer();
|
SpeechSynthesizer mss = SpeechSynthesizer.createSynthesizer();
|
||||||
|
|
||||||
mss.startSpeaking(text, new SynthesizerListener() {
|
mss.startSpeaking(text, new SynthesizerListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onBufferProgress(int progress, int beginPos, int endPos,
|
public void onBufferProgress(int progress, int beginPos, int endPos,
|
||||||
@ -26,6 +30,7 @@ public class AudioTools {
|
|||||||
if (progress == 100) {
|
if (progress == 100) {
|
||||||
mss.destroy();
|
mss.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -58,9 +63,54 @@ public class AudioTools {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
public static void getAudio(String text, ObjectInterface objectInterface){
|
||||||
|
SpeechSynthesizer mss = SpeechSynthesizer.createSynthesizer();
|
||||||
|
mss.setParameter(SpeechConstant.VOICE_NAME, "xiaoyu");
|
||||||
|
// 设置语速,范围0~100
|
||||||
|
mss.setParameter(SpeechConstant.SPEED, "50");
|
||||||
|
// 设置语调,范围0~100
|
||||||
|
//mss.setParameter(SpeechConstant.PITCH, "50");
|
||||||
|
// 设置音量,范围0~100
|
||||||
|
mss.setParameter(SpeechConstant.VOLUME, "100");
|
||||||
|
|
||||||
|
String fileName="html" + File.separator + "audio" + File.separator + System.currentTimeMillis() + ".wav";
|
||||||
|
mss.synthesizeToUri(
|
||||||
|
text,
|
||||||
|
fileName,
|
||||||
|
new SynthesizeToUriListener() {
|
||||||
|
@Override
|
||||||
|
public void onBufferProgress(int progress) {
|
||||||
|
System.out.println("progress = " + progress);
|
||||||
|
if (progress == 100) {
|
||||||
|
objectInterface.out(fileName);
|
||||||
|
mss.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSynthesizeCompleted(String s, SpeechError speechError) {
|
||||||
|
System.out.println("s = " + s);
|
||||||
|
System.out.println("speechError = " + speechError.getErrorDesc());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEvent(int i, int i1, int i2, int i3, Object o, Object o1) {
|
||||||
|
System.out.println("i = " + i + ", i1 = " + i1 + ", i2 = " + i2 + ", i3 = " + i3 + ", o = " + o + ", o1 = " + o1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
init();
|
init();
|
||||||
playText("小爱同学,开灯");
|
getAudio("警告!你已经进入监控范围,请立即离开!", new ObjectInterface() {
|
||||||
|
@Override
|
||||||
|
public void out(String data) {
|
||||||
|
super.out(data);
|
||||||
|
System.out.println(data);
|
||||||
|
File file=new File(data);
|
||||||
|
System.out.println(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Tools {
|
public class Tools {
|
||||||
private static float UPSPower=-1.0f;
|
private static int UPSPower=-1;
|
||||||
/**
|
/**
|
||||||
* 设置Cookie
|
* 设置Cookie
|
||||||
*
|
*
|
||||||
@ -249,7 +249,7 @@ public class Tools {
|
|||||||
file.transferTo(saveFile);
|
file.transferTo(saveFile);
|
||||||
fileName = URLEncoder.encode(fileName, "UTF-8");
|
fileName = URLEncoder.encode(fileName, "UTF-8");
|
||||||
com.yutou.nas.utils.Log.i("上传文件保存路径:" + saveFile.getAbsolutePath());
|
com.yutou.nas.utils.Log.i("上传文件保存路径:" + saveFile.getAbsolutePath());
|
||||||
return path + fileName;
|
return path+"/"+ fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void download(String url, DownloadInterface downloadInterface) {
|
public static void download(String url, DownloadInterface downloadInterface) {
|
||||||
@ -378,7 +378,7 @@ public class Tools {
|
|||||||
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getSystemUPSPower(){
|
public static int getSystemUPSPower(){
|
||||||
AppTools.exec("/sbin/apcaccess |grep BCHARGE ", new ObjectInterface() {
|
AppTools.exec("/sbin/apcaccess |grep BCHARGE ", new ObjectInterface() {
|
||||||
@Override
|
@Override
|
||||||
public void out(String data) {
|
public void out(String data) {
|
||||||
@ -387,7 +387,7 @@ public class Tools {
|
|||||||
Matcher matcher=pattern.matcher(data);
|
Matcher matcher=pattern.matcher(data);
|
||||||
if(matcher.find()) {
|
if(matcher.find()) {
|
||||||
String ups = matcher.group();
|
String ups = matcher.group();
|
||||||
UPSPower=Float.parseFloat(ups);
|
UPSPower= (int) Float.parseFloat(ups);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},false,true);
|
},false,true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user