75 lines
1.5 KiB
C++
75 lines
1.5 KiB
C++
#ifndef FILETRANSECEIVER_H
|
|
#define FILETRANSECEIVER_H
|
|
|
|
#include <QObject>
|
|
#include <QThread>
|
|
#include<stdio.h>
|
|
#include<sys/types.h>
|
|
#include<sys/socket.h>
|
|
#include<netinet/in.h>
|
|
#include<arpa/inet.h>
|
|
#include<string.h>
|
|
#include<stdlib.h>
|
|
#include<unistd.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
#include <QMessageBox>
|
|
#include <QDebug>
|
|
#include <QFile>
|
|
#define DOC_DIR "/home/plg/doc"
|
|
#define SEARCH 100
|
|
#define DOWN 200
|
|
#define END 500
|
|
#define FAIL 300
|
|
#define SUCCESS 400
|
|
#define UP 600
|
|
#define UPGRADE 601
|
|
|
|
struct msg
|
|
{
|
|
int type;
|
|
int flag;
|
|
char buf[64];
|
|
char fname[100];
|
|
};
|
|
|
|
struct datasNet
|
|
{
|
|
unsigned char Header[2];//0x51,0xa5
|
|
unsigned char InstructionCode:8;//0x1,0x2,0x3...
|
|
unsigned char DataLenght[4];
|
|
unsigned char *Data;
|
|
unsigned char Checksum;
|
|
unsigned char Ender[2];//0xa5,0x5a
|
|
};
|
|
typedef unsigned char UCHAR;
|
|
|
|
class FileTranseceiver : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit FileTranseceiver(uint16_t hostshort);
|
|
~FileTranseceiver(void);
|
|
|
|
int ftp_download(int connfd,struct msg info);
|
|
int upload_ftp(int connfd,struct msg info);
|
|
void start();
|
|
void showData(QString tag,QByteArray dat)const;
|
|
|
|
protected slots:
|
|
void connectListen();
|
|
private:
|
|
uint16_t port;
|
|
int sockfd;
|
|
int connfd;
|
|
QThread *serverThead;
|
|
int upload_and_upgrade(int connfd, msg info);
|
|
void connectListen5001();
|
|
void connectListen5002();
|
|
bool CheckSumIn( UCHAR *buf, unsigned int len);
|
|
signals:
|
|
void fileRecieved(QString fileName);
|
|
};
|
|
|
|
#endif // FILETRANSECEIVER_H
|