#ifndef DOGTHREAD_H
#define DOGTHREAD_H

#include <QThread>
#include <QDateTime>
#include <QStringList>
#include <QTcpSocket>
#include <QFile>
#include <QByteArray>
#include <stdio.h>

#define daefile "/opt/db/daemon.cfg"

typedef unsigned char * POINTER;
typedef unsigned long int UINT4;
typedef struct {
 UINT4 state[4];         /* state (ABCD) */
 UINT4 count[2];  /* number of bits, modulo 2^64 (lsb first) */
 unsigned char buffer[64];       /* input buffer */
} MD5_CTX;

class dogThread : public QThread
{
    Q_OBJECT
public:
    explicit dogThread(QObject *parent = 0, QStringList params=QStringList());
    void start_app();
    void chk_version();
    int mk_verqry(unsigned char *cmd);
    int mk_proqry(unsigned char *cmd, int idx);
    bool check_frame(QByteArray rtn, int idx, FILE *fd);
    void set_termtime();
    void save_cfg();
    void chk_file();
    bool load_param();
    void chk_param(char *buf);
    void trim(char *buf, char *dat);
    void run();

signals:

public slots:

private:
    QStringList Params;
    uint start_t;
    int start_h;
    QTcpSocket *so;
    unsigned long Length,t_Length;
    MD5_CTX context;
    unsigned char Major,Minor,t_Major,t_Minor;
    char Checksum[33],t_Checksum[33],t_DeviceTypeId[40];
    time_t UpTime,t_UpTime;
    bool runFlag;
};

#endif // DOGTHREAD_H
