⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atlasmsg.h

📁 cell phone source code
💻 H
字号:
// PalmMsg.h: interface for the CAtlasMsg class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PALMMSG_H__BB2F41A0_6C56_11D3_8AB6_5254AB104A0B__INCLUDED_)
#define AFX_PALMMSG_H__BB2F41A0_6C56_11D3_8AB6_5254AB104A0B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define P_BAUDRATE_DEFAULT	5
#define P_BAUDRATE_2400		1
#define P_BAUDRATE_9600		2
#define P_BAUDRATE_14400	3
#define P_BAUDRATE_19200	4
#define P_BAUDRATE_38400	5
#define P_BAUDRATE_57600	6
#define P_BAUDRATE_115200	7

#define P_CONNECT_COM1		0
#define P_CONNECT_COM2		1

#define P_CHIP_ATLAS		0
#define P_CHIP_TITAN		1

#define P_TIME_OUT	 5000


// Maximum length of data field in a packet is 2048 bytes, which yields in 2054 total packet length. 
#define P_MAX_DATA_LENGTH	128
#define P_MAX_PACKET_LENGTH	134

// Elementary Units of the Protocol
#define P_NUL		0x00	// Initialization Byte 
#define P_ENQ		0x05	// Action Complete Notification
#define P_ACK		0x06	// Positive Achnowledgement
#define P_DC1		0x11	// Unable to Execute Command
#define P_NAK		0x15	// Negative Acknowledgement, also Camera Signature  
#define P_END		0xff	// Termination Byte 

// Packet - Variable length sequence of bytes. Known packet types are in the following:
#define P_DATA_UNFINISHED	0x02	// Data packet that is not last in sequence 
#define P_DATA				0x03	// Data packet that is last in sequence 
#define P_CMD				0x1b	// Command packet 

/*
Packet structure as the following:
Offset	Length		Meaning 
0		1			Packet type 
1		1			Packet subtype/sequence 
2		2			Length of data 
4		variable	Data 
-2		2			Checksum 
*/

// Packet subtype
// Command packet has subtype 0x43 or 0x53. Only the first command packet in a session has subtype 0x53. 
#define P_CMD_FIRST		0x53
#define P_CMD_NORMAL	0x43

// Data packets that are sent in responce to a single command are numbered starting from zero. 
// If all requested data fits in one packet, it has type 0x03(P_DATA) and sequence 0. 

/* 
Command is a sequance of bytes sent in the data field of a command packet. 
Command format and codes are as follows:
Offset	Length		Description 
0		1			Command code 
1		1			Register number or subcode 
2		variable	Optional argument 
*/

// Five command codes are known:	Argument	Description
#define P_CMD_SET_REG	0		//	int32		Set value of integer register 
#define P_CMD_GET_REG	1		//	none		Read value of integer register 
#define P_CMD_ACTION	2		//	vdata		Take action unrelated to registers 
#define P_CMD_SET_VDATA	3		//	vdata		Set value of vdata register 
#define P_CMD_GET_VDATA	4		//	none		Read value of vdata register 
#define P_CMD_WAIT_CONNECT  5   //   none       Wait connect response from device

// The following registers are known:		Type	
#define P_CMD_CUR_IMG_TYPE			1	//	int32	
#define P_CMD_NAND_CS				2	//	int32	
#define P_CMD_BOOT_STAGE			3	//	int32	
#define P_CMD_FRAME_LEN				4	//	int32	
#define P_CMD_CUR_IMG_LENGTH		5	//	int32
#define P_CMD_NBOOT_RESERVED_BYTE   6   //  int32
#define P_CMD_EBOOT_RESERVED_BYTE   7   //  int32
#define P_CMD_DM_RESERVED_BYTE      8   //  int32
#define P_CMD_NK_RESERVED_BYTE      9   //  int32
#define P_CMD_XIP_INFO              10   //  int32


// For command 2 (P_CMD_ACTION), the second byte is action code not register number. The following action codes are known:
//									Code	Argument			Description 
#define P_ACTION_WRITE_IMG			0	//	single zero byte	
#define P_ACTION_UPDATE_TOC			1	//	single zero byte	
#define P_ACTION_OPEN_DATA_PIPE		2	//	single zero byte	
#define P_ACTION_CLOSE_DATA_PIPE	3	//	single zero byte	

class CAtlasMsg
{
public:
	CAtlasMsg();
	virtual ~CAtlasMsg();

	void Reset();

// Pack message
public:
	inline int PackNUL()	{	return PackNone(P_NUL);	}	
	inline int PackENQ()	{	return PackNone(P_ENQ);	}	
	inline int PackACK()	{	return PackNone(P_ACK);	}	
	inline int PackDC1()	{	return PackNone(P_DC1);	}	
	inline int PackNAK()	{	return PackNone(P_NAK);	}	
	inline int PackEND()	{	return PackNone(P_END);	}	

	inline void PackToFirstCmd()	{	m_pBuf[1] = P_CMD_FIRST;	}

	inline int PackData(const BYTE * pData, int iLength)	{	return Pack(P_DATA, 0, pData, iLength);	}

	int PackCmdSetReg(int iReg, int iVal);
	int PackCmdGetReg(int iReg);
	int PackCmdAction(int iAction, int iArgument);
	int PackCmdSetVData(int iReg, const BYTE * pData, int iLength);
	int PackCmdGetVData(int iReg);
    int PackCmdWaitConnect();
	int PackUnfinishedData(const BYTE * pData, int iLength);
	int PackLastData(const BYTE * pData, int iLength);

	inline int GetLength()	{	return m_iLength;	}
	inline BYTE * GetBuf()	{	return m_pBuf;	}

// Unpack message
public:
	BOOL Unpack(BOOL & bDataError);

	inline void SetLength(int iLength)	{	m_iLength = iLength;	}
	int SetBuf(BYTE * pData, int iLength);
	inline int GetType()	{	return m_iType;	}
	inline BYTE * GetVData()	{	return m_pCmd;	}
	inline int GetVDataLength()	{	return m_iVDataLength;	}

	inline BOOL IsFirstCmd()	{	return m_bFirstCmd;	}

	inline int GetCmdCode()	{	return m_iCmdCode;	}
	inline int GetCmdReg()	{	return m_iCmdReg;	}
	inline int GetCmdVal()	{	return m_iCmdVal;	}

// Pack message
protected:
	int PackNone(int iType);
	int Pack(int iType, int iSub, const BYTE * pData, int iLength);

// Unpack message
protected:
	BOOL UnpackData(BOOL & bDataError);
	BOOL UnpackCmd();

protected:
	int GetCheckSum(const BYTE * pData, int iLength);

protected:
	int  m_iLength;
	BYTE m_pBuf[P_MAX_PACKET_LENGTH];
	BYTE m_pCmd[P_MAX_DATA_LENGTH];

	int  m_iType;
	BOOL m_bFirstCmd;
	int  m_iVDataLength;

	BYTE m_iPackSequence;
	BYTE m_iUnpackSequence;

	int  m_iCmdCode;
	int  m_iCmdReg;
	int  m_iCmdVal;
};

#endif // !defined(AFX_PALMMSG_H__BB2F41A0_6C56_11D3_8AB6_5254AB104A0B__INCLUDED_)





















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -