|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
StartNetworkTask进程是在cfg文件中创建的进程。主要用于接收上位机通过TCP传来的图片数据以及将处理结果传输给上位机。具体流程本节介绍。7 Y4 ]: w6 \( s" T6 N3 c
% s' W: O; G* \' ^& O, L+ C
一、StartNetworkTask
; S/ t7 J5 t0 ^: K* v: e$ r, _- C- _
1 TCP的配置! D$ a o+ M& }! o3 {
2 ?$ l6 V z: }9 f
- rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
- if( rc )
- {
- printf("NC_SystemOpen Failed (%d)\n",rc);
- for(;;);
- }
- // Create and build the system configuration from scratch.
- // Create a new configuration
- hCfg = CfgNew();
- if( !hCfg )
- {
- printf("Unable to create configuration\n");
- goto main_exit;
- }
- // THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION!!
- rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
- if( rc )
- {
- printf("NC_SystemOpen Failed (%d)\n",rc);
- for(;;);
- }
- // Create and build the system configuration from scratch.
- // Create a new configuration
- hCfg = CfgNew();
- if( !hCfg )
- {
- printf("Unable to create configuration\n");
- goto main_exit;
- }
- // We better validate the length of the supplied names
- if( strlen( DomainName ) >= CFG_DOMAIN_MAX ||
- strlen( HostName ) >= CFG_HOSTNAME_MAX )
- {
- printf("Names too long\n");
- goto main_exit;
- }
- // Add our global hostname to hCfg (to be claimed in all connected domains)
- CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
- strlen(HostName), (UINT8 *)HostName, 0 );
- // If the IP address is specified, manually configure IP and Gateway
- #if defined(_SCBP6618X_) || defined(_EVMTCI6614_) || defined(DEVICE_K2H) || defined(DEVICE_K2K)
- /* SCBP6618x, EVMTCI6614, EVMK2H, EVMK2K always uses DHCP */
- if (0)
- #else
- if (1)//(!platform_get_switch_state(1))
- #endif
- {
- CI_IPNET NA;
- CI_ROUTE RT;
- IPN IPTmp;
- // Setup manual IP address
- bzero( &NA, sizeof(NA) );
- NA.IPAddr = inet_addr(LocalIPAddr); //设置IP
- NA.IPMask = inet_addr(LocalIPMask); //设置掩码
- strcpy( NA.Domain, DomainName );
- NA.NetType = 0;
- // Add the address to inteRFace 1
- CfgAddEntry( hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (UINT8 *)&NA, 0 );
- // Add the default gateway. Since it is the default, the
- // destination address and mask are both zero (we go ahead
- // and show the assignment for clarity).
- bzero( &RT, sizeof(RT) );
- RT.IPDestAddr = 0;
- RT.IPDestMask = 0;
- RT.IPGateAddr = inet_addr(GatewayIP);
- // Add the route
- CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 0,sizeof(CI_ROUTE), (UINT8 *)&RT, 0 );
- // Manually add the DNS server when specified
- IPTmp = inet_addr(DNSServer);// "0.0.0.0"
- if( IPTmp )
- CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
- 0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0 );
- }
- // Else we specify DHCP
- else
- {
- CI_SERVICE_DHCPC dhcpc;
- // Specify DHCP Service on IF-1
- bzero( &dhcpc, sizeof(dhcpc) );
- dhcpc.cisargs.Mode = CIS_FLG_IFIDXVALID;
- dhcpc.cisargs.IfIdx = 1;
- dhcpc.cisargs.pCbSrv = &ServiceReport;
- CfgAddEntry( hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_DHCPCLIENT, 0,
- sizeof(dhcpc), (UINT8 *)&dhcpc, 0 );
- }
- // Configure IPStack/OS Options
- // We don't want to see debug messages less than WARNINGS
- rc = DBG_ERROR;
- CfgAddEntry( hCfg, CFGTAG_OS, CFGITEM_OS_DBGPRINTLEVEL,
- CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );
- //
- // This code sets up the TCP and UDP buffer sizes
- // (Note 8192 is actually the default. This code is here to
- // illustrate how the buffer and limit sizes are configured.)
- //
- /* TCP Transmit buffer size */
- rc = 64000;
- CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPTXBUF,
- CFG_ADDMODE_UNIQUE, sizeof(uint), (uint8_t *)&rc, 0 );
- /* TCP Receive buffer size (copy mode) */
- rc = 64000;
- CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXBUF,
- CFG_ADDMODE_UNIQUE, sizeof(uint), (uint8_t *)&rc, 0 );
- /* TCP Receive limit (non-copy mode) */
- rc = 64000;
- CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKTCPRXLIMIT,
- CFG_ADDMODE_UNIQUE, sizeof(uint), (uint8_t *)&rc, 0 );
- // UDP Receive limit
- rc = 8192;
- CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKUDPRXLIMIT,
- CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );/ _! x0 l: o) T* B( e
& H- y! s. J# v& ^$ h; b$ b/ m3 I7 W8 k! W- X
- do
- {
- // 调用起始函数 调用结束函数 调用IP地址设置函数
- rc = NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr );
- } while( rc > 0 );
- 7 d! b! k2 n2 k; E+ {/ \4 s
/ p2 L# }; T9 l7 O0 N9 E$ M+ X* Y; N K: V3 o- B- C/ g4 L, ^
// 调用起始函数 调用结束函数 调用IP地址设置函数$ L" C6 a2 |% c$ C1 g
rc = NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr );
! l$ V& G) X2 r( `; s( [7 V } while( rc > 0 );% m# v: b0 @9 x4 z) X
' l% r6 x) v! S; h) U
1 n, Z% S! x6 V) @7 c" P m& d0 A% @1 @
% [- y" O# M% @8 N4 c
2 g2 s" f }3 [/ f
7 P \2 k# b. ]* I& ]
|
|