lqs10 发表于 2012-4-8 19:51:27

GU900D GPRS模块OPEN AT示例代码

很多人都喜欢研究程序,这里提供GU900D模块的OPEN AT的自动化单元代码。

//////////////////////////////////////////////////// custom_app.c ///////////////////////////////////////////////////////////////////////////////////////

#include "gu_sdk.h"

extern void ut_at_result_handler(gu_message_req_struct *msg_req);
extern void ut_keypad_handler(gu_message_req_struct *msg_req);
extern void ut_eint_handler(gu_message_req_struct *msg_req);
extern void ut_uart_data_handler(gu_message_req_struct *msg_req);

extern void ut_timer_expire_handler();


static gu_uint8 gImage_hfy[] = {
0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0x60,0x40,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0xE0,
0xE0,
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,0x40,0x40,0x40,0xC0,0xE0,
0x20,
0x20,0x40,0xC0,0x80,0x00,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xE0,
0x00,
0x00,0x00,0x00,0x00,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x0C,0x86,0xC3,0x79,0x39,0x13,
0xFF,
0xFD,0x11,0x31,0xE5,0xC7,0x83,0x01,0x00,0x84,0x84,0xC5,0x65,0x75,0xDD,0x8F,
0xF7,
0xF5,0x8D,0xDD,0x75,0x65,0xE5,0xC4,0x44,0x00,0x82,0xC2,0x72,0x3E,0xFF,0xFF,
0x9A,
0x92,0x84,0xDD,0x59,0x40,0xFF,0xFF,0x20,0x20,0x00,0x21,0x21,0x31,0xFF,0xFF,
0x0D,
0x05,0x19,0x79,0xE9,0x8F,0xCF,0x79,0x39,0x09,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x01,0x00,0x00,0x08,0x18,
0x1F,
0x0F,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00,0x04,0x04,0x06,0x02,0x0B,0x19,
0x1F,
0x0F,0x01,0x03,0x06,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,
0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x80,0x80,0x08,0x18,0x1F,0x0F,
0x88,
0x88,0x0C,0x86,0x83,0x01,0x03,0x06,0x0C,0x0C,0x04,0x80,0x80,0x00,0x00,0x00,
0x00,
0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x04,0x04,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x1C,0x1E,0x02,0x82,
0xE2,
0x7E,0x1C,0x00,0x00,0x1C,0xBE,0xE2,0x42,0xE2,0xBE,0x1C,0x00,0x00,0x20,0x60,
0xE0,
0xA0,0xE0,0x60,0x20,0x00,0x00,0xF8,0xFC,0x66,0x22,0x66,0xC6,0x80,0x00,0x00,
0xC0,
0xF0,0x38,0x0C,0xFE,0xFE,0x00,0x00,0xC4,0xF4,0xFF,0xFF,0x34,0x25,0x7D,0x7D,
0x57,
0xD7,0xD5,0x57,0x7F,0x7D,0x01,0x00,0x00,0x04,0x04,0xFF,0xFF,0x44,0x44,0x42,
0x42,
0xFF,0xFF,0x42,0x42,0x7E,0x7E,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00,0x00,0x00,0x0C,0x0E,0x0B,0x09,
0x08,
0x0C,0x0C,0x00,0x00,0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,0x00,0x08,0x0C,
0x0F,
0x0B,0x0F,0x0C,0x08,0x00,0x00,0x03,0x07,0x0C,0x08,0x0C,0x07,0x03,0x00,0x00,
0x01,
0x01,0x09,0x09,0x0F,0x0F,0x09,0x00,0x00,0x00,0x3F,0x3F,0x00,0x21,0x21,0x31,
0x1D,
0x0F,0x07,0x0D,0x19,0x39,0x31,0x11,0x00,0x02,0x06,0x07,0x03,0x21,0x31,0x1C,
0x0F,
0x03,0x01,0x03,0x06,0x0C,0x1C,0x18,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,
0xFF,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0xFF,
};
static void LCD_display_fb(gu_uint8 *fb)
{
        gu_uint8 Pages,Columns;
        gu_uint16 k=0;

        gu_lcd_send_cmd(0x40);                                                                //display start line set *?*
        for (Pages=0; Pages<=7; Pages++)
        {       
                gu_lcd_send_cmd(0xb0 + Pages);                                        //page address set
                gu_lcd_send_cmd(0x10);
                gu_lcd_send_cmd(0x00);                                                        //set column address

                for (Columns=0; Columns < 128; Columns++)
                {       
                        gu_lcd_send_data(fb);
                }
        }
}
static void ut_message_handler(gu_message_req_struct *msg_req)
{
        switch (msg_req->msg_type)
        {
                case GU_MSG_AT_RESULT:
                {
                        ut_at_result_handler(msg_req);
                        break;
                }
                case GU_MSG_KEYPAD_EVT:
                {
                        ut_keypad_handler(msg_req);
                        break;
                }
                case GU_MSG_EINT_EVT:
                {
                        ut_eint_handler(msg_req);
                        break;
                }
                case GU_MSG_UART_DATA_EVT:
                {
                        ut_uart_data_handler(msg_req);
                        break;
                }
      case GU_MSG_TIMER_EXPIRE:
      {
              ut_timer_expire_handler();
            break;
                }

                default:
                        break;
        }
       
}

