#include "HDTBase.h"
//保存在铁电里面的数据
#define SSI_INITLIZE_FLAG 0 //0~7 8个字节的初始化标志
#define SSI_POS_ID 8 //8~9 2字节的设备编号 支持65535台编码
#define SSI_POS_PASSWORD 10 //10~12 3个字节的密码 解压缩后(6个字节)
#define FM_HR_G2_POWER 18
#define SSI_LIST_RECORD 36 //1字节 记录数目
#define SSI_SERVER_IP 40 //15个字节的IP地址
#define SSI_SERVER_PORT 55 //5个字节的端口号
#define SSI_INITLIZE_TAG "HDT30004"
#define LANGUAGE_GB2312_CHINESE 0
#define LANGUAGE_BIG5_CHINESE 1
#define LANGUAGE_ENGLISH 2
#define UHF_POWER_CHANNEL 0 //0 RFID 1 GPRS
//机号
int g_nPosID;
//设备开机密码
char g_pszPassword[8];
char g_pszProductID[8];
//UHF模块功耗设定
int g_nUHFPower;
int g_nUHFOpen;
char g_MenuItemChinese[][32] = {"1.读卡信息","2.信息下载","3.设置功率","4.设置时间","5.关 机",""};
int debugPrintf(const char * fmt,...)
{
return 0;
}
void SSI_UHFTerminal()
{
unsigned char pszCommand[512];
int nPort1,nPort2;
HDT_OpenPort(1);
HDT_SetPortBaudRate(1,57600);
HDT_ResetPort(1);
vEnableIsrs();
strcpy((char*)pszCommand,"Welcome to use UHF setup\r\n");
HDT_SendPortBytes(1,strlen((char*)pszCommand),pszCommand);
HDT_Sleep(100);
HDT_UHFOpen(UHF_POWER_CHANNEL);
HDT_ClearClient();
HDT_DisplayText16x16EX(0,0," UHF Terminal Test ",WHITE);
HDT_DisplayText16x16(5,0,"Make sure connect PC",NORMAL);
HDT_DisplayText16x16(6,0,"Open Hyper Terminal ",NORMAL);
HDT_DisplayText16x16(7,0,"Default baud=38400bps",NORMAL);
//while(1)
//{
// HDT_SendPortByte(3,'x');HDT_SendPortByte(3,'x');HDT_SendPortByte(3,'x');
// nPort2 = HDT_GetPortBytesCount(3);
// if(nPort2)break;
// HDT_Sleep(100);
//
//}
//HDT_SendPortByte(3,0x0d);
while(1)
{
nPort1 = HDT_GetPortBytesCount(1);
if(nPort1)
{
nPort1 = HDT_GetPortBytes(1,0,pszCommand);
HDT_SendPortBytes(3,nPort1,pszCommand);
}
nPort2 = HDT_GetPortBytesCount(3);
if(nPort2)
{
nPort2 = HDT_GetPortBytes(3,0,pszCommand);
HDT_SendPortBytes(1,nPort2,pszCommand);
}
if(KEY_C == HDT_GetKeyPress())
{
HDT_Buzzle(100);
HDT_UHFClose();
return;
}
HDT_Sleep(1);
}
}
/*
功能:取特定的输入,返回输入的字符串
参数:nRow 指定行 nCol 指定列 pszBuffer 是输入缓冲 nMaxLength 是接收最大长度 nMask 0 正常显示 1 按照密码方式显示
*/
int SSI_GetString(int nRow,int nCol,char* pszBuffer,int nMaxLength,int nMask)
{
unsigned char nKey;
char pszDisplay[32];
char pszTemp[32];
int i;
int nIdle;
i = 0;
memset(pszTemp,0x00,32);
memset(pszTemp,0x20,nMaxLength);
HDT_DisplayText16x16(nRow,nCol,pszTemp,NORMAL);
//HDT_DisplayCursor(nRow,nCol,3,8);
while(1)
{
nKey = HDT_GetKeyPress();
if(nKey)nIdle = 0;
switch(nKey)
{
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
case '0' : if(nMaxLength > i)
{
HDT_Buzzle(50);pszBuffer[i++] = nKey;
if(0 == nMask)
sprintf(pszDisplay,"%s",pszBuffer);
else
{
memset(pszTemp,0x00,32);
memset(pszTemp,'*',i);
sprintf(pszDisplay,"%s",pszTemp);
}
HDT_DisplayText16x16(nRow,nCol,pszDisplay,WHITE);
}
else
HDT_Buzzle(50);
HDT_DelayTime(60);
break;
case KEY_C : HDT_DisplayText16x16(nRow,nCol,pszTemp,NORMAL);
HDT_Buzzle(30);
i--;if(0 > i)return -1;
pszBuffer[i] = 0x00;
if(0 == nMask)
sprintf(pszDisplay,"%s",pszBuffer);
else
{
memset(pszTemp,0x00,32);
memset(pszTemp,'*',i);
sprintf(pszDisplay,"%s",pszTemp);
}
HDT_DisplayText16x16(nRow,nCol,pszDisplay,WHITE);
HDT_DelayTime(50);
break;
case KEY_OK : HDT_Buzzle(50);return strlen(pszBuffer);
//case KEY_LSCAN :
//case KEY_RSCAN : return -1;
}
HDT_DelayTime(60);
nIdle++;
if(400 < nIdle)return 0;
}
return 0;
}
int SSI_Login()
{
char pszBuffer[16];
int nLength,nCount;
for(nCount=1;nCount<20;nCount++)
HDT_ClearLine8x8(nCount);
if(LANGUAGE_GB2312_CHINESE == HDT_GetLanguage())HDT_DisplayText16x16(5,0,"请输密码:",NORMAL);
if(LANGUAGE_ENGLISH == HDT_GetLanguage())HDT_DisplayText16x16(5,0,"Password:",NORMAL);
if(LANGUAGE_GB2312_CHINESE == HDT_GetLanguage())HDT_DisplayText16x16(8,0,"请输入密码...",NORMAL);
if(LANGUAGE_ENGLISH == HDT_GetLanguage())HDT_DisplayText16x16(8,0,"Input Password...",NORMAL);
HDT_DelayTime(200);
for(nCount=0;nCount<3;nCount++)
{//
memset(pszBuffer,0x00,16);
SSI_GetString(5,9,pszBuffer,6,1);
if(0 == strcmp(pszBuffer,g_pszPassword))
{
HDT_ClearLine16x16(7);
HDT_ClearLine16x16(8);
if(LANGUAGE_GB2312_CHINESE == HDT_GetLanguage())HDT_DisplayText16x16(8,0,"密码正确...",NORMAL);
if(LANGUAGE_ENGLISH == HDT_GetLanguage())HDT_DisplayText16x16(8,0,"Password ...OK",NORMAL);
HDT_Buzzle(300);
HDT_DelayTime(1000);
return 0;
}
if(LANGUAGE_GB2312_CHINESE == HDT_GetLanguage())HDT_DisplayText16x16(7,0,"密码错误...",NORMAL);
if(LANGUAGE_ENGLISH == HDT_GetLanguage())HDT_DisplayText16x16(7,0,"Password Invalid...",NORMAL);
if(LANGUAGE_GB2312_CHINESE == HDT_GetLanguage())HDT_DisplayText16x16(8,0,"请重新输入密码...",NORMAL);
if(LANGUAGE_ENGLISH == HDT_GetLanguage())HDT_DisplayText16x16(8,0,"Try Again...",NORMAL);
HDT_Buzzle(200);
HDT_DelayTime(1000);
}
return 1;
}
/*
功能:显示开机画面
*/
void SplashLogo()
{
char pszDisplay[64];
unsigned char nKey;
unsigned char pszBuffer[128];
unsigned char pszDateTime[16];
unsigned char* pszImage;
int i,nIdle;
int nResult;
char* pszCheck;
HDT_ClearDisplay();
//判断是不是第一次运行程序
memset(pszBuffer,0x00,128);
HDT_FMReadBytes(SSI_INITLIZE_FLAG,8,pszBuffer);
if(memcmp(pszBuffer,SSI_INITLIZE_TAG,8))
{
if(LANGUAGE_GB2312_CHINESE == HDT_GetLanguage())HDT_DisplayText16x16(1,0,"第一次运行...",NORMAL);
if(LANGUAGE_ENGLISH == HDT_GetLanguage())HDT_DisplayText16x16(1,0,"Firsr Run",NORMAL);
if(LANGUAGE_GB2312_CHINESE == HDT_GetLanguage())HDT_DisplayText16x16(8,0,"正在初始化...",NORMAL);
if(LANGUAGE_ENGLISH == HDT_GetLanguage())HDT_DisplayText16x16(8,0,"Initlize...",NORMAL);
//初始化标志
memcpy(pszBuffer,SSI_INITLIZE_TAG,8);
HDT_FMWriteBytes(SSI_INITLIZE_FLAG,8,pszBuffer);
//初始化机号 0000
memset(pszBuffer,0x00,128);
HDT_FMWriteBytes(SSI_POS_ID,2,pszBuffer);
//初始化密码 000000
memset(pszBuffer,0x00,128);
HDT_FMWriteBytes(SSI_POS_PASSWORD,3,pszBuffer);
pszBuffer[0] = 20;
HDT_FMWriteBytes(FM_HR_G2_POWER,1,pszBuffer);
//公司标示
//if(LANGUAGE_GB2312_CHINESE == HDT_GetLanguage())memcpy(pszBuffer,"F8 设置公司标识",16);
//if(LANGUAGE_ENGLISH == HDT_GetLanguage())memcpy(pszBuffer,"F8 Set Logo...",16);
//HDT_FMWriteBytes(SSI_COMPANY_ID,4,pszBuffer);
//设备记录数为0
HDT_DisplayText16x16(8,0,"初始化文件系统... ",NORMAL);
ffsInitialize();
HDT_Buzzle(100);
HDT_ResetDevice();
}
if(ffsOpen() < 0)
{
HDT_DisplayText16x16(8,0,"文件系统错误... ",NORMAL);
HDT_Buzzle(300);
HDT_Sleep(3000);
HDT_PowerOff();
}
pszImage = (unsigned char*)malloc(4096*sizeof(unsigned char));
nResult = HDT_ReadBinary("FTA_LOGO.JPG",pszImage,0,0);
if(0 < nResult)GUI_JPEG_Draw(pszImage,nResult,40,4);
free(pszImage);
//读取系统配置文件,首先读编号和密码
HDT_FMReadBytes(SSI_POS_ID,2,pszBuffer);
g_nPosID = pszBuffer[0]*256 + pszBuffer[1];
HDT_FMReadBytes(SSI_POS_PASSWORD,3,pszBuffer);
sprintf(g_