nrmenus.c
来自「在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LE」· C语言 代码 · 共 1,653 行 · 第 1/3 页
C
1,653 行
ns_printf(pio, "RX ");
if(NDEBUG & LOSSY_TX)
ns_printf(pio, "TX");
ns_printf(pio, "\n");
}
return 0;
}
#endif /* LOSSY_IO */
extern queue bigfreeq; /* big free buffers */
extern queue lilfreeq; /* small free buffers */
extern unsigned lilbufs;
extern unsigned bigbufs;
/* FUNCTION: dumpqueues()
*
* PARAM1: void * pio
*
* RETURNS:
*/
int
dumpqueues(void * pio)
{
ns_printf(pio,"bigfreeq: head:%p, tail:%p, len:%d, min:%d, max:%d\n",
(void far *)bigfreeq.q_head, (void far *)bigfreeq.q_tail,
bigfreeq.q_len, bigfreeq.q_min, bigfreeq.q_max);
ns_printf(pio,"lilfreeq: head:%p, tail:%p, len:%d, min:%d, max:%d\n",
(void far *)lilfreeq.q_head, (void far *)lilfreeq.q_tail,
lilfreeq.q_len, lilfreeq.q_min, lilfreeq.q_max);
ns_printf(pio,"rcvdq: head:%p, tail:%p, len:%d, min:%d, max:%d\n",
(void far *)rcvdq.q_head, (void far *)rcvdq.q_tail,
rcvdq.q_len, rcvdq.q_min, rcvdq.q_max);
return 0;
}
#ifdef NPDEBUG
extern PACKET pktlog[MAXPACKETS];
#endif
/* FUNCTION: dumpbufs()
*
* dumpbufs() - dump packet free queues
*
* PARAM1: void * pio
*
* RETURNS:
*/
int
dumpbufs(void * pio)
{
#ifdef NPDEBUG
int i;
PACKET pkt;
int lines = 1; /* output line count for paging */
char * cp;
int offset = 0;
/* optional parameter is how far into the each buffer to start display */
cp = nextarg(((GEN_IO)pio)->inbuf);
if (cp && *cp)
{
offset = atoi(cp);
}
ns_printf(pio,"PACKET len buffer que data offset %d\n",offset);
for (i = 0; i < (int)(lilbufs+bigbufs); i++ )
{
pkt = pktlog[i];
ns_printf(pio,"%p,%4d,%p,%s:",
pkt, pkt->nb_blen, pkt->nb_buff, qname(pkt));
hexdump(pio,pkt->nb_buff + offset, 12);
lines++;
if ( con_page(pio,lines) )
return 0 ;
}
#else
ns_printf(pio,"Not debug build\n");
#endif
return 0;
}
#ifdef INCLUDE_TCP
#ifdef NET_STATS
char * socket_queue_name(PACKET pkt);
#endif /* NET_STATS */
#endif /* INCLUDE_TCP */
/* FUNCTION: qname()
*
* return 3 char name of queue PACKET is in
*
* PARAM1: PACKET pkt
*
* RETURNS:
*/
char * qname(PACKET pkt)
{
qp tmp;
#ifdef INCLUDE_TCP
#ifdef NET_STATS
char * so_queue_name;
#endif /* NET_STATS */
#endif /* INCLUDE_TCP */
/* search for packet in the known queues: */
for (tmp = lilfreeq.q_head; tmp; tmp = tmp->qe_next)
if (tmp == (qp)pkt)
return "lil";
for (tmp = bigfreeq.q_head; tmp; tmp = tmp->qe_next)
if (tmp == (qp)pkt)
return "big";
for (tmp = rcvdq.q_head; tmp; tmp = tmp->qe_next)
if (tmp == (qp)pkt)
return "rcv";
#ifdef INCLUDE_TCP
#ifdef NET_STATS
/* check to see if the packet is in one of the socket queues */
so_queue_name = socket_queue_name(pkt);
if (so_queue_name)
return so_queue_name;
#endif /* NET_STATS */
#endif /* INCLUDE_TCP */
return "non";
}
extern char * name;
/* FUNCTION: showver()
*
* PARAM1: void * pio
*
* RETURNS:
*/
int
showver(void * pio)
{
ns_printf(pio,"%s\n", name);
return 0;
}
extern char * prompt;
char * oldprompt = "OOPS> ";
/* if we have to deal with Intel's 16 bit segmented architecture */
#ifdef SEG16_16
/* FUNCTION: dump_bytes()
*
* segment:offset version of dump_bytes()
*
* PARAM1: void * pio
*
* RETURNS:
*/
int
dump_bytes(void * pio)
{
char * cp;
unshort seg, offset;
int length;
cp = nextarg(((GEN_IO)pio)->inbuf); /* see if user put addr on cmd line */
if (!*cp)
goto db_prompt;
seg = (unshort)atoh(cp);
cp = strchr(cp, ':'); /* find colon in string */
if (!cp)
goto db_prompt;
cp++;
offset = (unshort)atoh(cp);
cp = nextarg(cp); /* see if user specified length to dump */
if (*cp) /* cp should point to end of args or length */
length = atoh(cp);
else /* no length on command line, set a reasonable default */
length = 16;
hexdump(pio,_MK_FP(seg, offset), length);
return 0;
db_prompt: /* prompt user for correct format */
ns_printf(pio,"enter memory location in hex seg:offset form, followed by optional length.\n");
return -1;
}
#else /* SEG16_16 */
/* FUNCTION: dump_bytes()
*
* flat memory version of dump_bytes()
*
* PARAM1: void * pio
*
* RETURNS:
*/
int
dump_bytes(void * pio)
{
char * cp;
unsigned int address;
int length;
cp = nextarg(((GEN_IO)pio)->inbuf); /* see if user put addr on cmd line */
if (!*cp)
goto db_prompt;
address = atoh(cp);
cp = nextarg(cp); /* see if user specified length to dump */
if (*cp) /* cp should point to end of args or length */
length = atoh(cp);
else /* no length on command line, set a reasonable default */
length = 16;
hexdump(pio,(void *) address, length);
return 0;
db_prompt: /* prompt user for correct format */
ns_printf(pio,"enter memory location in hex, followed by optional length.\n");
return -1;
}
#endif /* SEG16_16 */
/* FUNCTION: menu_exit()
*
* PARAM1: void * pio
*
* RETURNS:
*/
int
menu_exit(void * pio)
{
USE_VOID(pio);
netexit(0); /* shut down hardware & exit to system */
return 0; /* keeps compiler from whining */
}
#ifdef UDPSTEST
/* FUNCTION: udpecho()
*
* PARAM1: void * pio
*
* RETURNS:
*/
int udpecho(void * pio)
{
long times = 1;
char * arg2;
arg2 = nextarg(((GEN_IO)pio)->inbuf); /* get iteration arg from cmd line */
if (arg2 && *arg2)
times = atol(arg2);
if (times < 1)
{
ns_printf(pio,"command line arg must be number of echos to send\n");
return -1;
}
if (activehost == 0L)
{
ns_printf(pio,"IP host to echo to must be set with \"host\" command\n");
return -1;
}
/* send echo - this prints it's own errors */
udp_sendecho(pio,activehost, deflength, times);
return 0;
}
#endif /* UDPSTEST */
#ifdef TCP_ECHOTEST
/* FUNCTION: tcpecho()
*
* PARAM1: void * pio
*
* RETURNS:
*/
int tcpecho(void * pio)
{
long times = 1;
char * arg2;
arg2 = nextarg(((GEN_IO)pio)->inbuf); /* get iteration arg from cmd line */
if (arg2 && *arg2)
times = atol(arg2);
if (times < 1)
{
ns_printf(pio,"command line arg must be number of echos to send\n");
return -1;
}
if (activehost == 0L)
{
ns_printf(pio,"IP host to echo to must be set with \"host\" command\n");
return -1;
}
/* send echo - this prints it's own errors */
tcp_sendecho(pio,activehost, (long)deflength, times);
return 0;
}
#endif /* TCP_ECHOTEST */
#ifdef IP_ROUTING
char * route_prots[] =
{
"foo",
"OTHER",
"LOCAL",
"NETMGT",
"ICMP",
"EGP",
"GGP",
"HELLO",
"RIP",
};
#ifdef BTREE_ROUTES
/* FUNCTION: btree_routes()
*
* Helper function for displaying routes in the binary tree. A pointer to
* this is passed to avldepthfirst();
*
* PARAM1: current RtMib
* PARAM2: pointer to pio
* PARAM3: depth in tree
*
* RETURNS:
*/
static brtcount;
void
btree_routes(struct RtMib * rtp, long param, int depth)
{
void * pio = (void*)param;
brtcount++;
/* if this is first entry then display heading */
if(brtcount == 1)
ns_printf(pio,"..IPaddr.......mask.........nexthop...iface..type\n");
while(depth--)
ns_printf(pio, " ");
ns_printf(pio,"%u.%u.%u.%u %u.%u.%u.%u %u.%u.%u.%u %d %s\n",
PUSH_IPADDR(rtp->ipRouteDest),
PUSH_IPADDR(rtp->ipRouteMask),
PUSH_IPADDR(rtp->ipRouteNextHop),
(int)rtp->ipRouteIfIndex,
route_prots[(int)rtp->ipRouteProto]);
}
#endif /* BTREE_ROUTES */
/* FUNCTION: show_routes()
*
* PARAM1: void * pio
*
* RETURNS:
*/
int
show_routes(void * pio)
{
int rtcount = 0;
#ifdef BTREE_ROUTES
brtcount = 0;
avldepthfirst(rt_mib, btree_routes, (long)pio, 0);
rtcount = brtcount;
#else /* not BTREE_ROUTES */
RTMIB rtp;
if(!rt_mib) /* system not fully up yet */
return -1;
for (rtp = rt_mib; rtp < rt_mib + ipRoutes; rtp++)
{
if (!rtp->ipRouteNextHop) /* empty slot */
continue;
rtcount++;
if (rtcount == 1)
ns_printf(pio,"..IPaddr.......mask.........nexthop...iface..type\n");
ns_printf(pio,"%u.%u.%u.%u %u.%u.%u.%u %u.%u.%u.%u %d %s\n",
PUSH_IPADDR(rtp->ipRouteDest),
PUSH_IPADDR(rtp->ipRouteMask),
PUSH_IPADDR(rtp->ipRouteNextHop),
(int)rtp->ipRouteIfIndex,
route_prots[(int)rtp->ipRouteProto]);
}
#endif /* BTREE_ROUTES */
if (rtcount == 0)
ns_printf(pio,"no IP routes set\n");
return 0;
}
/* FUNCTION: mn_add_route()
*
* menu routine to manually add a route. format is target.ip
* target.mask next.hop iface.
*
*
* PARAM1: void * pio
*
* RETURNS:
*/
int mn_add_route(void * pio)
{
char * cp; /* text for interface index */
int ifindex; /* value of interface index */
unsigned snbits;
int i;
char * errmsg;
RTMIB rtp;
NET ifp;
struct ip_args
{ /* for reading in IP addresses from console buf */
char * text;
ip_addr ipaddr;
} ipargs[4];
cp = nextarg(((GEN_IO)pio)->inbuf); /* start of command line args */
for (i = 0; i <= 3; i++) /* read in 4 args */
{
ipargs[i].text = cp;
if (i == 3) /* last arg is not an IP address, so we're done */
break;
/* null terminate IP address arg */
cp = strchr(ipargs[i].text, ' ');
if (cp)
{
*cp++ = '\0'; /* terminate this arg */
while (*cp == ' ')cp++; /* find next arg */
}
else /* no space after arg == bogus command line */
{
ns_printf(pio,"usage: target.ip target.mask next.hop iface \n");
ns_printf(pio," where 1st 3 parms are in IP dot notation, last is digit 1-%d\n",
ifNumber);
return -1;
}
/* call parse_ipad to fill in IP address from text */
errmsg = parse_ipad(&ipargs[i].ipaddr, &snbits, ipargs[i].text);
if (errmsg)
{
ns_printf(pio,"bad IP format \"%s\" in arg %d, \n problem: %s\n",
ipargs[i].text, i, errmsg);
return -1;
}
}
ifp = if_netbytext(pio, ipargs[i].text);
if (ifp == NULL)
return -1;
else
ifindex = if_netnumber(ifp);
rtp = add_route(ipargs[0].ipaddr, ipargs[1].ipaddr, ipargs[2].ipaddr,
ifindex, IPRP_LOCAL);
if (!rtp)
{
ns_printf(pio,"add_route failed, table full?\n");
return -1;
}
return 0;
}
#endif /* IP_ROUTING */
/* FUNCTION: set_ipaddr()
*
* Allows console user to set an IP address of an interface on the fly. Usefull
* for testing, but dangerous in field.
*
* PARAM1: void * pio
*
* RETURNS:
*/
int
set_ipaddr(void * pio)
{
char * cp;
char * iptext;
ip_addr ipaddr;
ip_addr mask;
unsigned int snbits;
struct net * ifp;
int iface = 0;
ns_printf(pio, "WARNING: 'setip' will kill all current net connections!!!!\n");
cp = nextarg(((GEN_IO)pio)->inbuf); /* see if user put addr on cmd line */
if (!*cp)
{
ns_printf(pio, "usage: setip X.X.X.X [iface (name or 1-n)]\n");
return -1;
}
iptext = cp; /* save pointer to IP spec */
cp = nextarg(cp); /* see if user specified interface number */
if (*cp)
{
ifp = if_netbytext(pio, cp);
if(ifp == NULL)
return -1;
iface = if_netnumber(ifp);
}
else /* no iface number given, default to first static */
{
ifp = nets[0];
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?