123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- #pragma once
- #include "uart/ProtocolSender.h"
- #include "restclient-cpp/restclient.h"
- #include "service/BusinessConfig.h"
- #include "base/http_client.h"
- #include <string>
- /*
- *此文件由GUI工具生成
- *文件功能:用于处理用户的逻辑相应代码
- *功能说明:
- *========================onButtonClick_XXXX
- 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称,
- 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
- *========================onSlideWindowItemClick_XXXX(int index)
- 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
- 如slideWindow1;index 代表按下图标的偏移值
- *========================onSeekBarChange_XXXX(int progress)
- 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
- 如SeekBar1;progress 代表当前的进度值
- *========================ogetListItemCount_XXXX()
- 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称,
- 如List1;返回值为当前列表的总条数
- *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
- 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称,
- 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
- *========================常用接口===============
- *LOGD(...) 打印调试信息的接口
- *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字****
- *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
- *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12
- *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
- *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
- *
- * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示
- */
- static int choiceDeviceInt = 0;
- static int choiceHospitalInt = 0;
- static int choicePartInt = 0;
- static int choiceRoomInt = 0;
- static int choiceBedInt = 0;
- Json::Value hospitalList;
- Json::Value hospitalFrameTree;
- Json::Value partFrameTree;
- Json::Value roomFrameTree;
- Json::Value bedFrameTree;
- Json::Value choicePart;
- Json::Value choiceRoom;
- Json::Value choiceBed;
- Json::Value addDevice;
- static string deviceMacMsg = "";
- static string mac = StoragePreferences::getString(STORE_MAC_ADDR, "0.0.0.0");
- static void getHospital() {
- std::string url = getHttpGateway() + "/arrange/hospitals";
- LOGD("请求医院列表. url = %s", url.c_str());
- RestClient::Response r = RestClient::get(url);
- if (r.code != 200) {
- LOGD("请求医院列表-> 错误代码: %d", r.code);
- return;
- }
- LOGD("获得医院列表. result = %s", r.body.c_str());
- //解析json
- Json::Reader reader;
- Json::Value root;
- if(reader.parse(r.body, root, false)) {
- hospitalList = root;
- mHospitalListViewPtr->refreshListView();
- }
- }
- static void initFrame() {
- if (hospitalFrameTree.size() == 0) {
- return;
- }
- partFrameTree = hospitalFrameTree["frame_part_vos"];
- if (partFrameTree.size() == 0) {
- choicePart.clear();
- mChoicePartButtonPtr->setText("");
- return;
- }
- choicePart = partFrameTree[choicePartInt]["frame_part"];
- mChoicePartButtonPtr->setText(choicePart["full_name"].asString());
- addDevice["part_id"] = choicePart["part_id"];
- roomFrameTree = partFrameTree[choicePartInt]["frame_room_vos"];
- if (roomFrameTree.size() == 0) {
- choiceRoom.clear();
- mChoiceRoomButtonPtr->setText("");
- return;
- }
- choiceRoom = roomFrameTree[choiceRoomInt]["frame_room"];
- mChoiceRoomButtonPtr->setText(choiceRoom["full_name"].asString());
- if (choiceDeviceInt == 0) {
- addDevice["frame_id"] = choiceRoom["id"];
- LOGD("门口机注册空间id ===> %d", choiceRoom["id"].asInt());
- }
- else {
- bedFrameTree = roomFrameTree[choiceRoomInt]["frame_bed_list"];
- if (bedFrameTree.size() == 0) {
- choiceBed.clear();
- mChoiceBedButtonPtr->setText("");
- return;
- }
- choiceBed = bedFrameTree[choiceBedInt]["frame_bed"];
- addDevice["frame_id"] = choiceBed["id"];
- LOGD("手柄注册空间id ===> %d", choiceBed["id"].asInt());
- mChoiceBedButtonPtr->setText(choiceBed["full_name"].asString());
- }
- }
- static void getHospitalFrameTree(string hospitalId) {
- std::string url = getHttpGateway() + "/arrange/frame_hospital/" + hospitalId;
- LOGD("请求医院空间节点树状图. url = %s", url.c_str());
- RestClient::Response r = RestClient::get(url);
- if (r.code != 200) {
- LOGD("请求医院空间节点树状图-> 错误代码: %d", r.code);
- return;
- }
- LOGD("获得医院空间节点树状图. result = %s", r.body.c_str());
- //解析json
- Json::Reader reader;
- Json::Value root;
- if(reader.parse(r.body, root, false)) {
- hospitalFrameTree = root;
- initFrame();
- }
- }
- static void initHospital() {
- choicePartInt = 0;
- choiceRoomInt = 0;
- choiceBedInt = 0;
- if (choiceHospitalInt != 0 || hospitalFrameTree.size() == 0) {
- choiceHospitalInt = 0;
- mHospitalListViewPtr->refreshListView();
- getHospitalFrameTree(hospitalList[choiceHospitalInt]["shop_id"].asString());
- }
- else {
- initFrame();
- }
- }
- Json::Value getFrameTree(std::string frame) {
- if (frame == "getPartFrame") {
- return partFrameTree;
- }
- else if (frame == "getRoomFrame") {
- return roomFrameTree;
- }
- else if (frame == "getBedFrame") {
- return bedFrameTree;
- }
- Json::Value nullValue;
- return nullValue;
- }
- void setPartFrameTree(int index) {
- choicePartInt = index;
- choicePart = partFrameTree[choicePartInt]["frame_part"];
- mChoicePartButtonPtr->setText(choicePart["full_name"].asString());
- addDevice["part_id"] = choicePart["part_id"];
- roomFrameTree = partFrameTree[choicePartInt]["frame_room_vos"];
- setRoomFrameTree(0);
- }
- void setRoomFrameTree(int index) {
- choiceRoomInt = index;
- if (roomFrameTree.size() == 0) {
- choiceRoom.clear();
- mChoiceRoomButtonPtr->setText("");
- return;
- }
- choiceRoom = roomFrameTree[choiceRoomInt]["frame_room"];
- mChoiceRoomButtonPtr->setText(choiceRoom["full_name"].asString());
- if (choiceDeviceInt == 0) {
- addDevice["frame_id"] = choiceRoom["id"];
- LOGD("门口机注册空间id ===> %d", choiceRoom["id"].asInt());
- }
- else {
- bedFrameTree = roomFrameTree[choiceRoomInt]["frame_bed_list"];
- setBedFrameTree(0);
- }
- }
- void setBedFrameTree(int index) {
- choiceBedInt = index;
- if (bedFrameTree.size() == 0) {
- choiceBed.clear();
- mChoiceBedButtonPtr->setText("");
- return;
- }
- choiceBed = bedFrameTree[choiceBedInt]["frame_bed"];
- addDevice["frame_id"] = choiceBed["id"];
- LOGD("手柄注册空间id ===> %d", choiceBed["id"].asInt());
- mChoiceBedButtonPtr->setText(choiceBed["full_name"].asString());
- }
- void _addDevice() {
- string url = getHttpGateway() + "/arrange/linux_add_device";
- string content_type = std::string("application/json");
- Json::FastWriter writer;
- string data = writer.write(addDevice);
- LOGD("data =============> %s", data.c_str());
- LOGD("注册医院设备. url = %s", url.c_str());
- RestClient::Response r = RestClient::post(url, content_type, data);
- if (r.code != 200) {
- LOGD("注册医院设备-> 错误代码: %d", r.code);
- string errorMsg = LANGUAGEMANAGER->getValue("AddDeviceErrorMsg") + to_string(r.code);
- LOGD("r.body ===> %s", r.body.c_str());
- string error = "DEVICE_MAC_REPEAT";
- size_t pos = r.body.find(error);
- if (pos != std::string::npos) {
- errorMsg = LANGUAGEMANAGER->getValue("DEVICE_MAC_REPEAT");
- }
- error = "DEVICE_FRAME_FAILED";
- pos = r.body.find(error);
- if (pos != std::string::npos) {
- errorMsg = LANGUAGEMANAGER->getValue("DEVICE_FRAME_FAILED");
- }
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "warn");
- intent->putExtra(warnText, errorMsg);
- EASYUICONTEXT->openActivity("functionActivity", intent);
- return;
- }
- LOGD("注册医院设备. result = %s", r.body.c_str());
- //解析json
- Json::Reader reader;
- Json::Value root;
- if(reader.parse(r.body, root, false)) {
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "success");
- intent->putExtra(functionText, LANGUAGEMANAGER->getValue("AddDeviceSuccess"));
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- }
- /**
- * 注册定时器
- * 填充数组用于注册定时器
- * 注意:id不能重复
- */
- static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
- //{0, 6000}, //定时器id=0, 时间间隔6秒
- //{1, 1000},
- };
- /**
- * 当界面构造时触发
- */
- static void onUI_init(){
- //Tips :添加 UI初始化的显示代码到这里,如:mText1Ptr->setText("123");
- getHospital();
- mDeviceRadioGroupPtr->setCheckedID(ID_DEVICEADD_DeviceRadioButton1);
- choiceDeviceInt = 0;
- choiceHospitalInt = 0;
- choiceHospitalInt = 0;
- choicePartInt = 0;
- choiceRoomInt = 0;
- choiceBedInt = 0;
- }
- /**
- * 当切换到该界面时触发
- */
- static void onUI_intent(const Intent *intentPtr) {
- if (intentPtr != NULL) {
- //TODO
- }
- }
- /*
- * 当界面显示时触发
- */
- static void onUI_show() {
- EASYUICONTEXT->hideStatusBar();
- EASYUICONTEXT->hideNaviBar();
- }
- /*
- * 当界面隐藏时触发
- */
- static void onUI_hide() {
- }
- /*
- * 当界面完全退出时触发
- */
- static void onUI_quit() {
- }
- /**
- * 串口数据回调接口
- */
- static void onProtocolDataUpdate(const SProtocolData &data) {
- }
- /**
- * 定时器触发函数
- * 不建议在此函数中写耗时操作,否则将影响UI刷新
- * 参数: id
- * 当前所触发定时器的id,与注册时的id相同
- * 返回值: true
- * 继续运行当前定时器
- * false
- * 停止运行当前定时器
- */
- static bool onUI_Timer(int id){
- switch (id) {
- default:
- break;
- }
- return true;
- }
- /**
- * 有新的触摸事件时触发
- * 参数:ev
- * 新的触摸事件
- * 返回值:true
- * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
- * false
- * 触摸事件将继续传递到控件上
- */
- static bool ondeviceAddActivityTouchEvent(const MotionEvent &ev) {
- switch (ev.mActionStatus) {
- case MotionEvent::E_ACTION_DOWN://触摸按下
- //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
- break;
- case MotionEvent::E_ACTION_MOVE://触摸滑动
- break;
- case MotionEvent::E_ACTION_UP: //触摸抬起
- break;
- default:
- break;
- }
- return false;
- }
- static bool onButtonClick_sys_back(ZKButton *pButton) {
- LOGD(" ButtonClick sys_back !!!\n");
- return false;
- }
- static void onCheckedChanged_DeviceRadioGroup(ZKRadioGroup* pRadioGroup, int checkedID) {
- LOGD(" RadioGroup DeviceRadioGroup checked %d", checkedID);
- switch(checkedID) {
- case ID_DEVICEADD_DeviceRadioButton1:
- choiceDeviceInt = 0;
- deviceMacMsg = LANGUAGEMANAGER->getValue("DeviceAddMsg") + " \n" + LANGUAGEMANAGER->getValue("DeviceAddMsg4") + mac;
- mDeviceMacTextViewPtr->setText(deviceMacMsg);
- mBedTextViewPtr->setVisible(false);
- mChoiceBedButtonPtr->setVisible(false);
- addDevice["device_type"] = 3;
- addDevice["name"] = LANGUAGEMANAGER->getValue("RoomDevice");
- addDevice["eth_mac"] = mac;
- addDevice["code"] = "SW10600101C-CM";
- addDevice["model"] = "linux_door";
- addDevice["soft_ver"] = "SV1.0";
- addDevice["hard_ver"] = "HV1.0";
- addDevice["status"] = 1;
- initHospital();
- break;
- case ID_DEVICEADD_DeviceRadioButton2:
- choiceDeviceInt = 1;
- deviceMacMsg = LANGUAGEMANAGER->getValue("DeviceAddMsg2") + " \n" + LANGUAGEMANAGER->getValue("DeviceAddMsg4") + mac + ":h1";
- mDeviceMacTextViewPtr->setText(deviceMacMsg);
- mBedTextViewPtr->setVisible(true);
- mChoiceBedButtonPtr->setVisible(true);
- addDevice["device_type"] = 4;
- addDevice["name"] = LANGUAGEMANAGER->getValue("BedDevice");
- addDevice["eth_mac"] = mac + ":h1";
- addDevice["code"] = "SW10600101C-CM";
- addDevice["model"] = "linux_handle";
- addDevice["soft_ver"] = "SV1.0";
- addDevice["hard_ver"] = "HV1.0";
- addDevice["status"] = 1;
- initHospital();
- break;
- case ID_DEVICEADD_DeviceRadioButton3:
- choiceDeviceInt = 2;
- deviceMacMsg = LANGUAGEMANAGER->getValue("DeviceAddMsg3") + " \n" + LANGUAGEMANAGER->getValue("DeviceAddMsg4") + mac + ":h2";
- mDeviceMacTextViewPtr->setText(deviceMacMsg);
- mBedTextViewPtr->setVisible(true);
- mChoiceBedButtonPtr->setVisible(true);
- addDevice["device_type"] = 4;
- addDevice["name"] = LANGUAGEMANAGER->getValue("BedDevice");
- addDevice["eth_mac"] = mac + ":h2";
- addDevice["code"] = "SW10600101C-CM";
- addDevice["model"] = "linux_handle";
- addDevice["soft_ver"] = "SV1.0";
- addDevice["hard_ver"] = "HV1.0";
- addDevice["status"] = 1;
- initHospital();
- break;
- }
- }
- static int getListItemCount_HospitalListView(const ZKListView *pListView) {
- //LOGD("getListItemCount_HospitalListView !\n");
- return hospitalList.size();
- }
- static void obtainListItemData_HospitalListView(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index) {
- //LOGD(" obtainListItemData_ HospitalListView !!!\n");
- if (hospitalList.size() == 0) {
- return;
- }
- pListItem->setText(hospitalList[index]["full_name"].asString());
- if (choiceHospitalInt == index) {
- pListItem->setSelected(true);
- }
- else {
- pListItem->setSelected(false);
- }
- }
- static void onListItemClick_HospitalListView(ZKListView *pListView, int index, int id) {
- //LOGD(" onListItemClick_ HospitalListView !!!\n");
- if (choiceHospitalInt != index) {
- choiceHospitalInt = index;
- getHospitalFrameTree(hospitalList[choiceHospitalInt]["shop_id"].asString());
- }
- }
- static bool onButtonClick_ChoicePartButton(ZKButton *pButton) {
- LOGD(" ButtonClick ChoicePartButton !!!\n");
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "getPartFrame");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- return false;
- }
- static bool onButtonClick_ChoiceRoomButton(ZKButton *pButton) {
- LOGD(" ButtonClick ChoiceRoomButton !!!\n");
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "getRoomFrame");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- return false;
- }
- static bool onButtonClick_ChoiceBedButton(ZKButton *pButton) {
- LOGD(" ButtonClick ChoiceBedButton !!!\n");
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "getBedFrame");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- return false;
- }
- static bool onButtonClick_ConfirmButton(ZKButton *pButton) {
- LOGD(" ButtonClick ConfirmButton !!!\n");
- if (addDevice.isMember("frame_id")) {
- _addDevice();
- }
- else {
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "warn");
- intent->putExtra(warnText, LANGUAGEMANAGER->getValue("AddDeviceFrameFailed"));
- EASYUICONTEXT->openActivity("functionActivity", intent);
- }
- return false;
- }
- static bool onButtonClick_RebootButton(ZKButton *pButton) {
- LOGD(" ButtonClick RebootButton !!!\n");
- Intent* intent = new Intent();
- intent->putExtra(functionWindows, "reboot");
- EASYUICONTEXT->openActivity("functionActivity", intent);
- return false;
- }
|