📄 pinghost.c
字号:
/***********************************************************
* MODULE: Init.c
*
* PURPOSE:
* This file is the test for network application.
* you can run it with the help.
*
* COPYRIGHT (C) 2000-2001, CoreTek Systems Inc.
* ALL RIGHTS RESERVED
***********************************************************
* AUTHOR(S):
*
* DATE CREATED: 2001
*
* MODIFICATIONS:
* Date userName Description
* 2001.2.20 Wang lijie
* 2001.4.10 ChengShuai
* 2001.10.16 ChenTie
***********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "usr_config.h"
#include <irq.h>
#include "sys/types.h"
#include "DnetStat.h"
#include "DnetBase.h"
#include "DnetSock.h"
#include "osaware.h"
#define DEMO_TASKSLEEP(t) delta_task_wake_after(t)
#define DEMO_DEBUG printf
#define DEMO_CLOCKGET(t) delta_clock_get(DELTA_CLOCK_GET_TICKS_SINCE_BOOT,(void *)t);
#ifdef DELTA_NET
#if ( defined(Dnet_USE_PPP) && !defined(Dnet_USE_ETHER) )
#define conf_DIALUPCONNECTMODE (unsigned char *)"DialUp connect mode: ALWAYS" /*always dialup*/
#elif ( !defined(Dnet_USE_PPP) && defined(Dnet_USE_ETHER) )
#define conf_DIALUPCONNECTMODE (unsigned char *)"DialUp connect mode: NEVER" /*never dialup*/
#define conf_NetPlinkTaskPRI (unsigned char *)"network ppp link task priority: 6"
#elif ( defined(Dnet_USE_PPP) && defined(Dnet_USE_ETHER) )
#define conf_DIALUPCONNECTMODE (unsigned char *)"DialUp connect mode: AUTO" /*dialup when ethernet is invalid*/
#endif
#define MAXPARMS 40
struct dnet_confparam user_parms[MAXPARMS] = {
{conf_NETDEBUG},
{conf_DIALUPCONNECTMODE},
#ifdef Dnet_USE_ETHER
{conf_IPADDR}, /* Local IP address */
{conf_SUBMASK}, /* Subnetwork mask */
{conf_GATEWAY}, /* Gateway address */
{conf_RARPCLN}, /*RARP */
#endif/*fDnet_USE_ETHER*/
#ifdef Dnet_USE_PPP
{conf_CONSOLELOG}, /* Log Modem & PPP events to console */
{conf_KEEPALIVE}, /* seconds between PPP echos, 0=disable */
{conf_CLIENTTMO}, /* timeout for connects as client */
{conf_REQUESTVJ}, /* request that the other side do VJ compression */
{conf_REQUIREPAP}, /* PAP support */
{conf_DIALPHONE}, /* phone number to dial*/
{conf_MODEMINIT}, /* initialization "AT" command */
{conf_USERNAME}, /* user name */
{conf_PASSWORD}, /* user password */
{conf_LINETMO}, /* idle modem line timeout, 0=infinite */
{conf_LINEPROTOCOL}, /* LineProtocol:1=PPP, 2=SLIP */
#endif/*Dnet_USE_PPP*/
{conf_DHCPCLN}, /* DHCP */
{conf_DNSCLN}, /* DNS client */
{conf_DNSSVR1}, /* DNS server */
{conf_DNSSVR2},
/*{conf_DNSSVR3},*/
#ifdef Dnet_SNMP_AGENT
{conf_SNMPGET},
{conf_SNMPSET},
{conf_SNMPSYSCON},
{conf_SNMPSYSNAME},
{conf_SNMPSYSLOC},
{conf_SNMPTRAPTARGET},
{conf_SNMPTRAPCOMM},
#endif/*Dnet_SNMP_AGENT*/
{conf_PINGAPP},
{conf_TELENTCLN},
{conf_NetRcvTaskPRI},
{conf_NetTimrTaskPRI},
{conf_NetPlinkTaskPRI},
{conf_NetMaxSocks},
{conf_END},
};
#endif/*DELTA_NET*/
#ifdef Dnet_USE_ETHER
extern int Ethdrv_Prepare(void);
#endif
#ifdef Dnet_USE_PPP
extern int Uartdrv_Prepare(void);
extern int Uartdrv_Open(void);
extern int Uartdrv_Close(void);
extern int Uartdrv_Output(char *buf,int len);
extern int Uartdrv_Input(char * buf,int *lenptr);
#endif
#define PINGHOST_COMMAND "ping 192.168.0.151 -n 10"
/***********************************************************
* MODULE: Ph_Task
*
* PURPOSE:
* main body of pinghost task
*
* PARAMETERS:
* Input: none
* Output: none
* Return value: none
*
***********************************************************/
static void Ph_Task()
{
int retval=DNET_SUCCESS;
while (1)
{
#if ( defined(Dnet_USE_PPP) && !defined(Dnet_USE_ETHER) )
retval = Dnet_DialUpState();
if ( retval >= DNET_S_PPP_CONNECTED )
{
Dnet_DialUpDisconnect();
while ( Dnet_DialUpState() >= DNET_S_PPP_CONNECTED )
DEMO_TASKSLEEP(1000);
}
retval = Dnet_DialUpConnect();
if ( retval == DNET_SUCCESS )
{
retval = Dnet_DialUpState();
while ( Dnet_DialUpState() >= DNET_S_PPP_DIALING )
DEMO_TASKSLEEP(1000);
retval = Dnet_DialUpState();
}
if ( retval != DNET_S_PPP_CONNECTED )
{
DEMO_TASKSLEEP(1000);
continue;
}
#endif
retval = ping(PINGHOST_COMMAND);
if (retval != DNET_SUCCESS)
{
DEMO_DEBUG("ping failed %d\n",retval);
DEMO_TASKSLEEP(10000);
}
}
}
/***********************************************************
* MODULE: Init()
*
* PURPOSE:
* This routine is the initialization task for this test program.
* It is a user initialization task and has the responsibility for creating
* and starting the tasks that make up the test. If the time of day
* clock is required for the test, it should also be set to a known
* value by this function.
*
* PARAMETERS
* Input: none
* Output: none
* Return value: none
*
***********************************************************/
#define UART2 2
#define UART1 1
extern void UartInit(int baudrate, int serial);
delta_task Init(void)
{
int e=0;
delta_name taskname;
int taskpri=10;
delta_id taskid;
/*初始化串口,设置波特率为38400*/
UartInit( 115200, UART1);
#if (!CONFIGURE_USE_BURN_MODE)
mount_osaware();
#endif
/* 设置输出设备,设置底层的字符输出函数,实现输出重定向
* 在使用pintf,putc,puts等I/O输出函数前必须先用该函数设置字符输出函数,否则输出无效。
*/
set_outputfunc((outputfunc_ptr)uart_putchar_to_uart1);
printf("dsadf\r\n");
#ifdef DELTA_NET
#ifdef Dnet_USE_ETHER
/*准备以太网*/
e = Ethdrv_Prepare();
if (e != DNET_SUCCESS)
{
printf("ether driver prepare failed\n");
delta_task_delete( DELTA_SELF );
}
#endif
#ifdef Dnet_USE_PPP
/*准备UART*/
e = Uartdrv_Prepare();
if (e != DNET_SUCCESS)
{
printf("uart drviver prepare failed\n");
delta_task_delete( DELTA_SELF );
}
#endif
/*配置DeltaNET*/
e = Dnet_Config((struct dnet_confparam *)&user_parms);
if (e != DNET_SUCCESS)
{
printf("DeltaNet config failed\n");
delta_task_delete( DELTA_SELF );
}
/*初始化DeltaNET*/
e = Dnet_Init();
if (e != DNET_SUCCESS)
{
printf("DeltaNet init failed\n");
delta_task_delete( DELTA_SELF );
}
#endif
taskname = delta_build_name('P','I','N','G');
e = delta_task_create ( taskname,
taskpri++,
1024 * 10,
DELTA_DEFAULT_MODES,
DELTA_DEFAULT_ATTRIBUTES,
&taskid
);
if (e != DELTA_SUCCESSFUL)
{
printf("pinghost task create failed:%d\n\r",e);
delta_task_delete( DELTA_SELF );
}
e = delta_task_start ( taskid,(delta_task_entry)Ph_Task, 0 );\
if (e != DELTA_SUCCESSFUL)
{
printf("pinghost task start failed:%d\n\r",e);
delta_task_delete( DELTA_SELF );
}
delta_task_delete( DELTA_SELF );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -