ControlsPage.qml 13 KB

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