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

📄 3gtestgui.c

📁 3G module test program
💻 C
字号:
/**************************************************************
Copyright (C), 2007, Compal Electronics Co., Ltd.
All rights reserved.

$Workfile: 3GTestGUI.c $
$Revision: 1.1 $
$Author: kenkc_chen $
$Date: 2007/12/17 09:24:15 $

Description: GUI of 3G test program.

$Log: 
**************************************************************/
#include "3GTest.h"

//===================================================
// Global variables 
//=================================================== 
GtkWidget *label3G;
GtkWidget *labelCard;
GtkWidget *labelReg;

int gFilePointer; // Descriptor of file
int ret = SUCCEED; // value for return
//===================================================
// Functions
//===================================================
/*****************************************
Function:     SetText
Description:  Show result text on label
Parameter: 
   pWidger[input]: pointer of lable
    buffer[input]: text want to show
     color[input]: color of text
      desc[input]: pango font description
Return: No
Remark:
******************************************/
void SetText(GtkWidget *pWidger, const char *buffer, GdkColor *color, PangoFontDescription *desc)
{
    //  Set text font in label
    gtk_widget_modify_font(pWidger, desc);
    // Render the color of text
    gtk_widget_modify_fg(pWidger, GTK_STATE_NORMAL, color);
    // Set text onto widget
    gtk_label_set_text((GtkLabel*)pWidger, buffer);
}

/*****************************************
Function:     ShowResult
Description:  Show result on label
Parameter: 
    which[input]: flag of which lable
    result[input]: flag of pass or fail
    buffer[output]: message received
Return: No
Remark:
******************************************/
void ShowResult(int which, int result, unsigned char *buffer)
{
    gdk_threads_enter(); 
    GdkColor color; // Color for result text
    PangoFontDescription *desc = NULL;
    
    // for 3G module test
    if (1 == which)
    {
        // Set font description
        

        if (result == SUCCEED) // Test successful
        {            desc = pango_font_description_from_string ("Sans Bold 15"); 
            gdk_color_parse("green", &color); // Get green color            char str[100];
            sprintf(str, "PASS: Module-- %s", buffer);
            SetText(label3G, str, &color, desc); // Show pass on label
            ret = SUCCEED;
        }
        else if (result == ERROR) // Test failed
        {            desc = pango_font_description_from_string ("Sans Bold 40"); 
            gdk_color_parse("red", &color); // Get red color
            SetText(label3G, "FAIL", &color, desc); // Show fail on label
            ret = ERROR;
        }
    }
    // for SIM card test
    else if (2 == which)
    {
        if (result == SUCCEED) // Test successful
        {
            desc = pango_font_description_from_string ("Sans Bold 40"); 
            gdk_color_parse("green", &color); // Get green color
            SetText(labelCard, "PASS", &color, desc); // Show pass on label
            ret = SUCCEED;
        }
        else 
        {
            // Set font description
            desc = pango_font_description_from_string ("Sans Regular 15"); 
            gdk_color_parse("red", &color); // Get red color
            if (result == SIM_NOT_IN) // Test failed
            {                
                SetText(labelCard, "FAIL: SIM not inserted", &color, desc); // Show fail on label
                ret = SIM_NOT_IN;
            }
            else if (result == SIM_PUK) // Test failed
            {                
                SetText(labelCard, "FAIL: SIM PIN protect", &color, desc); // Show fail on label
                ret = SIM_PUK;
            }
            else if (result == ERROR) // Test failed
            {            
                SetText(labelCard, "FAIL: unknowed error", &color, desc); // Show fail on label
                ret = ERROR;
            }
        }
    }
    // for register test
    else if (3 == which)
    {
        // Set font description
        
        desc = pango_font_description_from_string ("Sans Bold 15"); 
        if (result == SUCCEED) // Test successful
        {
            char str[500];            if ( buffer[0] < 128 )            {
                sprintf(str, "PASS: %s", buffer);            }            else            {                 int i = 0;                char tempStr[10];                strcpy(str, "PASS: ");                while(buffer[i] != '\0')                {                    sprintf(tempStr, "%02X ", buffer[i++]);                    strcat(str, tempStr);                }            }
            gdk_color_parse("green", &color); // Get green color
            SetText(labelReg, str, &color, desc); // Show pass on label
            ret = SUCCEED;
        }
        else
        {
            gdk_color_parse("red", &color); // Get red color
            if (result == REG_FAIL) // Test failed
            {               
                SetText(labelReg, "FAIL: Limited Service", &color, desc); // Show fail on label
                ret = REG_FAIL;
            }
            else if (result == ERROR)
            {
                SetText(labelReg, "FAIL: unknowed error", &color, desc); // Show fail on label
                ret = ERROR;
            }
        }
    }
    gdk_threads_leave();   
}

