Ver a proveniência

鸿鹄中学上位机业务修改

鸿鹄中学一拖二
pry há 3 meses
ascendente
cometimento
d468976aa1
8 ficheiros alterados com 245 adições e 169 eliminações
  1. +2
    -0
      app/build.gradle
  2. +36
    -0
      app/src/main/java/com/bonait/bnframework/HBL/HttpServer.java
  3. +114
    -0
      app/src/main/java/com/bonait/bnframework/business/ConfigData.java
  4. +11
    -0
      app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
  5. +13
    -167
      app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java
  6. +10
    -2
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/DoubleFryingpanFragment.java
  7. +17
    -0
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java
  8. +42
    -0
      app/src/main/res/layout/activity_systemparameter.xml

+ 2
- 0
app/build.gradle Ver ficheiro

@@ -171,4 +171,6 @@ dependencies {
implementation 'com.contrarywind:Android-PickerView:3.2.6'

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9'
//http服务器组件
implementation 'org.nanohttpd:nanohttpd:2.3.1'
}

+ 36
- 0
app/src/main/java/com/bonait/bnframework/HBL/HttpServer.java Ver ficheiro

@@ -0,0 +1,36 @@
package com.bonait.bnframework.HBL;

import com.bonait.bnframework.common.helper.MessageLog;
import com.bonait.bnframework.common.helper.SendData;
import com.google.gson.Gson;
import com.lzy.okgo.model.HttpParams;

import java.util.Map;

import fi.iki.elonen.NanoHTTPD;

public class HttpServer extends NanoHTTPD {
public HttpServer() {
super(35000);
try{
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
}catch (Exception ex){
MessageLog.ShowError("启动服务失败!"+ex.getMessage());
}
}
@Override
public Response serve(IHTTPSession session) {
try{
if (session.getMethod()==Method.POST){
Map<String,String> headers= session.getHeaders();//获取请求头数据
if(session.getUri().contains("/api/GetMainConsoleData")){
return newFixedLengthResponse(Response.Status.OK, HttpParams.MEDIA_TYPE_JSON.toString(), new Gson().toJson( new SendData())); // 返回响应
}
}
return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, HttpParams.MEDIA_TYPE_JSON.toString(), new Gson().toJson("不是有效的请求")); // 返回响应
}catch (Exception ex){
MessageLog.ShowError("请求失败!"+ex.getMessage());
return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, HttpParams.MEDIA_TYPE_JSON.toString(), new Gson().toJson(ex.getMessage())); // 返回响应
}
}
}

+ 114
- 0
app/src/main/java/com/bonait/bnframework/business/ConfigData.java Ver ficheiro

@@ -1,11 +1,14 @@
package com.bonait.bnframework.business;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;

import com.bonait.bnframework.HBL.Dialog.WaitDialog;
import com.bonait.bnframework.HBL.Task;
import com.bonait.bnframework.R;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.constant.MessageName;
@@ -23,9 +26,11 @@ import com.bonait.bnframework.common.db.mode.BPA_SYSTEMSET;
import com.bonait.bnframework.common.db.mode.BPA_USER;
import com.bonait.bnframework.common.db.mode.Res_PLCADDRESS;
import com.bonait.bnframework.common.helper.ConfigUtil;
import com.bonait.bnframework.common.helper.I.IRun;
import com.bonait.bnframework.common.helper.I.IRunT;
import com.bonait.bnframework.common.helper.Json;
import com.bonait.bnframework.common.helper.MessageLog;
import com.bonait.bnframework.common.helper.SendData;
import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback;
import com.bonait.bnframework.common.image.utils.LocalCacheUtils;
import com.bonait.bnframework.common.message.MessageManager;
@@ -58,6 +63,7 @@ import com.bonait.bnframework.common.utils.ToastUtils;
import com.bonait.bnframework.common.view.GoodEditDialog;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.HttpHeaders;
import com.lzy.okgo.model.Response;

