#pragma once #include "uart/ProtocolSender.h" #include "utils/Log.h" #include "net/net.h" #include #include "restclient-cpp/restclient.h" #include "curl/curl.h" #include "net/tcp_client.h" /* *此文件由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 + /” 快捷键可以打开智能提示 */ #if 0 static net::Conn* conn; class MyThread: public Thread { public: /** * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作 * return true 继续线程 * false 退出线程 */ virtual bool readyToRun() { LOGD("Thread 已经创建完成"); return true; } /** * 线程循环函数 * * return true 继续线程循环 * false 推出线程 */ virtual bool threadLoop() { LOGD("线程循环函数"); //检查是否有退出线程的请求,如果有,则返回false,立即退出线程 if (exitPending()) { return false; } conn = net::Dial("tcp", "192.168.1.149:5080"); if (conn) { byte buf[1024] = {0}; const char* req = "{type:'DEVICE',action:'CONNECT',data:'12345678abc'}"; //发送 conn->Write((byte*)req, strlen(req)); while (true && !exitPending()) { //读取,超时1000毫秒 int n = conn->Read(buf, sizeof(buf) - 1, 1000); if (n > 0) { buf[n] = 0; LOGD("读取 %d字节: %s", n, buf); } else if (n == 0) { LOGD("连接正常断开"); break; } else if (n == net::E_TIMEOUT) { LOGD("读取超时"); } else { LOGD("出错"); break; } } //关闭连接 conn->Close(); //释放内存 delete conn; conn = NULL; } //返回真,继续下次线程循环 return true; } }; static MyThread my_thread; #endif /** * 注册定时器 * 填充数组用于注册定时器 * 注意: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"); } /** * 当切换到该界面时触发 */ static void onUI_intent(const Intent *intentPtr) { if (intentPtr != NULL) { //TODO } } /* * 当界面显示时触发 */ static void onUI_show() { } /* * 当界面隐藏时触发 */ static void onUI_hide() { } /* * 当界面完全退出时触发 */ static void onUI_quit() { pthread_exit(NULL); } /** * 串口数据回调接口 */ static void onProtocolDataUpdate(const SProtocolData &data) { } /** * 定时器触发函数 * 不建议在此函数中写耗时操作,否则将影响UI刷新 * 参数: id * 当前所触发定时器的id,与注册时的id相同 * 返回值: true * 继续运行当前定时器 * false * 停止运行当前定时器 */ static bool onUI_Timer(int id){ switch (id) { case 0: // if (conn) { // const char* req = "000"; // conn->Write((byte*)req, strlen(req)); // } break; default: break; } return true; } /** * 有新的触摸事件时触发 * 参数:ev * 新的触摸事件 * 返回值:true * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上 * false * 触摸事件将继续传递到控件上 */ static bool ontestActivityTouchEvent(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_Button1(ZKButton *pButton) { LOGD(" ButtonClick Button1 !!!\n"); //调用线程类的run函数启动线程, 参数为线程名,可以任意指定。 //my_thread.run("this is thread name"); return false; } static bool onButtonClick_Button2(ZKButton *pButton) { LOGD(" ButtonClick Button2 !!!\n"); //请求退出线程,并且等待,直到线程完全退出后,该函数才返回 //my_thread.requestExitAndWait(); return false; } static bool onButtonClick_Button3(ZKButton *pButton) { LOGD(" ButtonClick Button3 !!!\n"); const char* req = "{type:'DEVICE',action:'CONNECT',data:'12345678abc'}"; TcpClient::instance()->sendMsg(req); return false; } static bool onButtonClick_Button4(ZKButton *pButton) { LOGD(" ButtonClick Button4 !!!\n"); //发起HTTP GET请求 RestClient::Response r = RestClient::get("http://192.168.1.54:8006/deviceBed/getDeviceInfo/200"); string str = r.body; LOGD("%s", str.c_str()); /* * {"id":200,"union_id":"615fb00552faff0008ab7c06","create_time":1633660933,"update_time":1646034250,"part_id":2,"sync_time":null,"frame_id":70,"device_type":4,"sign_type":null,"code":"C94775","model":"M41176","soft_ver":"SV1.0","hard_ver":"HV1.0","name":"平板","phone_number":null,"eth_mac":"b56f457f760ffce7","eth_ip":"113.110.228.57","eth_ip_port":"40798","wifi_mac":"null","wifi_ip":"null","wifi_hostname":"null","wifi_password":"null","status":1,"sip_ip":"172.28.100.100","sip_id":"4000002000","sip_password":"4000002000","sip_status":false,"member_id":437,"bool_backup":null,"backup_id":null,"priority":1,"config":"null","role_id":null,"trans_rs485_id":null,"trans_audio_id":null,"group_id":null,"led_resolution_ratio":null,"led_voice":null,"led_font_size":null} */ //解析json Json::Reader reader; Json::Value root; if (reader.parse(str, root, false)){ LOGD("解析JSON成功"); if (root.isMember("union_id")){ LOGD("union_id = %s", root["union_id"].asString().c_str()); } } return false; } static bool onButtonClick_Button6(ZKButton *pButton) { LOGD(" ButtonClick Button6 !!!\n"); EASYUICONTEXT->openActivity("ui1Activity"); return false; } static bool onButtonClick_Button7(ZKButton *pButton) { LOGD(" ButtonClick Button7 !!!\n"); EASYUICONTEXT->openActivity("ui3Activity"); return false; } static bool onButtonClick_Button8(ZKButton *pButton) { LOGD(" ButtonClick Button8 !!!\n"); EASYUICONTEXT->openActivity("callActivity"); return false; }