⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demoi.c

📁 基于nucleus操作系统的GPRS无线数据传输终端全套源文件。包括支持ARM7的BSP,操作系统
💻 C
字号:
#include "plus\nucleus.h"
#include "net\inc\nu_net.h"             /* Nucleus NET interface, including
                                           Sockets API, TFTP Client and RIP2. */

/* Target specific. */

/*
 * Set the default configuration of the SNMPv1 agent in the
 * following section.  
 */
/*-------------------- Start of User Definable Region ------------------*/
#if (INCLUDE_SNMP==NU_TRUE)
#include "snmp/inc/snmp_prt.h"
#include "snmp/inc/xtypes.h"
#include "snmp/inc/snmp.h"
#include "snmp/inc/agent.h"
#include "snmp/inc/link.h"
#include "snmp/inc/prot.h"
#include "snmp/inc/mac.h"
#include "snmp/inc/snmp_cfg.h"

UINT8       cfig_date[DATESTRLENGTH]                    = "January 14, 1953";
UINT32      cfig_snmpd                                  = SNMP_PORT;
UINT32      authentrap_onoff                            = ON;
UINT32      coldtrap_onoff                              = ON;
UINT8       cfig_mac[MAC_ETHER_ADDR_LEN]                = {0x00, 0x20, 0x6E, 0x00, 0x00, 0x01};
UINT32      cfig_hostid                                 = 0xc0c86401UL;
UINT32      cfig_netmask                                = 0xFFFFFF00UL;
UINT8       cfig_portname[MAX_PORTS][SNMP_HOSTNAME_LEN] = {"Port1"};
UINT8       cfig_hostname[SNMP_HOSTNAME_LEN+1]          = "SNMPv1_Host";

comm_t  Comms[MAX_COMMS] = 
{
        {"public", NU_TRUE, NU_TRUE, NU_TRUE},
        {"private", NU_TRUE, NU_TRUE, NU_TRUE},
        {"", NU_TRUE, NU_TRUE, 0},
        {"", NU_TRUE, NU_TRUE, 0},
        {"", NU_TRUE, NU_TRUE, 0},
        {"", NU_TRUE, NU_TRUE, 0},
        {"", NU_TRUE, NU_TRUE, 0},
        {"", NU_TRUE, NU_TRUE, 0}
        /*-name----read--write-trap-*/
} ;

/*
 * Set the address and community of the accessing host
 * (SNMP Manager)
 * This must match the manager that is running against
 * the SNMPv1 agent
 */
snmphost_t Hosts[MAX_HOSTS] = {
    { "Host1", "public", 0xC0C86432UL },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 },
    { {0}, {0}, 0 }
};
#endif

/* CONFIGURABLE PARAMETERS */
CHAR    DEMOI_SMTP_Server[] =   {(CHAR) 0,(CHAR) 0,(CHAR) 0,(CHAR) 0};
CHAR	DEMOI_FTP_Server[]  =	{(CHAR) 0,(CHAR) 0,(CHAR) 0,(CHAR) 0};
CHAR    DEMOI_Local_Ip[]    =   {(CHAR) 0,(CHAR) 0,(CHAR) 0,(CHAR) 0};
CHAR    DEMOI_Subnet[]      =   {(CHAR) 255, (CHAR) 255, (CHAR) 255, (CHAR) 0};

extern STATUS VDRV_Lookup_Host(CHAR *hostname, CHAR *ip_addr);
extern STATUS VDRV_Init(DV_DEVICE_ENTRY *device);

/* end target specific. */

CHAR *DEMOI_Foreign_Name;

extern VOID            *next_available_memory;
extern NU_EVENT_GROUP   Init_Complete;
NU_DEVICE               DEMOI_Devices[1];
NU_MEMORY_POOL          DEMOI_NET_Memory_Pool;

/* Function Prototypes */
VOID DEMOI_Exit(INT);
VOID DEMOI_Init_Task(UNSIGNED argc, VOID *argv);

VOID DEMOI_Init_Task(UNSIGNED argc, VOID *argv)
{
    NU_HOSTENT  hentry;
    STATUS      status;
    
    /* Access argc and argv to avoid compilation warnings. */
	status = (INT)argc + (INT)argv; 
    
    /* Create the memory pool for use by NET. It will contain
       the NET memory buffers. */
    status = NU_Create_Memory_Pool(&DEMOI_NET_Memory_Pool, "NETMEM",
        next_available_memory, NU_NET_BUFFER_POOL_SIZE, 50, NU_FIFO);
    
    /* Make sure the allocation worked. */
    if (status != NU_SUCCESS)
    {
        NU_Printf("error at call to NU_Create_Memory_Pool().\n");
        DEMOI_Exit (-1);
    }

    /* call network initialization */
    if(NU_Init_Net(&DEMOI_NET_Memory_Pool) != NU_SUCCESS)
    {
        NU_Printf("error at call to NU_Init_Net().\n");
        DEMOI_Exit (-1);
    }

/* Target specific. */

    if (NU_Argc < 2){
        NU_Printf("No Local Host Specified, using MYTCPSERVER \n");
        NU_Argv[1] = "MYTCPSERVER";
    }

        /* Lookup the IP address for this host. */
    if (VDRV_Lookup_Host(NU_Argv[1], DEMOI_Local_Ip) != NU_SUCCESS)
    {
        NU_Printf("The hostname %s could not be found.\n", NU_Argv[1]);
        DEMOI_Exit(0);
    }
    
    DEMOI_Devices[0].dv_name = NU_Argv[1];
    DEMOI_Devices[0].dv_hw.ether.dv_irq = 0;          /* The IRQ, io_addr, and     */
    DEMOI_Devices[0].dv_hw.ether.dv_io_addr = 0;      /* shared_addr are not used. */
    DEMOI_Devices[0].dv_hw.ether.dv_shared_addr = 0;   

    DEMOI_Devices[0].dv_init = VDRV_Init;
    memcpy (DEMOI_Devices[0].dv_ip_addr, DEMOI_Local_Ip, 4);
    memcpy (DEMOI_Devices[0].dv_subnet_mask, DEMOI_Subnet, 4);
    DEMOI_Devices[0].dv_flags = 0;

    /* If a server was given, then store it else set the server name to null. */
    if (NU_Argc == 3)
    {
        DEMOI_Foreign_Name = NU_Argv[2];

	    /* Retrieve the IP address of the server */
	    if (NU_Get_Host_By_Name (DEMOI_Foreign_Name, &hentry) != NU_SUCCESS)
		    DEMOI_Exit(-2);

        memcpy(DEMOI_SMTP_Server, hentry.h_addr, hentry.h_length);
		memcpy(DEMOI_FTP_Server, hentry.h_addr, hentry.h_length);

    }
    else
        DEMOI_Foreign_Name = NU_NULL;

/* end target specific. */

    if (NU_Init_Devices(DEMOI_Devices, 1) != NU_SUCCESS)
    {
        NU_Printf("error at call to NU_Init_Devices().\n");
        DEMOI_Exit (-3);
    }

    /* Now that NET initialization is complete set the even to start
       all the other tasks. */
    NU_Set_Events (&Init_Complete, NU_TRUE, NU_OR);

}

VOID DEMOI_Exit(INT n)
{
    NU_Sleep(336);
    exit(n);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -