1 Star 0 Fork 0

qinxude/rk3568ui

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
jsonanalysis.h 22.16 KB
一键复制 编辑 原始数据 按行查看 历史
qinxude 提交于 2024-09-03 09:38 . 3568ui base
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
#ifndef JSONANALYSIS_H
#define JSONANALYSIS_H
#include <QByteArray>
#include <QList>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include "datadictionary.h"
typedef enum {
BB_CLOUD_CMD = 0,
}JsonProType_t;
typedef enum{
STRING_TYPE = 0,
FLOAT_TYPE,
INT_TYPE,
}DataType_t;
typedef struct {
JsonProType_t Type;
QByteArray Data;
QByteArray Result;
}DataSt_t;
class SpecialRead {
public:
SpecialRead()
{
m_DataDictionary = DataDictionary::GetInstance();
m_Next = nullptr;
m_Cmd1 = "";
}
void AddNextExec(SpecialRead *_Next){m_Next = _Next;}
bool CmdExec(QString Cmd,QString &Data,QString &err)
{
if(isExec(Cmd)){
return Exec(Cmd,Data,err);
}else if(m_Next){
return m_Next->CmdExec(Cmd,Data,err);
}else {
err = "data " + Cmd + " Unsupported ;";
return false;
}
return false;
}
void Reset()
{
_Reset();
if(m_Next)
m_Next->Reset();
}
protected:
virtual bool Exec(QString Cmd,QString &Data,QString &err) = 0;
virtual void _Reset() = 0;
QString m_Cmd1;
DataDictionary *m_DataDictionary;
private:
bool isExec(QString Cmd)
{
return (Cmd == m_Cmd1);
}
SpecialRead *m_Next;
};
class GosdtyRead : public SpecialRead
{
public:
GosdtyRead(){m_Cmd1 = "v1osdty";}
protected:
bool Exec(QString Cmd,QString &Data,QString &err)
{
int _data = m_DataDictionary->GetSystemData(SYS_OSD_DEVICE).toInt();
if(_data == HK_DEVICE || _data == WWA_DEVICE || _data == OTHER_DEVICE){
Data.setNum(2);
}else if(_data == LOCAL_DEVICE){
Data.setNum(1);
}else if(_data == OSD_CLOSE){
Data.setNum(3);
}else {
err = Cmd + " data abnormal;";
}
return true;
}
void _Reset(){}
};
class GosdtpRead : public SpecialRead
{
public:
GosdtpRead(){m_Cmd1 = "v1osdtp";}
protected:
bool Exec(QString Cmd,QString &Data,QString &err)
{
int _data = m_DataDictionary->GetSystemData(SYS_OSD_DEVICE).toInt();
if(_data == HK_DEVICE ){
Data.setNum(1);
}else if( _data == WWA_DEVICE){
Data.setNum(2);
}else {
Data.setNum(3);
}
return true;
}
void _Reset(){}
};
class SpecialExec {
public:
SpecialExec()
{
m_DataDictionary = DataDictionary::GetInstance();
m_Next = nullptr;
m_Cmd1 = "";
m_Cmd2 = "";
m_Cmd3 = "";
}
void AddNextExec(SpecialExec *_Next){m_Next = _Next;}
bool CmdExec(QString Cmd,QString Data,QString &err)
{
if(isExec(Cmd)){
return Exec(Cmd,Data,err);
}else if(m_Next){
return m_Next->CmdExec(Cmd,Data,err);
}else {
err = "data " + Cmd + " Unsupported ;";
return false;
}
return false;
}
void Reset()
{
_Reset();
if(m_Next)
m_Next->Reset();
}
protected:
virtual bool Exec(QString Cmd,QString Data,QString &err) = 0;
virtual void _Reset() = 0;
QString m_Cmd1;
QString m_Cmd2;
QString m_Cmd3;
DataDictionary *m_DataDictionary;
private:
bool isExec(QString Cmd)
{
return (Cmd == m_Cmd1) | \
(Cmd == m_Cmd2) | \
(Cmd == m_Cmd3);
}
SpecialExec *m_Next;
};
class MsgCleanCmd : public SpecialExec
{
public:
MsgCleanCmd(){m_Cmd1 = "msgclean";}
protected:
bool Exec(QString Cmd,QString Data,QString &err)
{
int _data = Data.toInt();
if(_data == 1){
m_DataDictionary->SetMisData(MIS_CUSTOM_ALM_MSG,QString(""));
m_DataDictionary->SetMisData(MIS_CUSTOM_ALM_TIMER,0);
}else {
err = Cmd + " cmd data is not 1 ;";
return false;
}
return true;
}
void _Reset(){}
};
class GksdwCmd : public SpecialExec
{
public:
GksdwCmd()
{
m_Cmd1 = "gksdw";
m_Cmd2 = "gspjd";
m_Cmd3 = "gdwcz";
_Reset();
}
protected:
bool Exec(QString Cmd,QString Data,QString &err)
{
if(Cmd == m_Cmd1){
return Cmd1Exec(Data,err);
}else if (Cmd == m_Cmd2) {
return Cmd2Exec(Data,err);
}else if (Cmd == m_Cmd3){
return Cmd3Exec(Data,err);
}
return true;
}
void _Reset()
{
Cmd1ExecEnd = false;
Cmd2ExecEnd = false;
Cmd3ExecEnd = false;
Cmd1Data = 0.0;
Cmd2Data = 0.0;
Cmd3Data = 0.0;
}
private:
bool Cmd1Exec(QString Data,QString &err)
{
bool exec = false;
Cmd1ExecEnd = true;
if(Data.toInt() != 1){
err = m_Cmd1 + " cmd data is not 1 ;";
return false;
}
if(Cmd2ExecEnd){
exec = true;
m_DataDictionary->SetCameraCtlData(CAM_REQ_H_ANGLE,Cmd2Data);
}
if(Cmd3ExecEnd){
exec = true;
m_DataDictionary->SetCameraCtlData(CAM_REQ_V_ANGLE,Cmd3Data);
}
if(exec == false){
err = m_Cmd1 + " err spjd or czjd have not setted ;";
return false;
}
return true;
}
bool Cmd2Exec(QString Data,QString &err)
{
if(Cmd1ExecEnd){
err = m_Cmd2 + " err ksdw is execed ;";
return false;
}
Cmd2Data = Data.toDouble();
Cmd2ExecEnd = true;
return true;
}
bool Cmd3Exec(QString Data,QString &err)
{
if(Cmd1ExecEnd){
err = m_Cmd3 + " err ksdw is execed ;";
return false;
}
Cmd3Data = Data.toDouble();
Cmd3ExecEnd = true;
return true;
}
private:
bool Cmd1ExecEnd;
bool Cmd2ExecEnd;
bool Cmd3ExecEnd;
double Cmd1Data;
double Cmd2Data;
double Cmd3Data;
};
class GsxCmd : public SpecialExec
{
public:
GsxCmd(){
m_Cmd1 = "gs";
m_Cmd2 = "gx";
_Reset();
}
protected:
bool Exec(QString Cmd,QString Data,QString &err)
{
if(Cmd == m_Cmd1){
return Cmd1Exec(Data,err);
}else if(Cmd == m_Cmd2) {
return Cmd2Exec(Data,err);
}
return true;
}
void _Reset()
{
Cmd1ExecEnd = false;
Cmd2ExecEnd = false;
}
private:
bool Cmd1Exec(QString Data,QString &err)
{
if(Cmd2ExecEnd){
err = m_Cmd1 + " err because gx is executed ;";
return false;
}
double CurV = m_DataDictionary->GetCameraCtlData(CAM_CUR_V_VALUE).toDouble();
double Step = m_DataDictionary->GetMisData(MIS_CAMERA_STEP_CAL).toDouble();
m_DataDictionary->SetCameraCtlData(CAM_REQ_V_VALUE,CurV+Step);
Cmd1ExecEnd = true;
return true;
}
bool Cmd2Exec(QString Data,QString &err)
{
if(Cmd1ExecEnd){
err = m_Cmd2 + " err because gs is executed ;";
return false;
}
double CurV = m_DataDictionary->GetCameraCtlData(CAM_CUR_V_VALUE).toDouble();
double Step = m_DataDictionary->GetMisData(MIS_CAMERA_STEP_CAL).toDouble();
m_DataDictionary->SetCameraCtlData(CAM_REQ_V_VALUE,CurV-Step);
Cmd2ExecEnd = true;
return true;
}
private:
bool Cmd1ExecEnd;
bool Cmd2ExecEnd;
};
class GzyCmd : public SpecialExec
{
public:
GzyCmd(){
m_Cmd1 = "gz";
m_Cmd2 = "gy";
_Reset();
}
protected:
bool Exec(QString Cmd,QString Data,QString &err)
{
if(Cmd == m_Cmd1){
return Cmd1Exec(Data,err);
}else if(Cmd == m_Cmd2) {
return Cmd2Exec(Data,err);
}
return true;
}
void _Reset()
{
Cmd1ExecEnd = false;
Cmd2ExecEnd = false;
}
private:
bool Cmd1Exec(QString Data,QString &err)
{
if(Cmd2ExecEnd){
err = m_Cmd1 + " err because gy is executed ;";
return false;
}
double CurV = m_DataDictionary->GetCameraCtlData(CAM_CUR_H_VALUE).toDouble();
double Step = m_DataDictionary->GetMisData(MIS_CAMERA_STEP_CAL).toDouble();
m_DataDictionary->SetCameraCtlData(CAM_REQ_H_VALUE,CurV-Step);
Cmd1ExecEnd = true;
return true;
}
bool Cmd2Exec(QString Data,QString &err)
{
if(Cmd1ExecEnd){
err = m_Cmd2 + " err because gz is executed ;";
return false;
}
double CurV = m_DataDictionary->GetCameraCtlData(CAM_CUR_H_VALUE).toDouble();
double Step = m_DataDictionary->GetMisData(MIS_CAMERA_STEP_CAL).toDouble();
m_DataDictionary->SetCameraCtlData(CAM_REQ_H_VALUE,CurV+Step);
Cmd2ExecEnd = true;
return true;
}
private:
bool Cmd1ExecEnd;
bool Cmd2ExecEnd;
};
class GfdsxCmd : public SpecialExec
{
public:
GfdsxCmd(){
m_Cmd1 = "gfd";
m_Cmd2 = "gsx";
_Reset();
}
protected:
bool Exec(QString Cmd,QString Data,QString &err)
{
if(Cmd == m_Cmd1){
return Cmd1Exec(Data,err);
}else if(Cmd == m_Cmd2) {
return Cmd2Exec(Data,err);
}
return true;
}
void _Reset()
{
Cmd1ExecEnd = false;
Cmd2ExecEnd = false;
}
private:
bool Cmd1Exec(QString Data,QString &err)
{
if(Cmd2ExecEnd){
err = m_Cmd1 + " err because gsx is executed ;";
return false;
}
double CurV = m_DataDictionary->GetCameraCtlData(CAM_CUR_ZOOM_VALUE).toDouble();
double Step = m_DataDictionary->GetMisData(MIS_CAMERA_STEP_CAL).toDouble();
m_DataDictionary->SetCameraCtlData(CAM_REQ_ZOOM_VALUE,CurV+Step);
Cmd1ExecEnd = true;
return true;
}
bool Cmd2Exec(QString Data,QString &err)
{
if(Cmd1ExecEnd){
err = m_Cmd2 + " err because gfd is executed ;";
return false;
}
double CurV = m_DataDictionary->GetCameraCtlData(CAM_CUR_ZOOM_VALUE).toDouble();
double Step = m_DataDictionary->GetMisData(MIS_CAMERA_STEP_CAL).toDouble();
m_DataDictionary->SetCameraCtlData(CAM_REQ_ZOOM_VALUE,CurV-Step);
Cmd2ExecEnd = true;
return true;
}
private:
bool Cmd1ExecEnd;
bool Cmd2ExecEnd;
};
class GosdCmd : public SpecialExec
{
public:
GosdCmd(){
m_Cmd1 = "v1osdty";
m_Cmd2 = "v1osdtp";
_Reset();
}
protected:
bool Exec(QString Cmd,QString Data,QString &err)
{
if(Cmd == m_Cmd1){
return Cmd1Exec(Data,err);
}else if(Cmd == m_Cmd2) {
return Cmd2Exec(Data,err);
}
return true;
}
void _Reset()
{
Cmd1ExecEnd = false;
Cmd2ExecEnd = false;
Cmd1V = 0;
Cmd2V = 0;
}
private:
bool Cmd1Exec(QString Data,QString &err)
{
Cmd1V = Data.toInt();
if(Cmd1V == 1) //本地叠加
{
m_DataDictionary->SetSystemData(SYS_OSD_DEVICE,LOCAL_DEVICE);
}
else if(Cmd1V == 3)//不显示
{
m_DataDictionary->SetSystemData(SYS_OSD_DEVICE,OSD_CLOSE);
}
else if(Cmd1V == 2)//远程叠加
{
if(Cmd2ExecEnd)
{
if(Cmd2V == 1)
{
m_DataDictionary->SetSystemData(SYS_OSD_DEVICE,HK_DEVICE);
}
else if(Cmd2V == 2)
{
m_DataDictionary->SetSystemData(SYS_OSD_DEVICE,WWA_DEVICE);
}
else if(Cmd2V == 3)
{
m_DataDictionary->SetSystemData(SYS_OSD_DEVICE,OTHER_DEVICE);
}
else
{
err = m_Cmd2 + " data : " + QString().number(Cmd2V) + " Unsupported;";
}
}
}
else
{
err = m_Cmd1 + " data : " + Data + " Unsupported;";
return false;
}
Cmd1ExecEnd = true;
return true;
}
bool Cmd2Exec(QString Data,QString &err)
{
Cmd2V = Data.toInt();
if(Cmd1ExecEnd && Cmd1V == 2)
{
if(Cmd2V == 1)
{
m_DataDictionary->SetSystemData(SYS_OSD_DEVICE,HK_DEVICE);
}
else if(Cmd2V == 2)
{
m_DataDictionary->SetSystemData(SYS_OSD_DEVICE,WWA_DEVICE);
}
else if(Cmd2V == 3)
{
m_DataDictionary->SetSystemData(SYS_OSD_DEVICE,OTHER_DEVICE);
}
else
{
err = m_Cmd2 + " data : " + QString().number(Cmd2V) + " Unsupported;";
return false;
}
}
Cmd2ExecEnd = true;
return true;
}
private:
bool Cmd1ExecEnd;
bool Cmd2ExecEnd;
int Cmd1V;
int Cmd2V;
};
class SysRebootCmd : public SpecialExec
{
public:
SysRebootCmd(){
m_Cmd1 = "sysreboot";
_Reset();
}
protected:
bool Exec(QString Cmd,QString Data,QString &err)
{
if(Data.toInt() == 1){
m_DataDictionary->SetMisData(MIS_SYSREBOOT,1);
}else {
err = m_Cmd1 + " err data is not 1 ;";
return false;
}
return true;
}
void _Reset()
{
}
private:
};
class JsonKeyToSys {
public:
JsonKeyToSys(){
m_DataDictionary = DataDictionary::GetInstance();
m_SpecialCmdExec = new MsgCleanCmd;
SpecialExec *Ksdw = new GksdwCmd;
SpecialExec *Sx = new GsxCmd;
SpecialExec *Zy = new GzyCmd;
SpecialExec *Fdsx = new GfdsxCmd;
SpecialExec *SysReboot = new SysRebootCmd;
SpecialExec *osd = new GosdCmd;
m_SpecialCmdExec->AddNextExec(Ksdw);
Ksdw->AddNextExec(Sx);
Sx->AddNextExec(Zy);
Zy->AddNextExec(Fdsx);
Fdsx->AddNextExec(SysReboot);
SysReboot->AddNextExec(osd);
m_SpecialRead = new GosdtyRead;
SpecialRead *osdtp = new GosdtpRead;
m_SpecialRead->AddNextExec(osdtp);
}
private:
enum Access {
RO = 0x1,
WO = 0x2,
RW = RO | WO,
};
#define READ_ACCESS(x) (x & RO)
#define WRITE_ACCESS(x) (x & WO)
typedef struct {
QString Key;
int Index;
enum Access Access;
DataType_t Type;
}KeyToSys_t;
KeyToSys_t m_Tbl[62] = {
{"ei" ,MIS_NET_DEV,RW,STRING_TYPE},
{"eitype" ,MIS_NET_TYPE,RW,INT_TYPE},
{"eip" ,MIS_NET_IP,RW,STRING_TYPE},
{"eipmask" ,MIS_NET_MASK,RW,STRING_TYPE},
{"egate" ,MIS_NET_GATEWAY,RW,STRING_TYPE},
{"edns" ,MIS_NET_DNS,RW,STRING_TYPE},
{"yaddr" ,SYS_SYNC_FACEID_HOST ,RW,STRING_TYPE},
{"yport" ,SYS_SYNC_FACEID_POST ,RW,INT_TYPE},
{"fen" ,SYS_FACEID_ENABLE ,RW,INT_TYPE},
{"fjp" ,SYS_FACEID_JUMP ,RW,INT_TYPE},
{"ft" ,MIS_FACEID_TIMEOUT ,RW,INT_TYPE},
{"v1ip" ,SYS_CAMERA_IP1 ,RW,STRING_TYPE},
{"v1port" ,SYS_CAMERA_PORT1 ,RW,INT_TYPE},
{"v1usr" ,SYS_CAMERA_USERNAME1 ,RW,STRING_TYPE},
{"v1pd" ,SYS_CAMERA_PASSWORD1 ,RW,STRING_TYPE},
{"v1rtsp" ,SYS_CAMERA_URL1 ,RW,STRING_TYPE},
{"v1rtpt" ,SYS_PTZ_PORT ,RW,INT_TYPE},
{"v1osdpt" ,SYS_OSD_PORT ,RW,INT_TYPE},
{"v1osdty" ,1 ,RW,INT_TYPE},
{"v1osdtp" ,1 ,RW,INT_TYPE},
{"v1x" ,SYS_OSD_X_POS ,RW,INT_TYPE},
{"v1y" ,SYS_OSD_Y_POS ,RW,INT_TYPE},
{"v1st" ,MIS_CAMERA_STA1 ,RO,INT_TYPE},
{"v1jmp" ,MIS_DISPLAY_INTERVAL1 ,RW,INT_TYPE},
{"v2ip" ,SYS_CAMERA_IP2 ,RW,STRING_TYPE},
{"v2port" ,SYS_CAMERA_PORT2 ,RW,INT_TYPE},
{"v2usr" ,SYS_CAMERA_USERNAME2 ,RW,STRING_TYPE},
{"v2pd" ,SYS_CAMERA_PASSWORD2 ,RW,STRING_TYPE},
{"v2rtsp" ,SYS_CAMERA_URL2 ,RW,STRING_TYPE},
{"v2st" ,MIS_CAMERA_STA2 ,RO,INT_TYPE},
{"v2jmp" ,MIS_DISPLAY_INTERVAL2 ,RW,INT_TYPE},
{"v3ip" ,SYS_CAMERA_IP3 ,RW,STRING_TYPE},
{"v3port" ,SYS_CAMERA_PORT3 ,RW,INT_TYPE},
{"v3usr" ,SYS_CAMERA_USERNAME3 ,RW,STRING_TYPE},
{"v3pd" ,SYS_CAMERA_PASSWORD3 ,RW,STRING_TYPE},
{"v3rtsp" ,SYS_CAMERA_URL3 ,RW,STRING_TYPE},
{"v3st" ,MIS_CAMERA_STA3 ,RO,INT_TYPE},
{"v3jmp" ,MIS_DISPLAY_INTERVAL3 ,RW,INT_TYPE},
{"gen" ,MIS_ALIGN_STA ,RW,INT_TYPE},
{"gqj" ,MIS_CAMERA_GUN_STA ,RW,INT_TYPE},
{"gbc" ,MIS_CAMERA_STEP ,RW,INT_TYPE},
{"gbs" ,MIS_CAMERA_MAX_ZOOM ,RW,INT_TYPE},
{"gjl" ,MIS_CAMERA_MAX_DISTANCE,RW,INT_TYPE},
{"gsp" ,MIS_H_ANGLE_INIT ,RW,FLOAT_TYPE},
{"gczjd" ,MIS_ALIGN_V_ANGLE ,RW,FLOAT_TYPE},
{"gczjl" ,MIS_ALIGN_V_HEIGHT ,RW,FLOAT_TYPE},
{"ggdxs" ,MIS_ALIGN_V_HEIGHT_RATIO,RW,FLOAT_TYPE},
{"gjx" ,MIS_CAMERA_IMAGE ,RW,INT_TYPE},
{"gpl" ,MIS_FOLLOW_HOOK_FRQ ,RW,INT_TYPE},
{"gs" ,1 ,WO,INT_TYPE},
{"gx" ,1 ,WO,INT_TYPE},
{"gz" ,1 ,WO,INT_TYPE},
{"gy" ,1 ,WO,INT_TYPE},
{"gfd" ,1 ,WO,INT_TYPE},
{"gsx" ,1 ,WO,INT_TYPE},
{"gspjd" ,CAM_CUR_H_ANGLE ,RO,FLOAT_TYPE},
{"gdwcz" ,CAM_CUR_V_ANGLE ,RO,FLOAT_TYPE},
{"gksdw" ,1 ,WO,INT_TYPE},
{"msg" ,MIS_CUSTOM_ALM_MSG ,RW,STRING_TYPE},
{"msgtime" ,MIS_CUSTOM_ALM_TIMER ,RW,INT_TYPE},
{"msgclean" ,1 ,WO,INT_TYPE},
{"sysreboot" ,1 ,WO,INT_TYPE},
};
DataDictionary *m_DataDictionary;
SpecialExec *m_SpecialCmdExec;
SpecialRead *m_SpecialRead;
private:
bool ReadSysData(int Index,QString &Data)
{
bool Result = true;
switch(Index & DATA_INDEX_MASK){
case SYS_INDEX_BASE:
Data = m_DataDictionary->GetSystemData((SystemDataIndex_t)Index);
break;
case MIS_INDEX_BASE:
Data = m_DataDictionary->GetMisData((MisDataIndex_t)Index);
break;
case CAMERA_CTL_INDEX_BASE:
Data = m_DataDictionary->GetMisData((MisDataIndex_t)Index);
break;
default:
Result = false;
break;
}
return Result;
}
bool WriteSysData(int Index,QString Data)
{
bool Result = true;
switch(Index & DATA_INDEX_MASK){
case SYS_INDEX_BASE:
m_DataDictionary->SetSystemData((SystemDataIndex_t)Index,Data);
break;
case MIS_INDEX_BASE:
m_DataDictionary->SetMisData((MisDataIndex_t)Index,Data);
break;
case CAMERA_CTL_INDEX_BASE:
m_DataDictionary->SetMisData((MisDataIndex_t)Index,Data);
break;
default:
Result = false;
break;
}
return Result;
}
public:
bool Read(QJsonObject &Ob,QString &err)
{
bool Result = false;
if(!Ob.contains("k"))
{
err = "data format err ;";
return Result;
}
QString k = Ob["k"].toString();
for(int i = 0;i < sizeof (m_Tbl)/sizeof (KeyToSys_t);i++)
{
if(m_Tbl[i].Key == k && READ_ACCESS(m_Tbl[i].Access))
{
Ob.remove("v");
QString data ;
err = "";
Result = ReadSysData(m_Tbl[i].Index,data);
if(Result == false)
{
Result = m_SpecialRead->CmdExec(k,data,err);
}
if(Result && err.isEmpty()){
if(m_Tbl[i].Type == STRING_TYPE){
Ob.insert("v",data);
}else if(m_Tbl[i].Type == INT_TYPE){
Ob.insert("v",data.toInt());
}else if(m_Tbl[i].Type == FLOAT_TYPE){
Ob.insert("v",data.toDouble());
}
}
break;
}
}
if(!Result)
{
err = "data " + k + " Unsupported or No access";
}
return Result;
}
bool Write(QJsonObject &Ob,QString &err)
{
bool Result = false;
if(!Ob.contains("k") || !Ob.contains("v"))
{
err = "frm format err , have no \"k\" or \"v\";";
return Result;
}
QString k = Ob["k"].toString();
QString data = "";
for(int i = 0;i < sizeof (m_Tbl)/sizeof (KeyToSys_t);i++)
{
if(m_Tbl[i].Key == k )
{
if(m_Tbl[i].Type == STRING_TYPE && Ob.value("v").isString()){
data = Ob.value("v").toString();
}else if(m_Tbl[i].Type == INT_TYPE && Ob.value("v").isDouble()){
data.setNum(Ob.value("v").toInt());
}else if(m_Tbl[i].Type == FLOAT_TYPE && Ob.value("v").isDouble()){
data.setNum(Ob.value("v").toDouble());
}else{
err = "data format err ,type is error;";
break;
}
if(WRITE_ACCESS(m_Tbl[i].Access))
Result = WriteSysData(m_Tbl[i].Index,data);
break;
}
}
if(!Result)
{
Result = m_SpecialCmdExec->CmdExec(k,data,err);
if(Result && err.isEmpty()){
err = "data " + k + " Unsupported or No access";
}
}
return Result;
}
void WriteReset(){ m_SpecialCmdExec->Reset(); }
};
class JsonAnalysis
{
public:
JsonAnalysis();
QByteArray Analysis(JsonProType_t T,QByteArray Data);
private:
QByteArray BBCloudCmdAnalysis(QByteArray Data);
int BBCloudCmdRead(QJsonArray &Data,QString &errMsg);
int BBCloudCmdWrite(QJsonArray Data,QString &errMsg);
void BBCloudResult(QJsonObject &Ob, int cmd, int code = 0, QString Msg = QString(""));
void BBCloudAddDataResult(QJsonObject &Ob,QJsonArray Arr);
int GetCmd(QJsonObject Ob);
bool GetData(QJsonObject Ob,QJsonArray &Arr,QString &err);
JsonKeyToSys m_JsonKeyToSys;
};
#endif // JSONANALYSIS_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/qinxude/rk3568ui.git
[email protected]:qinxude/rk3568ui.git
qinxude
rk3568ui
rk3568ui
master

搜索帮助