/*****************************************
Function:     OpenLogFile
Description:  open log file for recording
Parameter: No    
Return: No
Remark:
******************************************/
void OpenLogFile(void)
{
    // open logfile for result recording
    if ((gFilePointer = open(LOG_FILE_PATH, O_RDWR|O_APPEND)) == FAIL)
    {
        printf("Open logfile failed!\n");        
    }
}

/*****************************************
Function:     WriteLogFile
Description:  write test result to log file
Parameter: 
    buffer[input]: text want to write to log file
Return: No
Remark:
******************************************/
void WriteLogFile(const char *buffer)
{
    if (write(gFilePointer,buffer,strlen(buffer)) == ZERO_LEN)
    {
        printf("write Logfile failed/n");    
    }
}

/*****************************************
Function:     SetLayOut
Description:  set layout of Test UI
Parameter: No    
Return: No
Remark:
******************************************/
void SetupGuiLayout()
{
    
    GtkWidget *window;    // Pointer of main window
    GtkWidget *mainTable; // Container for all other widgets
    GtkWidget *closeButton;

    GtkWidget *frame3G;     // Frame of test result text
    GtkWidget *frameCard;
    GtkWidget *frameReg;

    GtkWidget *separator; // Pointer of separator between button and text
    PangoFontDescription *fontDescri = NULL;
    GtkWidget *closeLabel; 
    // Create window widget
    window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "3G Test");
    gtk_window_set_default_size(GTK_WINDOW(window),
                            WINDOW_WIDTH,WINDOW_HEIGHT);
    g_signal_connect(G_OBJECT(window), "delete_event", gtk_main_quit, NULL);

    //Create area of test result
    frame3G = gtk_frame_new("3G module detect: ");
    frameCard = gtk_frame_new("SIM Card: ");
    frameReg = gtk_frame_new("Register to network: ");

    label3G = gtk_label_new("");
    labelCard = gtk_label_new("");
    labelReg = gtk_label_new("");
    
    //Create close button
    closeButton = gtk_button_new_with_label("Close");
     
    fontDescri = pango_font_description_new();
    closeLabel = gtk_bin_get_child(GTK_BIN(closeButton)); 
    pango_font_description_set_weight(fontDescri, PANGO_WEIGHT_BOLD);             // Weight of font: Bold
    pango_font_description_set_size(fontDescri, 20 * PANGO_SCALE);                // Size of font: 20
    gtk_widget_modify_font(closeLabel, fontDescri);                                    // Change font of the label
   
    g_signal_connect(G_OBJECT(closeButton), "clicked", gtk_main_quit, NULL);
    
    mainTable = gtk_table_new(3,30,TRUE);  

    gtk_container_add(GTK_CONTAINER(frame3G), label3G);
    gtk_container_add(GTK_CONTAINER(frameCard), labelCard);
    gtk_container_add(GTK_CONTAINER(frameReg), labelReg);
    separator = gtk_vseparator_new();

    // Attach every container and single widget to main table
    gtk_table_attach_defaults(GTK_TABLE(mainTable), frame3G, 0, 17, 0, 1);
    gtk_table_attach_defaults(GTK_TABLE(mainTable), frameCard, 0, 17, 1, 2);
    gtk_table_attach_defaults(GTK_TABLE(mainTable), frameReg, 0, 17, 2, 3);

    gtk_table_attach_defaults(GTK_TABLE(mainTable), separator, 17, 18, 0, 3);
    gtk_table_attach_defaults(GTK_TABLE(mainTable), closeButton, 18, 30, 0, 3);
    
    //add main table to main window
    gtk_container_add(GTK_CONTAINER(window), mainTable); 

    gtk_widget_show_all(window);

}

/*****************************************
Function:     main
Description:  main function of GUI 3G Test
Parameter:
    argc[input]: number of parameter
    argv[input]: pointer of parameter
Return:
    SUCCEED: test succeed
      ERROR: test failed
Remark:
******************************************/
int main(int argc, char **argv)
{
    
     // Open logfile   
    OpenLogFile();

    // Initial of gthread and gtk
    if (!g_thread_supported())
    { 
        g_thread_init (NULL);
    }    
    gdk_threads_init();
    gtk_init(&argc, &argv);
    
    // Set UI layout
    SetupGuiLayout();

    // Begin to test 3G module
    if (g_thread_create(Test3G, NULL, FALSE, NULL) == 0) 
    {
        printf("Launch thread failed!\n");
    }
    
    // Main loop
    gdk_threads_enter();
    gtk_main();
    gdk_threads_leave();

    printf("ret is ........%d\n",ret);
    if (ret == SUCCEED)
    {
        WriteLogFile("3G Test is successful!\n");       
    }
    else
    {
        WriteLogFile("3G Test failed!\n");  
    }

    return ret;
    
    
}

⌨️ 快捷键说明

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