@@ -154,6 +160,12 @@ public class ConfigData {
case 10:
set.value = String.valueOf(ConfigName.getInstance().DevicePort);
break;
case 11:
set.value = ConfigName.getInstance().F1HMIAddress;
break;
case 12:
set.value = ConfigName.getInstance().F2HMIAddress;
break;
}
set.deviceID = ConfigName.getInstance().DeviceId;
set.userID = ConfigName.getInstance().user.userID;
@@ -234,11 +246,113 @@ public class ConfigData {
case 10:
ConfigName.getInstance().DevicePort = Integer.parseInt(item.value);
break;
case 11:
ConfigName.getInstance().F1HMIAddress = item.value;
break;
case 12:
ConfigName.getInstance().F2HMIAddress = item.value;
break;
}

}
}

IRun run1;
IRun run2;

/**
* 同步商品数据到设备屏幕
*/
public void DownDataToDevice(Context context, Activity activity){
// AtomicBoolean one =new AtomicBoolean(false);
// AtomicBoolean two = new AtomicBoolean(false);
// WaitDialog.Show("商品下发","开始下发商品到一号炒锅",context,activity);
Task.Run(()->{
try{
// run1=()->{
// WaitDialog.AddText("开始下发商品到二号炒锅");
// String url1 = "http://" + ConfigName.getInstance().F2HMIAddress+":36000/api/DownGoodsData";
// OkGo.<String>post(url1).upJson(new Gson().toJson(new SendData())).tag(this).execute(new StringCallback() {
// @Override
// public void onSuccess(Response<String> response) {
// ToastUtils.info("下发数据到二号设备成功!");
// WaitDialog.AddText("下发商品到二号炒锅成功");
// two.set(true);
// if(run2!=null)run2.Run();
// }
// @Override
// public void onError(Response<String> val){
// ToastUtils.info("下发数据到二号设备失败!");
// WaitDialog.AddText("下发商品到二号炒锅失败");
// Task.Delay(1000);
// if(run2!=null)run2.Run();
// }
// });
//
// };

// run2=()->{
// ConfigName.getInstance().IsChangeGoods=false;
// if(!one.get()&&!two.get()){
// WaitDialog.TimeOut("商品同步到一号、二号炒锅失败!");
// return;
// }
// if(!one.get()){
// WaitDialog.TimeOut("商品同步到一号炒锅失败!");
// return;
// }
// if(!two.get()){
// WaitDialog.TimeOut("商品同步到二号炒锅失败!");
// return;
// }
// WaitDialog.Dismiss();
// };

String url = "http://" + ConfigName.getInstance().F1HMIAddress+":36000/api/DownGoodsData";
OkGo.<String>post(url).upJson(new Gson().toJson(new SendData())).tag(this).execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
ToastUtils.info("下发商品到一号设备成功!");
WaitDialog.AddText("下发商品到一号炒锅成功");
// one.set(true);
}

@Override
public void onError(Response<String> val){
ToastUtils.info("下发商品到一号设备失败!");
WaitDialog.AddText("下发商品到一号炒锅失败");
// Task.Delay(1000);
}
});

String url1 = "http://" + ConfigName.getInstance().F2HMIAddress+":36000/api/DownGoodsData";
OkGo.<String>post(url1).upJson(new Gson().toJson(new SendData())).tag(this).execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
Task.Delay(1500);
ToastUtils.info("下发数据到二号设备成功!");
WaitDialog.AddText("下发商品到二号炒锅成功");
// two.set(true);
// if(run2!=null)run2.Run();
}
@Override
public void onError(Response<String> val){
Task.Delay(1500);
ToastUtils.info("下发数据到二号设备失败!");
WaitDialog.AddText("下发商品到二号炒锅失败");
// if(run2!=null)run2.Run();
}
});


}catch (Exception e){
MessageLog.ShowError("下发商品失败!"+e.getMessage());
WaitDialog.TimeOut("下发商品失败");
ToastUtils.error("下发商品失败!"+e.getMessage());
}
});
}

/**
* 切换环境
*/


+ 11
- 0
app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java Ver ficheiro

