📄 main.c
字号:
#include <utility.h>#include <ansi_c.h>#include "gsm.h"#include "gsmcmd.h"#include "gsmutils.h"#include "gprs_a.h"#include "cq.h"int nSocket = -1;int Remote_port = -1;char Remote_ip[ 64 ] = { 0, };void TCP_send ( char * pData ){ if ( GPRS_get_status () == GPRS_DISCONNECTED ) { if ( GPRS_connect ( "INTERNET" ) == GPRS_DISCONNECTED ) { printf ( "ERROR: GPRS connect fail\n" ); return; } } if ( nSocket < 0 ) { strcpy ( Remote_ip, "203.160.252.54" );// nSocket = socket_open ( 0, SOCKET_TCP, (char *)Remote_ip, (Remote_port = 10000) ); nSocket = socket_open ( 0, SOCKET_UDP, (char *)Remote_ip, (Remote_port = 12000) ); if ( nSocket < 0 ) { printf ( "ERROR: socket open fail\n" ); return; } } socket_write ( nSocket, pData, strlen ( pData ) );}void gsm_init ( void );void gsm_check ( void );void ftp_test ( void );unsignedchar szRSP[ 32 + 1 ];unsignedchar szTCP[ 1024 + 1 ];void clearfile ( char * pfile );#include "ftpdwl.h"int ftp_log ( unsigned char * p, int nbytes, int seek );#ifdef NONE_CRC_PACK#define FTP_RSP_LEN 128#else#define FTP_RSP_LEN (PACKSIZE + CRC_SIZE)#endifstaticunsignedchar szFTP[ FTP_RSP_LEN + 1 ];t_ftp ftpinfo = {#if 0 21, (unsigned char *)"219.084.014.102",#else 1596, (unsigned char *)"221.231.140.211",#endif (unsigned char *)"slg", // login username (unsigned char *)"123", // login password#ifdef NONE_CRC_PACK (unsigned char *)"TOMFILE", // file name 87300, // file size#else (unsigned char *)"USER.crc", // file name 87644, // file size#endif 1000000, // timeout ftp_log, 0, // bytes received 0, // port 2 0, // ip 2 0, // ctrl socket 0, // data socket szFTP, // tmp buffer FTP_RSP_LEN};int main ( int argc, char * argv[] ){int i = 0;int n = 0;staticint c = 0; gsm_init (); Delay ( 2 ); AT_sendCMD ( "AT", 0 ); AT_recvRSP ( szRSP, 32 ); if ( GPRS_get_status () == GPRS_DISCONNECTED ) { // while ( GPRS_restart ( "INTERNET" ) == GPRS_DISCONNECTED ) printf ( "ERROR: GPRS connect fail\n" ); while ( GPRS_restart ( "INTERNET" ) == GPRS_DISCONNECTED ) printf ( "ERROR: GPRS connect fail\n" ); } clearfile ( "aipr.log" ); clearfile ( "USERTEST" ); while ( 1 ) { ftp_dwl ( &ftpinfo ); while ( 1 ) printf ( "DWL OK\n" ); continue; gsm_check (); Delay ( 1 ); n = socket_read ( 1, szTCP, 1024 ); if ( n ) { szTCP[ n ] = 0; printf ( "socket read: (%04d)\n%s\n", n, szTCP ); Delay ( 2 ); }#if 0 if ( i++ < 5 ) continue; i = 0; AT_sendCMD ( "AT", 0 ); AT_recvRSP ( szRSP, 32 ); continue;#endif#if 1 sprintf ( szTCP, "Hello World! (%04d)\r\n", c++ ); TCP_send ( szTCP );#endif } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -