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

📄 posmain.c

📁 这是一个基于UCLinux下的一个GPRS 移动POS设备的代码
💻 C
字号:
/***************************************************************************/
/*                                                                         */
/* Copyright (C) HANGZHOU SUNYARD TECHNOLOGY CO., LTD.                     */
/*                                                                         */
/***************************************************************************/
/*                                                                         */
/*  SYNOPSIS:  This is demo application                                    */
/*             designed to run on the S520                              */
/*                                                                         */
/***************************************************************************/
#include "pos.h"

TRANS_REC  gTrans;               // transaction struct       
int        ngMenuIdle = 30;
int	   ngCommWay;

static int  IdleDisplay( void );
static void DisplayTime( void );
static int  DoPosMenu(void);
static int  RestoreEnv(char *strFileName);
static void DoSetParam();
static void DoDetail();

extern void DoSale();
extern void DoHostParam();
extern void DoSysParam();
extern void DoLoadMasterKey();
extern void DoQueryDetail();
extern void DoDeleteDetail();


// *******************************************************************
// Function  Name   : main
// Function         : the main function
// Parameter        :
// Return           :
// *******************************************************************
main()
{
    int nRet, nSignalLevel, nComm;
    char key[ 8 ], temp[40], disp[60];

    //Open the clear the screen
    Syd_OpenLCD();
    Syd_ClearScreen();
/*    
    if ( Syd_GetEnv( "FIRSTRUN", temp, 1 ) < 0 || temp[0] == '1' )
    {
        Syd_DisplayLine( 3, "Init System Param", 0, ALIGN_CENTER );
        if ( RestoreEnv( PARA_FILE ) < 0 )
        {
            Syd_DisplayLine( 3, "Init Fail!", 0, ALIGN_CENTER );
            Syd_ErrorMessage( 4, "Reboot Pls", 0, ALIGN_CENTER );
            while( 1 );
        }
        if ( Syd_PutEnv( "FIRSTRUN", "0" ) < 0 )
        {
            Syd_ErrorMessage( 4, "Reboot Pls", 0, ALIGN_CENTER );
            while( 1 );
        }
    }
*/  
    if (Syd_GetEnv( "#COMM", temp, 1 ) < 0)
    {   
        Syd_ErrorMessage( 4, "system error", 0, ALIGN_CENTER );
        while( 1 );
    }
    
    temp[1] = 0;
    ngCommWay = atoi(temp);
    
    Syd_DisplayLine( 3, "Init Communication", 0, ALIGN_CENTER );
    while ( Syd_InitComm(ngCommWay) < 0 )
    {
        Syd_ErrorMessage( 3, "Init fail", 0, ALIGN_CENTER );
        Syd_DisplayLine( 4, "Retrying...", 0, ALIGN_CENTER );
    }
    if (ngCommWay == COMM_GPRS)
    	Syd_ConnectGPRS();
     
    while( 1 )
    {
        IdleDisplay();
        do
        {
            nRet = 0;
            memset( &gTrans, 0, sizeof( gTrans ) );

            nRet = DoPosMenu();
        } while ( nRet != -1 );
    }

}

static int DoPosMenu(void)
{
    time_t tStart;
    int nKey, nRet=0;
	
    Syd_ClearScreen();
    Syd_DisplayLine( 1, "     Main  Menu      ", 1, ALIGN_CENTER );
    Syd_DisplayLine( 2, "  1.Sale", 0, ALIGN_LEFT );
    Syd_DisplayLine( 3, "  2.Transaction Detail", 0, ALIGN_LEFT );
    Syd_DisplayLine( 4, "  3.Set parameter", 0, ALIGN_LEFT );
    
    tStart = time( NULL );
    do
    {
        if ( time( NULL ) - tStart > ngMenuIdle )
            return -1;

        nKey = Sys_Key_CheckKey();
        switch (nKey)
        {
        case KEY_1:  
            DoSale();
            nRet = 1;
            break;
        case KEY_2:
            DoDetail();
            nRet = 1;
            break;
        case KEY_3:  
            DoSetParam();
            nRet = 1;
            break;
        case KEY_CANCEL:
            nRet = -1;
            break;
        default:
            break;
        }
    } while (nRet == 0);
    
    return nRet;
}

void DoSetParam()
{
    int nKey;
	
    Syd_ClearScreen();
    Syd_DisplayLine( 1, "    Set Parameter    ", 1, ALIGN_CENTER );
    Syd_DisplayLine( 2, "  1.Host Parameter", 0, ALIGN_LEFT );
    Syd_DisplayLine( 3, "  2.System Parameter ", 0, ALIGN_LEFT );
    Syd_DisplayLine( 4, "  3.Master Key", 0, ALIGN_LEFT );
 
    while (1)
    {
        nKey = Sys_Key_WaitKey();
        switch (nKey)
        {
        case KEY_1:  
            DoHostParam();
            return;
        case KEY_2:
            DoSysParam();
            return;
        case KEY_3:
            DoLoadMasterKey();
            return;
        case KEY_CANCEL:
            return;
        default:
            break;
        }
    }
    return;
}