void gu_main_task()
{
        const char *test_str = "GU900D unit test start....\r\n";
        gu_message_req_struct *msg_req = NULL;

        // execute the ut_timer_expire_handler after 5 seconds
        gu_app_start_timer(3000);
        LCD_display_fb(gImage_hfy);
        gu_uart2_send_data((gu_uint8*)test_str, strlen(test_str));

        gu_gpio_mode_setup(GU_PIN_CTS, GU_IO_MODE_5);
        gu_gpio_mode_setup(GU_PIN_RTS, GU_IO_MODE_5);

        while (1) {
                if ((msg_req = gu_get_message())) {

                        // Process the current message
                        ut_message_handler(msg_req);
                        gu_free_message(msg_req);
                }
        }
}




//////////////////////////////////////////////////// custom_unit_test.c ///////////////////////////////////////////////////////////////////////////////////////
#include "gu_sdk.h"
#include "stdlib.h"

extern void Uart_Printf(char * fmt, ...);
extern void ut_timer_expire_handler();
/////////// macro definitions ////////////////////////////////////////////
#define NUM_ELEMS(x) (sizeof(x)/sizeof(x))

#define UNIT_TEST_OK(feature)                        do { \
        Uart_Printf("[%s] unit test OK\r\n", feature); \
        } while (0);

#define UNIT_TEST_ERR(feature, code)        do { \
        Uart_Printf("[%s] unit test ERR, %d\r\n", feature, code); \
        return; \
        } while (0);


#define UNIT_TEST_DBG(feature, fmt, ...) do {\
        Uart_Printf("[%s] ", feature); \
    Uart_Printf(fmt, __VA_ARGS__); \
    Uart_Printf("\r\n"); \
    } while(0)

#define GU_AUDIO_TEST        "AUDIO"
#define GU_MEM_TEST                "MEM"
#define GU_FLASH_ACCESS        "FLASH"
#define GU_AT_RESULT        "AT RET"
#define GU_ADC_VOL                "ADC"

#define GU_KEYPAD_EVENT        "KEYPAD"
#define GU_EINT_EVENT        "EINT"
#define GU_UART_EVENT        "UART"

////////////////////////////////////////////////////////////////////

static gu_uint8        gu_test_func_id = 0;
static gu_uint16 gu_at_cmd_index = 0;


typedef struct {
        gu_char*cmd;
        gu_char*expect_str;
}gu_at_cmd_expect_struct;

/////////// gloabl / module variant ////////////////////////////////////////////
static gu_at_cmd_expect_struct gu_at_cmd_ut_list[] = {
        {"AT\r\n", "OK"},
        {"ATE0\r\n", "OK"},
        {"AT+CMGF=1\r\n", "OK"},
        {"AT+CSQ\r\n", "OK"},
        {"AT+CPIN?\r\n", "OK"},
        {"AT+CREG=2\r\n", "OK"},
        {"AT+CIPSCONT?\r\n", "OK"},
        {"AT+CSQ\r\n", "OK"},
        {"AT+CIPSTART?\r\n", "OK"},
        //{"ATD10010;\r\n", "OK"},
        {"ATD10086;\r\n", "OK"},
        {"ATH\r\n", "OK"},
        {"AT+ENBR\r\n", "OK"},
        {NULL, NULL}
};

