| |
serdev1.pwp
//
// PicoWeb Project File "serdev1"
//
// This project shows how to use the serial port from CGI routines used by
// Web pages. This same processing can be done with a user-supplied TCP/IP
// port (i.e., not using Web pages). Please refer to the sample project
// "sertcp" for an example of this.
//
// This project has three Web pages:
//
// main.htm - home page
// command.htm - send command strings to serial port using FORMs
// string.htm - passes a string parameter from HTML code to CGI routine
//
// The Web page "main.htm" simply has links to the other two Web pages.
//
// The Web page "command.htm" allows the user to send arbitrary strings out
// the PicoWeb serial port. This is done using HTML FORMs, with the string
// to be output sent as a URL parameter. The routine "send_cmd" is called by
// a PicoWeb HTML tag embedded in the Web page. Each time the CGI routine
// "send_cmd" is called, it sends any data after the URL parameter "C="
// to the PicoWeb serial port. Then any data waiting in the serial port
// input queue will be sent back. The serial port queue will be read and
// any characters found there will be sent back in one or more outgoing TCP
// packets until either (1) the end-of-line character is detected (set by
// #define SER_PORT_EOL_CHAR), (2) an inter-character timeout is exceeded
// (set be #define SER_PORT_TIMEOUT_MSECS), or (3) the maximum number
// of character allowed in a response packet is exceeded (set by #define
// SER_MAX_CHARS 1024). The #define SER_CLEAR_QUEUE determines whether
// the serial port queue is cleared each time a new packet is received.
//
// The Web page "string.htm" demonstrate how to pass a parameter string
// embedded in an PicoWeb HTML tag in a Web page's HTML code to a CGI pcode
// routine. The CGI routine "string" prints out this passed string to the
// Web page. It just as well could have been written to the serial port
// instead. Here is the output of the "string.htm" Web page as delivered
// by tghe PicoWeb and it's special HTML tags:
//
// Passing "Parameters" to CGI Routines in PicoWeb HTML Tags
//
// The following PicoWeb tag has a "string parameter" after the
// "?":
//
// `string.cgi?"hello+world%21%0D%0A"`
//
// in order to cause the string "hello world!\r\n" to be output.
//
// The CGI routine "string" referenced in the above tag is defined
// as follows in the project file:
//
// string:
// pprinturl psetparm_parm,1 ; print passed "tag parameter" string
// pret
//
// When the above tag is placed in an HTML file (i.e., this one),
// the contents of the string is output to the HTML stream,
// resulting in the following line:
//
// hello world!
//
//
// The string is decoded according to the same rules as HTTP
// URL's, namely "+" is mapped to " " and %hh is mapped to the
// character whose hex value is hh. Note the use of "%0D" and
// "%0A" to cause a CR and a LF to be output.
//
// By directing the output from the CGI routine which prints
// out the passed string to the serial port, the above string
// could have been sent there instead of to this Web page.
//
#define EEPROM_IP /* IP address stored in EEPROM */
#define NET_CONFIG_IP /* allow IP address reconfiguration via net */
#define ENABLE_WATCHDOG
#undef DEBUGGER /* no debugger...we're using serial port */
#define DEBUGGER /* enable debugger */
//#define CLOCK 8000000
#define CLOCK 7372000
#define BAUD_RATE 19200
#define SER_PORT_TIMEOUT_MSECS 1000 /* serial port input timeout */
#define SER_PORT_EOL_CHAR 0x0d /* serial input end-of-line character */
/* don't define for no EOL processing */
#define SER_MAX_CHARS 1024 /* max. characters allowed in response packet */
// HTML and images
main.htm
command.htm
string.htm
// public CGI routines
send_cmd.cgi
print_cmd.cgi
string.cgi
// linker directives (search or add)
//link add serial_normal.o
//link search kernel.a
//------------------ included AVR assembly language follows ---------------
#avr_reset
.cseg
.eseg
#avr_slow
.cseg
.eseg
#avr_fast
#avr_asm
#define putchar_serial pmovbi putc_b,0
#define putchar_net pmovbi putc_b,1
#define serial_binary pser_mode 1
#define serial_normal pser_mode 0
.eseg
;
; send_cmd
;
; Send command from URL parameter string to serial port and
; output response back from serial port
;
send_cmd:
putchar_serial ; switch putchar to serial port
serial_binary ; put serial port in binary mode
pcall serdev_print_url_cmd ; send command from URL string
pprint "\r\n" ; send terminator
get_response:
putchar_net ; switch putchar back to ''net
pcall serdev_copynet ; copy serial port input to net
pret
;
; print_cmd
;
; Read command from URL parameter string and output
;
print_cmd:
pmovwi buf+2,0
pjump serdev_print_url_cmd1
;
; serdev_print_url_cmd
;
; print command string in URL after "C="
;
serdev_print_url_cmd:
pmovwi buf+2,1
serdev_print_url_cmd1:
purlparm buf,"C=" ; search for command string
pjumpne 1f ; exit if not found
pprinturl buf,[buf+2]
1:
pret
;
; serdev_copynet
;
; loop reading chars from the serial buffer and writing to ''net until
; CR encountered (or timeout)
;
.cseg
serdev_copynet:
pmovwi buf+2,SER_MAX_CHARS ; zero max. character counter
serdev_copynet_loop:
; get char from serial port with TO
psgetcto buf,PSGETCTO_MSECS(SER_PORT_TIMEOUT_MSECS)
pjumpeq serdev_copydone ; no more chars!
#ifdef SER_PORT_EOL_CHAR
pcmpbi buf,SER_PORT_EOL_CHAR ; check for EOL character (exit if found)
pjumpeq serdev_copydone
#endif
pputcb buf ; output character
pdecw buf+2 ; decrement character counter
pjumpeq serdev_copydone ; exit now if counter hit zero
pjump serdev_copynet_loop ; back for more
serdev_copydone:
pret
.eseg
string:
;; un-comment next two lines to send to serial port instead of the net
;;putchar_serial ; switch putchar to serial port
;;serial_binary ; put serial port in binary mode
pprinturl psetparm_parm,1 ; print passed "tag parameter" string
pret
Back
|
|
|