void DoDetail()
{
    int nKey;
	
    Syd_ClearScreen();
    Syd_DisplayLine( 1, " Transaction Detail  ", 1, ALIGN_CENTER );
    Syd_DisplayLine( 2, "  1.Query", 0, ALIGN_LEFT );
    Syd_DisplayLine( 3, "  2.Delete ", 0, ALIGN_LEFT );
    
    while (1)
    {
        nKey = Sys_Key_WaitKey();
        switch (nKey)
        {
        case KEY_1:  
            DoQueryDetail();
            return;
        case KEY_2:
            DoDeleteDetail();
            return;
        case KEY_CANCEL:
            return;
        default:
            break;
        }
    }
    return;
}

// *******************************************************************
// Function  Name   : IdleDisplay
// Function         : when POS IDLE display the LOGO
// Parameter        : 
// Return           : 
// *******************************************************************
int  IdleDisplay(void)
{
    int nRet;
    
    Syd_ClearScreen();
    Syd_DrawBitmap(0, 0, DISPLAY_LOGO_FILE);
    
    DisplayFlag();
//    Syd_DisplayLine(1, "      Sunyard        ", 0, ALIGN_CENTER);
    
    //turn off backlit display
    Sys_El_Onoff(ON);
    
//    Syd_ClearScreen();
//    Syd_DisplayLine(3, "      sleep...       ", 0, ALIGN_CENTER);
//    Sys_Sleep_Set();
//    Syd_DisplayLine(4, "   Wireless POS    ", 0, ALIGN_CENTER);
    
    while (1) 
    {
        nRet = Sys_Key_CheckKey();
        if (nRet > 0) 
        {
            //turn on backlit display
            Sys_El_Onoff(ON);
            if (nRet == KEY_UP || nRet == KEY_DOWN) 
                break;
        }
        DisplayTime();
    }
    return 1;
}

// *******************************************************************
// Function  Name   : DisplayTime
// Function         : 
// Parameter        :
// Return           :
// *******************************************************************
static void DisplayTime()
{
    char strNowTime[25], strTimeString[25];
    
    // get the date and time
    Sys_RTC_Get(strNowTime);

    memcpy(strTimeString, strNowTime, 4); strTimeString[4] = '-';
    memcpy(strTimeString+5, strNowTime+4, 2); strTimeString[7] = '-';
    memcpy(strTimeString+8, strNowTime+6, 2); strTimeString[10] = ' ';
    memcpy(strTimeString+11, strNowTime+8, 2); strTimeString[13] = ':';
    memcpy(strTimeString+14, strNowTime+10, 2); strTimeString[16] = ':';
    memcpy(strTimeString+17, strNowTime+12, 2); strTimeString[19] = 0;

    Syd_DisplayLine(5, strTimeString, 0, ALIGN_RIGHT);
}

// *******************************************************************
// Function  Name   : RestoreEnv
// Function         : Restor the envirment from a file
// Parameter        :
// Return           : 0:   SUCCESS
//                  : < 0: fail
// *******************************************************************
int  RestoreEnv(char *strFileName)
{
    FILE *fp;
    char temp[1024], strEnvName[20], strEnvValue[1024];
    short i, j;
  
    fp = fopen(strFileName, "r");
    if (fp == NULL) 
    {
        return -1;
    }
  
    while (!feof(fp)) 
    {
        if (fgets(temp, sizeof(temp), fp) == NULL) 
            break;
        if (strlen(temp) < 3) 
            continue;
  
        for (i = 0; temp[i] != ' ' && temp[i] != 0 && temp[i] != '\r' && temp[i] != '\n';i++) 
        {
            strEnvName[i] = temp[i];
        }
        if (temp[i] != ' ') 
        {
            fclose(fp);
            return -2;
        }
        strEnvName[i] = 0;
        while (temp[i] != '\"' && temp[i] != 0 && temp[i] != '\r' && temp[i] != '\n') 
            i++;
        if (temp[i] != '\"') 
        {
            fclose(fp);
            return -2;
        }
        i++;
        j = 0;
        while (temp[i] != '\"' && temp[i] != 0 && temp[i] != '\r' && temp[i] != '\n')
            strEnvValue[j++] = temp[i++];
            
        if (temp[i] != '\"') 
        {
            fclose(fp);
            return -2;
        }
        strEnvValue[j] = 0;
  
        if (Syd_PutEnv(strEnvName, strEnvValue) < 0) 
        {
            fclose(fp);
            return -3;
        }
    }
    fclose(fp);
    return RET_SUCCESS;
}

⌨️ 快捷键说明

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