qt/LedOK/globaldefine.h
2022-08-25 18:37:24 +08:00

339 lines
13 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef GLOBALDEFINE_H
#define GLOBALDEFINE_H
#include <QString>
#define MACRO_FENGEFU "/"
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonDocument>
#include <communication/hpptclient.h>
enum {
MainPage_DeviceManager = 0,
MainPage_ProgManager,
MainPage_Setting,
MainPage_LoraScreen,
MainPage_End,
};
enum {
ENUM_IMPORT_DLG=1,
ENUM_EXPORT_DLG=2,
ENUM_DELETE_DLG=3,
ENUM_SELECT_NETWORK=5,
};
#define STREAM_SYNC_HEAD_NUM 3
#define STREAM_SYNC_HEAD 0x7e
typedef struct _SYSTIMER
{
int y; //获取年份
int m; //获取当前月份
int d; //获得几号
int h; //获取当前为几时
int mm; //获取分钟
int s; //获取秒
int w; //获取星期几注意1为星期天7为星期六
}SYSTIMER,*P_SYSTIMER;
typedef struct _RESTORE_IP
{
char cNewIp[20];
char cMask[20];
char cGateway[20];
char cDns[20];
// char cLocalIp[20];
}RESTORE_IP,*P_RESTORE_IP;
typedef struct _STREAM_PACKET
{
unsigned char SyncHead[STREAM_SYNC_HEAD_NUM];
unsigned char ucCommType;
char ucSerialCode[20];
unsigned int iLength;
char pDataBuffer[2049];
}STREAM_PACKET,* P_STREAM_PACKET;
enum _NET_COMMU_TYPE
{
COMMAND_SAVE_ADVANCE_PARAM_NOT_RESET=0x40,
COMMAND_ONLY_RESET_CARD_IP=0X43,
COMMAND_SET_M31_DOUBLE_HUB=0X44,
COMMAND_CONNECT_COLSE =0x7A,
COMMAND_UPGRADE = 0x80,
COMMAND_SIGNLE_FILE_UPGRADE ,
COMMAND_LOOPCHECK ,
COMMAND_VERIFY_CLOCK ,
COMMAND_SCREEN_OPERATOR,//0x84
COMMAND_SET_SERIAL_NUM,
NET_COMMU_TYPE_PLAY_IN_LINE , // 网络同步在线播放.
NET_COMMU_TYPE_PREVIEW_IN_LINE, // 网络在线预览.
NET_COMMU_TYPE_UPGRADE_SYSTEM, // 系统升级.
NET_COMMU_TYPE_RECOVER_SYSTEM, // 系统还原到上一次正确的启动.
SCREEN_OPERATOR_COMM_PARAMS_SAVE, // 参数保存.
NET_COMMU_TYPE_COMM_EXIT,//普通退出,不重启
NET_COMMU_TYPE_AUDIO_PLAY,//0X8C
NET_COMMU_TYPE_IO,
NET_COMMU_TYPE_IO_CHECK,
NET_COMMU_TYPE_LIMITE_TIME,
NET_COMMU_TYPE_SYSTEM_BROADCAST,//0X90
NET_COMMU_TYPE_REALTIME_INSERT_PLAY,
//NET_COMMU_TYPE_SHANSUO_INSERT_PLAY,
NET_COMMU_TYPE_MODIFY_SERIAL_ID,
NET_COMMU_TYPE_KERNEL_UPGRADE_SYSTEM,
NET_COMMU_TYPE_UPGRADE_FINISHED_EXIT,
NET_COMMU_TYPE_REAL_TIME_INSERT_PLAY_WITH_LIST_EXIT,
NET_COMMU_TYPE_ZNSZ,// 智能设置命令.
NET_COMMU_TYPE_SELECT_PROGRAM_PLAY,// 选节目播放.0x97
NET_COMMU_TYPE_SELECT_MULI_PROGRAM_PLAY,//98选播多个节目
NET_COMMU_TYPE_GET_PROGRAM_NAME,//99获取所有节目的名称
NET_COMMU_TYPE_GET_CUR_PLAY_STATUS,//9a查询当前播放的详细信息
NET_COMMU_TYPE_POWER_PANEL_ON_OR_OFF,//9b开关大屏幕
NET_COMMU_TYPE_ADJUST_BRIGHTNESS,//9c调节亮度
NET_COMMU_TYPE_GET_SYSTEM_STATUS,//9d获取系统状态
NET_COMMU_TYPE_VERIFY_SIGN,//校验签名9e
NET_COMMU_TYPE_SET_WEB_SERVER_PARAM,//配置web服务器参数
NET_COMMU_TYPE_GET_WEB_SERVER_PARAM,//a0
NET_COMMU_TYPE_SET_WIFI_PARAM,//a1配置wifi参数
NET_COMMU_TYPE_GET_WIFI_PARAM,//a2获取wifi参数
NET_COMMU_TYPE_SCAN_AP_WIFI_PARAM,//a3获取ap热点的名称
NET_COMMU_TYPE_GET_ANDROID=0xa4,
NET_COMMU_TYPE_INSTALL_APK=0xa5,
NET_COMMU_TYPE_UNINSTALL_APK=0xa6,
NET_COMMU_TYPE_SET_DNS=0xa7,
NET_COMMU_TYPE_GET_DNS=0xa8,
NET_COMMU_TYPE_SET_PROXY=0xa9,
NET_COMMU_TYPE_GET_PROXY=0xaa,
NET_COMMU_TYPE_SET_ANDROID_COMMUNICATION=0xab,
NET_COMMU_TYPE_GET_ANDROID_COMMUNICATION=0xac,
NET_COMMU_TYPE_GET_SIM_STATUS=0xad,
NET_COMMU_TYPE_GET_APN_PARAM=0xae,
NET_COMMU_TYPE_GET_APK_VERSION=0xaf,
NET_COMMU_TYPE_SET_REALTIME_PARAM=0xb0,
NET_COMMU_TYPE_GET_REALTIME_PARAM=0xb1,
NET_COMMU_TYPE_SET_REALTIME_LINSTEN_PARAM=0xb2,
NET_COMMU_TYPE_GET_REALTIME_LINSTEN_PARAM=0xb3,
NET_COMMU_TYPE_SET_HUAWEI_4G=0xB4,
NET_COMMU_TYPE_GET_HUAWEI_4G=0xB5,
NET_COMMU_TYPE_CLEAR_ANDROID_PROGRAM=0xB6,
NET_COMMU_TYPE_SET_AP_PARAM=0xB7,
NET_COMMU_TYPE_GET_AP_PARAM=0xB8,
GET_REALY_RESOLUTION=0xB9,
GET_REALY_ANDROID_FIRMWARE_INFO=0xBA,
NET_COMMU_TYPE_NUM,
COMMAND_UPGRADE_ANSWER =0xC0,
COMMAND_SIGNLE_FILE_UPGRADE_ANSWER ,
COMMAND_LOOPCHECK_ANSWER ,
COMMAND_VERIFY_CLOCK_ANSWER ,
COMMAND_SCREEN_OPERATOR_ANSWER,
COMMAND_SET_SERIAL_NUM_ANSWER,
NET_COMMU_TYPE_PLAY_IN_LINE_ANSWER , // 网络同步在线播放.
NET_COMMU_TYPE_PREVIEW_IN_LINE_ANSWER, // 网络在线预览.
NET_COMMU_TYPE_UPGRADE_SYSTEM_ANSWER, // 系统升级.
NET_COMMU_TYPE_RECOVER_SYSTEM_ANSWER, // 系统还原到上一次正确的启动.
SCREEN_OPERATOR_COMM_PARAMS_SAVE_ANSWER,
NET_COMMU_TYPE_COMM_EXIT_ANSWER,
NET_COMMU_TYPE_AUDIO_PLAY_ANSWER,//0XcC
NET_COMMU_TYPE_IO_ANSWER,
NET_COMMU_TYPE_IO_CHECK_ANSWER,
NET_COMMU_TYPE_LIMITE_TIME_ANSWER,
////
NET_COMMU_TYPE_SYSTEM_BROADCAST_ANSWER,
NET_COMMU_TYPE_REALTIME_INSERT_PLAY_ANSWER,
NET_COMMU_TYPE_REALTIME_INSERT_PLAY_WITH_GLINT_ANSWER , //带闪烁功能的实时插播
NET_COMMU_TYPE_KERNEL_UPGRADE_SYSTEM_ANSWER,
NET_COMMU_TYPE_UPGRADE_FINISHED_EXIT_ANSWER,//0xd4
NET_COMMU_TYPE_REAL_TIME_INSERT_PLAY_WITH_LIST_EXIT_ANSWER,
NET_COMMU_TYPE_ZNSZ_ANSWER,// 智能设置命令.
NET_COMMU_TYPE_SELECT_PROGRAM_PLAY_ANSWER,//0x97 选节目播放.
NET_COMMU_TYPE_SELECT_MULI_PROGRAM_PLAY_ANSWER,
NET_COMMU_TYPE_GET_PROGRAM_NAME_ANSWER,
NET_COMMU_TYPE_GET_CUR_PLAY_STATUS_ANSWER,
NET_COMMU_TYPE_POWER_PANEL_ON_OR_OFF_ANSWER,
NET_COMMU_TYPE_ADJUST_BRIGHTNESS_ANSWER,
NET_COMMU_TYPE_GET_SYSTEM_STATUS_ANSWER,//获取系统状态
NET_COMMU_TYPE_NUM_ANSWER,
COMMAND_CONNECT_COLSE_ANSWER
};
extern bool gTextAntialiasing;
extern bool gShowLoraScreen;
extern bool isTextValid(const QString &strIP);
extern quint64 dirFileSize(const QString &path);
extern bool isFileExist(QString fullFileName);
extern QString getRandomString(int length);
extern void HttpPostByTypeJsonObject(HpptClient *pHpptClient, QString strUrl,QJsonObject json);
extern bool copyDir(const QString &source, const QString &destination, bool override);
extern unsigned char GetCheckCodeIn8(unsigned char * pBuffer,unsigned int uiSize);
enum _ENUM_CONTRL_WIDGET {
Setting_Bright=0,
Setting_PowerControl,
Setting_NetCfg,
Setting_VerifyClock,
Setting_Encrypt,
Setting_HDMI,
Setting_Volume,
Setting_Advanced,
Setting_Test,
Setting_End,
};
QNetworkRequest netReq(const QString &url, int = QNetworkRequest::DefaultTransferTimeoutConstant, const QVariant &contentType = QVariant::Invalid);
inline QNetworkRequest reqForJson(const QString &url) {
return netReq(url, 10000, "application/json");
}
QString parseReplyJson(QNetworkReply *, QJsonDocument * = 0);
QString checkReplyForJson(QNetworkReply *, QJsonDocument * = 0);
#define Def_CtrlReqPre \
waitingDlg->show();\
auto card = gSelCards->at(0);\
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));
#define Def_CtrlSetReqAfter \
QString err = checkReplyForJson(reply);\
if(! err.isEmpty()) {\
waitingDlg->close();\
QMessageBox::critical(gMainWin, tr("Error"), err);\
return;\
}\
waitingDlg->success();
#define Def_CtrlSingleGetReply \
QJsonDocument json;\
QString err = checkReplyForJson(reply, &json);\
if(! err.isEmpty()) {\
waitingDlg->close();\
QMessageBox::critical(gMainWin, tr("Error"), err);\
return;\
}
#define Def_CtrlSetMulti(tip) \
auto reply = Tools::netManager().post(reqForJson("http://"+card->m_strCardIp+":2016/settings"), QJsonDocument{json}.toJson(QJsonDocument::Compact));\
connect(reply, &QNetworkReply::finished, this, [reply, card] {\
QString err = checkReplyForJson(reply);\
gFdResInfo->append(card->m_strCardId+" "+tip+" "+(err.isEmpty()?QCoreApplication::translate("Def","Success"):err));\
});
#define DDDef_HttpCheckJsonErr\
auto error = reply->error();\
if(error != QNetworkReply::NoError) {\
auto errStr = reply->errorString();\
if(error==QNetworkReply::OperationCanceledError) {\
error = QNetworkReply::TimeoutError;\
errStr = QCoreApplication::translate("Def","Connection Timeout");\
}\
if(waitingDlg) waitingDlg->close();\
QMessageBox::critical(gMainWin, QCoreApplication::translate("Def","Error"), QString::number(error)+" "+QMetaEnum::fromType<QNetworkReply::NetworkError>().valueToKey(error)+" "+errStr);\
return;\
}\
auto status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();\
if(status != 200) {\
if(waitingDlg) waitingDlg->close();\
QMessageBox::critical(gMainWin, QCoreApplication::translate("Def","Error"), QString::number(status)+" "+reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString());\
return;\
}\
auto resp = reply->readAll();\
QJsonParseError jsonErr;\
QJsonDocument json = QJsonDocument::fromJson(resp, &jsonErr);\
if(jsonErr.error != QJsonParseError::NoError) {\
if(waitingDlg) waitingDlg->close();\
QMessageBox::critical(gMainWin, QCoreApplication::translate("Def","Error"), "JsonParseError "+jsonErr.errorString());\
return;\
}\
if(! json["success"].toBool()) {\
if(waitingDlg) waitingDlg->close();\
QMessageBox::warning(gMainWin, QCoreApplication::translate("Def","Tip Info"), QCoreApplication::translate("Def","Fail"));\
return;\
}
#define CHECK_CARD_SELECTED \
if(m_pLedlist!=nullptr) {\
if(m_pLedlist->count()==0 || (m_pLedlist->count()==1 && m_pLedCard==nullptr)) {\
QMessageBox::information(gMainWin, tr("Tip"), tr("NoSelectedController"));\
return;\
}\
}
#define MACRO_DEFINE_TIPDLG_FUCN(TIP,SUCCESS,FAILED) \
if(m_pLedlist!=nullptr) {\
if(m_pLedlist->count()<=1) {\
if(m_pLedCard!=nullptr) {\
HttpPostByTypeJsonObject(pHpptClient,m_strUrl,json);\
if(m_PostingDlg==nullptr) {\
m_PostingDlg = new LoEmptyDialog(this);\
connect(m_PostingDlg,SIGNAL(sigClose()),this,SLOT(DeletePostingDlg()));\
connect(m_pGetAskTimer,SIGNAL(timeout()),m_PostingDlg,SLOT(TimerOutUnlock()));\
m_PostingDlg->lock(TIP,SUCCESS,FAILED);\
m_pGetAskTimer->start(5000);\
m_PostingDlg->exec();\
}\
}\
} else emit sigSend(json,TIP);\
}
#define MACRO_DEFINE_TIPDLG_ALL_FUCN(READBACK,SUCCESS,FAILED) \
if(m_pLedCard!=nullptr)\
{\
if(m_PostingDlg==nullptr)\
{\
m_PostingDlg = new LoEmptyDialog(this);\
connect(m_PostingDlg,SIGNAL(sigClose()),this,SLOT(DeletePostingDlg()));\
connect(m_pGetAskTimer,SIGNAL(timeout()),m_PostingDlg,SLOT(TimerOutUnlock()));\
m_PostingDlg->lock(READBACK+" "+m_pLedCard->m_strCardId,SUCCESS,FAILED);\
m_pGetAskTimer->start(5000);\
m_PostingDlg->exec();\
}\
}\
#define MARCO_DEFINE_CONTROL_FUNC2(PARENT,PARENT1) \
pHpptClient = new HpptClient(this);\
connect(pHpptClient,SIGNAL(httpPostRspReady(QString , QString , QByteArray )),this,SLOT(OnProHttpResponse(QString , QString , QByteArray)));\
pHpptClientAll = new HpptClient(this);\
connect(pHpptClientAll,SIGNAL(httpPostRspReady(QString , QString , QByteArray )),this,SLOT(OnProHttpResponseAll(QString , QString , QByteArray)));\
m_pGetAskTimer=new QTimer(this);\
connect(PARENT1,SIGNAL(sigSwitchIndexChanged(int)),this,SLOT(OnControlTypeSwitchIndexChanged(int)));\
connect(PARENT,SIGNAL(sigSelectedDeviceList(QList<LedCard *> *)),this,SLOT(onSelectedDeviceList(QList<LedCard *> *)));\
connect(this,SIGNAL(sigSend(QJsonObject &,QString)),PARENT,SLOT(OnControlSendJson(QJsonObject &,QString)));\
onSelectedDeviceList(list);
#define MACRO_ASKTIME_STOP \
if(m_pGetAskTimer && m_pGetAskTimer->isActive()) m_pGetAskTimer->stop();
#define MACRO_POSTING_DLG_UNLOCK \
if(m_PostingDlg && m_PostingDlg->getLockStatus()) m_PostingDlg->unlock();
#define MACRO_DEFINE_CONTROL_FUNC3 \
if(m_pLedlist!=nullptr)\
{\
if(m_pLedlist->count()==1)\
{\
m_pLedCard=list->at(0);\
m_strUrl="http://"+m_pLedCard->m_strCardIp+":2016/settings";\
if(m_oldLedlist!=m_pLedCard&&m_bSelected==true)\
{\
m_oldLedlist=m_pLedCard;\
onReadbackAllThisPage();\
}\
}\
}
typedef struct _ST_ANSY_PROGRAM_PACKET
{
unsigned char SyncHead[3];
unsigned char ucCommType;
int iBaoLiu;
unsigned int iLength;
unsigned char pDataBuffer[20];
}ST_ANSY_PROGRAM_PACKET,*P_ST_ANSY_PROGRAM_PACKET;
#endif // GLOBALDEFINE_H