testLogic.cc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #pragma once
  2. #include "uart/ProtocolSender.h"
  3. #include "utils/Log.h"
  4. #include "net/net.h"
  5. #include <system/Thread.h>
  6. #include "restclient-cpp/restclient.h"
  7. #include "curl/curl.h"
  8. #include "net/tcp_client.h"
  9. /*
  10. *此文件由GUI工具生成
  11. *文件功能:用于处理用户的逻辑相应代码
  12. *功能说明:
  13. *========================onButtonClick_XXXX
  14. 当页面中的按键按下后系统会调用对应的函数,XXX代表GUI工具里面的[ID值]名称,
  15. 如Button1,当返回值为false的时候系统将不再处理这个按键,返回true的时候系统将会继续处理此按键。比如SYS_BACK.
  16. *========================onSlideWindowItemClick_XXXX(int index)
  17. 当页面中存在滑动窗口并且用户点击了滑动窗口的图标后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  18. 如slideWindow1;index 代表按下图标的偏移值
  19. *========================onSeekBarChange_XXXX(int progress)
  20. 当页面中存在滑动条并且用户改变了进度后系统会调用此函数,XXX代表GUI工具里面的[ID值]名称,
  21. 如SeekBar1;progress 代表当前的进度值
  22. *========================ogetListItemCount_XXXX()
  23. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表的总数目,XXX代表GUI工具里面的[ID值]名称,
  24. 如List1;返回值为当前列表的总条数
  25. *========================oobtainListItemData_XXXX(ZKListView::ZKListItem *pListItem, int index)
  26. 当页面中存在滑动列表的时候,更新的时候系统会调用此接口获取列表当前条目下的内容信息,XXX代表GUI工具里面的[ID值]名称,
  27. 如List1;pListItem 是贴图中的单条目对象,index是列表总目的偏移量。具体见函数说明
  28. *========================常用接口===============
  29. *LOGD(...) 打印调试信息的接口
  30. *mTextXXXPtr->setText("****") 在控件TextXXX上显示文字****
  31. *mButton1Ptr->setSelected(true); 将控件mButton1设置为选中模式,图片会切换成选中图片,按钮文字会切换为选中后的颜色
  32. *mSeekBarPtr->setProgress(12) 在控件mSeekBar上将进度调整到12
  33. *mListView1Ptr->refreshListView() 让mListView1 重新刷新,当列表数据变化后调用
  34. *mDashbroadView1Ptr->setTargetAngle(120) 在控件mDashbroadView1上指针显示角度调整到120度
  35. *
  36. * 在Eclipse编辑器中 使用 “alt + /” 快捷键可以打开智能提示
  37. */
  38. #if 0
  39. static net::Conn* conn;
  40. class MyThread: public Thread {
  41. public:
  42. /**
  43. * 线程创建成功后会调用该函数,可以在该函数中做一些初始化操作
  44. * return true 继续线程
  45. * false 退出线程
  46. */
  47. virtual bool readyToRun() {
  48. LOGD("Thread 已经创建完成");
  49. return true;
  50. }
  51. /**
  52. * 线程循环函数
  53. *
  54. * return true 继续线程循环
  55. * false 推出线程
  56. */
  57. virtual bool threadLoop() {
  58. LOGD("线程循环函数");
  59. //检查是否有退出线程的请求,如果有,则返回false,立即退出线程
  60. if (exitPending()) {
  61. return false;
  62. }
  63. conn = net::Dial("tcp", "192.168.1.149:5080");
  64. if (conn) {
  65. byte buf[1024] = {0};
  66. const char* req = "{type:'DEVICE',action:'CONNECT',data:'12345678abc'}";
  67. //发送
  68. conn->Write((byte*)req, strlen(req));
  69. while (true && !exitPending()) {
  70. //读取,超时1000毫秒
  71. int n = conn->Read(buf, sizeof(buf) - 1, 1000);
  72. if (n > 0) {
  73. buf[n] = 0;
  74. LOGD("读取 %d字节: %s", n, buf);
  75. } else if (n == 0) {
  76. LOGD("连接正常断开");
  77. break;
  78. } else if (n == net::E_TIMEOUT) {
  79. LOGD("读取超时");
  80. } else {
  81. LOGD("出错");
  82. break;
  83. }
  84. }
  85. //关闭连接
  86. conn->Close();
  87. //释放内存
  88. delete conn;
  89. conn = NULL;
  90. }
  91. //返回真,继续下次线程循环
  92. return true;
  93. }
  94. };
  95. static MyThread my_thread;
  96. #endif
  97. /**
  98. * 注册定时器
  99. * 填充数组用于注册定时器
  100. * 注意:id不能重复
  101. */
  102. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  103. {0, 6000}, //定时器id=0, 时间间隔6秒
  104. //{1, 1000},
  105. };
  106. /**
  107. * 当界面构造时触发
  108. */
  109. static void onUI_init(){
  110. //Tips :添加 UI初始化的显示代码到这里,如:mText1Ptr->setText("123");
  111. }
  112. /**
  113. * 当切换到该界面时触发
  114. */
  115. static void onUI_intent(const Intent *intentPtr) {
  116. if (intentPtr != NULL) {
  117. //TODO
  118. }
  119. }
  120. /*
  121. * 当界面显示时触发
  122. */
  123. static void onUI_show() {
  124. }
  125. /*
  126. * 当界面隐藏时触发
  127. */
  128. static void onUI_hide() {
  129. }
  130. /*
  131. * 当界面完全退出时触发
  132. */
  133. static void onUI_quit() {
  134. pthread_exit(NULL);
  135. }
  136. /**
  137. * 串口数据回调接口
  138. */
  139. static void onProtocolDataUpdate(const SProtocolData &data) {
  140. }
  141. /**
  142. * 定时器触发函数
  143. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  144. * 参数: id
  145. * 当前所触发定时器的id,与注册时的id相同
  146. * 返回值: true
  147. * 继续运行当前定时器
  148. * false
  149. * 停止运行当前定时器
  150. */
  151. static bool onUI_Timer(int id){
  152. switch (id) {
  153. case 0:
  154. // if (conn) {
  155. // const char* req = "000";
  156. // conn->Write((byte*)req, strlen(req));
  157. // }
  158. break;
  159. default:
  160. break;
  161. }
  162. return true;
  163. }
  164. /**
  165. * 有新的触摸事件时触发
  166. * 参数:ev
  167. * 新的触摸事件
  168. * 返回值:true * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上 * false
  169. * 触摸事件将继续传递到控件上
  170. */
  171. static bool ontestActivityTouchEvent(const MotionEvent &ev) {
  172. switch (ev.mActionStatus) {
  173. case MotionEvent::E_ACTION_DOWN://触摸按下
  174. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  175. break;
  176. case MotionEvent::E_ACTION_MOVE://触摸滑动
  177. break;
  178. case MotionEvent::E_ACTION_UP: //触摸抬起
  179. break;
  180. default:
  181. break;
  182. }
  183. return false;
  184. }
  185. static bool onButtonClick_Button1(ZKButton *pButton) {
  186. LOGD(" ButtonClick Button1 !!!\n");
  187. //调用线程类的run函数启动线程, 参数为线程名,可以任意指定。
  188. //my_thread.run("this is thread name");
  189. return false;
  190. }
  191. static bool onButtonClick_Button2(ZKButton *pButton) {
  192. LOGD(" ButtonClick Button2 !!!\n");
  193. //请求退出线程,并且等待,直到线程完全退出后,该函数才返回
  194. //my_thread.requestExitAndWait();
  195. return false;
  196. }
  197. static bool onButtonClick_Button3(ZKButton *pButton) {
  198. LOGD(" ButtonClick Button3 !!!\n");
  199. const char* req = "{type:'DEVICE',action:'CONNECT',data:'12345678abc'}";
  200. TcpClient::instance()->sendMsg(req);
  201. return false;
  202. }
  203. static bool onButtonClick_Button4(ZKButton *pButton) {
  204. LOGD(" ButtonClick Button4 !!!\n");
  205. //发起HTTP GET请求
  206. RestClient::Response r = RestClient::get("http://192.168.1.54:8006/deviceBed/getDeviceInfo/200");
  207. string str = r.body;
  208. LOGD("%s", str.c_str());
  209. /*
  210. * {"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}
  211. */
  212. //解析json
  213. Json::Reader reader;
  214. Json::Value root;
  215. if (reader.parse(str, root, false)){
  216. LOGD("解析JSON成功");
  217. if (root.isMember("union_id")){
  218. LOGD("union_id = %s", root["union_id"].asString().c_str());
  219. }
  220. }
  221. return false;
  222. }
  223. static bool onButtonClick_Button6(ZKButton *pButton) {
  224. LOGD(" ButtonClick Button6 !!!\n");
  225. EASYUICONTEXT->openActivity("ui1Activity");
  226. return false;
  227. }
  228. static bool onButtonClick_Button7(ZKButton *pButton) {
  229. LOGD(" ButtonClick Button7 !!!\n");
  230. EASYUICONTEXT->openActivity("ui3Activity");
  231. return false;
  232. }
  233. static bool onButtonClick_Button8(ZKButton *pButton) {
  234. LOGD(" ButtonClick Button8 !!!\n");
  235. EASYUICONTEXT->openActivity("callActivity");
  236. return false;
  237. }