static const char * s_finalResponsesError[] = {   
        "ERROR",   
        "+CMS ERROR:",   
        "+CME ERROR:",   
        "NO CARRIER", /* sometimes! */   
        "NO ANSWER",   
        "NO DIALTONE",
};

static const char * s_finalResponsesSuccess[] = {   
        "OK",   
        "CONNECT"       /* some stacks start up data on another channel */
};

/** returns 1 if line starts with prefix, 0 if it does not */
int strStartsWith(const char *line, const char *prefix)
{   
        for ( ; (*line != '\0' || *line != '\r') && *prefix != '\0' ; line++, prefix++)
        {      
                if (*line != *prefix)
                {            
                        return 0;      
                }   
        }   
        return (*prefix == '\0');
}

static int isFinalResponseError(const char *line)
{   
        gu_uint8 i;   

        for (i = 0 ; i < NUM_ELEMS(s_finalResponsesError) ; i++)
        {      
                if (strStartsWith(line, s_finalResponsesError))
                {            
                        return 1;      
                }   
        }   
        return 0;
}

static int isFinalResponseSuccess(const char *line)
{
        gu_uint8 i;   
        for (i = 0 ; i < NUM_ELEMS(s_finalResponsesSuccess) ; i++)
        {      
                if (strStartsWith(line, s_finalResponsesSuccess))
                {            
                        return 1;      
                }   
        }   
        return 0;
}

// Play all audio id
void ut_audio_test_func()

{
        static gu_uint16 i = GU_RING_IMY_01;

        gu_bool ret;

        if (i == GU_TONE_KEY_STAR)
        {
                i = GU_RING_IMY_01;
                gu_send_at_command("AT+CLVL=6\r\n", 11);
        }
        else if (i == GU_RING_IMY_10)
        {
                gu_test_func_id++;
        }
        UNIT_TEST_DBG(GU_AUDIO_TEST, "stop %d\r\n", i - 1);
        gu_app_stop_audio(i - 1);
        UNIT_TEST_DBG(GU_AUDIO_TEST, "play %d", i);
    ret = gu_app_play_audio(i, GU_AUDIO_PLAY_ONCE, GU_DEVICE_SPEAKER);
    UNIT_TEST_DBG(GU_AUDIO_TEST, "%d\r\n", ret);
    //kal_sleep_task(kal_milli_secs_to_ticks(i >= GU_RING_IMY_01 ? 10000:1000));   
    //gu_app_stop_audio(i);

        i = i++;
}



unsigned char buf_al[ 8 *1024];

unsigned char buf_al2[ 10 *1024];

unsigned char buf_al3[ 16 *1024];



void ut_mem_test_func()

{
       
        unsigned char buf_tmpl;
       
        unsigned char buf_tmpl2[ 2 *1024];
       
        gu_uint8 *p_alloc ;
       

        p_alloc = gu_app_malloc(2*1024);
       

        memset(buf_al, 10, sizeof(buf_al));
       
        memset(buf_al2, 10, sizeof(buf_al2));
       
        memset(buf_al3, 10, sizeof(buf_al3));
       
        memset(buf_tmpl, 0xFF, sizeof(buf_tmpl));
       
        memset(p_alloc, 0xFF, sizeof(1024));

        UNIT_TEST_DBG(GU_MEM_TEST, "buf_al: %X", &buf_al);
       
        UNIT_TEST_DBG(GU_MEM_TEST, "buf_al2: %X", &buf_al2);
       
        UNIT_TEST_DBG(GU_MEM_TEST, "buf_al3: %X", &buf_al3);
       
        UNIT_TEST_DBG(GU_MEM_TEST, "buf_tmpl: %X", &buf_tmpl);
       
        UNIT_TEST_DBG(GU_MEM_TEST, "buf_tmpl2: %X", &buf_tmpl2);

       
        UNIT_TEST_DBG(GU_MEM_TEST, "p_alloc: %X", p_alloc);

       

        gu_app_free(p_alloc);

        gu_test_func_id++;
}


