cgi.c
来自「针对AVR单片机开发的嵌入式操作系统」· C语言 代码 · 共 721 行 · 第 1/2 页
C
721 行
HtmlInOutPortRow(stream, 'B', inb(PINB), inb(PORTB), inb(DDRB), 0xFF);
HtmlSeparatorRow(stream, 10, 5);
HtmlInOutPortRow(stream, 'D', inb(PIND), inb(PORTD), inb(DDRD), 0xFF);
HtmlSeparatorRow(stream, 10, 5);
HtmlInOutPortRow(stream, 'E', inb(PINE), inb(PORTE), inb(DDRE), 0xDC);
HtmlSeparatorRow(stream, 10, 5);
fputs("<tr><th>F</th><td>Status</td>", stream);
HtmlLedRow(stream, 8, 1, inb(PINF), inb(PINF), 0);
fputs("</tr>\r\n", stream);
fputs_P(foot, stream);
fflush(stream);
return 0;
}
/*!
* \brief CGI callback function to display the status of the CPU ports.
*
* Creates HTML code to show the status of CPU ports B, D, E and F.
* The page will be automatically refreshed every 5 seconds.
*
* \image html sport.gif
*
*
*
* This function is called by the HTTP module when a browser requests
* a CGI function, for which this routine has been registered via
* NutRegisterCgi().
*
* \param stream Stream device of the HTTP connection.
* \param req Pointer to the CGI REQUEST structure. Detailed information
* is available in the Nut/OS API documentation.
*
* \return 0 on success or -1 in case of any failure.
*/
int CpuPortStatus(FILE * stream, REQUEST * req)
{
static prog_char head[] = /* */
"<html>" /* */
"<head>" /* */
"<meta http-equiv=\"refresh\" content=\"5; URL=" PORT_STATUS_CGI "\">" /* */
"<title>Ethernut CPU Port Status</title>" /* */
"</head>" /* */
"<body bgcolor=\"#C7D0D9\"><a href=\"/\">" /* */
"<img src=\"/enmini.gif\" border=\"0\" width=\"70\" height=\"17\">" /* */
"</a><div align=\"center\">" /* */
"<table border=\"1\" cellspacing=\"0\">\r\n" /* */
"<thead><tr><th rowspan=\"2\"> PORT </th>" /* */
"<th colspan=\"8\">Bit</th></tr>" /* */
"<tr><th>7</th><th>6</th><th>5</th><th>4</th><th>3</th>" /* */
"<th>2</th><th>1</th><th>0</th></tr>" /* */
"</thead><tfoot>\r\n";
NutHttpSendHeaderTop(stream, req, 200, "Ok");
NutHttpSendHeaderBot(stream, "text/html", -1);
fputs_P(head, stream);
fputs("<tr><th>B</th>", stream);
HtmlLedRow(stream, 8, 1, inb(PINB), inb(PORTB), inb(DDRB));
fputs("</tr>\r\n", stream);
fputs("<tr><th>D</th>", stream);
HtmlLedRow(stream, 8, 1, inb(PIND), inb(PORTD), inb(DDRD));
fputs("</tr>\r\n", stream);
fputs("<tr><th>E</th>", stream);
HtmlLedRow(stream, 8, 1, inb(PINE), inb(PORTE), inb(DDRE));
fputs("</tr>\r\n", stream);
fputs("<tr><th>F</th>", stream);
HtmlLedRow(stream, 8, 1, inb(PINF), inb(PINF), 0);
fputs("</tr>\r\n", stream);
fputs("</tfoot></table><br></div></body>\r\n</html>", stream);
fflush(stream);
return 0;
}
/*!
* \brief CGI callback function to control a shift register output board.
*
* Creates HTML code to show the status of any attached shift register
* output board plus a HTML form to modify the current relay status
* via checkboxes.
*
* The resulting HTML code is send back to the browser. If the submit
* button is clicked on this page, this function will be called again
* to process the checkboxes and display the updated status.
*
* \image html relay.gif
*
*
*
* This function is called by the HTTP module when a browser requests
* a CGI function, for which this routine has been registered via
* NutRegisterCgi().
*
* \param stream Stream device of the HTTP connection.
* \param req Pointer to the CGI REQUEST structure. Detailed information
* is available in the Nut/OS API documentation.
*
* \return 0 on success or -1 in case of any failure.
*/
int SpiRelayControl(FILE * stream, REQUEST * req)
{
u_char i;
static prog_char head[] = "<html>" /* */
"<head>" /* */
"<meta http-equiv=\"expires\" content=\"0\">" /* */
"<title>Ethernut Shift Register Output</title>" /* */
"</head>" /* */
"<body bgcolor=\"#C7D0D9\"><a href=\"/\">" /* */
"<img src=\"/enmini.gif\" border=\"0\" width=\"70\" height=\"17\">" /* */
"</a><div align=\"center\">";
static prog_char foot[] = "</tfoot></table><br>" /* */
" <input type=\"submit\" value=\" Set \"> " /* */
" <input type=\"reset\" value=\" Cancel \"> " /* */
"</form>\r\n";
if (spi_no == 255)
SpiDigitalInit(&spi_ni, &spi_no);
NutHttpSendHeaderTop(stream, req, 200, "Ok");
NutHttpSendHeaderBot(stream, "text/html", -1);
fputs_P(head, stream);
if (spi_no) {
if (req->req_query)
ProcessCgiRelayRequest(req->req_query);
fputs("<form action=\"" RELAY_CONTROL_CGI "\" enctype=\"text/plain\">" /* */
"<table border=\"1\" cellspacing=\"0\">\r\n" /* */
"<thead><tr><th> </th><th colspan=\"", stream);
fprintf(stream, "%u", spi_no);
fputs("\">Relay</th></tr><tr><td> </td>", stream);
for (i = 1; i <= spi_no; i++)
fprintf(stream, "<th>%u</th>", i);
fputs("</tr></thead><tfoot>\r\n", stream);
fputs("<tr><td> </td>", stream);
if (relay_known)
HtmlLedRow(stream, spi_no, 0, relay_status, relay_status, 0xFFFFFFFF);
else
HtmlLedRow(stream, spi_no, 0, relay_status, ~relay_status, 0xFFFFFFFF);
fputs("</tr>\r\n", stream);
fputs("<tr><td>On</td>", stream);
HtmlCheckboxRow(stream, spi_no, 0, "S", relay_status, 0xFFFFFFFF);
fputs("</tr>\r\n", stream);
fputs_P(foot, stream);
} else
fputs("No Outputs", stream);
fputs("</div></body>\r\n</html>", stream);
fflush(stream);
return 0;
}
/*!
* \brief CGI callback function to query a shift register input board.
*
* This function is called by the HTTP helper routines when a browser requests
* a CGI function, for which this routine has been registered via
* NutRegisterCgi().
*
* \image html opto.gif
*
*
*
* Creates HTML code to show the status of the optically isolated inputs
* of an attached input shift register board. The page will be automatically
* refreshed every 5 seconds.
*
* \param stream Stream device of the HTTP connection.
* \param req Pointer to the CGI REQUEST structure. Detailed information
* is available in the Nut/OS API documentation.
*
* \return 0 on success or -1 in case of any failure.
*/
int SpiOptoStatus(FILE * stream, REQUEST * req)
{
u_long status;
u_char i;
static prog_char title[] = "<title>Ethernut Shift Register Input</title>" /* */
"</head><body bgcolor=\"#C7D0D9\"><a href=\"/\">" /* */
"<img src=\"/enmini.gif\" border=\"0\" width=\"70\" height=\"17\">" /* */
"</a><div align=\"center\">";
if (spi_ni == 255)
SpiDigitalInit(&spi_ni, &spi_no);
NutHttpSendHeaderTop(stream, req, 200, "Ok");
NutHttpSendHeaderBot(stream, "text/html", -1);
fputs("<html><head>", stream);
if (spi_ni)
fputs("<meta http-equiv=\"refresh\" content=\"5; URL=" OPTO_STATUS_CGI "\">", stream);
fputs_P(title, stream);
if (spi_ni) {
fputs("<table border=\"1\" cellspacing=\"0\">\r\n" /* */
"<thead><tr><th colspan=\"", stream);
fprintf(stream, "%u", spi_ni);
fputs("\">Input</th></tr><tr>", stream);
for (i = 1; i <= spi_ni; i++)
fprintf(stream, "<th>%u</th>", i);
fputs("</tr></thead><tfoot><tr>\r\n", stream);
status = SpiDigitalGet(spi_ni);
HtmlLedRow(stream, spi_ni, 0, status, status, 0);
fputs("</tfoot></table><br>", stream);
} else
fputs("No Inputs", stream);
fputs("</div></body>\r\n</html>", stream);
fflush(stream);
return 0;
}
/*!
* \brief CGI callback function to control the Charon II LEDs.
*
* Creates HTML code to show the status of any attached shift register
* output board plus a HTML form to modify the current relay status
* via checkboxes.
*
* The resulting HTML code is send back to the browser. If the submit
* button is clicked on this page, this function will be called again
* to process the checkboxes and display the updated status.
*
* \image html relay.gif
*
*
*
* This function is called by the HTTP module when a browser requests
* a CGI function, for which this routine has been registered via
* NutRegisterCgi().
*
* \param stream Stream device of the HTTP connection.
* \param req Pointer to the CGI REQUEST structure. Detailed information
* is available in the Nut/OS API documentation.
*
* \return 0 on success or -1 in case of any failure.
*/
int CharonLedControl(FILE * stream, REQUEST * req)
{
static u_char led_status;
u_char i;
char *name;
char *value;
int pcount = NutHttpGetParameterCount(req);
static prog_char head[] = "<html>" /* */
"<head>" /* */
"<meta http-equiv=\"expires\" content=\"0\">" /* */
"<title>Charon II LEDs</title>" /* */
"</head>" /* */
"<body bgcolor=\"#C7D0D9\"><a href=\"/\">" /* */
"<img src=\"/enmini.gif\" border=\"0\" width=\"70\" height=\"17\">" /* */
"</a><div align=\"center\">";
static prog_char foot[] = "</tfoot></table><br>" /* */
" <input type=\"submit\" value=\" Set \"> " /* */
" <input type=\"reset\" value=\" Cancel \"> " /* */
"</form>\r\n";
NutHttpSendHeaderTop(stream, req, 200, "Ok");
NutHttpSendHeaderBot(stream, "text/html", -1);
fputs_P(head, stream);
led_status = 0;
for (i = 0; i < pcount; i++) {
name = NutHttpGetParameterName(req, i);
value = NutHttpGetParameterValue(req, i);
if (*name == 'S') {
led_status |= 1 << (7 - (*value - '0'));
}
}
if (pcount > 0)
DevBoardShiftLedOut(~led_status);
fputs("<form action=\"" CHARON_CONTROL_CGI "\" enctype=\"text/plain\">" /* */
"<table border=\"1\" cellspacing=\"0\">\r\n" /* */
"<thead><tr><th> </th><th colspan=\"8\">" /* */
"LED</th></tr><tr><td> </td>", stream);
for (i = 1; i <= 8; i++) {
fprintf(stream, "<th>%u</th>", i);
}
fputs("</tr></thead><tfoot>\r\n", stream);
fputs("<tr><td> </td>", stream);
HtmlLedRow(stream, 8, 0, led_status, led_status, 0xFFFFFFFF);
fputs("</tr>\r\n", stream);
fputs("<tr><td>On</td>", stream);
HtmlCheckboxRow(stream, 8, 0, "S", led_status, 0xFFFFFFFF);
fputs("</tr>\r\n", stream);
fputs_P(foot, stream);
fputs("</div></body>\r\n</html>", stream);
fflush(stream);
return 0;
}
/*!
* \brief CGI callback function to query the Charon II switches.
*
* This function is called by the HTTP helper routines when a browser requests
* a CGI function, for which this routine has been registered via
* NutRegisterCgi().
*
* \image html opto.gif
*
*
*
* Creates HTML code to show the status of the optically isolated inputs
* of an attached SPI input board. The page will be automatically refreshed
* every 5 seconds.
*
* \param stream Stream device of the HTTP connection.
* \param req Pointer to the CGI REQUEST structure. Detailed information
* is available in the Nut/OS API documentation.
*
* \return 0 on success or -1 in case of any failure.
*/
int CharonSwitchStatus(FILE * stream, REQUEST * req)
{
u_char status;
u_char i;
static prog_char title[] = "<title>Charon II Switches</title>" /* */
"</head><body bgcolor=\"#C7D0D9\"><a href=\"/\">" /* */
"<img src=\"/enmini.gif\" border=\"0\" width=\"70\" height=\"17\">" /* */
"</a><div align=\"center\">";
NutHttpSendHeaderTop(stream, req, 200, "Ok");
NutHttpSendHeaderBot(stream, "text/html", -1);
fputs("<html><head>", stream);
fputs("<meta http-equiv=\"refresh\" content=\"5; URL=" CHARON_STATUS_CGI "\">", stream);
fputs_P(title, stream);
fputs("<table border=\"1\" cellspacing=\"0\">\r\n" /* */
"<thead><tr><th colspan=\"8\">" /* */
"Switches</th></tr><tr>", stream);
for (i = 1; i <= 8; i++) {
fprintf(stream, "<th>%u</th>", i);
}
fputs("</tr></thead><tfoot><tr>\r\n", stream);
status = ~DevBoardShiftByteIn();
HtmlLedRow(stream, 8, 0, status, status, 0);
fputs("</tfoot></table><br>", stream);
fputs("</div></body>\r\n</html>", stream);
fflush(stream);
return 0;
}
/*@}*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?