SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Thu Sep 06 12:52:48 2012 +0000
Revision:
2:25e12a7fe0aa
Parent:
0:2a53a4c3238c
Open source version 1.a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lorcansmith 0:2a53a4c3238c 1
lorcansmith 0:2a53a4c3238c 2 /*
lorcansmith 0:2a53a4c3238c 3 Generated: Enet_SPI_LPC1768.bin
lorcansmith 0:2a53a4c3238c 4
lorcansmith 0:2a53a4c3238c 5 mbed test software for Ethernet HTTPServer with simultaneous SPI for 4 data byte updates
lorcansmith 0:2a53a4c3238c 6
lorcansmith 0:2a53a4c3238c 7 Version Date Author Change
lorcansmith 0:2a53a4c3238c 8 0.2: 06/10/11 LS Add block checksum character to SPI data
lorcansmith 0:2a53a4c3238c 9 0.3: 07/10/11 LS Add SPI read from cmd_buf
lorcansmith 0:2a53a4c3238c 10 0.4: 13/10/11 LS Integrated with HTTP server example code
lorcansmith 0:2a53a4c3238c 11 0.5: 18/10/11 LS Initial file handling
lorcansmith 0:2a53a4c3238c 12 0.6: 26/10/11 LS File IO handled by SPI_server class
lorcansmith 0:2a53a4c3238c 13 0.78: 17/11/11 LS Add SNMP files for system info reporting, but HTTP svr.bind disabled
lorcansmith 2:25e12a7fe0aa 14 0.79 12/12/11 LS Reads network addresses from file & uses enterprise address
lorcansmith 0:2a53a4c3238c 15 0.80 18/12/11 LS Save last number read in read_addrs_from_file().
lorcansmith 0:2a53a4c3238c 16 0.81 22/12/11 LS Add new_cmd_idx to indicate which parameter has been set (0 for none).
lorcansmith 0:2a53a4c3238c 17 0.82 22/12/11 LS Add blinker to show comms activity
lorcansmith 0:2a53a4c3238c 18 0.83 23/12/11 LS Clear cmd_buf[0] after SPI been read 4 times
lorcansmith 0:2a53a4c3238c 19 0.84 27/12/11 LS snmp_fw_version & f3k_fw_version saved as 4 char strings
lorcansmith 0:2a53a4c3238c 20 0.85 29/12/11 LS Update f3k_sys_set_value() & f3k_sys_set_test() to enable net address change
lorcansmith 0:2a53a4c3238c 21 0.90 29/12/11 LS Add 3-step routine for passing commands over SPI bus from cmd_buf
lorcansmith 0:2a53a4c3238c 22 0.94 10/01/12 LS Add led_link = LPC_GPIO1->FIOPIN & (1<<25) in netservice.cpp
lorcansmith 0:2a53a4c3238c 23 0.95 11/01/12 LS Fix f3k_speed reporting error in private_mib.c
lorcansmith 0:2a53a4c3238c 24 0.96 12/01/12 LS Move led_link = LPC_GPIO1->FIOPIN & (1<<25) to eth_poll in eth_drv.cpp
lorcansmith 0:2a53a4c3238c 25 0.98 26/04/12 LS Increase snmp_publiccommunity[7] to [21] and allow this to be set from file
lorcansmith 0:2a53a4c3238c 26 0.99 08/06/12 LS #define SNMP_TRAP_DESTINATIONS 1. Declare th_ad[4] for host trap address
lorcansmith 0:2a53a4c3238c 27 Add init_traps() to ensure head-head link status trap is sent
lorcansmith 0:2a53a4c3238c 28 21/06/12 Add check for changes to IO bytes and chk_SPI_active() every 60 seconds
lorcansmith 0:2a53a4c3238c 29 1.00 22/06/12 LS Save SNMP changes to net addresses & mask4_IO_registers in net_adrs.txt
lorcansmith 0:2a53a4c3238c 30
lorcansmith 0:2a53a4c3238c 31 http://192.168.99.99/rpc/offset,604 writes 604 to reg_offset
lorcansmith 0:2a53a4c3238c 32 http://192.168.99.99/rpc/led2/write,1 writes 1 to led2
lorcansmith 0:2a53a4c3238c 33 http://192.168.99.99/files/IO1000PX.htm uploads file IO1000PX.htm
lorcansmith 0:2a53a4c3238c 34 */
lorcansmith 0:2a53a4c3238c 35
lorcansmith 0:2a53a4c3238c 36 #include "mbed.h"
lorcansmith 0:2a53a4c3238c 37 #include "EthernetNetIf.h"
lorcansmith 0:2a53a4c3238c 38 #include "HTTPServer.h"
lorcansmith 2:25e12a7fe0aa 39 #include "lwip/snmp_structs.h"
lorcansmith 2:25e12a7fe0aa 40 #include "lwip/snmp_msg.h"
lorcansmith 0:2a53a4c3238c 41 #include "IO_file.h"
lorcansmith 0:2a53a4c3238c 42
lorcansmith 0:2a53a4c3238c 43 #define LPC1768 0x60 // SPI address of LPC1768 module
lorcansmith 0:2a53a4c3238c 44 #define READ_IO 0x01 // bit in address field for data reads
lorcansmith 0:2a53a4c3238c 45 #define SPI_BYTES 4 // # of data bytes in SPI message
lorcansmith 0:2a53a4c3238c 46 #define INV_SPI_CNT 0xfffff // invalid (over-range SPI count
lorcansmith 0:2a53a4c3238c 47 #define NUM_READ 8 // # of SPI replies for valid reads
lorcansmith 0:2a53a4c3238c 48 #define NUM_INDX 4 // # of SPI replies for valid cmd_buf index
lorcansmith 0:2a53a4c3238c 49 #define MAX_CMD 4 // size of CMD buffer
lorcansmith 0:2a53a4c3238c 50 #define NO_CMD 0xff // data on cmd_buf[0] when NO_CMD to be sent
lorcansmith 0:2a53a4c3238c 51 #define NO_UPDATE 0 // NO change to Ethernet addresses
lorcansmith 0:2a53a4c3238c 52 #define UPDATED 0xff // Ethernet addresses updated in file
lorcansmith 0:2a53a4c3238c 53 #define NET_ADRS_FILE "/webfs/net_adrs.txt"
lorcansmith 0:2a53a4c3238c 54
lorcansmith 0:2a53a4c3238c 55
lorcansmith 2:25e12a7fe0aa 56 const char * snmp_fw_version = "1.a";
lorcansmith 0:2a53a4c3238c 57
lorcansmith 0:2a53a4c3238c 58 /* default ethernet address setup */
lorcansmith 0:2a53a4c3238c 59 unsigned char ip_ad[4] = {192,168,99,99};
lorcansmith 0:2a53a4c3238c 60 unsigned char msk_ad[4] = {255,255,255,0};
lorcansmith 0:2a53a4c3238c 61 unsigned char gwy_ad[4] = {192,168,99,253};
lorcansmith 0:2a53a4c3238c 62 unsigned char dns_ad[4] = {192,168,99,253};
lorcansmith 0:2a53a4c3238c 63 unsigned char th_ad[4] = {146,38,105,49}; // v0.99: host address for SNMP traps
lorcansmith 0:2a53a4c3238c 64 unsigned char net_addrs_set = false; // flags net address update from SNMP
lorcansmith 2:25e12a7fe0aa 65 unsigned char net_addrs_chng = NO_UPDATE; // flags net address changed in main CPU
lorcansmith 0:2a53a4c3238c 66 unsigned char byte_changed = false; // true if any IO regs have changed
lorcansmith 0:2a53a4c3238c 67 unsigned char all_IO_updated = false; // true if all 32 IO regs have been read
lorcansmith 0:2a53a4c3238c 68 char hex_mask[12]; // IO mask as hex string
lorcansmith 0:2a53a4c3238c 69 unsigned long mask4_IO_registers = 0x3fffffff; // mask for IO regs ignoring IO31 & 32
lorcansmith 0:2a53a4c3238c 70 unsigned long spi_count = 0; // last SPI_COUNT saved in SPI interrupt
lorcansmith 0:2a53a4c3238c 71 unsigned char spi_active = true; // avoid false trap message at start
lorcansmith 0:2a53a4c3238c 72
lorcansmith 2:25e12a7fe0aa 73 static u8_t syslocation[32]; /* v0.9b */
lorcansmith 0:2a53a4c3238c 74 u8_t sysloc_len;
lorcansmith 0:2a53a4c3238c 75
lorcansmith 0:2a53a4c3238c 76 SPISlave spi_slave(p11, p12, p13, p14); // mosi, miso, sclk, ssel
lorcansmith 0:2a53a4c3238c 77
lorcansmith 0:2a53a4c3238c 78 Ticker comms_tick;
lorcansmith 0:2a53a4c3238c 79 Ticker sys_tick; // system tick for SNMP sysuptime report
lorcansmith 0:2a53a4c3238c 80 Ticker spi_tick; // tick for monitoring SPI activity
lorcansmith 0:2a53a4c3238c 81 Timeout cold_start_delay;
lorcansmith 0:2a53a4c3238c 82
lorcansmith 2:25e12a7fe0aa 83 DigitalOut led1(LED1, "led1"); // mimics head-head link status o/p in main CPU I/O
lorcansmith 0:2a53a4c3238c 84 DigitalOut led2(LED2, "led2");
lorcansmith 0:2a53a4c3238c 85 DigitalOut led3(LED3, "led3");
lorcansmith 0:2a53a4c3238c 86 DigitalOut led4(LED4, "led4");
lorcansmith 0:2a53a4c3238c 87 DigitalOut led_link(p29); // Green link status: ON=good, Blink=Activity
lorcansmith 0:2a53a4c3238c 88 DigitalOut led_speed(p30); // Yellow link speed: ON for 100Mb/s
lorcansmith 0:2a53a4c3238c 89
lorcansmith 0:2a53a4c3238c 90 unsigned char blink_led = false;
lorcansmith 0:2a53a4c3238c 91 unsigned char trap_init = false; // true after cold_start trap sent
lorcansmith 0:2a53a4c3238c 92
lorcansmith 0:2a53a4c3238c 93 LocalFileSystem fs( "webfs" );
lorcansmith 0:2a53a4c3238c 94
lorcansmith 0:2a53a4c3238c 95 IpAddr mip, mnm, mgw, mdns; // instantiate from core\ipaddr.cpp
lorcansmith 0:2a53a4c3238c 96
lorcansmith 0:2a53a4c3238c 97 //EthernetNetIf eth; // use if DNS sets up address
lorcansmith 0:2a53a4c3238c 98
lorcansmith 0:2a53a4c3238c 99 HTTPServer svr;
lorcansmith 0:2a53a4c3238c 100 SPI_Server fsvr( "fsvr" );
lorcansmith 0:2a53a4c3238c 101
lorcansmith 0:2a53a4c3238c 102 Serial pc( USBTX, USBRX ); // for diagnostic serial comms to PC via USB
lorcansmith 0:2a53a4c3238c 103
lorcansmith 0:2a53a4c3238c 104 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 105 /* SPI interface data and routines */
lorcansmith 0:2a53a4c3238c 106 /****************************************************************************/
lorcansmith 2:25e12a7fe0aa 107 /* commands sent to main CPU cpu from cmd_buf[0] and
lorcansmith 0:2a53a4c3238c 108 waiting commands stored in higher indices until sent */
lorcansmith 0:2a53a4c3238c 109 unsigned char cmd_buf[ MAX_CMD ]; // store for commands from Ethernet
lorcansmith 0:2a53a4c3238c 110 unsigned char new_cmd_idx;
lorcansmith 0:2a53a4c3238c 111
lorcansmith 0:2a53a4c3238c 112
lorcansmith 0:2a53a4c3238c 113 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 114 /* SPI_Server:
lorcansmith 0:2a53a4c3238c 115 * Description: Instantiates Class to hold & access all data read from RAM by SPI
lorcansmith 0:2a53a4c3238c 116 * Called by FSHandler::doGet() in services\http\server\impl
lorcansmith 0:2a53a4c3238c 117 * Parameters: name of object instantiated
lorcansmith 0:2a53a4c3238c 118 * Returns: NONE
lorcansmith 0:2a53a4c3238c 119 */
lorcansmith 0:2a53a4c3238c 120 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 121 SPI_Server::SPI_Server(const char * name)
lorcansmith 0:2a53a4c3238c 122 {
lorcansmith 0:2a53a4c3238c 123 int idx;
lorcansmith 0:2a53a4c3238c 124 for ( idx = 0; idx < MAX_RAM; idx++ )
lorcansmith 2:25e12a7fe0aa 125 {
lorcansmith 2:25e12a7fe0aa 126 ram_img[ idx ] = (MAX_RAM - idx) & 0xff;
lorcansmith 0:2a53a4c3238c 127 }
lorcansmith 0:2a53a4c3238c 128 reg_offset = 0;
lorcansmith 0:2a53a4c3238c 129 }
lorcansmith 0:2a53a4c3238c 130
lorcansmith 0:2a53a4c3238c 131 SPI_Server::~SPI_Server()
lorcansmith 0:2a53a4c3238c 132 {
lorcansmith 0:2a53a4c3238c 133 if(fp) fclose(fp);
lorcansmith 0:2a53a4c3238c 134 }
lorcansmith 0:2a53a4c3238c 135
lorcansmith 0:2a53a4c3238c 136 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 137 /* update_IO_file:
lorcansmith 0:2a53a4c3238c 138 * Description: Reads data from ram_img[] into IO1000PX.htm for web access
lorcansmith 0:2a53a4c3238c 139 * Called by FSHandler::doGet() in services\http\server\impl
lorcansmith 0:2a53a4c3238c 140 * Globals used: NONE
lorcansmith 0:2a53a4c3238c 141 * Parameters: NONE
lorcansmith 0:2a53a4c3238c 142 * Returns: 0 if OK, 1 if failed to open files
lorcansmith 0:2a53a4c3238c 143 */
lorcansmith 0:2a53a4c3238c 144 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 145 int SPI_Server::update_IO_file()
lorcansmith 0:2a53a4c3238c 146 {
lorcansmith 0:2a53a4c3238c 147 int c, i; // characters read/written in files
lorcansmith 0:2a53a4c3238c 148 unsigned short chnl, dval; // data from 1000PX
lorcansmith 0:2a53a4c3238c 149
lorcansmith 0:2a53a4c3238c 150 DBG("\r\nIn SPI_Server::update_IO_file()\r\n");
lorcansmith 0:2a53a4c3238c 151 FILE *fr = fopen("/webfs/hdr.htm", "r");
lorcansmith 0:2a53a4c3238c 152 if(!fr) {
lorcansmith 0:2a53a4c3238c 153 fprintf(stderr, "\r\nFile /webfs/hdr.htm could not be opened!\r\n");
lorcansmith 0:2a53a4c3238c 154 exit(1);
lorcansmith 0:2a53a4c3238c 155 }
lorcansmith 0:2a53a4c3238c 156 else
lorcansmith 0:2a53a4c3238c 157 {
lorcansmith 0:2a53a4c3238c 158 fp = fopen( "/webfs/IO1000PX.htm", "w" );
lorcansmith 0:2a53a4c3238c 159 if(!fp) {
lorcansmith 0:2a53a4c3238c 160 fprintf(stderr, "\r\nFile /webfs/IO1000PX.htm could not be opened to write!\r\n" );
lorcansmith 0:2a53a4c3238c 161 exit(1);
lorcansmith 0:2a53a4c3238c 162 }
lorcansmith 0:2a53a4c3238c 163 else
lorcansmith 0:2a53a4c3238c 164 {
lorcansmith 0:2a53a4c3238c 165 while ( (c = fgetc(fr)) != EOF )
lorcansmith 0:2a53a4c3238c 166 {
lorcansmith 0:2a53a4c3238c 167 fputc( c, fp );
lorcansmith 0:2a53a4c3238c 168 }
lorcansmith 0:2a53a4c3238c 169 fclose(fr);
lorcansmith 0:2a53a4c3238c 170 DBG("\r\nIn SPI_Server::update_IO_file() - header copied\r\n");
lorcansmith 0:2a53a4c3238c 171 for ( i = 0; i < 16; i++ )
lorcansmith 0:2a53a4c3238c 172 {
lorcansmith 0:2a53a4c3238c 173 chnl = reg_offset + i;
lorcansmith 0:2a53a4c3238c 174 dval = 256 * ram_img[ 2*chnl ] + ram_img[ 2*chnl + 1 ];
lorcansmith 0:2a53a4c3238c 175 fprintf(fp, " <TR VALIGN=TOP>\r\n");
lorcansmith 0:2a53a4c3238c 176 fprintf(fp, " <TD WIDTH=124>\r\n");
lorcansmith 0:2a53a4c3238c 177 fprintf(fp, " <P>%02d</P>\r\n", chnl );
lorcansmith 0:2a53a4c3238c 178 fprintf(fp, " </TD>\r\n");
lorcansmith 0:2a53a4c3238c 179 fprintf(fp, " <TD WIDTH=124>\r\n");
lorcansmith 0:2a53a4c3238c 180 fprintf(fp, " <P>%d</P>\r\n", dval );
lorcansmith 0:2a53a4c3238c 181 fprintf(fp, " </TD>\r\n");
lorcansmith 0:2a53a4c3238c 182 fprintf(fp, " <TD WIDTH=124>\r\n");
lorcansmith 0:2a53a4c3238c 183 fprintf(fp, " <P>%02x</P>\r\n", (dval/256) );
lorcansmith 0:2a53a4c3238c 184 fprintf(fp, " </TD>\r\n");
lorcansmith 0:2a53a4c3238c 185 fprintf(fp, " <TD WIDTH=124>\r\n");
lorcansmith 0:2a53a4c3238c 186 fprintf(fp, " <P>%02x</P>\r\n", (dval & 0xff) );
lorcansmith 0:2a53a4c3238c 187 fprintf(fp, " </TD>\r\n");
lorcansmith 0:2a53a4c3238c 188 fprintf(fp, " </TR>\r\n");
lorcansmith 0:2a53a4c3238c 189 }
lorcansmith 0:2a53a4c3238c 190 fprintf(fp, "</TABLE>\r\n<P><BR><BR>\r\n</P>\r\n</BODY>\r\n</HTML>\r\n");
lorcansmith 0:2a53a4c3238c 191 }
lorcansmith 0:2a53a4c3238c 192 }
lorcansmith 0:2a53a4c3238c 193 fclose(fp);
lorcansmith 0:2a53a4c3238c 194 // fclose(fr);
lorcansmith 0:2a53a4c3238c 195 return 0;
lorcansmith 0:2a53a4c3238c 196 }
lorcansmith 0:2a53a4c3238c 197
lorcansmith 0:2a53a4c3238c 198 int SPI_Server::read( void )
lorcansmith 0:2a53a4c3238c 199 {
lorcansmith 0:2a53a4c3238c 200 DBG("\r\nIn SPI_Server::read()\r\n");
lorcansmith 0:2a53a4c3238c 201 return reg_offset;
lorcansmith 0:2a53a4c3238c 202 }
lorcansmith 0:2a53a4c3238c 203
lorcansmith 0:2a53a4c3238c 204 void SPI_Server::write( int new_offset )
lorcansmith 0:2a53a4c3238c 205 {
lorcansmith 0:2a53a4c3238c 206 DBG("\r\nIn SPI_Server::write()\r\n");
lorcansmith 0:2a53a4c3238c 207 if ( (new_offset >= 0) && (new_offset < MAX_RAM) ) reg_offset = new_offset;
lorcansmith 0:2a53a4c3238c 208 }
lorcansmith 0:2a53a4c3238c 209
lorcansmith 0:2a53a4c3238c 210 unsigned char SPI_Server::get_byte( unsigned short idx )
lorcansmith 0:2a53a4c3238c 211 {
lorcansmith 0:2a53a4c3238c 212 return ram_img[ idx ];
lorcansmith 0:2a53a4c3238c 213 }
lorcansmith 0:2a53a4c3238c 214
lorcansmith 0:2a53a4c3238c 215 void SPI_Server::put_byte( unsigned short idx, unsigned char new_byte )
lorcansmith 0:2a53a4c3238c 216 {
lorcansmith 0:2a53a4c3238c 217 if ( idx < MAX_RAM )
lorcansmith 0:2a53a4c3238c 218 ram_img[ idx ] = new_byte;
lorcansmith 0:2a53a4c3238c 219 }
lorcansmith 0:2a53a4c3238c 220
lorcansmith 0:2a53a4c3238c 221 unsigned short SPI_Server::get_error( void )
lorcansmith 0:2a53a4c3238c 222 {
lorcansmith 2:25e12a7fe0aa 223 // return error register value from main CPU
lorcansmith 0:2a53a4c3238c 224 return (256 * ram_img[ 1786 ]) + ram_img[ 1787 ];
lorcansmith 0:2a53a4c3238c 225 }
lorcansmith 0:2a53a4c3238c 226
lorcansmith 0:2a53a4c3238c 227 unsigned short SPI_Server::get_SPI_count( void )
lorcansmith 0:2a53a4c3238c 228 {
lorcansmith 2:25e12a7fe0aa 229 // return SPI write count from main CPU - indicates main CPU running OK
lorcansmith 0:2a53a4c3238c 230 return (256 * ram_img[ SPI_COUNT ]) + ram_img[ SPI_COUNT + 1 ];
lorcansmith 0:2a53a4c3238c 231 }
lorcansmith 0:2a53a4c3238c 232
lorcansmith 0:2a53a4c3238c 233 unsigned char * SPI_Server::net_address_ptr( void )
lorcansmith 0:2a53a4c3238c 234 {
lorcansmith 0:2a53a4c3238c 235 return &ram_img[ NET_IP_ADDRESS ];
lorcansmith 0:2a53a4c3238c 236 }
lorcansmith 0:2a53a4c3238c 237
lorcansmith 0:2a53a4c3238c 238 unsigned char * SPI_Server::trap_host_ptr( void )
lorcansmith 0:2a53a4c3238c 239 {
lorcansmith 0:2a53a4c3238c 240 return &ram_img[ TRAP_HOST_ADDRESS ];
lorcansmith 0:2a53a4c3238c 241 }
lorcansmith 0:2a53a4c3238c 242
lorcansmith 0:2a53a4c3238c 243 #if 0
lorcansmith 0:2a53a4c3238c 244 //#ifdef MBED_RPC trap_host_ptr
lorcansmith 0:2a53a4c3238c 245 const struct rpc_method *SPI_Server::get_rpc_methods() {
lorcansmith 0:2a53a4c3238c 246 static const rpc_method methods[] = {
lorcansmith 0:2a53a4c3238c 247 { "read", rpc_method_caller<int, SPI_Server, &SPI_Server::read> },
lorcansmith 0:2a53a4c3238c 248 { "write", rpc_method_caller<SPI_Server, int, &SPI_Server::write> },
lorcansmith 0:2a53a4c3238c 249 RPC_METHOD_SUPER(Base) //Stream)
lorcansmith 0:2a53a4c3238c 250 };
lorcansmith 0:2a53a4c3238c 251 return methods;
lorcansmith 0:2a53a4c3238c 252 }
lorcansmith 0:2a53a4c3238c 253
lorcansmith 0:2a53a4c3238c 254 struct rpc_class *SPI_Server::get_rpc_class() {
lorcansmith 0:2a53a4c3238c 255 static const rpc_function funcs[] = {
lorcansmith 0:2a53a4c3238c 256 { "new", rpc_function_caller<const char*, int, &Base::construct<SPI_Server, int> > },
lorcansmith 0:2a53a4c3238c 257 RPC_METHOD_END
lorcansmith 0:2a53a4c3238c 258 };
lorcansmith 0:2a53a4c3238c 259 static rpc_class c = { "SPI_Server", funcs, NULL };
lorcansmith 0:2a53a4c3238c 260 return &c;
lorcansmith 0:2a53a4c3238c 261 }
lorcansmith 0:2a53a4c3238c 262 #endif
lorcansmith 0:2a53a4c3238c 263
lorcansmith 0:2a53a4c3238c 264 void check4write_offset( char * req )
lorcansmith 0:2a53a4c3238c 265 {
lorcansmith 0:2a53a4c3238c 266 unsigned char l, c, i;
lorcansmith 0:2a53a4c3238c 267 char v[ 20 ] = {0};
lorcansmith 0:2a53a4c3238c 268 char s[ 20 ] = {0};
lorcansmith 0:2a53a4c3238c 269 char * p;
lorcansmith 0:2a53a4c3238c 270
lorcansmith 0:2a53a4c3238c 271 strcpy( v, "/offset," );
lorcansmith 0:2a53a4c3238c 272 p = strstr( req, v );
lorcansmith 0:2a53a4c3238c 273 strcpy( s, p );
lorcansmith 0:2a53a4c3238c 274 if ( p != NULL )
lorcansmith 0:2a53a4c3238c 275 {
lorcansmith 0:2a53a4c3238c 276 i = strlen(v);
lorcansmith 0:2a53a4c3238c 277 l = strlen(s);
lorcansmith 0:2a53a4c3238c 278 if ( (l > i) && (l < (i + 6)) )
lorcansmith 0:2a53a4c3238c 279 {
lorcansmith 0:2a53a4c3238c 280 l -= i;
lorcansmith 0:2a53a4c3238c 281 for ( c = 0; c < l; c++ )
lorcansmith 0:2a53a4c3238c 282 {
lorcansmith 0:2a53a4c3238c 283 v[ c ] = s[ i + c ];
lorcansmith 0:2a53a4c3238c 284 }
lorcansmith 0:2a53a4c3238c 285 v[ c ] = 0;
lorcansmith 0:2a53a4c3238c 286 fsvr.write( atoi(v) );
lorcansmith 0:2a53a4c3238c 287 }
lorcansmith 0:2a53a4c3238c 288 }
lorcansmith 0:2a53a4c3238c 289 }
lorcansmith 0:2a53a4c3238c 290
lorcansmith 0:2a53a4c3238c 291 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 292 /* get_SPI_data:
lorcansmith 0:2a53a4c3238c 293 * Description: Implements transaction as SPI slave.
lorcansmith 0:2a53a4c3238c 294 * Reads 4 data bytes from SPI bus into destbuf for SPI write, or
lorcansmith 0:2a53a4c3238c 295 * Puts 1 byte from srcbuf onto SPI for SPI read
lorcansmith 0:2a53a4c3238c 296 * Called by main when spi_slave.receive interrupts
lorcansmith 0:2a53a4c3238c 297 * LPC1768 SPI slave handles a maximum of 8 bytes per transfer
lorcansmith 0:2a53a4c3238c 298 * Globals used: NONE
lorcansmith 0:2a53a4c3238c 299 * Parameters: IN/OUT: unsigned char * srcbuf : buffer to read from
lorcansmith 0:2a53a4c3238c 300 * Returns: int buf_idx : index to SPI data in destbuf/srcbuf
lorcansmith 0:2a53a4c3238c 301 */
lorcansmith 0:2a53a4c3238c 302 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 303 int get_SPI_data( unsigned char * srcbuf )
lorcansmith 0:2a53a4c3238c 304 {
lorcansmith 0:2a53a4c3238c 305 static unsigned char rd_cnt; // v0.83: count of times valid data put on bus
lorcansmith 0:2a53a4c3238c 306 int buf_idx = 0xffff; // index to save SPI data into destbuf
lorcansmith 0:2a53a4c3238c 307 int idx; // index to compare with net address block
lorcansmith 0:2a53a4c3238c 308 unsigned char spi_buf[ 8 ]; // temporary buffer for SPI data received
lorcansmith 0:2a53a4c3238c 309 unsigned char byte_cnt; // count of SPI data bytes received
lorcansmith 0:2a53a4c3238c 310 unsigned char spiv; // SPI value - initial slave address
lorcansmith 0:2a53a4c3238c 311 unsigned char bcc = 0; // received block check character
lorcansmith 0:2a53a4c3238c 312 unsigned char bcc_ok = false; // default to reject messages without bcc
lorcansmith 0:2a53a4c3238c 313
lorcansmith 0:2a53a4c3238c 314 spiv = spi_slave.read(); // Read byte from master
lorcansmith 0:2a53a4c3238c 315 if ( (spiv & 0xfe) == (LPC1768 & 0xfe) )
lorcansmith 0:2a53a4c3238c 316 {
lorcansmith 0:2a53a4c3238c 317 if ( spiv & READ_IO )
lorcansmith 0:2a53a4c3238c 318 {
lorcansmith 0:2a53a4c3238c 319 led4 = 1;
lorcansmith 0:2a53a4c3238c 320 led3 = 0;
lorcansmith 0:2a53a4c3238c 321 if ( *srcbuf < NO_CMD )
lorcansmith 2:25e12a7fe0aa 322 { // new data to be read by main CPU cpu
lorcansmith 0:2a53a4c3238c 323 if ( ++rd_cnt >= NUM_READ )
lorcansmith 0:2a53a4c3238c 324 { // v0.83: clear data after 4 reads
lorcansmith 0:2a53a4c3238c 325 spi_slave.reply( NO_CMD ); // put invalid data in SPI buffer
lorcansmith 0:2a53a4c3238c 326 *srcbuf = NO_CMD;
lorcansmith 0:2a53a4c3238c 327 rd_cnt = 0;
lorcansmith 0:2a53a4c3238c 328 }
lorcansmith 0:2a53a4c3238c 329 else if ( rd_cnt >= NUM_INDX )
lorcansmith 0:2a53a4c3238c 330 { // next put data from srcbuf in SPI buffer
lorcansmith 0:2a53a4c3238c 331 spi_slave.reply( *srcbuf );
lorcansmith 0:2a53a4c3238c 332 }
lorcansmith 0:2a53a4c3238c 333 else // put new_cmd_idx on SPI bus first
lorcansmith 0:2a53a4c3238c 334 {
lorcansmith 0:2a53a4c3238c 335 spi_slave.reply( NO_CMD - new_cmd_idx ); // put new_cmd_idx in SPI buffer
lorcansmith 0:2a53a4c3238c 336 }
lorcansmith 0:2a53a4c3238c 337 } // end if ( *srcbuf < 0xff )
lorcansmith 0:2a53a4c3238c 338 else
lorcansmith 0:2a53a4c3238c 339 {
lorcansmith 0:2a53a4c3238c 340 rd_cnt = 0; // re-initialise read count
lorcansmith 0:2a53a4c3238c 341 spi_slave.reply( NO_CMD ); // put invalid data in SPI buffer
lorcansmith 0:2a53a4c3238c 342 }
lorcansmith 0:2a53a4c3238c 343 }
lorcansmith 0:2a53a4c3238c 344 else // NOT READ_IO - data write
lorcansmith 0:2a53a4c3238c 345 {
lorcansmith 0:2a53a4c3238c 346 buf_idx = spi_slave.read(); // Read ms index from master
lorcansmith 0:2a53a4c3238c 347 bcc ^= buf_idx; // Start checksum calculation
lorcansmith 0:2a53a4c3238c 348 buf_idx *= 256; // Make ms index from master
lorcansmith 0:2a53a4c3238c 349 buf_idx += spi_slave.read(); // Read ls index from master
lorcansmith 0:2a53a4c3238c 350 bcc ^= (buf_idx & 0xff);
lorcansmith 0:2a53a4c3238c 351 byte_cnt = 0;
lorcansmith 0:2a53a4c3238c 352 while( spi_slave.receive() ) {
lorcansmith 0:2a53a4c3238c 353 if( byte_cnt < SPI_BYTES ) { // Read 4 data bytes
lorcansmith 0:2a53a4c3238c 354 spi_buf[ byte_cnt ] = spi_slave.read();
lorcansmith 0:2a53a4c3238c 355 bcc ^= spi_buf[ byte_cnt++ ];
lorcansmith 0:2a53a4c3238c 356 }
lorcansmith 0:2a53a4c3238c 357 else if ( byte_cnt == SPI_BYTES ) {
lorcansmith 0:2a53a4c3238c 358 spiv = spi_slave.read();
lorcansmith 0:2a53a4c3238c 359 bcc_ok = ( bcc == spiv );
lorcansmith 0:2a53a4c3238c 360 }
lorcansmith 0:2a53a4c3238c 361 } // end while ( spi_slave.receive() )
lorcansmith 0:2a53a4c3238c 362 if ( bcc_ok && (buf_idx < MAX_RAM) )
lorcansmith 0:2a53a4c3238c 363 {
lorcansmith 0:2a53a4c3238c 364 for( byte_cnt = 0; byte_cnt < SPI_BYTES; byte_cnt++ )
lorcansmith 0:2a53a4c3238c 365 {
lorcansmith 0:2a53a4c3238c 366 idx = buf_idx + byte_cnt;
lorcansmith 2:25e12a7fe0aa 367 if ( idx <= MAX_IO_REG_BYTE )
lorcansmith 2:25e12a7fe0aa 368 { // check for IO changed from last saved
lorcansmith 2:25e12a7fe0aa 369 if ( (spi_buf[ byte_cnt ] != fsvr.get_byte( idx )) && !byte_changed )
lorcansmith 2:25e12a7fe0aa 370 {
lorcansmith 2:25e12a7fe0aa 371 if ( mask4_IO_registers & (1 << (idx/2)) )
lorcansmith 0:2a53a4c3238c 372 { // masked-in register has changed
lorcansmith 0:2a53a4c3238c 373 byte_changed = true;
lorcansmith 0:2a53a4c3238c 374 }
lorcansmith 0:2a53a4c3238c 375 }
lorcansmith 0:2a53a4c3238c 376 if ( idx == MAX_IO_REG_BYTE )
lorcansmith 0:2a53a4c3238c 377 { // after each I/O scan
lorcansmith 0:2a53a4c3238c 378 all_IO_updated = true;
lorcansmith 0:2a53a4c3238c 379 spi_count = fsvr.get_SPI_count(); // save last SPI_count value
lorcansmith 0:2a53a4c3238c 380 }
lorcansmith 0:2a53a4c3238c 381 }
lorcansmith 0:2a53a4c3238c 382 else if ( idx == NET_ADDRESS_CHANGE )
lorcansmith 2:25e12a7fe0aa 383 { // v0.93: check for net address update from main CPU CPU
lorcansmith 0:2a53a4c3238c 384 if ( spi_buf[ byte_cnt ] == NO_UPDATE )
lorcansmith 0:2a53a4c3238c 385 {
lorcansmith 0:2a53a4c3238c 386 net_addrs_chng = NO_UPDATE;
lorcansmith 0:2a53a4c3238c 387 }
lorcansmith 0:2a53a4c3238c 388 else if ( net_addrs_chng != UPDATED )
lorcansmith 0:2a53a4c3238c 389 {
lorcansmith 0:2a53a4c3238c 390 net_addrs_chng = spi_buf[ byte_cnt ];
lorcansmith 0:2a53a4c3238c 391 }
lorcansmith 0:2a53a4c3238c 392 }
lorcansmith 0:2a53a4c3238c 393 fsvr.put_byte( idx, spi_buf[ byte_cnt ] ); // save byte read from SPI
lorcansmith 0:2a53a4c3238c 394 }
lorcansmith 0:2a53a4c3238c 395 led3 = 0;
lorcansmith 0:2a53a4c3238c 396 }
lorcansmith 0:2a53a4c3238c 397 else // checksum failed
lorcansmith 0:2a53a4c3238c 398 {
lorcansmith 0:2a53a4c3238c 399 led3 = 1;
lorcansmith 0:2a53a4c3238c 400 }
lorcansmith 0:2a53a4c3238c 401 led4 = 0;
lorcansmith 0:2a53a4c3238c 402 } // end else not READ_IO
lorcansmith 0:2a53a4c3238c 403 } // end if ( (spiv & 0xfe) == (LPC1768 & 0xfe) )
lorcansmith 0:2a53a4c3238c 404 return buf_idx;
lorcansmith 0:2a53a4c3238c 405 }
lorcansmith 0:2a53a4c3238c 406
lorcansmith 0:2a53a4c3238c 407 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 408 /* chk_SPI_active:
lorcansmith 0:2a53a4c3238c 409 * Description: checks spi_count has been updated in SPI interrupt
lorcansmith 0:2a53a4c3238c 410 * to be called by timer, independently of SPI interrupt
lorcansmith 0:2a53a4c3238c 411 * Globals used: spi_active, spi_count
lorcansmith 0:2a53a4c3238c 412 * Parameters: NONE
lorcansmith 0:2a53a4c3238c 413 * Returns: NONE
lorcansmith 0:2a53a4c3238c 414 */
lorcansmith 0:2a53a4c3238c 415 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 416 void chk_SPI_active( void )
lorcansmith 0:2a53a4c3238c 417 {
lorcansmith 0:2a53a4c3238c 418 if ( spi_count == INV_SPI_CNT )
lorcansmith 0:2a53a4c3238c 419 {
lorcansmith 0:2a53a4c3238c 420 spi_active = false; // flag SPI failure
lorcansmith 0:2a53a4c3238c 421 }
lorcansmith 0:2a53a4c3238c 422 else
lorcansmith 0:2a53a4c3238c 423 {
lorcansmith 0:2a53a4c3238c 424 spi_count = INV_SPI_CNT; // set to be overwritten by next SPI update
lorcansmith 0:2a53a4c3238c 425 spi_active = true; // SPI updated OK
lorcansmith 0:2a53a4c3238c 426 }
lorcansmith 0:2a53a4c3238c 427 }
lorcansmith 0:2a53a4c3238c 428
lorcansmith 0:2a53a4c3238c 429 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 430 /* get_hex_mask:
lorcansmith 2:25e12a7fe0aa 431 * Description: converts long mask4_IO_registers to hexadecimal string
lorcansmith 2:25e12a7fe0aa 432 * Globals used: mask4_IO_registers, hex_mask
lorcansmith 2:25e12a7fe0aa 433 * Parameters: NONE
lorcansmith 0:2a53a4c3238c 434 * Returns: pointer to hex_mask
lorcansmith 0:2a53a4c3238c 435 */
lorcansmith 0:2a53a4c3238c 436 /****************************************************************************/
lorcansmith 2:25e12a7fe0aa 437 char * get_hex_mask( void )
lorcansmith 0:2a53a4c3238c 438 {
lorcansmith 0:2a53a4c3238c 439 unsigned char i;
lorcansmith 0:2a53a4c3238c 440 for ( i = 0; i < 12; i++ )
lorcansmith 0:2a53a4c3238c 441 {
lorcansmith 0:2a53a4c3238c 442 hex_mask[ i ] = 0;
lorcansmith 0:2a53a4c3238c 443 }
lorcansmith 2:25e12a7fe0aa 444 sprintf(hex_mask, "%08x", mask4_IO_registers);
lorcansmith 0:2a53a4c3238c 445 return hex_mask;
lorcansmith 0:2a53a4c3238c 446 }
lorcansmith 0:2a53a4c3238c 447
lorcansmith 0:2a53a4c3238c 448 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 449 /* convert2decimal:
lorcansmith 0:2a53a4c3238c 450 * Description: converts hexadecimal string to long mask4_IO_registers
lorcansmith 2:25e12a7fe0aa 451 * Globals used: mask4_IO_registers
lorcansmith 0:2a53a4c3238c 452 * Parameters: u8_t * uc_ptr: pointer to hex-formatted mask string
lorcansmith 0:2a53a4c3238c 453 * u16_t len: length of string
lorcansmith 2:25e12a7fe0aa 454 * Returns: NONE
lorcansmith 0:2a53a4c3238c 455 */
lorcansmith 0:2a53a4c3238c 456 /****************************************************************************/
lorcansmith 2:25e12a7fe0aa 457 void convert2decimal( u8_t * uc_ptr, u16_t len )
lorcansmith 0:2a53a4c3238c 458 {
lorcansmith 0:2a53a4c3238c 459 char ch, i;
lorcansmith 0:2a53a4c3238c 460 unsigned long temp_sum = 0;
lorcansmith 0:2a53a4c3238c 461
lorcansmith 0:2a53a4c3238c 462 for ( i = 0; i < len; i++ )
lorcansmith 0:2a53a4c3238c 463 {
lorcansmith 0:2a53a4c3238c 464 ch = (char)*(uc_ptr + i);
lorcansmith 0:2a53a4c3238c 465 if ( islower( ch ) )
lorcansmith 0:2a53a4c3238c 466 {
lorcansmith 0:2a53a4c3238c 467 ch = ch - 'a' + 10;
lorcansmith 0:2a53a4c3238c 468 }
lorcansmith 0:2a53a4c3238c 469 else if ( isupper( ch ) )
lorcansmith 0:2a53a4c3238c 470 {
lorcansmith 0:2a53a4c3238c 471 ch = ch - 'A' + 10;
lorcansmith 0:2a53a4c3238c 472 }
lorcansmith 0:2a53a4c3238c 473 else if ( isdigit( ch ) )
lorcansmith 0:2a53a4c3238c 474 {
lorcansmith 0:2a53a4c3238c 475 ch = ch - '0';
lorcansmith 0:2a53a4c3238c 476 }
lorcansmith 0:2a53a4c3238c 477 else
lorcansmith 0:2a53a4c3238c 478 {
lorcansmith 0:2a53a4c3238c 479 temp_sum = 0xfffffff;
lorcansmith 0:2a53a4c3238c 480 ch = 15;
lorcansmith 0:2a53a4c3238c 481 i = len; // end on error;
lorcansmith 0:2a53a4c3238c 482 }
lorcansmith 0:2a53a4c3238c 483 temp_sum = 16 * temp_sum + ch;
lorcansmith 0:2a53a4c3238c 484 }
lorcansmith 2:25e12a7fe0aa 485 mask4_IO_registers = temp_sum;
lorcansmith 0:2a53a4c3238c 486 }
lorcansmith 0:2a53a4c3238c 487
lorcansmith 0:2a53a4c3238c 488 void send_ram( void )
lorcansmith 0:2a53a4c3238c 489 {
lorcansmith 0:2a53a4c3238c 490 static int idx;
lorcansmith 0:2a53a4c3238c 491 char i;
lorcansmith 0:2a53a4c3238c 492
lorcansmith 0:2a53a4c3238c 493 if ( (idx & 0x7ff) == 0 )
lorcansmith 0:2a53a4c3238c 494 {
lorcansmith 0:2a53a4c3238c 495 pc.printf("CMD data %x", idx );
lorcansmith 0:2a53a4c3238c 496 for ( i = 0; i < MAX_CMD; i++ )
lorcansmith 0:2a53a4c3238c 497 {
lorcansmith 0:2a53a4c3238c 498 pc.printf(", %x", cmd_buf[ i ] );
lorcansmith 0:2a53a4c3238c 499 }
lorcansmith 0:2a53a4c3238c 500 pc.printf( "\r\n" );
lorcansmith 0:2a53a4c3238c 501 pc.printf("RAM data %x", idx & 0x7ff );
lorcansmith 0:2a53a4c3238c 502 for ( i = 0; i < 8; i++ )
lorcansmith 0:2a53a4c3238c 503 {
lorcansmith 0:2a53a4c3238c 504 pc.printf(", %x", fsvr.get_byte(idx++ & 0x7ff) );
lorcansmith 0:2a53a4c3238c 505 }
lorcansmith 0:2a53a4c3238c 506 pc.printf( "\r\n" );
lorcansmith 0:2a53a4c3238c 507 }
lorcansmith 0:2a53a4c3238c 508 else
lorcansmith 0:2a53a4c3238c 509 {
lorcansmith 0:2a53a4c3238c 510 pc.printf("RAM data %x", idx & 0x7ff );
lorcansmith 0:2a53a4c3238c 511 for ( i = 0; i < 8; i++ )
lorcansmith 0:2a53a4c3238c 512 {
lorcansmith 0:2a53a4c3238c 513 pc.printf(", %x", fsvr.get_byte(idx++ & 0x7ff) );
lorcansmith 0:2a53a4c3238c 514 }
lorcansmith 0:2a53a4c3238c 515 pc.printf( "\r\n" );
lorcansmith 0:2a53a4c3238c 516 }
lorcansmith 0:2a53a4c3238c 517 }
lorcansmith 0:2a53a4c3238c 518
lorcansmith 0:2a53a4c3238c 519 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 520 /* write_addrs_to_file:
lorcansmith 0:2a53a4c3238c 521 * Description: Writes net addresses to /webfs/net_adrs.txt
lorcansmith 0:2a53a4c3238c 522 * Globals used: NET_ADRS_FILE
lorcansmith 0:2a53a4c3238c 523 * Parameters: NONE
lorcansmith 0:2a53a4c3238c 524 * Returns: 0 if OK, 1 if failed to open files
lorcansmith 0:2a53a4c3238c 525 */
lorcansmith 0:2a53a4c3238c 526 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 527 int write_addrs_to_file()
lorcansmith 0:2a53a4c3238c 528 {
lorcansmith 0:2a53a4c3238c 529 FILE *fp = fopen( NET_ADRS_FILE, "w" );
lorcansmith 0:2a53a4c3238c 530 if(!fp) {
lorcansmith 0:2a53a4c3238c 531 fprintf(stderr, "\r\nFile /webfs/net_adrs.txt could not be opened to write!\r\n");
lorcansmith 0:2a53a4c3238c 532 exit(1);
lorcansmith 0:2a53a4c3238c 533 }
lorcansmith 0:2a53a4c3238c 534 else // file opened OK, so save addresses
lorcansmith 0:2a53a4c3238c 535 {
lorcansmith 0:2a53a4c3238c 536 fprintf(fp, "IP address %u.%u.%u.%u \r\n", ip_ad[0],ip_ad[1],ip_ad[2],ip_ad[3]);
lorcansmith 0:2a53a4c3238c 537 fprintf(fp, "Address mask %u.%u.%u.%u \r\n", msk_ad[0],msk_ad[1],msk_ad[2],msk_ad[3]);
lorcansmith 0:2a53a4c3238c 538 fprintf(fp, "Gwy address %u.%u.%u.%u \r\n", gwy_ad[0],gwy_ad[1],gwy_ad[2],gwy_ad[3]);
lorcansmith 0:2a53a4c3238c 539 fprintf(fp, "DNS address %u.%u.%u.%u \r\n", dns_ad[0],dns_ad[1],dns_ad[2],dns_ad[3]);
lorcansmith 0:2a53a4c3238c 540 fprintf(fp, "%s\r\n", snmp_publiccommunity ); // v0.98: save community string
lorcansmith 0:2a53a4c3238c 541 fprintf(fp, "Trap host address %u.%u.%u.%u \r\n", th_ad[0],th_ad[1],th_ad[2],th_ad[3]);
lorcansmith 0:2a53a4c3238c 542 fprintf(fp, "%u \r\n", mask4_IO_registers );
lorcansmith 0:2a53a4c3238c 543 fclose(fp);
lorcansmith 0:2a53a4c3238c 544 } // file opened OK
lorcansmith 0:2a53a4c3238c 545 return 0;
lorcansmith 0:2a53a4c3238c 546 }
lorcansmith 0:2a53a4c3238c 547
lorcansmith 0:2a53a4c3238c 548 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 549 /* copy_trap_host_address: v0.99
lorcansmith 0:2a53a4c3238c 550 * Description: Copies src array to th_ad
lorcansmith 0:2a53a4c3238c 551 * Globals used: th_ad
lorcansmith 0:2a53a4c3238c 552 * net_addrs_chng set to UPDATED
lorcansmith 0:2a53a4c3238c 553 * Parameters: IN: unsigned char * src - source array of 4 bytes
lorcansmith 0:2a53a4c3238c 554 * Returns: NONE
lorcansmith 0:2a53a4c3238c 555 */
lorcansmith 0:2a53a4c3238c 556 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 557 void copy_trap_host_address( unsigned char * src )
lorcansmith 0:2a53a4c3238c 558 {
lorcansmith 0:2a53a4c3238c 559 unsigned char i;
lorcansmith 0:2a53a4c3238c 560 for ( i = 0; i < 4; i++ )
lorcansmith 0:2a53a4c3238c 561 {
lorcansmith 0:2a53a4c3238c 562 if ( src[ i ] != 0 )
lorcansmith 0:2a53a4c3238c 563 {
lorcansmith 0:2a53a4c3238c 564 {
lorcansmith 0:2a53a4c3238c 565 th_ad[ i ] = src[ i ];
lorcansmith 0:2a53a4c3238c 566 }
lorcansmith 0:2a53a4c3238c 567 }
lorcansmith 0:2a53a4c3238c 568 }
lorcansmith 0:2a53a4c3238c 569 net_addrs_chng = UPDATED;
lorcansmith 0:2a53a4c3238c 570 }
lorcansmith 0:2a53a4c3238c 571
lorcansmith 0:2a53a4c3238c 572 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 573 /* copy_net_addresses_from: v0.93
lorcansmith 0:2a53a4c3238c 574 * Description: Copies src array to ip_ad, msk_ad, gwy_ad, dns_ad
lorcansmith 0:2a53a4c3238c 575 * Globals used: ip_ad, msk_ad, gwy_ad, dns_ad
lorcansmith 0:2a53a4c3238c 576 * Parameters: IN: unsigned char * src - source array of 16 bytes
lorcansmith 0:2a53a4c3238c 577 * Returns: NONE
lorcansmith 0:2a53a4c3238c 578 */
lorcansmith 0:2a53a4c3238c 579 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 580 void copy_net_addresses_from( unsigned char * src )
lorcansmith 0:2a53a4c3238c 581 {
lorcansmith 0:2a53a4c3238c 582 unsigned char i;
lorcansmith 0:2a53a4c3238c 583 for ( i = 0; i < 4; i++ )
lorcansmith 0:2a53a4c3238c 584 {
lorcansmith 0:2a53a4c3238c 585 if ( src[ i ] != 0 )
lorcansmith 0:2a53a4c3238c 586 {
lorcansmith 0:2a53a4c3238c 587 ip_ad[ i ] = src[ i ];
lorcansmith 0:2a53a4c3238c 588 }
lorcansmith 0:2a53a4c3238c 589 }
lorcansmith 0:2a53a4c3238c 590 for ( i = 4; i < 8; i++ )
lorcansmith 0:2a53a4c3238c 591 {
lorcansmith 0:2a53a4c3238c 592 if ( src[ i ] != 0 )
lorcansmith 0:2a53a4c3238c 593 {
lorcansmith 0:2a53a4c3238c 594 msk_ad[ i-4 ] = src[ i ];
lorcansmith 0:2a53a4c3238c 595 }
lorcansmith 0:2a53a4c3238c 596 }
lorcansmith 0:2a53a4c3238c 597 for ( i = 8; i < 12; i++ )
lorcansmith 0:2a53a4c3238c 598 {
lorcansmith 0:2a53a4c3238c 599 if ( src[ i ] != 0 )
lorcansmith 0:2a53a4c3238c 600 {
lorcansmith 0:2a53a4c3238c 601 gwy_ad[ i-8 ] = src[ i ];
lorcansmith 0:2a53a4c3238c 602 }
lorcansmith 0:2a53a4c3238c 603 }
lorcansmith 0:2a53a4c3238c 604 for ( i = 12; i < 16; i++ )
lorcansmith 0:2a53a4c3238c 605 {
lorcansmith 0:2a53a4c3238c 606 if ( src[ i ] != 0 )
lorcansmith 0:2a53a4c3238c 607 {
lorcansmith 0:2a53a4c3238c 608 dns_ad[ i-12 ] = src[ i ];
lorcansmith 0:2a53a4c3238c 609 }
lorcansmith 0:2a53a4c3238c 610 }
lorcansmith 0:2a53a4c3238c 611 }
lorcansmith 0:2a53a4c3238c 612
lorcansmith 0:2a53a4c3238c 613 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 614 /* parse4numbers:
lorcansmith 0:2a53a4c3238c 615 * Description: Reads file fr and separates out max_num numbers delimited by
lorcansmith 0:2a53a4c3238c 616 * any non-digit characters
lorcansmith 0:2a53a4c3238c 617 * Globals used:
lorcansmith 0:2a53a4c3238c 618 * Parameters: IN: FILE *fr - file to read
lorcansmith 0:2a53a4c3238c 619 * OUT: unsigned char * numb - array of numbers read
lorcansmith 0:2a53a4c3238c 620 * IN: unsigned char max_num - number of numbers to read
lorcansmith 0:2a53a4c3238c 621 * Returns: NONE
lorcansmith 0:2a53a4c3238c 622 */
lorcansmith 0:2a53a4c3238c 623 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 624 void parse4numbers( FILE *fr, unsigned char * numb, unsigned char max_num )
lorcansmith 0:2a53a4c3238c 625 {
lorcansmith 0:2a53a4c3238c 626 int c, i, new_num;
lorcansmith 0:2a53a4c3238c 627 char digit_found = false;
lorcansmith 0:2a53a4c3238c 628 char number_completed = false;
lorcansmith 0:2a53a4c3238c 629
lorcansmith 0:2a53a4c3238c 630 i = new_num = 0;
lorcansmith 0:2a53a4c3238c 631 while ( ((c = fgetc(fr)) != EOF) && (i < max_num) )
lorcansmith 0:2a53a4c3238c 632 {
lorcansmith 0:2a53a4c3238c 633 numb[ i ] = 0;
lorcansmith 0:2a53a4c3238c 634 if ( c < '0' || c > '9' )
lorcansmith 0:2a53a4c3238c 635 { // not a numeric character
lorcansmith 0:2a53a4c3238c 636 if ( digit_found )
lorcansmith 0:2a53a4c3238c 637 {
lorcansmith 0:2a53a4c3238c 638 number_completed = true;
lorcansmith 0:2a53a4c3238c 639 if ( i >= (max_num - 1) )
lorcansmith 0:2a53a4c3238c 640 { // max_num distinct numbers read
lorcansmith 0:2a53a4c3238c 641 break;
lorcansmith 0:2a53a4c3238c 642 }
lorcansmith 0:2a53a4c3238c 643 }
lorcansmith 0:2a53a4c3238c 644 }
lorcansmith 0:2a53a4c3238c 645 else // numeric character
lorcansmith 0:2a53a4c3238c 646 {
lorcansmith 0:2a53a4c3238c 647 digit_found = true;
lorcansmith 0:2a53a4c3238c 648 if ( number_completed )
lorcansmith 0:2a53a4c3238c 649 { // save number into array
lorcansmith 0:2a53a4c3238c 650 numb[ i++ ] = new_num & 0xff;
lorcansmith 0:2a53a4c3238c 651 new_num = 0;
lorcansmith 0:2a53a4c3238c 652 }
lorcansmith 0:2a53a4c3238c 653 new_num = 10*new_num + c - '0';
lorcansmith 0:2a53a4c3238c 654 number_completed = false;
lorcansmith 0:2a53a4c3238c 655 } // else numeric character
lorcansmith 0:2a53a4c3238c 656 } // end while
lorcansmith 0:2a53a4c3238c 657 if ( (number_completed || (c == EOF)) && (i < max_num) )
lorcansmith 0:2a53a4c3238c 658 { // 0.80: save last number read
lorcansmith 0:2a53a4c3238c 659 numb[ i++ ] = new_num & 0xff;
lorcansmith 0:2a53a4c3238c 660 }
lorcansmith 0:2a53a4c3238c 661 }
lorcansmith 0:2a53a4c3238c 662
lorcansmith 0:2a53a4c3238c 663 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 664 /* read_addrs_from_file:
lorcansmith 0:2a53a4c3238c 665 * Description: Reads data from /webfs/net_adrs.txt
lorcansmith 0:2a53a4c3238c 666 * Globals used: NET_ADRS_FILE
lorcansmith 0:2a53a4c3238c 667 * Parameters: NONE
lorcansmith 0:2a53a4c3238c 668 * Returns: 0 if OK, 1 if failed to open files
lorcansmith 0:2a53a4c3238c 669 */
lorcansmith 0:2a53a4c3238c 670 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 671 int read_addrs_from_file()
lorcansmith 0:2a53a4c3238c 672 {
lorcansmith 0:2a53a4c3238c 673 int c, i;
lorcansmith 0:2a53a4c3238c 674 unsigned char numbers[17];
lorcansmith 0:2a53a4c3238c 675 char community[ MAX_COMMUNITY ];
lorcansmith 0:2a53a4c3238c 676
lorcansmith 0:2a53a4c3238c 677 for ( i = 0; i < MAX_COMMUNITY; i++ )
lorcansmith 0:2a53a4c3238c 678 {
lorcansmith 0:2a53a4c3238c 679 community[ i ] = 0;
lorcansmith 0:2a53a4c3238c 680 }
lorcansmith 0:2a53a4c3238c 681 FILE *fr = fopen( NET_ADRS_FILE, "r" );
lorcansmith 0:2a53a4c3238c 682 if(!fr) {
lorcansmith 0:2a53a4c3238c 683 fprintf(stderr, "\r\nFile /webfs/net_adrs.txt could not be opened!\r\n");
lorcansmith 0:2a53a4c3238c 684 exit(1);
lorcansmith 0:2a53a4c3238c 685 }
lorcansmith 0:2a53a4c3238c 686 else // file opened OK
lorcansmith 0:2a53a4c3238c 687 {
lorcansmith 0:2a53a4c3238c 688 parse4numbers( fr, numbers, 16 );
lorcansmith 0:2a53a4c3238c 689 copy_net_addresses_from( numbers ); // v0.93: new subroutine
lorcansmith 0:2a53a4c3238c 690 /* v0.98: now read the community string from the file after reading end of line */
lorcansmith 0:2a53a4c3238c 691 while ( ((c = fgetc(fr)) != EOF) && ((c == ' ') || (c == '\r') || (c == '\n')) );
lorcansmith 0:2a53a4c3238c 692 i = 0;
lorcansmith 0:2a53a4c3238c 693 do
lorcansmith 0:2a53a4c3238c 694 {
lorcansmith 0:2a53a4c3238c 695 c = (char)c;
lorcansmith 0:2a53a4c3238c 696 if ( (c != ' ') && (c != '\r') && (c != '\n') && (i < MAX_COMMUNITY-1) )
lorcansmith 0:2a53a4c3238c 697 {
lorcansmith 0:2a53a4c3238c 698 community[ i++ ] = c;
lorcansmith 0:2a53a4c3238c 699 }
lorcansmith 0:2a53a4c3238c 700 else // string terminated
lorcansmith 0:2a53a4c3238c 701 {
lorcansmith 0:2a53a4c3238c 702 break;
lorcansmith 0:2a53a4c3238c 703 }
lorcansmith 0:2a53a4c3238c 704 } while ( ((c = fgetc(fr)) != EOF) && (c != 0) );
lorcansmith 0:2a53a4c3238c 705 parse4numbers( fr, numbers, 4 ); // now read in Trap host address
lorcansmith 0:2a53a4c3238c 706 copy_trap_host_address( numbers );
lorcansmith 0:2a53a4c3238c 707 fscanf( fr, "%lu", &mask4_IO_registers );
lorcansmith 0:2a53a4c3238c 708 fclose(fr);
lorcansmith 0:2a53a4c3238c 709 } // file opened OK
lorcansmith 2:25e12a7fe0aa 710 if ( strlen(community) > 3 )
lorcansmith 0:2a53a4c3238c 711 { // string length 4 to 20 characters
lorcansmith 0:2a53a4c3238c 712 strcpy( snmp_publiccommunity, community );
lorcansmith 0:2a53a4c3238c 713 pc.printf("community: %s %d \r\n", snmp_publiccommunity, strlen(snmp_publiccommunity) );
lorcansmith 0:2a53a4c3238c 714 }
lorcansmith 0:2a53a4c3238c 715 else
lorcansmith 0:2a53a4c3238c 716 {
lorcansmith 0:2a53a4c3238c 717 pc.printf("community too short: %s %d \r\n", community, strlen(community) );
lorcansmith 0:2a53a4c3238c 718 }
lorcansmith 0:2a53a4c3238c 719 return 0;
lorcansmith 0:2a53a4c3238c 720 }
lorcansmith 0:2a53a4c3238c 721
lorcansmith 0:2a53a4c3238c 722 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 723 /* blinker:
lorcansmith 0:2a53a4c3238c 724 * Description: Blinks led_link for 10 calls
lorcansmith 0:2a53a4c3238c 725 * Globals used: led_link, blink_led,
lorcansmith 0:2a53a4c3238c 726 * Parameters: NONE
lorcansmith 0:2a53a4c3238c 727 * Returns: NONE
lorcansmith 0:2a53a4c3238c 728 */
lorcansmith 0:2a53a4c3238c 729 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 730 void blinker( void )
lorcansmith 0:2a53a4c3238c 731 {
lorcansmith 0:2a53a4c3238c 732 static unsigned char blink_cnt;
lorcansmith 0:2a53a4c3238c 733
lorcansmith 0:2a53a4c3238c 734 if ( blink_led && blink_cnt++ < 10 )
lorcansmith 0:2a53a4c3238c 735 {
lorcansmith 0:2a53a4c3238c 736 led_link = !led_link;
lorcansmith 0:2a53a4c3238c 737 }
lorcansmith 0:2a53a4c3238c 738 else
lorcansmith 0:2a53a4c3238c 739 {
lorcansmith 0:2a53a4c3238c 740 blink_cnt = 0;
lorcansmith 0:2a53a4c3238c 741 blink_led = false;
lorcansmith 0:2a53a4c3238c 742 }
lorcansmith 0:2a53a4c3238c 743 }
lorcansmith 0:2a53a4c3238c 744
lorcansmith 0:2a53a4c3238c 745 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 746 /* init_traps:
lorcansmith 0:2a53a4c3238c 747 * Description: initialises trap flags and sends cold start trap when done
lorcansmith 2:25e12a7fe0aa 748 * Globals used: trap_init set true after cold start
lorcansmith 0:2a53a4c3238c 749 * Parameters: NONE
lorcansmith 0:2a53a4c3238c 750 * Returns: NONE
lorcansmith 0:2a53a4c3238c 751 */
lorcansmith 0:2a53a4c3238c 752 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 753 void init_traps( void )
lorcansmith 0:2a53a4c3238c 754 {
lorcansmith 0:2a53a4c3238c 755 snmp_coldstart_trap();
lorcansmith 0:2a53a4c3238c 756 trap_init = true;
lorcansmith 0:2a53a4c3238c 757 }
lorcansmith 0:2a53a4c3238c 758
lorcansmith 0:2a53a4c3238c 759 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 760 /* check_all_traps:
lorcansmith 0:2a53a4c3238c 761 * Description: test states for all trap events and sends appropriate trap
lorcansmith 2:25e12a7fe0aa 762 * Globals used: led2: set to ON if SPI not active
lorcansmith 0:2a53a4c3238c 763 * byte_changed, all_IO_updated, spi_active
lorcansmith 0:2a53a4c3238c 764 * Parameters: NONE
lorcansmith 0:2a53a4c3238c 765 * Returns: NONE
lorcansmith 0:2a53a4c3238c 766 */
lorcansmith 0:2a53a4c3238c 767 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 768 void check_all_traps( void )
lorcansmith 0:2a53a4c3238c 769 {
lorcansmith 0:2a53a4c3238c 770 if ( !led1 && (fsvr.get_byte( H_H_LINK_LSBYTE ) || fsvr.get_byte( H_H_LINK_MSBYTE )) )
lorcansmith 0:2a53a4c3238c 771 { // change of link state
lorcansmith 0:2a53a4c3238c 772 led1 = 1; // flag: link is up when led1 on
lorcansmith 0:2a53a4c3238c 773 snmp_linkup_trap();
lorcansmith 0:2a53a4c3238c 774 }
lorcansmith 0:2a53a4c3238c 775 else if ( (fsvr.get_byte( H_H_LINK_LSBYTE ) == 0) && (fsvr.get_byte( H_H_LINK_MSBYTE ) == 0) && led1 )
lorcansmith 0:2a53a4c3238c 776 { // change of link state
lorcansmith 0:2a53a4c3238c 777 led1 = 0;
lorcansmith 0:2a53a4c3238c 778 snmp_linkdown_trap();
lorcansmith 0:2a53a4c3238c 779 }
lorcansmith 2:25e12a7fe0aa 780 if ( byte_changed && all_IO_updated )
lorcansmith 0:2a53a4c3238c 781 { // any masked-in I/O register changed
lorcansmith 0:2a53a4c3238c 782 f3kIOchange_trap();
lorcansmith 0:2a53a4c3238c 783 all_IO_updated = byte_changed = false;
lorcansmith 0:2a53a4c3238c 784 }
lorcansmith 0:2a53a4c3238c 785 if ( spi_active && led2 )
lorcansmith 0:2a53a4c3238c 786 {
lorcansmith 0:2a53a4c3238c 787 led2 = 0; // flag: SPI is up when led2 off
lorcansmith 0:2a53a4c3238c 788 snmp_SPIup_trap();
lorcansmith 0:2a53a4c3238c 789 }
lorcansmith 0:2a53a4c3238c 790 else if ( !spi_active && !led2 )
lorcansmith 0:2a53a4c3238c 791 {
lorcansmith 0:2a53a4c3238c 792 led2 = 1; // flag: SPI is down when led2 on
lorcansmith 0:2a53a4c3238c 793 snmp_SPIdown_trap();
lorcansmith 2:25e12a7fe0aa 794 }
lorcansmith 0:2a53a4c3238c 795 }
lorcansmith 0:2a53a4c3238c 796
lorcansmith 0:2a53a4c3238c 797
lorcansmith 0:2a53a4c3238c 798 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 799 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 800 int main() {
lorcansmith 0:2a53a4c3238c 801 int idx;
lorcansmith 0:2a53a4c3238c 802
lorcansmith 0:2a53a4c3238c 803 new_cmd_idx = 0xaa;
lorcansmith 0:2a53a4c3238c 804 for ( idx = 0; idx < MAX_CMD; idx++ )
lorcansmith 0:2a53a4c3238c 805 { // put meaningful non-valid data in cmd_buf
lorcansmith 0:2a53a4c3238c 806 cmd_buf[ idx ] = new_cmd_idx;
lorcansmith 0:2a53a4c3238c 807 }
lorcansmith 0:2a53a4c3238c 808 pc.printf("=================== Version %s ====================\r\n", snmp_fw_version);
lorcansmith 0:2a53a4c3238c 809 // pc.printf("Press any key to start...\r\n");
lorcansmith 0:2a53a4c3238c 810 led3 = 1;
lorcansmith 0:2a53a4c3238c 811
lorcansmith 2:25e12a7fe0aa 812 FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
lorcansmith 2:25e12a7fe0aa 813 FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
lorcansmith 0:2a53a4c3238c 814 read_addrs_from_file();
lorcansmith 0:2a53a4c3238c 815
lorcansmith 0:2a53a4c3238c 816 /* Force fixed Ethernet address */
lorcansmith 0:2a53a4c3238c 817 EthernetNetIf eth(
lorcansmith 0:2a53a4c3238c 818 IpAddr( ip_ad[0], ip_ad[1], ip_ad[2], ip_ad[3] ), //IP Address
lorcansmith 0:2a53a4c3238c 819 IpAddr( msk_ad[0], msk_ad[1], msk_ad[2], msk_ad[3] ), //Network Mask
lorcansmith 0:2a53a4c3238c 820 IpAddr( gwy_ad[0], gwy_ad[1], gwy_ad[2], gwy_ad[3] ), //Gateway
lorcansmith 0:2a53a4c3238c 821 IpAddr( dns_ad[0], dns_ad[1], dns_ad[2], dns_ad[3] ) //DNS Server
lorcansmith 0:2a53a4c3238c 822 );
lorcansmith 0:2a53a4c3238c 823
lorcansmith 0:2a53a4c3238c 824 Base::add_rpc_class<DigitalOut>();
lorcansmith 0:2a53a4c3238c 825 #if 0
lorcansmith 0:2a53a4c3238c 826 Base::add_rpc_class<SPI_Server>();
lorcansmith 0:2a53a4c3238c 827 #endif
lorcansmith 0:2a53a4c3238c 828
lorcansmith 0:2a53a4c3238c 829 // pc.getc(); // wait for keyboard
lorcansmith 0:2a53a4c3238c 830 led3 = 0;
lorcansmith 0:2a53a4c3238c 831
lorcansmith 0:2a53a4c3238c 832 strcpy( (char *)syslocation, (const char *)syslocation_default );
lorcansmith 0:2a53a4c3238c 833 sysloc_len = strlen( (const char *)syslocation );
lorcansmith 0:2a53a4c3238c 834 snmp_set_syslocation( syslocation, &sysloc_len );
lorcansmith 0:2a53a4c3238c 835
lorcansmith 0:2a53a4c3238c 836 pc.printf("\r\nSetting up...\r\n");
lorcansmith 0:2a53a4c3238c 837 EthernetErr ethErr = eth.setup();
lorcansmith 0:2a53a4c3238c 838 if( ethErr )
lorcansmith 0:2a53a4c3238c 839 {
lorcansmith 0:2a53a4c3238c 840 pc.printf("Error %d in Ethernet setup.\r\n", ethErr);
lorcansmith 0:2a53a4c3238c 841 // return -1;
lorcansmith 0:2a53a4c3238c 842 }
lorcansmith 0:2a53a4c3238c 843 else // Ethernet Setup OK
lorcansmith 0:2a53a4c3238c 844 {
lorcansmith 0:2a53a4c3238c 845 mip = eth.getIp();
lorcansmith 0:2a53a4c3238c 846 led3 = 1;
lorcansmith 0:2a53a4c3238c 847 led_speed = LPC_GPIO1->FIOPIN & (1<<26); // GPIO1.26 = "LED_SPEED".
lorcansmith 0:2a53a4c3238c 848 led_link = LPC_GPIO1->FIOPIN & (1<<25); // GPIO1.25 = "LED_LINK".
lorcansmith 0:2a53a4c3238c 849 pc.printf("\r\nEthernet Setup OK\r\n");
lorcansmith 0:2a53a4c3238c 850
lorcansmith 0:2a53a4c3238c 851 svr.addHandler<RPCHandler>("/rpc");
lorcansmith 0:2a53a4c3238c 852 svr.addHandler<FSHandler>("/files");
lorcansmith 0:2a53a4c3238c 853 svr.addHandler<FSHandler>("/"); //Default handler
lorcansmith 0:2a53a4c3238c 854 //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
lorcansmith 0:2a53a4c3238c 855
lorcansmith 0:2a53a4c3238c 856 // svr.bind(80); disable for SNMP development
lorcansmith 0:2a53a4c3238c 857
lorcansmith 0:2a53a4c3238c 858 // snmp_init(); done in lwip/core/init.c
lorcansmith 0:2a53a4c3238c 859
lorcansmith 0:2a53a4c3238c 860 pc.printf("Listening...\n\r");
lorcansmith 0:2a53a4c3238c 861
lorcansmith 0:2a53a4c3238c 862 snmp_trap_dst_ip_set( ONLY_TRAP, (ip_addr_t *)&th_ad[0] );
lorcansmith 0:2a53a4c3238c 863 snmp_trap_dst_enable( ONLY_TRAP, ENABLED );
lorcansmith 0:2a53a4c3238c 864 snmp_coldstart_trap(); // to force ARP call
lorcansmith 0:2a53a4c3238c 865
lorcansmith 0:2a53a4c3238c 866 led3 = led4 = 0;
lorcansmith 0:2a53a4c3238c 867 spi_slave.format(8,3); // Setup: byte data, high steady state clock, 2nd edge capture
lorcansmith 0:2a53a4c3238c 868
lorcansmith 0:2a53a4c3238c 869 sys_tick.attach( &snmp_inc_sysuptime, 0.01 );
lorcansmith 2:25e12a7fe0aa 870 spi_tick.attach( &chk_SPI_active, 60.0 );
lorcansmith 0:2a53a4c3238c 871 comms_tick.attach( &blinker, 0.07 ); // tick to blink activity LED
lorcansmith 0:2a53a4c3238c 872 cold_start_delay.attach( &init_traps, 30.0 ); // send cold_start trap after 30 seconds
lorcansmith 0:2a53a4c3238c 873
lorcansmith 0:2a53a4c3238c 874
lorcansmith 0:2a53a4c3238c 875 // Listen indefinitely to Ethernet and SPI
lorcansmith 0:2a53a4c3238c 876 while ( true )
lorcansmith 0:2a53a4c3238c 877 {
lorcansmith 0:2a53a4c3238c 878 Net::poll(); // check for Ethernet requests
lorcansmith 0:2a53a4c3238c 879
lorcansmith 0:2a53a4c3238c 880 if ( trap_init )
lorcansmith 0:2a53a4c3238c 881 {
lorcansmith 0:2a53a4c3238c 882 check_all_traps();
lorcansmith 0:2a53a4c3238c 883 }
lorcansmith 0:2a53a4c3238c 884
lorcansmith 0:2a53a4c3238c 885 if( spi_slave.receive() ) {
lorcansmith 0:2a53a4c3238c 886 // Data available - needs chip select line to activate
lorcansmith 0:2a53a4c3238c 887 get_SPI_data( cmd_buf );
lorcansmith 0:2a53a4c3238c 888 } // end if( spi_slave.receive() )
lorcansmith 0:2a53a4c3238c 889 if ( net_addrs_set )
lorcansmith 0:2a53a4c3238c 890 { // v0.99: address changed from SNMP i/f
lorcansmith 0:2a53a4c3238c 891 write_addrs_to_file();
lorcansmith 0:2a53a4c3238c 892 net_addrs_set = false;
lorcansmith 0:2a53a4c3238c 893 }
lorcansmith 0:2a53a4c3238c 894 } // end while ( true )
lorcansmith 0:2a53a4c3238c 895
lorcansmith 0:2a53a4c3238c 896 } // else Ethernet Setup OK
lorcansmith 0:2a53a4c3238c 897 return 0;
lorcansmith 0:2a53a4c3238c 898 }