void ut_flash_access_func()
{
        gu_int16         ret;
        gu_char                str_buf;
        gu_int32         max_size = 1024 * 1024;        // 1MB
        gu_uint8        rec_id = 0;
        int                 i = 0;
       
        // Flash access Unit test code
        for (rec_id = 0; rec_id < 10; rec_id++)
        {
                UNIT_TEST_DBG(GU_FLASH_ACCESS, "File %d, %d", rec_id, max_size / sizeof(str_buf));
               
                ret = gu_flash_alloc(rec_id, max_size);
                if (ret != GU_FLASH_NO_ERROR)
                {
                        gu_test_func_id++;
                        UNIT_TEST_OK(GU_FLASH_ACCESS);
                        return;
                }

                for (i = 0; i < max_size / sizeof(str_buf); i++)
                {
            memset(str_buf, 0, sizeof(str_buf));
            sprintf(str_buf, "unit test. %d, %d\r\n", rec_id, i);
            
                        ret = gu_flash_write(rec_id, i * sizeof(str_buf), str_buf,sizeof(str_buf));
                        if (ret != GU_FLASH_NO_ERROR)
                        {
                                UNIT_TEST_ERR(GU_FLASH_ACCESS, 2);
                        }
                        //UNIT_TEST_DBG(GU_FLASH_ACCESS, "write rec=%d", i);
                }
                // Write the data exceed the max_size of flash
          ret = gu_flash_write(rec_id, max_size, str_buf, sizeof(str_buf));
          if (ret == GU_FLASH_NO_ERROR)
          {
                  UNIT_TEST_ERR(GU_FLASH_ACCESS, 3);
          }

                // Read all data in possible
                for (i = 0; i < max_size / sizeof(str_buf); i++)
                {
                        memset(str_buf, 0, sizeof(str_buf));
                        ret = gu_flash_read(rec_id, i * sizeof(str_buf), str_buf, sizeof(str_buf));
                        if (ret != GU_FLASH_NO_ERROR)
                        {       
                                UNIT_TEST_ERR(GU_FLASH_ACCESS, 4);
                        }
                        //UNIT_TEST_DBG(GU_FLASH_ACCESS, "read rec=%s", str_buf);
                }

                // Read the data exceed the max_size of flash
          ret = gu_flash_read(rec_id, max_size, str_buf, sizeof(str_buf));
          if (ret == GU_FLASH_NO_ERROR)
          {
                  UNIT_TEST_ERR(GU_FLASH_ACCESS, 5);
          }
    }
        UNIT_TEST_OK(GU_FLASH_ACCESS);
        gu_test_func_id++;
}

////////////////////////////////////////////////////////////////////
extern int AtexBytes2String(const unsigned char* pSrc, char* pDst, int nSrcLength) ;

void ut_dump_to_uart_hex(gu_uint8 *data_buf, gu_int16 data_len)
{
    gu_uint8   data;
    gu_uint8   buffer;
    gu_int16   idx;

        sprintf(buffer, "HEX %d:\r\n", data_len);
        gu_uart1_send_data(buffer, strlen(buffer));
    data = '\0';
    buffer = '\0';
    for (idx = 0; idx < data_len; idx++)
    {
      AtexBytes2String(&data_buf, (char*)data, 1);
      data = ' ';
      data = '\0';
      strcat((char*)buffer, (char*)data);
      if ((idx + 1) % 20 == 0)
      {
            strcat((char*)buffer, "\r\n");
            gu_uart1_send_data(buffer, strlen((char*)buffer));
            buffer = '\0';
      }
    }
    idx = strlen((char*)buffer);
    if (idx > 0)
      gu_uart1_send_data(buffer, idx);
    gu_uart1_send_data((gu_uint8*)"\r\n", 2);
}


void ut_at_result_handler(gu_message_req_struct *msg_req)
{
        gu_char at_result;
        gu_char *at_ptr = at_result;
        gu_uint8 i;
        gu_bool        at_completed = GU_FALSE;
    gu_uint16curr = 0, len = 0;
    gu_uint16ulen = 128;
   
    memcpy(at_result, msg_req->data, msg_req->data_length);
    at_result = '\0';
        ut_dump_to_uart_hex(msg_req->data, msg_req->data_length);
        gu_uart1_send_data((gu_char*)msg_req->data, msg_req->data_length);
        return;
       
        do {
                while(*at_ptr == '\r' || *at_ptr == '\n')
                {                                 
                        at_ptr++;
                }
                if (*at_ptr == '\0')
                        break;
               
                if (isFinalResponseError(at_ptr))
                {
                        at_completed = GU_TRUE;
                        break;
                }
                else if (isFinalResponseSuccess(at_ptr))
                {
                        at_completed = GU_TRUE;
                        break;
                }
        } while ((at_ptr = (gu_char*)strstr(at_ptr, "\r")));

        if (!at_completed)
                return;

        if (gu_at_cmd_index >= NUM_ELEMS(gu_at_cmd_ut_list) - 1)
        {
                gu_test_func_id++;
        }
        //ut_timer_expire_handler();
        gu_app_start_timer(100);
}

