123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- import { userMobileLogin } from '../../api/wxlogin.js'
- import { getMobileBtsParamList } from '../../api/btsparam.js'
- import sysconfig from '../../sysconfig/sysconfig.js'
- const app = getApp()
- Page({
- data: {
- bestFrame: 0,
- bestMultiFrame: 0,
- bleDataList: [],
- btsParamList: [],
- btsDataList: [],
- btsMinCoordX: 0,
- btsMaxCoordX: 0,
- btsMinCoordY: 0,
- btsMaxCoordY: 0,
- canvasCtx: null,
- canvasWidth: 0,
- canvasHeight: 0,
- canvasPixelRatio: 1,
- coordDataList: [],
- },
-
- onLoad(options) {
-
- app.createWorker(this.workerMessageListenerHome)
-
-
-
- this.userLogin()
-
- this.initCanvas()
-
- app.startImu()
- },
-
- onReady() {
- },
-
- onShow() {
- },
-
- onHide() {
- },
-
- onUnload() {
-
- if (app.data.worker != null) {
- app.data.worker.postMessage({
- message: 'MAIN_WORKER_FREE_MEMORY',
- data: ''
- })
- }
- },
-
- onPullDownRefresh() {
- },
-
- onReachBottom() {
- },
-
- onShareAppMessage() {
- },
-
- workerMessageListenerHome(res) {
- switch (res.message) {
- case 'WORKER_MAIN_START_MONITOR_BLE_BTS':
- app.openBleAdapter()
- break
- case 'WORKER_MAIN_ORGANIZE_INSTALL_BTS_DATA':
- this.organizeBtsDataForWasm()
- break
- case 'WORKER_MAIN_START_REC':
- app.createRecorder()
- break
- case 'WORKER_MAIN_CURRENT_LOCATION_COORD':
- this.saveLocateCoord(res.data)
- break
- case 'WORKER_MAIN_NOTICE_DOWNLOAD_AUDIO_FILE':
- this.downloadAudioFile()
- break
- case 'WORKER_MAIN_NOTICE_READ_AUDIO_FILE':
- this.readAudioFile()
- break
- case 'WORKER_MAIN_SAVE_AUDIO_DATA':
- app.saveAduioDataToBin(res.data)
- break
- default:
- break
- }
- },
-
- userLogin() {
-
- wx.login({
- success: (res) => {
- var paramData = {};
- paramData.code = res.code;
- paramData.domain_name = sysconfig.domanName;
- userMobileLogin(paramData).then((resp) => {
-
- const tokenKey = sysconfig.user.tokenKey
- wx.setStorageSync(tokenKey, resp.data.data.token)
-
- const userInfoKey = sysconfig.user.userInfoKey
- wx.setStorageSync(userInfoKey, resp.data.data)
-
- this.getBtsParamList()
- }).catch((err) => {
- console.log("用户登录失败", err)
- })
- }
- })
- },
-
- getBtsParamList() {
-
- getMobileBtsParamList().then((resBtsPram) => {
- this.data.btsParamList = resBtsPram.data.data
-
- this.data.btsDataList = this.generateBtsDataList(this.data.btsParamList)
-
- this.calMaxMinCoordXY(this.data.btsDataList)
- }).catch((err) => {
- console.log("查询基站参数失败", err)
- })
- },
-
- initCanvas() {
-
- let self = this
- wx.getSystemInfo({
- success: (res) => {
- self.data.canvasPixelRatio = res.pixelRatio
- let myCanvasWidth = res.windowWidth - 5
- self.setData({
- canvasWidth: myCanvasWidth,
- canvasHeight: myCanvasWidth
- })
- }
- })
-
- wx.createSelectorQuery().select('#homeCanvas').fields({ node: true, size: true }).exec((res) => {
- let canvas = res[0].node
- if (canvas) {
- this.data.canvasCtx = canvas.getContext('2d')
- canvas.width = res[0].width * this.data.canvasPixelRatio
- canvas.height = res[0].height * this.data.canvasPixelRatio
- this.data.canvasCtx.scale(this.data.canvasPixelRatio, this.data.canvasPixelRatio)
-
- this.drawLocateTrack(0, 0, 0, this.data.coordDataList)
- }
- })
- },
-
- organizeBtsDataForWasm() {
- let dataList = []
- let oneItem = {}
-
- dataList.push(this.data.btsDataList.length)
- for (let i = 0; i < this.data.btsDataList.length; i++) {
- oneItem = this.data.btsDataList[i]
- dataList.push(oneItem.dwBuildId)
- dataList.push(oneItem.dwLayerId)
- dataList.push(oneItem.dwBtsId)
- dataList.push(oneItem.dwFreqIndex)
- dataList.push(oneItem.dwSlot)
- dataList.push(oneItem.dwCoordX)
- dataList.push(oneItem.dwCoordY)
- dataList.push(oneItem.dwCoordZ)
-
- dataList.push(oneItem.dwLctType)
- dataList.push(oneItem.dwTwoBtsNum)
- for (let i = 0; i < oneItem.dwTwoBtsNum; i++) {
- dataList.push(oneItem.adwTwoBtsList[i])
- }
- for (let i = oneItem.dwTwoBtsNum; i < 6; i++) {
- dataList.push(0)
- }
-
- for (let j = 0; j < 12; j++) {
- dataList.push(oneItem.adwBluetoothMac[j])
- }
-
- for (let k = 0; k < 12; k++) {
- dataList.push(oneItem.adwWifiMac[k])
- }
- }
-
- if (app.data.worker != null) {
- app.data.worker.postMessage({
- message: 'MAIN_WORKER_INSTALL_BTS_DATA',
- data: dataList
- })
- }
- },
-
- generateBtsDataList(btsParamList) {
- let dataList = []
-
- let btsNum = btsParamList.length;
- for (let i = 0; i < btsNum; i++) {
- let btsParam = btsParamList[i]
- let oneItem = this.generateOneBtsData(btsParam.bts_id, btsParam.carrier_id, btsParam.timeslot, btsParam.coord_x, btsParam.coord_y, btsParam.coord_z, btsParam.ble_name, btsParam.location_type, btsParam.two_bts_num, btsParam.two_bts_list)
- dataList.push(oneItem)
- }
- return dataList
- },
-
-
- generateOneBtsData(dwBtsId, dwFreqIndex, dwSlot, dwCoordX, dwCoordY, dwCoordZ, macAddressList, dwLctType, dwTwoBtsNum, adwTwoBtsList) {
- let installBts = {}
- let oneCharHex = ''
- let oneCharHexValue = 0
- installBts.dwBuildId = 1
- installBts.dwLayerId = 1
- installBts.dwBtsId = dwBtsId
- installBts.dwFreqIndex = dwFreqIndex - 1
- installBts.dwSlot = dwSlot - 1
- installBts.dwCoordX = dwCoordX
- installBts.dwCoordY = dwCoordY
- installBts.dwCoordZ = dwCoordZ
-
- installBts.dwLctType = dwLctType
-
- installBts.dwTwoBtsNum = dwTwoBtsNum;
-
- installBts.adwTwoBtsList = []
- let btsIdList = adwTwoBtsList.split(",")
- let btsId = 0
- for (let k = 0; k < dwTwoBtsNum; k++) {
- btsId = parseInt(btsIdList[k])
- installBts.adwTwoBtsList.push(btsId)
- }
-
- installBts.adwBluetoothMac = []
- for (let i = 0; i < 12; i++) {
- oneCharHex = macAddressList[i]
- oneCharHexValue = app.hexCharToValue(oneCharHex)
- installBts.adwBluetoothMac.push(oneCharHexValue)
- }
-
- installBts.adwWifiMac = []
- for (let j = 0; j < 12; j++) {
- oneCharHex = macAddressList[j]
- oneCharHexValue = app.hexCharToValue(oneCharHex)
- installBts.adwWifiMac.push(oneCharHexValue)
- }
- return installBts
- },
-
- calMaxMinCoordXY(btsDataList) {
- let maxTmpX = -10000000
- let minTmpX = 10000000
- let maxTmpY = -10000000
- let minTmpY = 10000000
- let xTmp = 0
- let yTmp = 0
- let btsNum = btsDataList.length
-
- for (let i = 0; i < btsNum; i++) {
- xTmp = btsDataList[i].dwCoordX
- if (xTmp > maxTmpX) {
- maxTmpX = xTmp
- }
- if (xTmp < minTmpX) {
- minTmpX = xTmp
- }
- yTmp = btsDataList[i].dwCoordY
- if (yTmp > maxTmpY) {
- maxTmpY = yTmp
- }
- if (yTmp < minTmpY) {
- minTmpY = yTmp
- }
- }
-
- this.setData({
- btsMinCoordX: minTmpX,
- btsMaxCoordX: maxTmpX,
- btsMinCoordY: minTmpY,
- btsMaxCoordY: maxTmpY
- })
-
- this.drawLocateTrack(1, 0, 0, this.data.coordDataList)
- },
-
- saveLocateCoord(coord) {
-
- this.data.coordDataList.push(coord)
-
- this.drawLocateTrack(2, coord.x, coord.y, this.data.coordDataList)
- },
-
- drawLocateTrack(type, coordinateX, coordinateY, coordDataList) {
- let i = 0
- let pos = 0
- let space = 10
- let lineCount = 40
- let ctxMinX = this.data.btsMinCoordX - 500
- let ctxMaxX = this.data.btsMaxCoordX + 500
- let ctxMinY = this.data.btsMinCoordY - 500
- let ctxMaxY = this.data.btsMaxCoordY + 500
- let ctxWidth = ctxMaxX - ctxMinX
- let ctxHeight = ctxMaxY - ctxMinY
- let radio = this.data.canvasWidth / ctxWidth
- let radioHeight = this.data.canvasHeight / ctxHeight
- if (radioHeight < radio) {
- radio = radioHeight
- }
- let positionCtx = this.data.canvasCtx
- positionCtx.fillStyle = "#0066FF"
- positionCtx.clearRect(0, 0, this.data.canvasWidth, this.data.canvasHeight)
- positionCtx.lineWidth = 0.5
-
- positionCtx.beginPath()
- positionCtx.strokeStyle = '#CCCCCC'
-
- space = parseFloat(this.data.canvasWidth) / lineCount
- for (i = 0; i < lineCount; i++) {
- pos = i * space
- positionCtx.moveTo(0, pos)
- positionCtx.lineTo(this.data.canvasWidth, pos)
- }
-
- space = parseFloat(this.data.canvasHeight) / lineCount
- for (i = 0; i < lineCount; i++) {
- pos = i * space
- positionCtx.moveTo(pos, 0)
- positionCtx.lineTo(pos, this.data.canvasHeight)
- }
- positionCtx.stroke()
- if (type === 0) {
- return
- }
-
- positionCtx.beginPath()
- positionCtx.fillStyle = "#FF0000"
- positionCtx.strokeStyle = '#FF0000'
- for (i = 0; i < this.data.btsDataList.length; i++) {
- let x = (this.data.btsDataList[i].dwCoordX - ctxMinX) * radio
- let y = this.data.canvasHeight - (this.data.btsDataList[i].dwCoordY - ctxMinY) * radio
- positionCtx.fillRect(x - 5, y - 5, 6, 6);
- }
- if (type === 1) {
- return
- }
-
- positionCtx.lineWidth = 1.2
- positionCtx.beginPath()
- positionCtx.strokeStyle = '#0A0A0A'
- for (i = 2; i < coordDataList.length; i++) {
- let point = coordDataList[i - 1]
- let x = (point.x - ctxMinX) * radio
- let y = this.data.canvasHeight - (point.y - ctxMinY) * radio
- positionCtx.moveTo(x, y)
- point = coordDataList[i]
- x = (point.x - ctxMinX) * radio
- y = this.data.canvasHeight - (point.y - ctxMinY) * radio
- positionCtx.lineTo(x, y)
- }
- positionCtx.stroke()
-
- positionCtx.beginPath()
- positionCtx.fillStyle = "#0000FF"
- positionCtx.strokeStyle = '#0000FF'
- let x = (coordinateX - ctxMinX) * radio
- let y = this.data.canvasHeight - (coordinateY - ctxMinY) * radio
- positionCtx.arc(x, y, 3, 0, 2 * Math.PI);
- positionCtx.fill()
- },
-
-
-
-
- generateBleBtsData() {
- let mac = "123456789ABC"
- let rssi = -58
- let item = {}
- item['mac'] = mac;
- item['rssi'] = rssi
- let dataList = []
- dataList.push(item)
- app.data.worker.postMessage({
- message: 'MAIN_WORKER_BLE_BTS_DATA',
- code: 100,
- data: dataList
- })
- },
-
- downloadAudioFile() {
- const url = "https://www.stp.intourism.cn/tdsadmin/line390-zt.wav"
- wx.downloadFile({
- url: url,
- success: (res) => {
- if (res.statusCode == 200) {
- app.data.wavFilePath = res.tempFilePath
- this.readAudioFile();
- }
- }
- })
- },
-
- readAudioFile() {
- let filePath = app.data.wavFilePath
- if (app.data.readFileTimes == null) {
- return
- }
-
- if (app.data.readFileTimes >= 360) {
- app.data.readFileTimes = 0
- return
- }
- const times = app.data.readFileTimes
- const fs = wx.getFileSystemManager();
- fs.readFile({
- filePath: `${filePath}`,
- position: 44 + times * 12000 * 2,
- length: 12000 * 2,
- success: (res) => {
- app.data.readFileTimes++
- app.data.worker.postMessage({
- message: 'MAIN_WORKER_AUDIO_DATA',
- data: res.data
- })
- },
- fail(res) {
- console.log(res);
- }
- })
- },
- })
|