Skip to content

Commit

Permalink
feat: support v2 weather sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryyip committed Sep 29, 2024
1 parent 5f97f1a commit c50c960
Show file tree
Hide file tree
Showing 7 changed files with 506 additions and 66 deletions.
155 changes: 155 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"ngSkus" : {
"101991044": "v2_2in1",
"101991045": "v2_2in1",
"101991021": "v2_5in1",
"101991232": "v2_6in1_light",
"101991022": "v2_7in1",
"101991023": "v2_8in1",
"101991024": "v2_10in1",
"101991025": "v2_10in1_carbon",
"101991063": "v2_11in1_noise",
"101991102": "v2_7in1_tsr",
"101991103": "v2_10in1_tsr",
"101991104": "v2_11in1_tsr_noise",
"101991050": "v2_7in1_radar",
"101991141": "v2_7in1_radar_tsr",
"101991202": "single_radar",
"101991062": "v2_9in1",
"101991061": "v2_6in1"
},
"ngSensorTypes" : {
"v2_2in1":["G2"],
"v2_5in1":["G1_THP", "G2"],
"v2_6in1":["G1_THP", "G4", "G6"],
"v2_6in1_light":["G1_THPL", "G2"],
"v2_7in1":["G1_THPL", "G2", "G3"],
"v2_8in1":["G1_THP", "G2", "G4", "G6"],
"v2_9in1":["G1_THPL", "G2", "G3", "G4"],
"v2_10in1":["G1_THPL", "G2", "G3", "G4", "G5"],
"v2_10in1_carbon":["G1_THPL", "G2", "G3", "G4", "G5"],
"v2_11in1_noise":["G1_THPL", "G2", "G3", "G4", "G5", "G6"],
"unknown":["G1_THPL", "G2", "G3", "G4", "G5", "G6"],
"v2_7in1_tsr":["G1_THP_TSR", "G2", "G3"],
"v2_10in1_tsr":["G1_THP_TSR", "G2", "G3", "G4", "G5"],
"v2_11in1_tsr_noise":["G1_THP_TSR", "G2", "G3", "G4", "G5", "G6"],
"v2_7in1_radar":["G1_THPL", "G2", "G3"],
"v2_7in1_radar_tsr":["G1_THP_TSR", "G2", "G3"],
"single_radar": ["G3"]
},
"ngGroupDefines" : {
"G1_THP":
{
"grpNameShort": "G1",
"grpName": "THP",
"meas": {
"AT": { "name": "Air Temperature", "unit": "#", "unitSuffix": "" },
"AH": { "name": "Air Humidity", "unit": "%RH", "unitSuffix": "" },
"AP": { "name": "Air Pressure", "unit": "#", "unitSuffix": "" }
}
},
"G1_THPL":
{
"grpNameShort": "G1",
"grpName": "THPL",
"meas": {
"AT": { "name": "Air Temperature", "unit": "#", "unitSuffix": "" },
"AH": { "name": "Air Humidity", "unit": "%RH", "unitSuffix": "" },
"AP": { "name": "Air Pressure", "unit": "#", "unitSuffix": "" },
"LX": { "name": "Light Intensity", "unit": "Lux", "unitSuffix": "" }
}
},
"G1_THP_TSR":
{
"grpNameShort": "G1",
"grpName": "THPL",
"meas": {
"AT": { "name": "Air Temperature", "unit": "#", "unitSuffix": "" },
"AH": { "name": "Air Humidity", "unit": "%RH", "unitSuffix": "" },
"AP": { "name": "Air Pressure", "unit": "#", "unitSuffix": "" },
"TSR": { "name": "Total Solar Radiation", "unit": "W/m²", "unitSuffix": "" },
"SD": { "name": "Sunlight Duration", "unit": "h", "unitSuffix": "" }
}
},
"G2":
{
"grpNameShort": "G2",
"grpName": "Wind",
"meas": {
"DN": { "name": "Min. Wind Direction", "unit": "°", "unitSuffix": "" },
"DM": { "name": "Max. Wind Direction", "unit": "°", "unitSuffix": "" },
"DA": { "name": "Avg. Wind Direction", "unit": "°", "unitSuffix": "" },
"SN": { "name": "Min. Wind Speed", "unit": "#", "unitSuffix": "" },
"SM": { "name": "Max. Wind Speed", "unit": "#", "unitSuffix": "" },
"SA": { "name": "Avg. Wind Speed", "unit": "#", "unitSuffix": "" }
}
},
"G3":
{
"grpNameShort": "G3",
"grpName": "Precipitation",
"meas": {
"RA": { "name": "Rain Accumulation", "unit": "#", "unitSuffix": "" },
"RD": { "name": "Rain Duration", "unit": "s", "unitSuffix": "" },
"RI": { "name": "Rain Intensity", "unit": "#", "unitSuffix": "/h" },
"RP": { "name": "Rain Peak Intensity", "unit": "#", "unitSuffix": "/h" }
}
},
"G4":
{
"grpNameShort": "G4",
"grpName": "Particulate Matter",
"meas": {
"PM2.5": { "name": "PM2.5", "unit": "ug/m³", "unitSuffix": "" },
"PM10": { "name": "PM10", "unit": "ug/m³", "unitSuffix": "" }
}
},
"G5":
{
"grpNameShort": "G5",
"grpName": "Carbon Dioxide",
"meas": {
"CO2": { "name": "Carbon Dioxide Concentration", "unit": "ppm", "unitSuffix": "" }
}
},
"G6":
{
"grpNameShort": "G6",
"grpName": "Noise",
"meas": {
"NOISE": { "name": "Sound Pressure Level", "unit": "dB", "unitSuffix": "" }
}
}
},
"ngGrpNameTransZh" : {
"THP": "温湿压",
"THPL": "温湿压光",
"Air Temperature": "空气温度",
"Air Humidity": "空气湿度",
"Air Pressure": "大气压",
"Light Intensity": "光照强度",
"Wind": "风速风向",
"Min. Wind Direction": "风向角最小值",
"Max. Wind Direction": "风向角最大值",
"Avg. Wind Direction": "风向角平均值",
"Min. Wind Speed": "风速最小值",
"Max. Wind Speed": "风速最大值",
"Avg. Wind Speed": "风速平均值",
"Precipitation": "降雨",
"Rain Accumulation": "累计降雨量",
"Rain Duration": "累计降雨时长",
"Rain Intensity": "降雨强度",
"Rain Peak Intensity": "降雨强度峰值",
"Misc.": "其他",
"Heating Temperature": "加热区域温度",
"Tilt Status": "倾倒状态",
"Particulate Matter": "颗粒物",
"Carbon Dioxide":"二氧化碳",
"Carbon Dioxide Concentration": "二氧化碳浓度",
"Noise": "噪声",
"Sound Pressure Level": "声压级",
"Total Solar Radiation": "太阳总辐射",
"Sunlight Duration": "日照时长",
"GlobalDefinesEnd": "-"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sensecap_one_cfg_tool",
"version": "1.3.1",
"version": "1.4.0",
"private": true,
"description": "SenseCAP One Configuration Tool",
"author": "Jack Shao <[email protected]>",
Expand Down
25 changes: 25 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
import { app, protocol, BrowserWindow, shell, ipcMain, dialog } from 'electron'
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
// const {SerialPort} = require('serialport')
const SerialPort = require('serialport')
const Menu = require("electron-create-menu")
import i18next from 'i18next'
Expand All @@ -15,6 +16,7 @@ const fsPromises = fs.promises
const Store = require('electron-store')
const store = new Store()
const { Readable } = require('stream')
// const { ReadlineParser } = require('@serialport/parser-readline')
const ReadlineParser = require('@serialport/parser-readline')
const dateFormat = require('dateformat')
const { once, EventEmitter } = require('events')
Expand Down Expand Up @@ -414,6 +416,7 @@ ipcMain.on('init-serial-req', (event, arg) => {
})

function serialOpen(event) {
// serial = new SerialPort({path: selectedSerialPort,
serial = new SerialPort(selectedSerialPort, {
baudRate: selectedSerialBaud || 115200,
autoOpen: false
Expand Down Expand Up @@ -770,6 +773,7 @@ ipcMain.on('dev-info-req', async (event) => {
let deviceInfoObj = {...snObj, ...versionsMap, 'MD': dateOfManuFriendlyStr, ...nameObj}
logger.debug('deviceInfoObj:', deviceInfoObj)
event.reply('dev-info-resp', deviceInfoObj)
broadcastMultiWindows('dev-info-got', deviceInfoObj, winSettings)

} catch (error) {
logger.warn('error when querying device info:', error)
Expand Down Expand Up @@ -1095,6 +1099,27 @@ ipcMain.on('broadcast-to-others', (event, eventName, ...args) => {
}
})

ipcMain.on('read-ng-config', (event) => {
logger.info('handle read-ng-config call ...')
let filePath = './config.json'

try{
fs.accessSync(filePath, fs.constants.R_OK)
} catch (error) {
logger.warn('can not access file:', filePath)
logger.debug(error)
throw new Error('can not read config.json')
}
try {
event.returnValue = fs.readFileSync(filePath, {
encoding: 'utf8'
})
} catch (error) {
logger.warn('error when read file:', filePath)
logger.debug(error)
throw new Error('read config.json error')
}
})

// Settings Save to File / Load from File
function genFilePath(ext) {
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@ import commonMessages from '../locale/common'
const Store = require('electron-store')
const store = new Store()
import { formatLocale } from "../utils"
const fs = require('fs')
// const logger = require("electron-log")

Vue.use(VueI18n)

let initLocale = store.get('selectedLocale') || navigator.language || 'en'

// Update locale message if we have config.json
let filePath = './config.json'
try{
fs.accessSync(filePath, fs.constants.R_OK)
let data = fs.readFileSync(filePath, {
encoding: 'utf8'
})
let cfg = JSON.parse(data)
for (let name in cfg['ngGrpNameTransZh']) {
commonMessages["zh"][name] = cfg['ngGrpNameTransZh'][name]
}
// logger.debug('init locale: ', commonMessages)

} catch(error) {
// logger.warn('error when read config.json:', error)
// logger.warn('skip reading config.json')
}

let i18n = new VueI18n({
locale: formatLocale(initLocale),
fallbackLocale: 'en',
Expand Down
Loading

0 comments on commit c50c960

Please sign in to comment.