/*
 * SSMprotocol2.h - Application Layer for the new Subaru SSM protocol
 *
 * Copyright (C) 2008-2012 Comer352L
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SSMPROTOCOL2_H
#define SSMPROTOCOL2_H



#include <vector>
#include "AbstractDiagInterface.h"
#include "SSMprotocol.h"
#include "SSMP2communication.h"
#include "SSMFlagbyteDefinitionsInterface.h"
#include "libFSSM.h"



class SSMprotocol2 : public SSMprotocol
{
	Q_OBJECT

public:
	SSMprotocol2(AbstractDiagInterface *diagInterface, QString language="en");
	~SSMprotocol2();
	// NON-COMMUNICATION-FUNCTIONS:
	CUsetupResult_dt setupCUdata(CUtype_dt CU);
	CUsetupResult_dt setupCUdata(CUtype_dt CU, bool ignoreIgnitionOFF=false);
	protocol_dt protocolType() { return SSM2; }
	bool hasVINsupport(bool *VINsup);
	bool hasIntegratedCC(bool *CCsup);
	bool hasClearMemory(bool *CMsup);
	bool hasClearMemory2(bool *CM2sup);
	bool getSupportedDCgroups(int *DCgroups);
	// COMMUNICATION BASED FUNCTIONS:
	bool getVIN(QString *VIN);
	bool startDCreading(int DCgroups);
	bool stopDCreading();
	bool startMBSWreading(const std::vector<MBSWmetadata_dt>& mbswmetaList);
	bool stopMBSWreading();
	bool getAdjustmentValue(unsigned char index, unsigned int *rawValue);
	bool getAllAdjustmentValues(std::vector<unsigned int> * rawValues);
	bool setAdjustmentValue(unsigned char index, unsigned int rawValue);
	bool startActuatorTest(unsigned char actuatorTestIndex);
	bool stopActuatorTesting();
	bool stopAllActuators();
	bool clearMemory(CMlevel_dt level, bool *success);
	bool testImmobilizerCommLine(immoTestResult_dt *result);
	bool isEngineRunning(bool *isrunning);
	bool isInTestMode(bool *testmode);
	bool waitForIgnitionOff();

private:
	SSMP2communication *_SSMP2com;
	// *** CONTROL UNIT BASIC DATA (SUPPORTED FEATURES) ***:
	bool _has_CM;
	bool _has_CM2;
	bool _has_integratedCC;
	bool _has_VINsupport;
	// Cruise Control Cancel Codes:
	std::vector<dc_defs_dt> _CCCCdefs;
	bool _memCCs_supported;

	bool validateVIN(char VIN[17]);

private slots:
	void processDCsRawdata(const std::vector<char>& dcrawdata, int duration_ms);

public slots:
	void resetCUdata();

};



#endif