void ut_at_cmd_list_func()
{
        gu_uint8        cmd_idx = gu_at_cmd_index % (NUM_ELEMS(gu_at_cmd_ut_list) - 1);

        if (gu_at_cmd_ut_list.cmd)
        {
                Uart_Printf("[%d]=%s", gu_at_cmd_index, gu_at_cmd_ut_list.cmd);
                gu_send_at_command(gu_at_cmd_ut_list.cmd,
                        strlen(gu_at_cmd_ut_list.cmd));
        }
        gu_at_cmd_index++;
               
}

void ut_keypad_handler(gu_message_req_struct *msg_req)
{
        gu_key_evt_struct *key_evt = (gu_key_evt_struct*)msg_req->data;

        UNIT_TEST_DBG(GU_KEYPAD_EVENT, "KEY CODE=%d, KEY TYPE=%d\r\n", key_evt->key_code, key_evt->key_type);
}

void ut_adc_vol_test_func()
{
        UNIT_TEST_DBG(GU_ADC_VOL, "ext1 adc=%d\r\n", gu_app_get_adc_val(GU_ADC_EXT1));
        UNIT_TEST_DBG(GU_ADC_VOL, "vbat adc=%d\r\n", gu_app_get_adc_val(GU_ADC_VBAT));
}

void ut_eint_handler(gu_message_req_struct *msg_req)
{
        gu_eint_evt_struct *eint_evt = (gu_eint_evt_struct*)msg_req->data;

        UNIT_TEST_DBG(GU_EINT_EVENT, "dev=%d, on_off=%d\r\n", eint_evt->dev_id, eint_evt->on_off);

        //ut_timer_expire_handler();
}

// This sample is to test the case of inputting AT command from uart1 or uart2
// The user uses the uart connection like as the normal AT command module
void ut_uart_data_handler(gu_message_req_struct *msg_req)
{
        gu_uart_data_evt_struct *uart_data = (gu_uart_data_evt_struct*)msg_req->data;

        if (uart_data->port == GU_UART_PORT1) {
                Uart_Printf((gu_char*)uart_data->data);
               
                                 // Handle Custome AT command
                if (memcmp(uart_data->data, "MIC1", 4) == 0)
                        gu_set_input_mic(GU_INPUT_MIC_1);
                else if (memcmp(uart_data->data, "MIC2", 4) == 0)
                        gu_set_input_mic(GU_INPUT_MIC_2);
                else
                        gu_send_at_command(uart_data->data, uart_data->data_length);
        }
        else if (uart_data->port == GU_UART_PORT2) {
                Uart2_Printf((gu_char*)uart_data->data);
        }
        else
                UNIT_TEST_ERR(GU_UART_EVENT, 1);
}

extern void AtexSetSleepModeReq(gu_uint8 index);

void ut_timer_expire(void* arg)
{
        //Uart_Printf("ut_timer_expire\r\n");
        //gu_start_timer(1, ut_timer_expire, NULL, 1000);
}

void ut_timer_expire_handler()
{

        switch (gu_test_func_id)
        {
                case 0:
                        gu_start_timer(1, ut_timer_expire, NULL, 1000);
                        ut_audio_test_func();
                        gu_app_start_timer(5000);
                        break;
      case 1:
              ut_mem_test_func();
              gu_app_start_timer(1000);
            break;
      case 2:
              ut_flash_access_func();
              gu_app_start_timer(1000);
            break;
      case 3:
              ut_at_cmd_list_func();
            break;
      case 4:
            ut_adc_vol_test_func();
            break;
        }
       
}

zemicxm007 发表于 2012-7-30 17:28:14

有没有音频的外围电路呢?比如加个录音芯片什么的

wozaijintian 发表于 2012-7-31 21:13:06

正在应用做一个GPRS的跟踪器, 效果还是不错,开发也相对简便,3个星期了。。。

仇先天 发表于 2013-3-11 16:35:58

mark。。。

Baldwin 发表于 2013-3-11 22:32:31

mark-------
页: [1]
查看完整版本: GU900D GPRS模块OPEN AT示例代码