@@ -172,6 +172,17 @@ public class ConfigName {

public String DeviceAddress="192.168.1.103";
public int DevicePort=502;

/**
* 炒锅1屏幕地址
*/
public String F1HMIAddress="10.0.2.15";

/**
* 炒锅2屏幕地址
*/
public String F2HMIAddress="10.0.2.15";

/**
* 是否有修改商品
*/


+ 13
- 167
app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java Ver ficheiro

@@ -3,6 +3,7 @@ package com.bonait.bnframework.modules.home.activity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pGroup;
@@ -13,6 +14,7 @@ import android.util.Log;

import com.bonait.bnframework.HBL.Dialog.AlertDialogButton;
import com.bonait.bnframework.HBL.Dialog.DialogHelper;
import com.bonait.bnframework.HBL.HttpServer;
import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ConfigData;
import com.bonait.bnframework.business.DoubleFryingpanControl;
@@ -58,159 +60,39 @@ public class BottomNavigationMainActivity extends BaseActivity {

@BindView(R.id.viewpager)
QMUIViewPager viewPager;


Context context;
Activity activity;
HttpServer hs;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottom_navigation_main);

context=this;
activity=this;
try {
ButterKnife.bind(this);
MediaPlayerHelper.getInstance().SetConText(getBaseContext());
mNavigateTabBar.onRestoreInstanceState(savedInstanceState);
mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.gongneng, R.mipmap.gongneng_selected, "功能"));
// mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.dingdan, R.mipmap.dingdan_selected, "日志"));
mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(0, 0, ""));
mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.shezhi, R.mipmap.shezhi_selected, "设置"));
// mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.comui_tab_person, R.mipmap.comui_tab_person_selected, "我的"));
mNavigateTabBar.setTabSelectListener(mOnNavigationItemSelectedListener);
initFragment();
Init();

TcpServer.getInstance().startServer(40000);

// TcpClient tcpClient = new TcpClient();
// tcpClient.Connect();
}
catch (Exception e){
Log.i("TAG", "onCreate: "+e.getMessage());
}



}

//region P2P通讯
// WifiP2pManager manager ;
// Channel channel ;
// private void P2pInit(){
// //初始化设备
// manager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
// channel = manager.initialize(this, getMainLooper(), null);
//
// // 监听Wifi-Direct事件
// channel.listenOnChannel(new WifiP2pManager.ChannelListener() {
// @Override
// public void onChannelDisconnected() {
//
// }
// // 处理设备发现、连接、连接变化等
// });
//
// // 发现其他Wifi-Direct设备
// manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
// public void onSuccess() {
// // 发现设备成功
// }
// public void onFailure(int reasonCode) {
// // 发现失败
// }
// });
//
// // 连接到选择的设备
// WifiP2pConfig config = new WifiP2pConfig();
// config.deviceAddress = "设备地址";
// manager.connect(channel, config, new WifiP2pManager.ActionListener() {
// @Override
// public void onSuccess() {
//
// }
//
// @Override
// public void onFailure(int i) {
//
// }
// // 连接成功或失败的回调
// });
//
// // 请求IP地址
// manager.requestGroupInfo(channel, new WifiP2pManager.GroupInfoListener() {
// public void onGroupInfoAvailable(WifiP2pGroup group) {
// InetAddress groupOwnerAddress = group.getOwner().getDeviceAddress();
// // 使用IP地址建立Socket连接
// }
// });
//
//
// WifiDirectHelper wdh = new WifiDirectHelper(manager,channel);
// wdh.register(this);
// manager.discoverPeers(channel, new WifiP2pManager.ActionListener() {
// @Override
// public void onSuccess() {
// // 搜索成功
// }
//
// @Override
// public void onFailure(int reason) {
// // 搜索失败
// }
// });
//
// manager.requestPeers(channel, new WifiP2pManager.PeerListListener() {
// @Override
// public void onPeersAvailable(WifiP2pDeviceList peers) {
// List<WifiP2pDevice> deviceList = new ArrayList<>(peers.getDeviceList());
// // 获取设备列表
// }
// });
//
//
//
// }
//
//
// // 当需要传输文件时,调用transferFile方法
// public void transferFile() {
// WifiP2pFileTransferServer server = new WifiP2pFileTransferServer(channel, this);
// server.setFileTransferListener(new WifiP2pFileTransferServer.FileTransferListener() {
// @Override
// public void onFileTransferStarted(String filename) {
// // 文件传输开始
// }
//
// @Override
// public void onFileTransferProgress(String filename, int progress) {
// // 文件传输进度更新
// }
//
// @Override
// public void onFileTransferFinished(String filename) {
// // 文件传输完成
// }
// });
//
// // 启动服务器
// server.startServer();
//
// // 选择要传输的文件
// File file = ...;
//
// // 发起对 chosenDevice 设备的文件传输请求
// server.transferFile(chosenDevice, file);
// }

