static void blink_led () { /* Blink the LEDs on an eval board */ const U8 led_val[4] = { 0x01,0x03,0x02,0x00,}; static U32 cnt; if (tick == __TRUE) { /* Every 100 ms */ tick = __FALSE; if (LEDrun == __TRUE) { LED_out (led_val[cnt]); if (++cnt >= sizeof(led_val)) { cnt = 0; } } if (LCDupdate == __TRUE) { upd_display (); } } }
__task void blink_led () { /* Blink the LEDs on an eval board */ const U8 led_val[4] = { 0x01,0x03,0x02,0x00,}; U32 cnt = 0; LEDrun = __TRUE; while(1) { /* Every 100 ms */ if (LEDrun == __TRUE) { LED_out (led_val[cnt]); if (++cnt >= sizeof(led_val)) { cnt = 0; } } if (LCDupdate == __TRUE) { upd_display (); } os_dly_wait(10); } }
void cgi_process_data (U8 code, U8 *dat, U16 len) { /* This function is called by HTTP server to process the returned Data */ /* for the CGI Form POST method. It is called on SUBMIT from the browser. */ /* Parameters: */ /* code - callback context code */ /* 0 = www-url-encoded form data */ /* 1 = filename for file upload (0-terminated string) */ /* 2 = file upload raw data */ /* 3 = end of file upload (file close requested) */ /* 4 = any xml encoded POST data (single or last stream) */ /* 5 = the same as 4, but with more xml data to follow */ /* Use http_get_content_type() to check the content type */ /* dat - pointer to POST received data */ /* len - received data length */ U8 passw[12],retyped[12]; U8 *var,stpassw; switch (code) { case 0: /* Url encoded form data received. */ break; default: /* Ignore all other codes. */ return; } P2 = 0; LEDrun = __TRUE; if (len == 0) { /* No data or all items (radio, checkbox) are off. */ LED_out (P2); return; } stpassw = 0; var = (U8 *)alloc_mem (40); do { /* Parse all returned parameters. */ dat = http_get_var (dat, var, 40); if (var[0] != 0) { /* Parameter found, returned string is non 0-length. */ if (str_scomp (var, "led0=on") == __TRUE) { P2 |= 0x01; } else if (str_scomp (var, "led1=on") == __TRUE) { P2 |= 0x02; } else if (str_scomp (var, "led2=on") == __TRUE) { P2 |= 0x04; } else if (str_scomp (var, "led3=on") == __TRUE) { P2 |= 0x08; } else if (str_scomp (var, "led4=on") == __TRUE) { P2 |= 0x10; } else if (str_scomp (var, "led5=on") == __TRUE) { P2 |= 0x20; } else if (str_scomp (var, "led6=on") == __TRUE) { P2 |= 0x40; } else if (str_scomp (var, "led7=on") == __TRUE) { P2 |= 0x80; } else if (str_scomp (var, "ctrl=Browser") == __TRUE) { LEDrun = __FALSE; } else if (str_scomp (var, "pw=") == __TRUE) { /* Change password. */ str_copy (passw, var+3); stpassw |= 1; } else if (str_scomp (var, "pw2=") == __TRUE) { /* Retyped password. */ str_copy (retyped, var+4); stpassw |= 2; } else if (str_scomp (var, "lcd1=") == __TRUE) { /* LCD Module Line 1 text. */ str_copy (lcd_text[0], var+5); LCDupdate = __TRUE; } else if (str_scomp (var, "lcd2=") == __TRUE) { /* LCD Module Line 2 text. */ str_copy (lcd_text[1], var+5); LCDupdate = __TRUE; } } }while (dat); free_mem ((OS_FRAME *)var); LED_out (P2); if (stpassw == 0x03) { len = strlen ((const char *)passw); if (mem_comp (passw, retyped, len) == __TRUE) { /* OK, both entered passwords the same, change it. */ str_copy (http_auth_passw, passw); } } }
static void write_leds (int mode) { /* No action on read access. */ if (mode == MIB_WRITE) { LED_out (LedOut); } }
U16 tnet_process_cmd (U8 *cmd, U8 *buf, U16 buflen, U32 *pvar) { /* This is a Telnet Client callback function to make a formatted output */ /* for 'stdout'. It returns the number of bytes written to the out buffer.*/ /* Hi-bit of return value (len is or-ed with 0x8000) is a disconnect flag.*/ /* Bit 14 (len is or-ed with 0x4000) is a repeat flag for the Tnet client.*/ /* If this bit is set to 1, the system will call the 'tnet_process_cmd()' */ /* again with parameter 'pvar' pointing to a 4-byte buffer. This buffer */ /* can be used for storing different status variables for this function. */ /* It is set to 0 by Telnet server on first call and is not altered by */ /* Telnet server for repeated calls. This function should NEVER write */ /* more than 'buflen' bytes to the buffer. */ /* Parameters: */ /* cmd - telnet received command string */ /* buf - Telnet transmit buffer */ /* buflen - length of this buffer (500-1400 bytes - depends on MSS) */ /* pvar - pointer to local storage buffer used for repeated loops */ /* This is a U32 variable - size is 4 bytes. Value is: */ /* - on 1st call = 0 */ /* - 2nd call = as set by this function on first call */ TCP_INFO *tsoc; REMOTEM rm; U32 val,ch,temp; U16 len = 0; switch (MYBUF(pvar)->id) { case 0: /* First call to this function, the value of '*pvar' is 0 */ break; case 1: /* Repeated call, command 'MEAS' measurements display. */ while (len < buflen-80) { /* Let's use as much of the buffer as possible. */ /* This will produce less packets and speedup the transfer. */ len += sprintf ((char *)(buf+len), "\r\n%4d", MYBUF(pvar)->idx); for (val = 0; val < 8; val++) { len += sprintf ((char *)(buf+len), "%7d", AD_in(val)); } if (++MYBUF(pvar)->idx >= MYBUF(pvar)->nmax) { /* OK, we are done. */ return (len); } } /* Request a repeated call, bit 14 is a repeat flag. */ return (len | 0x4000); case 2: /* Repeated call, TCP status display. */ while (len < buflen-80) { /* Let's use as much of the buffer as possible. */ /* This will produce less packets and speedup the transfer. */ if (MYBUF(pvar)->idx == 0) { len += str_copy (buf, (U8 *)tcp_stat); } tsoc = &tcp_socket[MYBUF(pvar)->idx]; len += sprintf ((char *)(buf+len), "\r\n%9d %10s ", MYBUF(pvar)->idx, state[tsoc->State]); if (tsoc->State <= TCP_STATE_CLOSED) { len += sprintf ((char *)(buf+len), " - - - -\r\n"); } else if (tsoc->State == TCP_STATE_LISTEN) { len += sprintf ((char *)(buf+len), " - - %5d -\r\n", tsoc->LocPort); } else { /* First temporary print for alignment. */ sprintf ((char *)(buf+len+16),"%d.%d.%d.%d",tsoc->RemIpAdr[0], tsoc->RemIpAdr[1],tsoc->RemIpAdr[2],tsoc->RemIpAdr[3]); len += sprintf ((char *)(buf+len),"%15s %5d %5d %4d\r\n", buf+len+16,tsoc->RemPort,tsoc->LocPort,tsoc->AliveTimer); } if (++MYBUF(pvar)->idx >= tcp_NumSocks) { /* OK, we are done, reset the index counter for next callback. */ MYBUF(pvar)->idx = 0; /* Setup a callback delay. This function will be called again after */ /* delay has expired. It is set to 20 system ticks 20 * 100ms = 2 sec. */ tnet_set_delay (20); break; } } /* Request a repeated call, bit 14 is a repeat flag. */ return (len |= 0x4000); } /* Simple Command line parser */ len = strlen ((const char *)cmd); if (tnet_ccmp (cmd, "LED") == __TRUE) { /* 'LED' command received */ if (len >= 5) { sscanf ((const char *)(cmd+4),"%x", &val); LED_out (val); len = 0; if (LEDrun == __TRUE) { len = str_copy (buf," --> Running Lights OFF"); LEDrun = __FALSE; } return (len); } len = 0; if (LEDrun == __FALSE) { len = str_copy (buf," --> Running Lights ON"); LEDrun = __TRUE; } return (len); } if (tnet_ccmp (cmd, "ADIN") == __TRUE) { /* 'ADIN' command received */ if (len >= 6) { sscanf ((const char *)(cmd+5),"%d",&ch); val = AD_in (ch); len = sprintf ((char *)buf,"\r\n ADIN %d = %d",ch,val); return (len); } } if (tnet_ccmp (cmd, "BYE") == __TRUE) { /* 'BYE' command, send message and disconnect */ len = str_copy (buf, "\r\nDisconnect...\r\n"); /* Hi bit of return value is a disconnect flag */ return (len | 0x8000); } if (tnet_ccmp (cmd, "PASSW") == __TRUE && tnet_EnAuth) { /* Change the system password. */ if (len == 5) { /* Disable password. */ tnet_auth_passw[0] = 0; } else { mem_copy (&tnet_auth_passw, &cmd[6], 20); } len = sprintf ((char *)buf, "\r\n OK, New Password: \"%s\"",tnet_auth_passw); return (len); } if (tnet_ccmp (cmd, "PASSWD") == __TRUE && tnet_EnAuth) { /* Only display the current system password. */ len = sprintf ((char *)buf, "\r\n System Password: \"%s\"",tnet_auth_passw); return (len); } if (tnet_ccmp (cmd, "MEAS") == __TRUE) { /* During the repeated call to this function, the 'cmd' buffer is locked, */ /* so we can use it for our temporary storage. Each Telnet session has its */ /* own buffer of size 96 bytes. We can use 95 bytes, last one is not free. */ /* Here the local storage '*pvar' is initialized to 0 by Telnet Server. */ MYBUF(pvar)->id = 1; if (len > 5) { /* We must be careful here, because data is overlaid. */ sscanf ((const char *)&cmd[5], "%d", &temp); MYBUF(pvar)->nmax = temp; } len = str_copy (buf,(U8 *)meas_header); if (MYBUF(pvar)->nmax) { /* Bit 14 is a repeat flag. */ len |= 0x4000; } return (len); } if (tnet_ccmp (cmd, "TCPSTAT") == __TRUE) { /* Display a TCP status similar to that in HTTP_Demo example. */ /* Here the local storage '*pvar' is initialized to 0 by Telnet Server. */ MYBUF(pvar)->id = 2; len = str_copy (buf, CLS); return (len | 0x4000); } if (tnet_ccmp (cmd, "RINFO") == __TRUE) { /* Display Remote Machine IP and MAC address. */ tnet_get_info (&rm); len = sprintf ((char *)buf,"\r\n Remote IP : %d.%d.%d.%d", rm.IpAdr[0],rm.IpAdr[1],rm.IpAdr[2],rm.IpAdr[3]); len += sprintf ((char *)(buf+len), "\r\n Remote MAC: %02X-%02X-%02X-%02X-%02X-%02X", rm.HwAdr[0],rm.HwAdr[1],rm.HwAdr[2], rm.HwAdr[3],rm.HwAdr[4],rm.HwAdr[5]); return (len); } if (tnet_ccmp (cmd, "HELP") == __TRUE || tnet_ccmp (cmd, "?") == __TRUE) { /* 'HELP' command, display help text */ len = str_copy (buf,(U8 *)tnet_help1); if (tnet_EnAuth) { len += str_copy (buf+len,(U8 *)tnet_help2); } len += str_copy (buf+len,(U8 *)tnet_help3); return (len); } /* Unknown command, display message */ len = str_copy (buf, "\r\n==> Unknown Command: "); len += str_copy (buf+len, cmd); return (len); }