Commit 33877290 by 陈桂东

数据同步

parents 86f4306a 912476ba
......@@ -12,9 +12,13 @@ export {HwInfoDao} from './src/main/ets/db/dao/HwInfoDao';
export {BzhxDao} from './src/main/ets/db/dao/BzhxDao';
export {QyInfoDao} from './src/main/ets/db/dao/QyInfoDao';
export {KfInfoDao} from './src/main/ets/db/dao/KfInfoDao';
export {Gldw} from './src/main/ets/entity/Gldw'
export {HjInfo} from './src/main/ets/entity/HjInfo'
export {HwInfo} from './src/main/ets/entity/HwInfo'
export {Bzhx} from './src/main/ets/entity/Bzhx'
export {KfInfo} from './src/main/ets/entity/KfInfo'
export {QyInfo} from './src/main/ets/entity/QyInfo'
export {Gldw} from './src/main/ets/entity/Gldw';
export {HjInfo} from './src/main/ets/entity/HjInfo';
export {WzdmDao} from './src/main/ets/db/dao/WzdmDao';
export {WzhxdmDao} from './src/main/ets/db/dao/WzhxdmDao';
export {Wzdm} from './src/main/ets/entity/Wzdm';
export {Wzhxdm} from './src/main/ets/entity/Wzhxdm';
\ No newline at end of file
......@@ -7,6 +7,7 @@
"main": "index.ets",
"version": "1.0.0",
"dependencies": {
"reflect-metadata": "^0.1.13"
"reflect-metadata": "^0.1.13",
"@ohos/axios": "^2.1.1"
}
}
......@@ -2,6 +2,7 @@ import relationalStore from '@ohos.data.relationalStore';
import { Wzdm } from '../../entity/Wzdm';
import BaseTable, { ValueType } from '../BaseTable';
import { Table } from '../decorator/Decorators';
import { SQLiteContext } from '../SQLiteContext';
/**
......@@ -52,4 +53,12 @@ export class WzdmDao extends BaseTable<Wzdm> {
)`;
return wzdm_sql;
}
async selectWZDM(lsm?:string):Promise<Wzdm[]>{
let wp = this.getPredicates();
if (lsm) {
wp.equalTo('LSM', lsm);
}
wp.orderByAsc('LSM');
return this.query(wp, this.getTableColumns())
}
}
\ No newline at end of file
import relationalStore from '@ohos.data.relationalStore';
import { Wzhxdm } from '../../entity/Wzhxdm';
import { Logger } from '../../utils/Logger';
import BaseTable, { ValueType } from '../BaseTable';
import { Table } from '../decorator/Decorators';
......@@ -58,4 +59,17 @@ export class WzhxdmDao extends BaseTable<Wzhxdm> {
)`;
return wzhxdm_sql;
}
async selectHXList(sql?: string): Promise<Wzhxdm[]> {
let db = await this.futureDb;
let rs = await db.querySql('', []);
let items: Wzhxdm[];
if (rs.goToFirstRow()) {
do {
Logger.info(this, 'queryAll rowIndex=' + rs.rowIndex)
items.push(this.toBean(rs))
} while (rs.goToNextRow())
}
return items;
}
}
\ No newline at end of file
{
"apiType": 'stageMode',
"buildOption": {
"externalNativeOptions": {
"path": "./src/main/cpp/CMakeLists.txt",
"arguments": "",
"abiFilters": [
"arm64-v8a"
],
"cppFlags": "",
},
"sourceOption": {
"workers": [
]
}
},
"targets": [
{
......
# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)
project(demo)
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${NATIVERENDER_ROOT_PATH}
${NATIVERENDER_ROOT_PATH}/include)
include_directories(${NATIVERENDER_ROOT_PATH}/serialprot/include)
find_library(
hilog-lib
hilog_ndk.z
)
add_library(entry SHARED hello.cpp)
target_link_libraries(entry PUBLIC libace_napi.z.so)
target_link_libraries(entry PUBLIC ${CMAKE_SOURCE_DIR}/../../../libs/arm64-v8a/libserialport.z.so)
target_link_libraries(entry PUBLIC ${hilog-lib} )
\ No newline at end of file
#ifndef SERIALPORT_H
#define SERIALPORT_H
#include <stddef.h>
#include "hilog/log.h"
/******************************************************
* 名称 :Gpio_Is_Enable
* 功能 :串口上电使能
* 入口参数 : GPIO_IS_ENABLE: GPIO是否使能
* [gpio-gpionu-gpiovalue:字符串必须以gpio-xx-xx形式]
* 出口参数 : 正确返回为1,错误返回为0
* *****************************************************/
int Gpio_Is_Enable(char* gpio_is_enable);
/******************************************************
* 名称 :Uart_Is_Enable
* 功能 :串口上电使能
* 入口参数 : PATH :串口使能控制节点路径 (uart0_module_status,uart1_module_status,...)
* IS_ENABLE: 串口是否使能(0:禁用 非0:使能)
* 出口参数 : 正确返回为1,错误返回为0
* *****************************************************/
int Uart_Is_Enable(char* path, unsigned int is_enable);
/******************************************************
* 名称 :SerialPort_open
* 功能 :打开差串口,返回串口设备文件描述符
* 入口参数 : PORT :串口号 (ttys0,s1,...)
* 出口参数 : 正确返回为大于0的整数,错误返回为0
* *****************************************************/
int SerialPort_open(char* port);
/*******************************************************************
* 名称: SerialPort_Init()
* 功能: 串口初始化
* 入口参数: fd 文件描述符
* speed 串口速度
* flow_ctrl 数据流控制
* databits 数据位 取值为 7 或者8
* stopbits 停止位 取值为 1 或者2
* parity 效验类型 取值为N,E,O,,S
* 出口参数: 正确返回为1,错误返回为0
*******************************************************************/
int SerialPort_Init(int fd, int speed,int flow_ctrlint ,int databits,int stopbits,int parity);
/*******************************************************************
* 名称: SerialPort_Recv
* 功能: 接收串口数据
* 入口参数: fd :文件描述符
* rcv_buf :接收串口中数据存入rcv_buf缓冲区中
* data_len :一帧数据的长度
* 出口参数: 正确返回为接收的字节数,错误返回为0
*******************************************************************/
int SerialPort_Recv(int fd, char *rcv_buf,int data_len);
/*******************************************************************
* 名称: SerialPort_Send
* 功能: 发送数据
* 入口参数: fd :文件描述符
* send_buf :存放串口发送数据
* data_len :一帧数据的个数
* 出口参数: 正确返回为发送的字节数,错误返回为0
*******************************************************************/
int SerialPort_Send(int fd, char *send_buf,int data_len);
/******************************************************
* 名称: SerialPort_close
* 功能: 关闭串口并返回串口设备文件描述
* 入口参数: fd :文件描述符
* 出口参数: void
*******************************************************************/
void SerialPort_close(int fd);
#endif
\ No newline at end of file
export const add: (a: number, b: number) => number;
/**
* 使能gpio口
* *******************参数说明***************************
* gpio:类型string,gpio口参数,格式为gpio-xx-x,其中xx为对应
* gpio口,x为0或1,1为使能gpio口,0为关闭gpio口,例使能gpio
* 口178,则gpio-178-1
* *******************返回说明***************************
* 类型int,大于0时打开串口成功,小于等于0时打开串口失败
*/
export const gpioisenale: (gpio: string) => number;
/**
* 打开串口
* *******************参数说明***************************
* path:类型string,串口路径,如/dev/ttyS0
* boardrate:类型int,波特率,如9600,115200
* ctrl:类型int,数据流控制,默认为0
* databits:类型int,数据位,默认为8
* stopbits:类型int,停止位,默认为1
* parity:类型int,校验位,0为无校验,1为奇校验,2为偶校验
* *******************返回说明***************************
* 类型int,大于0时打开串口成功,小于等于0时打开串口失败
*/
export const open: (path: string, boardrate:number,ctrl:number,databits:number,stopbits:number,parity:number) => number;
/**
* 发送串口数据
* *******************参数说明***************************
* data:类型string,发送的数据类型
* *******************返回说明***************************
* 类型int,大于0时发送成功,小于等于0时发送失败
*/
export const send: (data: string) => number;
/**
* 发送十六进制字符串串口数据
* *******************参数说明***************************
* data:类型string,发送的十六进制字符串类型
* *******************返回说明***************************
* 类型int,大于0时发送成功,小于等于0时发送失败
*/
export const sendhex: (data: string) => number;
/**
* 接收串口数据
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型string,长度大于等于1,数据接收成功
*/
export const recv: () => string;
/**
* 接收串口数据
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型字节数组,长度大于等于1,数据接收成功
*/
export const recvByte: () => Uint8Array;
/**
* 接收十六进制串口数据
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型string,长度大于等于1,数据接收成功
*/
export const recvhex: () => string;
/**
* 关闭串口
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 无
*/
export const close: () => void;
/**
* 打开5V供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,打开成功,打开失败
*/
export const power5von: () => number;
/**
* 关闭5V供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,关闭成功,关闭失败
*/
export const power5voff: () => number;
/**
* 打开SCAN供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,打开成功,打开失败
*/
export const powerscanon: () => number;
/**
* 关闭SCAN供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,关闭成功,关闭失败
*/
export const powerscanoff: () => number;
/**
* 打开RFID供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,打开成功,打开失败
*/
export const powerrfidon: () => number;
/**
* 关闭RFID供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,关闭成功,关闭失败
*/
export const powerrfidoff: () => number;
/**
* 打开PSAM供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,打开成功,打开失败
*/
export const powerpsamon: () => number;
/**
* 关闭PSAM供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,关闭成功,关闭失败
*/
export const powerpsamoff: () => number;
/**
* 打开电池供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,打开成功,打开失败
*/
export const powervbaton: () => number;
/**
* 关闭电池供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,关闭成功,关闭失败
*/
export const powervbatoff: () => number;
/**
* 打开USB OTG 5V供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,打开成功,打开失败
*/
export const powerusbotgon: () => number;
/**
* 关闭USB OTG 5V供电
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,关闭成功,关闭失败
*/
export const powerusbotgoff: () => number;
/**
* 触发扫描trig脚,拉低电平
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,拉低成功,拉低失败
*/
export const trigon: () => number;
/**
* 扫描trig脚,拉高电平
* *******************参数说明***************************
* 无
* *******************返回说明***************************
* 类型int,拉高成功,拉高失败
*/
export const trigoff: () => number;
\ No newline at end of file
import testNapi from 'libentry.so'
import Prompt from '@system.prompt';
import {
GClient,
MsgBaseInventoryEpc,
MsgBaseStop,
MsgBaseGetPower,
MsgBaseSetPower,
LogBaseEpcInfo,
LogBaseEpcOver
} from './harmonyOsReader.min'
import LightWeightMap from '@ohos.util.LightWeightMap';
import worker from '@ohos.worker';
import hilog from '@ohos.hilog';
import ScanAnalysis from './analysis/ScanAnalysis';
import emitter from '@ohos.events.emitter'
import SoundPlayer from './sound/SoundPlay'
import util from '@ohos.util';
export class IdentifyService {
private client: GClient = GClient.getInstance()
private tagMap: LightWeightMap<string, LogBaseEpcInfo> = new LightWeightMap()
private tagList: Array<LogBaseEpcInfo> = [];
private lastSpeed = 0
private readInterval = null
enableRead: boolean = true
private isOpen: Boolean = false;
work = new worker.Worker('entry/ets/identify/workers/Worker.ts', { name: "first worker in Stage model" })
textTimerController: TextTimerController = new TextTimerController()
/*打开RFID串口*/
openRfidPort() {
testNapi.powervbaton();
if (this.client.openSerial(testNapi, "/dev/ttyS1", 115200)) {
console.error("open /dev/ttyS1 成功")
this.client.callbackEpcInfo = (info: LogBaseEpcInfo) => {
if (info.result == 0) {
// console.error("EPC->" + info.epc + "==TID->" + info.tid + "==user->" + info.userdata)
if (!this.tagMap.get(info.epc)) {
this.tagMap.set(info.epc, info)
} else {
let value = this.tagMap.get(info.epc)
value.count += 1;
this.tagMap.set(info.epc, value)
}
if (!SoundPlayer.getLoop()) {
SoundPlayer.setLoop(true)
SoundPlayer.avPlayerFdSrcDemo()
}
}
};
this.client.callbackEpcOver = (over: LogBaseEpcOver) => {
console.info("call over------>" + over.rtMsg)
SoundPlayer.setLoop(false)
};
}
}
/*开启盘点*/
openRFIDInv() {
this.tagMap.clear()
this.tagList = []
let msg = new MsgBaseInventoryEpc();
msg.antennaEnable = 1;
msg.inventoryMode = 1;
let innerEvent = {
eventId: 1,
};
let epc: String = "";
var eventData = {
data: {
'epc': epc
},
priority: emitter.EventPriority.IMMEDIATE
}
// this.dataTitle = "EPC"
this.client.sendAsyncMsg(msg, () => {
if (msg.rtCode === 0) {
this.enableRead = false
this.textTimerController.reset()
this.textTimerController.start()
this.readInterval = setInterval(() => {
this.tagList = []
let readCount = 0
this.tagMap.forEach((value, key, map) => {
this.tagList.push(value)
console.log("读取EPC" + value.epc)
eventData.data.epc = value.epc
emitter.emit(innerEvent, eventData)
readCount += value.count
})
let rate = readCount - this.lastSpeed
if (rate <= 0) {
SoundPlayer.setLoop(false)
}
this.lastSpeed = readCount;
}, 1000)
} else {
Prompt.showToast({
message: "启动盘存失败"
});
}
})
}
/*停止盘点*/
stopRfidInv() {
console.log("zeng-:" + "stop");
let msg = new MsgBaseStop()
this.client.sendAsyncMsg(msg, () => {
if (msg.rtCode === 0) {
SoundPlayer.setLoop(false)
this.enableRead = true
this.textTimerController.pause()
clearInterval(this.readInterval)
} else {
Prompt.showToast({ message: "停止失败" });
}
});
}
/*关闭RFID串口*/
closeRFIDInv() {
this.client.close()
testNapi.powervbatoff()
SoundPlayer.setLoop(false)
}
/*打开扫描串口*/
openScanPort() {
testNapi.powerscanon();
//打开串口
try {
var ret = testNapi.open('/dev/ttyS0', 9600, 0, 8, 1, 0);
if (ret > 1) {
console.error("tag", "串口初始化成功");
//上拉gpio
this.isOpen = true;
//启动数据接收线程
this.executeWorkerFunc();
} else {
console.error("tag", "初始化失败");
}
console.error("tag", "onPageShow " + this.isOpen)
} catch (err) {
console.error(`初始化报错. Code:${err.code},message:${err.message}`);
}
console.log("tag", "onPageShow " + this.isOpen)
}
//异步函数用于接收线程返回
async executeWorkerFunc() {
//this.work.postMessage(this.isStart) ;
var strFlag = false;
var outputData = '';
this.work.onmessage = function (e) {
var data = e.data;
hilog.error(0x0000, 'hdwall testTag', 'work recv = %{public}s', data);
//用于跳出while(!strFlag)循环
strFlag = true;
}
this.work.onerror = function (e) {
hilog.error(0x0000, 'hdwall testTag', 'work recv = %{public}s', e.message);
}
//循环读取
while (this.isOpen) {
while (!strFlag) {
outputData = testNapi.recvhex();
//串口返回数据
if (outputData.length > 0) {
strFlag = true;
}
await ScanAnalysis.promiseCase(); //10ms延时
}
//结束线程的时候outputData可能为空
if (outputData.length > 0) {
//testNapi.gpioisenale('gpio-48-1') ;
let innerEvent = {
eventId: 2,
};
outputData = this.getGbkData(outputData)
console.error("tag", "《=========扫码数据=========》 " + outputData)
// let scanStr: String = ScanAnalysis.getScanData(outputData);
// console.error("tag", "《=========解码数据=========》" + scanStr.replace(/\s+/g, ''))
var eventData = {
data: {
'scancode': outputData
},
priority: emitter.EventPriority.IMMEDIATE
}
emitter.emit(innerEvent, eventData)
}
strFlag = false;
}
}
/*开启扫描*/
openScan() {
//参数说明value:gpio-178-0,下拉gpio 178
var value = "gpio-48-1";
var ret = testNapi.gpioisenale(value);
if (ret > 0) {
console.error("tag", "上拉成功");
}
// 等待100ms
ScanAnalysis.mySetTimeout(() => {
var downvalue = "gpio-48-0";
var downret = testNapi.gpioisenale(downvalue);
if (downret > 0) {
console.error("tag", 'scan:gpio: 下拉成功')
} else {
console.error("tag", 'scan:gpio: 下拉失败')
}
}, 100);
console.log("tag", '扫描时间:' + new Date().getTime())
}
/*关闭扫描*/
closeScan() {
this.isOpen = false;
testNapi.powerscanoff()
testNapi.close();
this.work.postMessage('stop recv');
}
/*设置读写器功率*/
setUpAnt(antPower: string) {
let msg = new MsgBaseSetPower()
msg.antPower = { 1: parseInt(antPower) }
this.client.sendAsyncMsg(msg, () => {
Prompt.showToast({
message: msg.rtCode === 0 ? "设置成功" : msg.rtMsg
});
})
}
/*查询读写器功率*/
searchAnt(): Promise<string> {
let antPower: string = "0";
let msg = new MsgBaseGetPower();
return new Promise((resolve) => {
this.client.sendAsyncMsg(msg, (err, result) => {
// 处理错误
antPower = msg.antPower[1] + "";
console.log("查询功率:", JSON.stringify(msg));
resolve(antPower);
});
});
}
getGbkData(scanData): string {
const array = new Uint8Array(scanData.length / 2);
for (let i = 0; i < scanData.length; i += 2) {
const byte = parseInt(scanData.substr(i, 2), 16);
array[i / 2] = byte;
}
//gbk 字节数组转中文
let textDedoder = util.TextDecoder.create('gbk', {ignoreBOM:true}) ;
let test = textDedoder.decodeWithStream(array, {stream: false}) ;
return test;
}
}
export default new IdentifyService()
\ No newline at end of file
export class ScanAnalysis {
getScanData(str: string): string {
str = str.replace("\u001E", "").replace("\u001D", "").replace("\u0004", "").replace("\u0000", "")
try {
//单品标签GM
if (str.includes("A950") && str.includes("A010") && str.includes("A005")) {
str = str.replace("07A950", "BZDPGM|")
.replace("A002", "|")
.replace("A006", "|")
.replace("A010", "|")
.replace("A005", "|");
}
//单品标签QR BZDPQR|17海校尉夏常服帽|861487753|62|202011|3502工厂
if (str.includes("A001") && str.includes("A010") && !str.includes("A061")) {
str = str.replace("07A001", "BZDPQR|")
.replace("A002", "|")
.replace("A006", "|")
.replace("A010", "|")
.replace("A005", "|");
}
//内包标签GM BZNBZGM|500171A00117海校尉夏常服帽|861487753|62|3502工厂
if (str.includes("A950") && str.includes("A005") && !str.includes("A010")) {
str = str.replace("07A950", "BZNBZGM|").replace("A002", "|").replace("A006", "|").replace("A005", "|");
}
//内包标签QR
if (str.includes("A950") && str.includes("A001")) {
str = str.replace("07A950", "BZNBZQR|")
.replace("A001", "|")
.replace("A002", "|")
.replace("A006", "|")
.replace("A005", "|");
}
//中包标签GM
if (str.includes("A950") && str.includes("A051") && !str.includes("A010")) {
let s = str.replace("07A950", "BZZBZGM|").replace("A002", "|").replace("A006", "|").replace("A051", "|");
let res: string[] = s.split("|");
//BZZBZGM|品名代码|物资标识码:数量
str = res[0] + "|" + res[1] + "|" + res[2] + ":" + res[4];
}
//中包标签QR BZZBZQR|17海校尉夏常服帽|861487753:10
if (str.includes("A001") && str.includes("A051") && !str.includes("A010")) {
let s = str.replace("07A001", "BZZBZQR|").replace("A002", "|").replace("A006", "|").replace("A051", "|");
let res: string[] = s.split("|");
//BZZBZQR|品名名称|物资标识码:数量
str = res[0] + "|" + res[1] + "|" + res[2] + ":" + res[4];
}
//外包标签GM
if (str.includes("A950") && str.includes("A051")) {
let s = str.replace("07A950", "BZWBZGM|")
.replace("A002", "|")
.replace("A006", "|")
.replace("A051", "|")
.replace("A061", "|")
.replace("A010", "|")
.replace("A015", "|");
let res: string[] = s.split("|");
//BZWBZGM|品名代码|物资标识码:数量
str = res[0] + "|" + res[1] + "|" + res[2] + ":" + res[4];
}
//外包(混)标签GM
if (str.includes("A951") && str.includes("A015")) {
let s = str.replace("07A951", "BZWBZGM|").replace("A061", "|").replace("A010", "|").replace("A015", "|");
let res: string[] = s.split("|");
let wzbsm = res[1].split(":"); //获取物资标识码:数量
//String pmdm = dao.getDataStringByString("Dpbq.getPmdm",wzbsm[0]);
let pmdm = "";
//BZWBZGM|品名代码|物资标识码:数量
str = res[0] + "|" + pmdm + "|" + res[1] + "|" + res[2] + "|" + res[4];
}
//外包标签QR BZWBZQR|17海校尉夏常服帽|864549931:27|20201113|3502工厂
if (str.includes("A051") && str.includes("A005")) {
//资产标签QR BZZCQR|17海校尉夏常服帽|864549931:27|20201113|3502工厂
if (str.includes("07A002")) {
let s = str.replace("07A002", "BZZCQR|")
.replace("A002", "|")
.replace("A006", "|")
.replace("A051", "|")
.replace("A061", "|")
.replace("A010", "|")
.replace("A005", "|")
.replace("A001", "|")
.replace("A901", "|")
.replace("A902", "|")
.replace("A038", "|");
let res: string[] = s.split("|");
//BZWBZGM|品名代码|物资标识码:数量
if (res[1].length > 0 && !res[1].includes("86")) {
str = res[0] + "|" + res[2] + "|" + res[3] + ":" + res[7] + "|" + res[8] + "|" + res[5];
} else {
str = res[0] + "|" + res[2] + "|" + res[1] + ":" + res[7] + "|" + res[8] + "|" + res[5];
}
} else {
//外包标签QR BZWBZQR|17海校尉夏常服帽|864549931:27
let s = str.replace("07A001", "BZWBZQR|")
.replace("A002", "|")
.replace("A006", "|")
.replace("A051", "|")
.replace("A061", "|")
.replace("A010", "|")
.replace("A005", "|");
let res: string[] = s.split("|");
//BZWBZGM|品名代码|物资标识码:数量|20201113|3502工厂
str = res[0] + "|" + res[1] + "|" + res[2] + ":" + res[4] + "|" + res[6] + "|" + res[7];
console.log("外包标签QR====>"+str)
}
}
//外包(混)标签QR BZWBZQR|17海校尉夏常服帽|861487753:11;864549931:11;863602076:11|2|20201113|3502工厂
if (str.includes("A001") && str.includes("A951")) {
str = str.replace("07A001", "BZWBZQR|")
.replace("A951", "|")
.replace("A061", "|")
.replace("A010", "|")
.replace("A005", "|");
console.log("外包(混)标签QR====>"+str)
}
} catch (err) {
console.error(`Failed to get preferences. Code:${err.code},message:${err.message}`)
}
return str;
}
mySetTimeout(callback, delay) {
return new Promise((resolve) => {
setTimeout(() => {
callback();
resolve(1);
}, delay);
});
}
promiseCase(): Promise<Object> {
let p = new Promise(function (resolve, reject) {
setTimeout(function () {
resolve(1)
}, 200)
}).then(undefined, (error) => {
})
return p;
}
}
export default new ScanAnalysis();
\ No newline at end of file
import { TitleBar } from '../../view/title/TitleBar'
import IdentifyService from '../IdentifySerivce'
import emitter from '@ohos.events.emitter';
@Extend(Button) function CommonButtonStyle() {
.borderWidth(2)
.borderColor('#0fa983')
.backgroundColor('#0FA983')
.fontColor('#fff')
.borderRadius(5)
.type(ButtonType.Normal)
.stateEffect(true)
}
@Entry
@Component
struct UHFDemo{
@State scanList: string[] = []
build(){
Column(){
Flex({ direction: FlexDirection.Column }) {
TitleBar({ title: "扫码 识别" })
List({ space: 2 }) {
ForEach(this.scanList, (item, index) => {
ListItem(){
Column() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
Text("扫码:")
.fontSize(16)
.fontStyle(FontStyle.Normal)
.fontColor($r("app.color.item_color_black"))
.width("20%")
.fontColor($r("app.color.item_color_black"))
Text(item)
.fontSize(16)
.fontColor($r("app.color.item_color_black"))
.width("80%")
.fontColor($r("app.color.font_description"))
}.backgroundColor("#fff").padding({top:5,bottom:5,left:5,right:5})
}
}
}
})
}.divider({ strokeWidth: 1, color: $r("app.color.item_color_black") }) .height("80%").width("100%")
Row() {
Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) {
Button("开启").CommonButtonStyle() .onKeyEvent((e: globalThis.KeyEvent) => {
if (e.keyCode == 2096 || e.keyCode == 2093) {
if (e.type == 1) {
IdentifyService.openScan()
}
}
console.error('keycode:' + e.keyCode)
}).width("45%").onClick(()=>{
//参数说明value:gpio-178-0,下拉gpio 178
IdentifyService.openScan()
})
Button("清除").CommonButtonStyle().width("45%").onClick(()=>{
this.scanList=[]
})
}
}.margin({left:10,right:10}).height(80)
}.width("100%")
}.linearGradient({
direction: GradientDirection.Right, // 渐变方向
repeating: true, // 渐变颜色是否重复
colors: [[0x36a3c0, 0.0], [0x97c6a6, 1], [0xc7d799, 0.0]] // 数组末尾元素占比小于1时满足重复着色效果
})
}
scanCodeListen() {
var innerEvent = { eventId: 2 }
emitter.on(innerEvent, (eventData) => {
if (innerEvent.eventId == 2) {
let result = eventData.data.scancode
console.log("扫码校验", "收到扫码信息:" + result)
this.showQRDetail(result)
}
})
}
showQRDetail(qrCode?:string){
this.scanList.push(qrCode)
}
onPageShow() {
console.error("========onPageShow=========")
this.scanCodeListen()
IdentifyService.openScanPort()
}
onPageHide(){
IdentifyService.closeScan()
/*取消扫码订阅*/
emitter.off(2);
}
}
\ No newline at end of file
import { TitleBar } from '../../view/title/TitleBar'
import IdentifyService from '../IdentifySerivce'
import emitter from '@ohos.events.emitter';
@Extend(Button) function CommonButtonStyle() {
.borderWidth(2)
.borderColor('#0fa983')
.backgroundColor('#0FA983')
.fontColor('#fff')
.borderRadius(5)
.type(ButtonType.Normal)
.stateEffect(true)
}
@Entry
@Component
struct UHFDemo{
@State doneEpcsList: string[] = []
build(){
Column(){
Flex({ direction: FlexDirection.Column }) {
TitleBar({ title: "RFID 识别" })
List({ space: 2 }) {
ForEach(this.doneEpcsList, (item, index) => {
ListItem(){
Column() {
Column() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
Text("EPC:")
.fontSize(16)
.fontStyle(FontStyle.Normal)
.fontColor($r("app.color.item_color_black"))
.width("20%")
.fontColor($r("app.color.item_color_black"))
Text(item)
.fontSize(16)
.fontColor($r("app.color.item_color_black"))
.width("80%")
.fontColor($r("app.color.font_description"))
}.backgroundColor("#fff").padding({top:5,bottom:5,left:5,right:5})
}
}
}
})
}.divider({ strokeWidth: 1, color: $r("app.color.item_color_black") }) .height("80%").width("100%")
Row() {
Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) {
Button("开启").CommonButtonStyle().width("45%").onClick(()=>{
IdentifyService.openRFIDInv()
})
Button("清除").CommonButtonStyle().width("45%").onClick(()=>{
this.doneEpcsList=[]
IdentifyService.stopRfidInv()
})
}
}.margin({left:10,right:10}).height(80)
}.width("100%")
}.linearGradient({
direction: GradientDirection.Right, // 渐变方向
repeating: true, // 渐变颜色是否重复
colors: [[0x36a3c0, 0.0], [0x97c6a6, 1], [0xc7d799, 0.0]] // 数组末尾元素占比小于1时满足重复着色效果
})
}
rfidInvListen() {
var innerEvent = {eventId: 1 }
emitter.on(innerEvent, (eventData) => {
if(innerEvent.eventId==1){
let result = eventData.data.epc
console.log("入库","收到EPC:" + result)
if(result!=undefined&&!this.doneEpcsList.includes(result)&&result.substring(0, 2)=='05'){
this.showList(result)
}
}
})
}
showList(epc?:string){
this.doneEpcsList.push(epc)
}
onPageShow() {
console.error("========onPageShow=========")
this.rfidInvListen()
IdentifyService.openRfidPort()
}
onPageHide(){
IdentifyService.closeRFIDInv()
/*取消盘点EPC订阅*/
emitter.off(1);
}
}
\ No newline at end of file
import media from '@ohos.multimedia.media';
import fs from '@ohos.file.fs';
import common from '@ohos.app.ability.common';
export class SoundPlayer {
private avPlayer;
private count: number = 0;
private loop: boolean = false;
setLoop(isLoop) {
this.loop = isLoop
if (!isLoop) {
if (this.avPlayer) {
this.avPlayer.stop()
}
}
}
getLoop() {
return this.loop
}
// 注册avplayer回调函数
setAVPlayerCallback() {
// seek操作结果回调函数
this.avPlayer.on('seekDone', (seekDoneTime) => {
console.error(`AVPlayer seek succeeded, seek time is ${seekDoneTime}`);
})
// error回调监听函数,当avPlayer在操作过程中出现错误时调用reset接口触发重置流程
this.avPlayer.on('error', (err) => {
console.error(`Invoke AVPlayer failed, code is ${err.code}, message is ${err.message}`);
this.avPlayer.reset(); // 调用reset重置资源,触发idle状态
})
// 状态机变化回调函数
this.avPlayer.on('stateChange', async (state, reason) => {
switch (state) {
case 'idle': // 成功调用reset接口后触发该状态机上报
console.error('AVPlayer state idle called.');
this.avPlayer.release(); // 调用release接口销毁实例对象
break;
case 'initialized': // avplayer 设置播放源后触发该状态上报
console.error('AVPlayer initialized called.');
this.avPlayer.prepare().then(() => {
console.error('AVPlayer prepare succeeded.');
}, (err) => {
console.error(`Invoke prepare failed, code is ${err.code}, message is ${err.message}`);
});
break;
case 'prepared': // prepare调用成功后上报该状态机
console.error('AVPlayer state prepared called.');
this.avPlayer.play(); // 调用播放接口开始播放
break;
case 'playing': // play成功调用后触发该状态机上报
console.error('AVPlayer state playing called.');
this.avPlayer.loop = this.loop
// this.avPlayer.setSpeed(media.PlaybackSpeed.SPEED_FORWARD_2_00_X)
// if (this.count !== 0) {
// console.error('AVPlayer start to seek.');
// this.avPlayer.seek(this.avPlayer.duration); //seek到音频末尾
// } else {
// this.avPlayer.pause(); // 调用暂停接口暂停播放
// }
// this.count++;
break;
case 'paused': // pause成功调用后触发该状态机上报
console.error('AVPlayer state paused called.');
this.avPlayer.play(); // 再次播放接口开始播放
break;
case 'completed': // 播放结束后触发该状态机上报
console.error('AVPlayer state completed called.');
this.avPlayer.stop(); //调用播放结束接口
break;
case 'stopped': // stop接口成功调用后触发该状态机上报
console.error('AVPlayer state stopped called.');
this.avPlayer.reset(); // 调用reset接口初始化avplayer状态
break;
case 'released':
console.error('AVPlayer state released called.');
break;
default:
console.error('AVPlayer state unknown called.');
break;
}
})
}
// 以下demo为使用fs文件系统打开沙箱地址获取媒体文件地址并通过url属性进行播放示例
async avPlayerUrlDemo() {
// 创建avPlayer实例对象
this.avPlayer = await media.createAVPlayer();
// 创建状态机变化回调函数
this.setAVPlayerCallback();
let fdPath = 'fd://';
// 通过UIAbilityContext获取沙箱地址filesDir,以下为Stage模型获方式,如需在FA模型上获取请参考《访问应用沙箱》获取地址
let context = getContext(this) as common.UIAbilityContext;
let pathDir = context.filesDir;
let path = pathDir + '/audio.mp3';
// 打开相应的资源文件地址获取fd,并为url赋值触发initialized状态机上报
let file = await fs.open(path);
fdPath = fdPath + '' + file.fd;
this.avPlayer.url = fdPath;
}
// 以下demo为使用资源管理接口获取打包在HAP内的媒体资源文件并通过fdSrc属性进行播放示例
async avPlayerFdSrcDemo() {
// 创建avPlayer实例对象
this.avPlayer = await media.createAVPlayer();
// 创建状态机变化回调函数
this.setAVPlayerCallback();
// 通过UIAbilityContext的resourceManager成员的getRawFd接口获取媒体资源播放地址
// 返回类型为{fd,offset,length},fd为HAP包fd地址,offset为媒体资源偏移量,length为播放长度
let context = getContext(this) as common.UIAbilityContext;
let fileDescriptor = await context.resourceManager.getRawFd('audio.mp3');
// 为fdSrc赋值触发initialized状态机上报
this.avPlayer.fdSrc = fileDescriptor;
}
}
export default new SoundPlayer()
\ No newline at end of file
// @ts-ignore
import worker, { DedicatedWorkerGlobalScope, MessageEvent, ErrorEvent } from '@ohos.worker';
import hilog from '@ohos.hilog';
var parentPort : DedicatedWorkerGlobalScope = worker.parentPort;
/**
* Defines the event handler to be called when the worker thread receives a message sent by the host thread.
* The event handler is executed in the worker thread.
*
* @param e message data
*/
parentPort.onmessage = function(e : MessageEvent<object>) {
var data = e.data ;
hilog.error(0x0000, "hdwall Worker", "onmessage %{public}s", data) ;
console.log("tag","onmessage" + data)
//hilog.error(0x0000, "hdwall Worker", "onmessage NAPI = %{public}d", testNapi.gpioisenale("gpio-178-1")) ;
//用来停止接收串口数据
parentPort.postMessage("123456");
}
/**
* Defines the event handler to be called when the worker receives a message that cannot be deserialized.
* The event handler is executed in the worker thread.
*/
parentPort.onmessageerror = function(e:MessageEvent<Object>) {
var data = e.data ;
console.log("tag","onmessageerror" + data)
//hilog.error(0x0000, "hdwall Worker", "onmessage NAPI = %{public}d", testNapi.gpioisenale("gpio-178-1")) ;
//用来停止接收串口数据
parentPort.postMessage(data);
}
/**
* Defines the event handler to be called when an exception occurs during worker execution.
* The event handler is executed in the worker thread.
*
* @param e error message
*/
parentPort.onerror = function(e : ErrorEvent) {
}
\ No newline at end of file
import { BzhxDao, SQLiteContext,Bzhx } from '@ohos/common'
import { uuid } from '@ohos/common/src/main/ets/utils/util'
import database from '../database/database'
import { Bzhx } from '@ohos/common/src/main/ets/entity/Bzhx'
import { importSql } from '../sql/index'
import { Wzdm, Wzhxdm,SQLiteContext, WzdmDao,WzhxdmDao, BzhxDao,Logger } from '@ohos/common'
// 被装号型
class BzhxModal {
......@@ -25,6 +29,14 @@ class BzhxModal {
let res = await SQLiteContext.with(BzhxDao).getBzhxList(pmdmsix)
return res;
}
async queryLsm(lsm?: string):Promise<Wzdm[]> {
let res = await SQLiteContext.with(WzdmDao).selectWZDM(lsm);
return res;
}
async queryHXlist(sql?: string):Promise<Wzhxdm[]> {
let res = await SQLiteContext.with(WzhxdmDao).selectHXList(sql);
return res;
}
}
const bzhxModal = new BzhxModal()
......
import { generalInitList, scanInitList, systemList, UniListItem } from '@ohos/system/src/main/ets/model/UniInitList'
import { TitleBar } from '../../view/title/TitleBar'
import { BasicDialog } from '../../view/BasicDialog/BasicDialog'
import promptAction from '@ohos.promptAction'
@Extend(Button) function CommonButtonStyle() {
.borderWidth(2)
......@@ -12,10 +13,52 @@ import { BasicDialog } from '../../view/BasicDialog/BasicDialog'
.stateEffect(true)
}
// 需要提交的表单
interface FormData {
httpURL: string,
httpPORT: string,
scoketURL: string,
scoketPORT: string,
themeName: string,
themeColor: string,
reconnection_mode: boolean,
push_mode: boolean,
transmission_mode: string,
continue_scan_mode: boolean,
scan_read_mode: string,
scanning_mode: string,
broadcastKey: string,
power: string
}
@Entry
@Component
export struct General {
@State systemTitle: Array<string> = ['直连配置','扫描配置','系统配置'];
@State clickItem: UniListItem = {
title: '',
showExtraIcon: true,
showArrow: true,
url: ''
};
@State formData: FormData = {
httpURL: '',
httpPORT: "",
scoketURL: "",
scoketPORT: "",
themeName: "",
themeColor: "",
reconnection_mode: true,
push_mode: true,
transmission_mode: "",
continue_scan_mode: false,
scan_read_mode: "",
scanning_mode: "",
broadcastKey: "",
power: ""
}
getListInfo(index:number):UniListItem[]{
switch (index){
case 0:
......@@ -29,19 +72,17 @@ export struct General {
break;
}
}
scroller: Scroller = new Scroller()
dialogController: CustomDialogController = new CustomDialogController({
builder: BasicDialog({
cancel: this.onCancel,
confirm: this.onSubmit,
title: '2.0业务终端IP'
clickItem: $clickItem,
formData: $formData,
}),
cancel: this.existApp,
autoCancel: true,
alignment: DialogAlignment.Default,
offset: { dx: 0, dy: -20 },
gridCount: 4,
customStyle: false
alignment: DialogAlignment.Center,
customStyle: true
})
onCancel() {
......@@ -92,7 +133,7 @@ export struct General {
Blank()
.layoutWeight(1)
Text(item.targetValue)
Text(this.formData[item?.key])
.fontSize(16)
.flexGrow(1)
.align(Alignment.End)
......@@ -105,7 +146,10 @@ export struct General {
}
.height(71)
.onClick(() => {
this.clickItem = item
if (this.dialogController != undefined) {
this.dialogController.open()
}
})
})
}
......@@ -122,7 +166,11 @@ export struct General {
}.height('82%')
Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) {
Button("保存").CommonButtonStyle()
Button("保存").CommonButtonStyle().onClick(() => {
promptAction.showToast({
message: JSON.stringify(this.formData)
})
})
Button("重置").CommonButtonStyle()
}
.height(70)
......@@ -137,4 +185,5 @@ export struct General {
})
}
}
\ No newline at end of file
}
import { UniListItem } from '@ohos/system/src/main/ets/model/UniInitList';
@Extend(Button) function CommonButtonStyle() {
.borderWidth(2)
.borderColor('#0fa983')
......@@ -8,10 +9,32 @@
.stateEffect(true)
}
// 需要提交的表单
interface FormData {
httpURL: string,
httpPORT: string,
scoketURL: string,
scoketPORT: string,
themeName: string,
themeColor: string,
reconnection_mode: boolean,
push_mode: boolean,
transmission_mode: string,
continue_scan_mode: boolean,
scan_read_mode: string,
scanning_mode: string,
broadcastKey: string,
power: string
}
@CustomDialog
@Component
export struct BasicDialog {
private title: string;
@Link formData: FormData;
@Link clickItem: UniListItem
controller: CustomDialogController
cancel: () => void
confirm: () => void
......@@ -28,16 +51,22 @@ export struct BasicDialog {
.color('#19ac88')
.opacity(0.6)
.margin({ left: 8, right: 8 })
Text(this.title)
.fontSize(20)
}.padding({ top: 10, bottom: 10 })
Text(this.clickItem.title).fontSize(20)
}
.padding({ top: 10, bottom: 10 })
}
this.container()
Column() {
TextInput({ placeholder: '', text: this.formData[this.clickItem?.key] }).height(40).width('90%').borderRadius(4)
.onChange((value: string) => {
this.formData[this.clickItem?.key] = value
})
}
Flex({ justifyContent: FlexAlign.SpaceAround }) {
Button('确认')
.onClick(() => {
// this.httpURL = this.textValue
this.controller.close()
this.confirm()
}).CommonButtonStyle()
......@@ -46,7 +75,10 @@ export struct BasicDialog {
this.controller.close()
this.cancel()
}).CommonButtonStyle()
}.margin({ bottom: 10 })
}.margin({ top: 10, bottom: 10 })
}
.width('86%')
.borderRadius(5)
.backgroundColor('#fff')
}
}
\ No newline at end of file
import { UniListItem } from '@ohos/system/src/main/ets/model/UniInitList';
@Extend(Button) function CommonButtonStyle() {
.borderWidth(2)
.borderColor('#0fa983')
.backgroundColor('#fff')
.fontColor('#0fa983')
.borderRadius(10)
.type(ButtonType.Normal)
.stateEffect(true)
}
@Observed
class UniList {
title: string; // 标题
showExtraIcon: boolean; // 是否显示额外的图标
showArrow: boolean; // 右边箭头
extraIcon?: Resource; // 图标本体
url?: string; // 跳转的URL
targetValue?: string; // 右侧的值
description?: string; // 描述
constructor(title, showExtraIcon, showArrow, extraIcon, url, targetValue, description) {
this.title = title;
this.showExtraIcon = showExtraIcon;
this.showArrow = showArrow;
this.extraIcon = extraIcon;
this.url = url;
this.targetValue = targetValue;
this.description = description;
}
}
@CustomDialog
@Component
export struct GeneralDialog {
// @ObjectLink uniList: UniList
controller: CustomDialogController
cancel: () => void
confirm: () => void
@BuilderParam container: () => void
textController: TextInputController = new TextInputController()
build() {
Column() {
Flex({ alignItems: ItemAlign.Start }) {
Row() {
Divider()
.vertical(true)
.height(14)
.strokeWidth(3)
.color('#19ac88')
.opacity(0.6)
.margin({ left: 8, right: 8 })
Text('').fontSize(20)
}
.padding({ top: 10, bottom: 10 })
}
Column() {
TextInput({ text: '', controller: this.textController })
.borderRadius(4)
.height(35)
.onChange((value: string) => {
})
}
.padding({ left: 10, right: 10 })
.width('100%')
.height(35)
Flex({ justifyContent: FlexAlign.SpaceAround }) {
Button('确认')
.onClick(() => {
this.controller.close()
this.confirm()
}).CommonButtonStyle()
Button('取消')
.onClick(() => {
this.controller.close()
this.cancel()
}).CommonButtonStyle()
}.margin({ top: 10, bottom: 10 })
}
.width('86%')
.borderRadius(5)
.backgroundColor('#fff')
}
}
\ No newline at end of file
......@@ -34,6 +34,8 @@
"pages/sub_systemMaintenance/Version",
"pages/sub_systemMaintenance/Feedback",
"pages/metailmange/WzStatus",
"pages/metailmange/UHFScanPage"
"pages/metailmange/UHFScanPage",
"identify/demo_page/UHFDemo",
"identify/demo_page/ScanDemo"
]
}
......@@ -24,7 +24,7 @@ export struct MaterialManagement {
Image($r("app.media.menu")).size({ width: 55, height: 55 }).padding(15)
.onClick(()=>{
router.pushUrl({
url: 'pages/setup/SetUpPage',
url: 'identify/demo_page/ScanDemo',
})
})
}.padding({top: `${StatusBarManager.get().getSystemBarOffset()}px`})
......
......@@ -6,8 +6,11 @@ export interface UniListItem {
url?: string; // 跳转的URL
targetValue?: string; // 右侧的值
description?: string; // 描述
key?: string; //对应的键值对
}
export const uniInitList: UniListItem[] = [
{
title: '数据同步',
......@@ -132,6 +135,7 @@ export const maintenanceList: UniListItem[] = [
export const generalInitList: UniListItem[] = [
{
title: '2.0业务数据服务IP',
key: 'httpURL',
showExtraIcon: true,
showArrow: true,
//extraIcon: '',
......@@ -140,6 +144,7 @@ export const generalInitList: UniListItem[] = [
},
{
title: '2.0业务终端IP',
key: 'httpPORT',
showExtraIcon: true,
showArrow: true,
//extraIcon: '',
......@@ -148,6 +153,7 @@ export const generalInitList: UniListItem[] = [
},
{
title: '2.0业务终端通讯端口',
key: 'scoketURL',
showExtraIcon: true,
showArrow: true,
//extraIcon: '',
......@@ -156,6 +162,7 @@ export const generalInitList: UniListItem[] = [
},
{
title: '传输方式',
key: 'transmission_mode',
showExtraIcon: true,
showArrow: true,
//extraIcon: '',
......@@ -164,6 +171,7 @@ export const generalInitList: UniListItem[] = [
},
{
title: '连接模式',
key: 'reconnection_mode',
showExtraIcon: true,
showArrow: true,
//extraIcon: '',
......@@ -172,6 +180,7 @@ export const generalInitList: UniListItem[] = [
},
{
title: '推送模式',
key: 'push_mode',
showExtraIcon: true,
showArrow: true,
//extraIcon: '',
......
......@@ -2,12 +2,17 @@
"lockfileVersion": 1,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {
"@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6"
"@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6",
"@ohos/axios@^2.1.1": "@ohos/axios@2.1.1"
},
"packages": {
"@ohos/hypium@1.0.6": {
"resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.6.tgz",
"integrity": "sha512-bb3DWeWhYrFqj9mPFV3yZQpkm36kbcK+YYaeY9g292QKSjOdmhEIQR2ULPvyMsgSR4usOBf5nnYrDmaCCXirgQ=="
},
"@ohos/axios@2.1.1": {
"resolved": "https://repo.harmonyos.com/ohpm/@ohos/axios/-/axios-2.1.1.har",
"integrity": "sha512-EQax257+eKKT0Rx7h6N6xvmKbDRWDjCCWOP2vyyktySFwvjtypXuXmQKEvRjmAalR6cqf8mbfhWmpg0bD9OQ3w=="
}
}
}
\ No newline at end of file
......@@ -8,5 +8,7 @@
"description": "Please describe the basic information.",
"main": "",
"version": "1.0.0",
"dependencies": {}
}
"dependencies": {
"@ohos/axios": "^2.1.1"
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论