//endregion


@Override
protected void onDestroy() {
// FryingpanTwoModebus.getInstance().Dispose();
// FryingpanOneModebus.getInstance().Dispose();
FryingpanModbusHelper.getInstance().Dispose();
YJDeviceHelper.getInstance().Close();
TcpServer.getInstance().stopServer();
if(hs!=null)
hs.stop();
//关闭PLC连接
ConfigData.getInstance().ColsePLC();
MediaPlayerHelper.getInstance().Release();
@@ -226,18 +108,15 @@ public class BottomNavigationMainActivity extends BaseActivity {
private void initFragment() {
fragmentList = new ArrayList<>();
fragmentList.add(new GongnengFragment());
// fragmentList.add(new DingDanfragment());

if(ConfigName.getInstance().versionSelectionEnum.equals("一拖四")){
fragmentList.add(new RobotMain());
}
else if (ConfigName.getInstance().versionSelectionEnum.equals("一拖二")){
fragmentList.add(new DoubleFryingpanFragment());
hs = new HttpServer();
}

// fragmentList.add(new MakeGoodFragment());//再来一单
fragmentList.add(new SheZhifragment());
// fragmentList.add(new MyFragment());
ConfigName.getInstance().fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragmentList);
viewPager.setAdapter(ConfigName.getInstance().fragmentAdapter);
ConfigName.getInstance().fragmentAdapter.SetViewPage(viewPager);
@@ -256,8 +135,6 @@ public class BottomNavigationMainActivity extends BaseActivity {
public void Init() {
//1.同步时间
NetworkUtils.SynchronizationTime();
//主持
//ConfigData.getInstance().GetOrganize(this);
//判断连接环境
ConfigData.getInstance().ToggleEnvironment();

@@ -280,18 +157,9 @@ public class BottomNavigationMainActivity extends BaseActivity {
// DialogHelper.showError(this,"机器人急停中!", AlertDialogButton.OK,null);
// };
}


//2.初始化PLC
// ReconnectModbus();
//MQTT数据监听
// OrderServer.Get().MqttInit();
}





/**
* 配置bottom底部菜单栏监听器,手指点击底部菜单监听
*/
@@ -299,41 +167,19 @@ public class BottomNavigationMainActivity extends BaseActivity {
= new MainNavigateTabBar.OnTabSelectedListener() {
@Override
public void onTabSelected(MainNavigateTabBar.ViewHolder holder) {
// int _postion = 2;
// switch (holder.tag) {
// case "功能":
// _postion = 0;
// break;
// case "订单":
// _postion = 1;
// break;
// case "设置":
// _postion = 3;
// break;
// case "我的":
// _postion = 4;
// break;
// case "":
// _postion = 2;
// break;
// }
int _postion = 0;
switch (holder.tag) {
case "功能":
_postion = 0;
break;
// case "订单":
// _postion = 1;
// break;
case "设置":
_postion =2;
break;
// case "我的":
// _postion = 4;
// break;
case "":
_postion = 1;
TcpServer.getInstance().SendData();
if(ConfigName.getInstance().IsChangeGoods) {
ConfigData.getInstance().DownDataToDevice(context,activity);
}
break;
}
viewPager.setCurrentItem(_postion);


+ 10
- 2
app/src/main/java/com/bonait/bnframework/modules/home/fragment/DoubleFryingpanFragment.java Ver ficheiro

@@ -1,6 +1,8 @@
package com.bonait.bnframework.modules.home.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
@@ -106,10 +108,15 @@ public class DoubleFryingpanFragment extends BaseFragment {
*/
private DialogView mWarehouselocSelectVisual;

Context context;
Activity activity;

@Override
protected View onCreateView() {
View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_double_fryingpan, null);
ButterKnife.bind(this, root);
context=getContext();
activity=getActivity();
return root;
}

@@ -225,8 +232,9 @@ public class DoubleFryingpanFragment extends BaseFragment {
btn_syncGoods.setOnClickListener((View v)->{
DialogHelper.showWarn(getContext(),"是否将本地商品同步到所有炒锅,此操作将覆盖炒锅本地商品,请问是否继续?",AlertDialogButton.YesNo,(s)->{
if(s){
ConfigName.getInstance().IsChangeGoods=true;
TcpServer.getInstance().SendData();
// ConfigName.getInstance().IsChangeGoods=true;
// TcpServer.getInstance().SendData();
ConfigData.getInstance().DownDataToDevice(context,activity);
}
});
});


+ 17
- 0
app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java Ver ficheiro

@@ -52,6 +52,10 @@ public class SystemParameterActivity extends BaseActivity {
EditText edittext3;
@BindView(R.id.edittext4)
EditText edittext4;
@BindView(R.id.hmi1_Ip)
EditText hmi1_Ip;
@BindView(R.id.hmi2_ip)
EditText hmi2_ip;
@BindView(R.id.environment)
Spinner environment;

@@ -106,6 +110,8 @@ public class SystemParameterActivity extends BaseActivity {
editTextLists.add(F2edittext2);
editTextLists.add(DeviceIp);
editTextLists.add(DevicePort);
editTextLists.add(hmi1_Ip);
editTextLists.add(hmi2_ip);

material_map.put("开发环境", 0);
material_map.put("测试环境", 1);
@@ -179,6 +185,14 @@ public class SystemParameterActivity extends BaseActivity {
ConfigName.getInstance().DevicePort = Integer.parseInt(item.value);
DevicePort.setText(item.value);
break;
case 11:
ConfigName.getInstance().F1HMIAddress = item.value;
hmi1_Ip.setText(item.value);
break;
case 12:
ConfigName.getInstance().F2HMIAddress = item.value;
hmi2_ip.setText(item.value);
break;

}
}
@@ -211,6 +225,9 @@ public class SystemParameterActivity extends BaseActivity {
ConfigName.getInstance().ClientAutoKey = edittext3.getText().toString();
ConfigName.getInstance().DeviceAutoKey = edittext4.getText().toString();

ConfigName.getInstance().F1HMIAddress = hmi1_Ip.getText().toString();
ConfigName.getInstance().F2HMIAddress = hmi2_ip.getText().toString();

ConfigName.getInstance().Environment = environment.getSelectedItem().toString();

boolean isgb = false;


+ 42
- 0
app/src/main/res/layout/activity_systemparameter.xml Ver ficheiro

@@ -202,6 +202,48 @@
</TableRow>

<!-- Table5-->
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp">
<com.qmuiteam.qmui.widget.textview.QMUILinkTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="炒锅屏幕1地址:" />
<EditText
android:id="@+id/hmi1_Ip"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@drawable/input_bj"
android:hint="请输入地址"
android:inputType="text"
android:maxLines="1"
android:padding="3dp"
android:textSize="12dp" />

<com.qmuiteam.qmui.widget.textview.QMUILinkTextView
android:layout_marginLeft="@dimen/dp_10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="炒锅屏幕2地址:" />
<EditText
android:id="@+id/hmi2_ip"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@drawable/input_bj"
android:hint="请输入地址"
android:inputType="text"
android:maxLines="1"
android:padding="3dp"
android:textSize="12dp"/>
</TableRow>

<!-- Table6-->
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"


Carregando…
Cancelar
Guardar