ControlsPage.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. import QtQuick
  2. import QtQuick.Controls
  3. import Qt.labs.settings 1.0 as QtLabs
  4. import QtQuick.Controls.Material 2.0
  5. import QtLocation 5.5
  6. import QtPositioning 5.5
  7. import QtMultimedia
  8. import Qt5Compat.GraphicalEffects
  9. import Felgo 4.0
  10. import "../controls"
  11. import "../common"
  12. //import MqttClient 1.0
  13. AppPage {
  14. id: controlsPage
  15. property string originalString: ""
  16. property string collectString: ""
  17. property string gps_state: "正在定位..."
  18. property string board_version: ""
  19. property bool connect_board: false
  20. property var tt
  21. property bool isonline: false
  22. property var net_list:[]
  23. property var picinfo_list:[]
  24. Material.accent: Theme.tintColor
  25. rightBarItem: IconButtonBarItem {
  26. iconType: IconType.paintbrush
  27. onClicked: {
  28. themeModal.open()
  29. }
  30. }
  31. Component.onCompleted: {
  32. originalString = myClass.deviceid
  33. }
  34. // 接收并显示日志消息
  35. Connections {
  36. target: mqtt
  37. onConnected: {
  38. console.log("mqtt connect")
  39. mqtt_sta.detailText="MQTT已连接"
  40. }
  41. onDisconnected: {
  42. console.log("mqtt disconnect")
  43. mqtt_sta.detailText="MQTT已断开"
  44. }
  45. }
  46. Connections{
  47. target: myClass
  48. }
  49. //串口
  50. Connections{
  51. target: serial
  52. onDataReceived:{
  53. var jsonData = JSON.parse(data)
  54. console.debug("接收到主板数据:",data.toString())
  55. if(jsonData.ext.work_sta==="0"){
  56. if(jsonData.ext.ds==="0"){
  57. work_header.text =qsTr("<b>设备开关:</b> 关机") + "-" + qsTr("<b>工作状态:</b> 待机")
  58. }else{
  59. work_header.text =qsTr("<b>设备开关:</b> 开机") + "-" + qsTr("<b>工作状态:</b> 待机")
  60. }
  61. }else if(jsonData.ext.work_sta==="1"){
  62. if(jsonData.ext.ds==="0"){
  63. work_header.text = qsTr("<b>设备开关:</b> 关机") + "-" + qsTr("<b>工作状态:</b> 采集")
  64. }else{
  65. work_header.text = qsTr("<b>设备开关:</b> 开机") + "-" + qsTr("<b>工作状态:</b> 采集")
  66. }
  67. }
  68. if(jsonData.ext.gps==="1"){
  69. gps_state = "成功"
  70. }
  71. if(jsonData.ext.coll_time){
  72. collectString = " [" +jsonData.ext.coll_time[0] + "," + jsonData.ext.coll_time[1] + "," + jsonData.ext.coll_time[2] + "]";
  73. }
  74. if(jsonData.ext.dat_f){
  75. serial.update_dat_f_main(jsonData.ext.dat_f);
  76. }
  77. board_version = jsonData.ext.dver
  78. work_header.detailText = "电压:" + jsonData.ext.vbat + " 电流:" + jsonData.ext.current + " 温度:" + jsonData.ext.at + " 湿度:" + jsonData.ext.ah ;
  79. }
  80. onDisconnect_485:{
  81. work_header.text =qsTr("485未连接,读取数据失败");
  82. }
  83. }
  84. MediaPlayer{
  85. id: audio
  86. audioOutput: AudioOutput{}
  87. source: Qt.resolvedUrl("../../assets/mp3/button.mp3")
  88. }
  89. AppFlickable {
  90. id: scroll
  91. anchors.fill: parent
  92. contentHeight: content.height
  93. // remove focus from controls if clicked outside
  94. MouseArea {
  95. anchors.fill: parent
  96. onClicked: {
  97. scroll.forceActiveFocus()
  98. }
  99. }
  100. Column {
  101. id: content
  102. width: parent.width
  103. Timer {
  104. interval: 500
  105. running: true
  106. repeat: true
  107. onTriggered: {
  108. menutab.title = Date().toString() + " 设备ID:" + originalString.toLowerCase() + " GPS状态:" + gps_state
  109. if(mqtt.checkLink()){
  110. mqtt_sta.detailText="MQTT已连接"
  111. }else{
  112. mqtt_sta.detailText="MQTT已断开"
  113. }
  114. net_list = mqtt.netMessage()
  115. if(net_list){
  116. if(net_list[0]==="1"){isonline = true}else{isonline = false}
  117. mqtt_sta.text = qsTr("<b>联网状态:</b> %1 (网卡名称:%2) (描述:%3)").arg(isonline? "已联网" : "未联网").arg(net_list[1]).arg(net_list[2])
  118. net_mes.text = qsTr("<b>[MAC] </b> %1").arg(net_list[3]) + qsTr("<b>[IPV4] </b> %1").arg(net_list[4])
  119. mqtt_sta.detailText += "<服务器地址:>" + net_list[5]
  120. mqtt_sta.detailText += "<数据上传间隔:>" + net_list[6] + "(" +net_list[7] + ")" + "分钟";
  121. }
  122. }
  123. }
  124. Section {
  125. id: menutab
  126. title: Date().toString()
  127. //SectionItem {
  128. //title: "运行状态"
  129. //anchors.horizontalCenter: parent.horizontalCenter
  130. AppCard {
  131. id: card
  132. width: parent.width
  133. // property real resetX: 0
  134. // x: resetX
  135. margin: dp(5)
  136. paper.radius: dp(5)
  137. header: SimpleRow {
  138. id: work_header
  139. //imageSource: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
  140. text: qsTr("<b>设备开关:</b> 开机") + qsTr("<b>工作状态:</b> 待机")
  141. detailText: "电压:" + jsonData.ext.vbat + " 电流:" + jsonData.ext.current + " 温度:" + jsonData.ext.at + " 湿度:" + jsonData.ext.ah ;
  142. badgeColor: "green"
  143. image.radius: image.width / 2
  144. image.fillMode: Image.PreserveAspectCrop
  145. style: StyleSimpleRow {
  146. showDisclosure: false
  147. backgroundColor: "transparent"
  148. }
  149. }
  150. media: AppImage {
  151. width: card.width
  152. fillMode: Image.PreserveAspectFit
  153. source: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
  154. }
  155. content: AppText{
  156. id: work_apptext
  157. width: card.width
  158. padding: dp(15)
  159. text: "设定采集时间:" + collectString;
  160. }
  161. }
  162. AppCard {
  163. id: card_net
  164. width: parent.width
  165. property real resetX: 0
  166. x: resetX
  167. margin: dp(5)
  168. paper.radius: dp(5)
  169. header: SimpleRow {
  170. id: mqtt_sta
  171. //imageSource: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
  172. text: qsTr("<b>联网状态:</b> %1 (%2)").arg(app.isOnline ? "已联网" : "未联网").arg(nativeUtils.connectionType)
  173. detailText: "AppCard detailed text"
  174. image.radius: image.width / 2
  175. image.fillMode: Image.PreserveAspectCrop
  176. style: StyleSimpleRow {
  177. showDisclosure: false
  178. backgroundColor: "transparent"
  179. }
  180. }
  181. media: AppImage {
  182. width: parent.width
  183. fillMode: Image.PreserveAspectFit
  184. source: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
  185. }
  186. content: AppText{
  187. id: net_mes
  188. width: parent.width
  189. padding: dp(15)
  190. text: "Mac" + "ipv4:";
  191. }
  192. }
  193. // AppCard {
  194. // id: card_cfg
  195. // width: parent.width
  196. // height: width*1.5
  197. // property real resetX: 0
  198. // x: resetX
  199. // margin: dp(5)
  200. // paper.radius: dp(5)
  201. // header: SimpleRow {
  202. // imageSource: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
  203. // text: "参数"
  204. // detailText: "AppCard detailed text"
  205. // image.radius: image.width / 2
  206. // image.fillMode: Image.PreserveAspectCrop
  207. // style: StyleSimpleRow {
  208. // showDisclosure: false
  209. // backgroundColor: "transparent"
  210. // }
  211. // }
  212. // media: AppImage {
  213. // width: card_cfg.width
  214. // fillMode: Image.PreserveAspectFit
  215. // source: Qt.resolvedUrl("../../assets/architecture-1477041_960_720.jpg")
  216. // }
  217. // content: AppText{
  218. // width: card_cfg.width
  219. // padding: dp(15)
  220. // text: "此界面显示参数等信息,运行时间等"
  221. // }
  222. // cardSwipeArea.onSwipeOutCompleted: {
  223. // card_cfg.x = card_cfg.resetX
  224. // card_cfg.rotation = 0
  225. // }
  226. // }
  227. //} // AppCard section
  228. } // convenience controls section
  229. Timer {
  230. interval: 1000
  231. running: true
  232. repeat: true
  233. onTriggered: {
  234. picinfo_list = serial.pathinfo()
  235. pic_path.text = "图片存储目录:" + picinfo_list[0]
  236. pic_count.text = "文件数量:" + picinfo_list[1]
  237. pic_total.text = "占用大小:" + picinfo_list[2] + "(Mb)"
  238. }
  239. }
  240. Section {
  241. title: "存储信息"
  242. bottomPadding: dp(Theme.navigationBar.defaultBarItemPadding)
  243. Grid {
  244. anchors.horizontalCenter: parent.horizontalCenter
  245. columns: 2
  246. rows: 4
  247. //horizontalItemAlignment: Grid.AlignHCenter
  248. Column{
  249. AppButton {
  250. text: "查询"
  251. flat: false
  252. onClicked: {
  253. serial.readPathinfo()
  254. }
  255. }
  256. AppButton {
  257. text: "清理"
  258. flat: false
  259. onClicked: {
  260. serial.removepic()
  261. }
  262. }
  263. }
  264. Column{
  265. AppText {
  266. id: pic_path
  267. text: "图片存储目录:" + picinfo_list[0]
  268. }
  269. AppText{
  270. id: pic_count
  271. text: "文件数量:" + picinfo_list[1]
  272. }
  273. AppText{
  274. id: pic_total
  275. text: "占用大小:" + picinfo_list[2]
  276. }
  277. }
  278. }
  279. } // native utils section }
  280. Section {
  281. title: "Device Info"
  282. bottomPadding: dp(15)
  283. Row {
  284. width: parent.width - dp(30)
  285. anchors.horizontalCenter: parent.horizontalCenter
  286. spacing: dp(5)
  287. Column {
  288. id: firstInfoColumn
  289. spacing: dp(5)
  290. width: (parent.width - parent.spacing) * 0.5
  291. AppText {
  292. text: "<b>OS Type:</b> " + system.osType
  293. font.pixelSize: sp(11)
  294. visible: system.osType !== "undefined"
  295. }
  296. AppText {
  297. text: "<b>OS Version:</b> " + system.osVersion
  298. font.pixelSize: sp(11)
  299. visible: system.osVersion !== "undefined"
  300. }
  301. AppText {
  302. text: "<b>Device Model:</b> " + nativeUtils.deviceModel()
  303. font.pixelSize: sp(11)
  304. visible: nativeUtils.deviceModel() !== "undefined"
  305. }
  306. AppText {
  307. text: qsTr("<b>Device Online:</b> %1 (%2)").arg(app.isOnline ? "Yes" : "No").arg(nativeUtils.connectionType)
  308. font.pixelSize: sp(11)
  309. }
  310. AppText {
  311. text: "<b>MAC Address:</b> " + system.macAddress
  312. font.pixelSize: sp(11)
  313. width: parent.width
  314. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
  315. visible: system.macAddress !== "undefined"
  316. }
  317. AppText {
  318. text: "<b>Unique Device Id:</b> " + system.UDID
  319. font.pixelSize: sp(11)
  320. width: parent.width
  321. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
  322. visible: system.UDID !== "undefined"
  323. }
  324. }
  325. Column {
  326. id: secondInfoColumn
  327. spacing: dp(5)
  328. width: firstInfoColumn.width
  329. AppText {
  330. text: "<b>Orientation:</b> " + (Theme.isPortrait ? "portrait" : "landscape")
  331. font.pixelSize: sp(11)
  332. }
  333. AppText {
  334. text: "<b>Statusbar Height:</b> " + Theme.statusBarHeight
  335. font.pixelSize: sp(11)
  336. }
  337. AppText {
  338. text: "<b>App Identifier:</b> " + system.appIdentifier
  339. font.pixelSize: sp(11)
  340. width: parent.width
  341. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
  342. visible: system.appIdentifier !== "undefined"
  343. }
  344. AppText {
  345. text: "<b>App Version:</b> " + system.appVersionCode
  346. font.pixelSize: sp(11)
  347. }
  348. AppText {
  349. text: "<b>Qt Version:</b> " + system.qtVersion
  350. font.pixelSize: sp(11)
  351. }
  352. AppText {
  353. text: "<b>Felgo Version:</b> " + system.felgoVersion + " (" + system.felgoVersionRef + ")"
  354. font.pixelSize: sp(11)
  355. }
  356. }
  357. }
  358. } // device info section
  359. } // content column
  360. } // flickable
  361. ThemeModal {
  362. id: themeModal
  363. pushBackContent: navigationStack
  364. } // theme modal
  365. } // page