Index: sources/cloudsync/CloudSyncController.h =================================================================== diff -u -r27cc308ff5113a9386899d3c8f8b29962a8498e1 -r928a1ed5d70358fc00c49df45725f989d16c370e --- sources/cloudsync/CloudSyncController.h (.../CloudSyncController.h) (revision 27cc308ff5113a9386899d3c8f8b29962a8498e1) +++ sources/cloudsync/CloudSyncController.h (.../CloudSyncController.h) (revision 928a1ed5d70358fc00c49df45725f989d16c370e) @@ -1,13 +1,13 @@ /*! * - * Copyright (c) 2021-2022 Diality Inc. - All Rights Reserved. + * Copyright (c) 2021-2023 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file CloudSyncController.h * \author (last) Behrouz NematiPour - * \date (last) 13-Dec-2021 + * \date (last) 19-Dec-2022 * \author (original) Behrouz NematiPour * \date (original) 14-Oct-2021 * @@ -68,24 +68,59 @@ quint64 _seq = 0; + bool _deviceInfoStop = true; + const qint8 _deviceInfoSecs = 1; // in seconds is used for the DG serial response message, if DG is detached UI will timeout after a second and will send the message regardless. + qint8 _deviceInfoWait = 0; + QString _deviceInfoHD = ""; + QString _deviceInfoDG = ""; + QString _deviceInfoUI = ""; + + enum Errors_Enum { - eError_OK , - eError_Count , - eError_Timestamp , - eError_Sequence , - eError_CRC , - eError_MessageID , - eError_ParamCount , - eError_Parameter , + // CS : 900 - 949 + // UI : 950 - 999 + eError_Unknown = 900, // Unknown error, initial error before error check - eError_NoHistory , - eError_LogFolder , - eError_LogFileInp , + // CS to UI Error start + eError_Registration = 901, + eError_TxReport = 902, + + + // UI to CS Error start + // eError_UI_Base = 950, // No Used + eError_HeaderCount = 951, + eError_Timestamp = 952, + eError_Sequence = 953, + eError_CRC = 954, + eError_MessageID = 955, + eError_InvalidID = 956, + eError_ParamCount = 957, + eError_ParamMismatch = 958, + eError_ParamMissing = 959, + + eError_NoHistory = 960, + eError_Duplicate = 961, + + eError_LogFolder = 962, + eError_LogFileInp = 963, + + eError_CredentialMake = 964, // the UI vault folder for cloudsync credentials can't be created. + eError_CredentialFile = 965, // the credential files sent to UI can't be find or read or doesn't exist.. + eError_CredentialCopy = 966, // the credential files sent to UI can't be copied to UI vault. + eError_CredentialRemove = 967, // the credential files sent to UI can't be removed. + eError_CredentialEmpty = 968, // the UI folder doesn't have credential files. + + eError_TxCodeNoParam = 969, // the received Tx Code not provided + eError_TxCodeEmpty = 970, // the received Tx Code is empty + + eError_OutFileEmpty = 971, // Out file has changed from CS2UI but the content is empty. + + eError_NotRegistered = 972, // avoid sending any message other than the device registration, when device is not registered. }; typedef QHash MessageList; - MessageList _lastReceivedData ; // sent message history for later send upon request. + MessageList _uiHistory ; // sent message history for later send upon request. enum Message_Enum { eMessage_Timestamp , @@ -98,58 +133,145 @@ typedef QStringList Params; struct Message { - qint64 timestamp = 0; + quint64 timestamp = 0; quint32 sequence = 0; quint8 crc = 0; qint32 id = 0; - qint64 paramCount = 0; + quint32 paramCount = 0; Params params { }; }; + enum Entity_Start_Index { + eUI = 1000, + eCS = 2000, + }; + enum MessageID_Enum { - eMessageID_DeviceInfo = 101, // CS asks for device info and UI sends back - eMessageID_WriteCredentials = 102, // CS asks to store credential and UI stores/confirms - eMessageID_ReadCredentials = 103, // CS asks for credentials and UI reads/sends - eMessageID_ResetFactory = 104, // CS asks for factory reset [no UI ack back yet] + eMessageID_Start = 0, + // // [ #1( ID ) <-> #2( ID ) ] Description ( #1 Requests and #2 responses ) - eMessageID_DeviceState = 201, // CS asks for device state and UI finds the history/sends - eMessageID_PatientID = 202, // [No CS req defined] UI sends the patient ID - eMessageID_TxReport = 203, // [No CS req defined] UI sends the Tx report - eMessageID_DeviceReport = 204, // [No CS req defined] UI sends the device report + eMessageID_DeviceRegister = 1, // [ UI(1001) -> CS( ) ] Device Registration Request + eMessageID_DeviceInfo = 2, // [ CS(2002) <-> UI(1002) ] Device information Request + eMessageID_CredentialsSave = 3, // [ CS(2003) -> UI( ) ] Save Credentials Request + eMessageID_CredentialsSend = 4, // [ CS(2004) <-> UI(1004) ] Send Credentials Request + eMessageID_ResetFactory = 5, // [ CS(2005) <-> UI(1005) ] Reset Factory Request + // Deployment + eMessageID_DeviceState = 6, // [ CS(2006) <-> UI(1006) ] Device State Request + // Tx Report + eMessageID_TxReport = 7, // [ UI(1007) -> CS(2007) ] TxReport Notify + // Tx Code + eMessageID_TxCodeDisplay = 8, // [ CS(2008) -> UI( ) ] Display TxCode Request - eMessageID_HeartBeat = 900, // CS sends the periodic Hb and UI can set the interval + // + // Subject to change so has been commented out for now + // + // eMessageID_PatientID = 202, // [No CS req defined] UI sends the patient ID + // eMessageID_DeviceReport = 204, // [No CS req defined] UI sends the device report + // eMessageID_HeartBeat = 900, // CS sends the periodic Hb and UI can set the interval + + eMessageID_Error = 999, // [ CS(2000) <-> UI(1000) ] Error Report + + eMessageID_Count }; + QHash paramCount { + { eMessageID_CredentialsSave , 3 }, + { eMessageID_TxCodeDisplay , 1 }, + { eMessageID_Error , 4 }, + }; + + enum DeviceInfo_Enum { + eDeviceInfo_Ix = 0, // received message data index of each HD, DG. Data index 0 is always the info. + eDeviceInfo_HD = 0, // stored index in the UI history. + eDeviceInfo_DG = 1, // stored index in the UI history. + eDeviceInfo_UI = 2, // stored index in the UI history. + }; + protected: void timerEvent(QTimerEvent *event) override; + bool event(QEvent* vEvent) override; public slots: bool init(); bool init(QThread &vThread); + void quit(); private slots: - void quit(); + void onWatchFileChange (const QString &vFile); + void onActionReceive (GuiActionType vAction, const QVariantList &vData); + void onTreatmentLogSave(const QString &vDeviceID , const QString &vPatientID , const QString &vFileName ); + void onInitComplete (); - void onWatchFileChange (const QString &vFile); - void onActionReceive (GuiActionType vAction, const QVariantList &vData); - void onTreatmentLogSave (const QString &vPatientID , - const QString &vDeviceID , - const QString &vFileName ); +signals: + void didInitComplete (); + void didTxCodeReceive (const QString &vTxCode); private: void initConnections(); void initThread(QThread &vThread); void quitThread(); - void checkDate (); - bool addCSBuffWatch(); - bool sendUIResponse (const QString &vContent); - bool sendUIBuff (const QString &vData); - bool sendUIHistory (qint32 vAction); - bool interpret(const QString &vContent, Message &vMessage); + quint8 generateCRC (quint64 vSecSinceEpoch, quint64 vSeq, const QStringList &vDataList); + bool validateCRC () { return true; } // has not been implemented/decided yet + void testWatchBuffDate (); + bool interpret (const QString &vContent, Message &vMessage); + + bool addCSBuffWatch (); + + QStringList makeUIBuff (const qint32 vMessageID , const QStringList &vPrm = {}); + + bool isDuplicate (const qint32 vMessageID , const QStringList &vData); + + bool sendUIResponse (const QString &vContent ); + bool sendUIBuff (const QStringList &vData ); + bool saveUIHistory (const qint32 vAction , const QVariantList &vData); + bool sendUIHistory (const qint32 vAction ); + bool sendMessage (const Message &vMessage ); + + bool writeInpFile (const QString &vInpBuff ); + QString toText (Errors_Enum vErrorID); QString toInfo (Errors_Enum vErrorID, const QVariantList &vInfoItems); void toLog (Errors_Enum vErrorID, const QVariantList &vInfoItems); + void errorOut (Errors_Enum vErrorID, const QVariantList &vInfoItems); + + qint32 UI2CS (qint32 vID) { return vID + eUI ; } + qint32 CS2UI (qint32 vID) { return abs(vID - eCS); } + + // error + bool sendError (); // eMessageID_Error + + // device information + bool saveDeviceInfo (GuiActionType vAction, const QVariantList &vData); // eMessageID_DeviceInfo + bool saveDeviceInfoTimeOut (); // eMessageID_DeviceInfo + bool sendDeviceInfo (); // eMessageID_DeviceInfo + void testDeviceInfoWait (); + void stopDeviceInfoWait (); + void initDeviceInfoWait (); + + // device registration request + bool sendDeviceRegister (); // eMessageID_DeviceRegister + bool testDeviceRegister (); // eMessageID_DeviceRegister + bool isRegistered (); + + // device state report + bool saveDeviceState (const QVariantList &vData); + bool sendDeviceState (); // eMessageID_DeviceState + + // Tx Report + void testPendingTxReports (); // eMessageID_TxReport + + // reset Factory + bool doResetFactory (); // eMessageID_ResetFactory + bool sendResetFactory (); // eMessageID_ResetFactory + + bool sendCredentialsSave (const Message &vMessage); // eMessageID_SaveCredentials + bool sendCredentialsSend (); // eMessageID_SendCredentials + bool sendCredentialsResponse(); + + bool sendTxCodeDisplay (const Message &vMessage); // eMessageID_TxCodeDisplay + + bool errorHandler (const Message &vMessage); // eMessageID_Error };