#pragma once
#include "ZZ_Types.h"
#include "pch.h"
#include "lwgps.h"
#include "lwrb.h"
#include <atomic>
using namespace ZZ_MISCDEF;
using namespace ZZ_MISCDEF::MISC_DETECTOR;

class CMainGrabber;
class BD357Controller :public QObject
{
	Q_OBJECT
public:
	BD357Controller(QObject* parent = nullptr);
	~BD357Controller();
private:
	std::atomic<int> m_iFlagIsGPSValid;
	std::atomic<int> m_iFlagIsContinuousUpdating;
	std::atomic<int> m_iFlagIsConnected;
public:
	int SetContext(CMainGrabber &pMainGrabber);
	int SetupMessagePipeline();
	int SyncDateOnce();
	int StartContinuousUpdating();
	int Initialize(GPSInfo &struGPSI);

	//test func
	int VSlot_SkipSyncDateOnce();
private:
	int ZZ_FormatTime(ZZ_U8 u8Year,ZZ_U8 u8Month, ZZ_U8 u8Day, ZZ_U8 u8Hour, ZZ_U8 u8Minute, ZZ_U8 u8Second);
public slots:
	int Slot_InitSelf();
	int Slot_SyncDateOnce();
private slots:
	
	//int HandleReadyRead();
signals:
	void Signal_InitSelf();
	void Signal_StartCapture();
	void Signal_UpdateStatus(int iValid);
	void Signal_UpdateDate(QTime qDate);
private:
	QDateTime     m_qdtDateTime, m_qdtDateTimeUTC;
	GPSInfo       m_struGPSInfo;
	ZZ_U8         m_u8GPSDataBuffer[10];
	lwgps_t       m_hLWGPS;
	lwrb_t        m_hlwrbBuffer;
	int           m_iBaudRate;
	QSerialPort*  m_pSerialPort;
	QByteArray    m_qbReadData;
	CMainGrabber* m_pMainGrabber;
};