📄 cgi_8c-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head> <meta name="robots" content="noindex"> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Ethernut WebPort</title> <link href="doxygen.css" rel="stylesheet" type="text/css"></head><body bgcolor="#ffffff"><!-- Generated by Doxygen 1.4.1 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div><div class="nav"><a class="el" href="dir_000000.html">webport</a></div><h1>cgi.c</h1><a href="cgi_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*</span>00002 <span class="comment"> * Copyright (C) 2002-2005 by egnite Software GmbH. All rights reserved.</span>00003 <span class="comment"> *</span>00004 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>00005 <span class="comment"> * modification, are permitted provided that the following conditions</span>00006 <span class="comment"> * are met:</span>00007 <span class="comment"> *</span>00008 <span class="comment"> * 1. Redistributions of source code must retain the above copyright</span>00009 <span class="comment"> * notice, this list of conditions and the following disclaimer.</span>00010 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>00011 <span class="comment"> * notice, this list of conditions and the following disclaimer in the</span>00012 <span class="comment"> * documentation and/or other materials provided with the distribution.</span>00013 <span class="comment"> * 3. Neither the name of the copyright holders nor the names of</span>00014 <span class="comment"> * contributors may be used to endorse or promote products derived</span>00015 <span class="comment"> * from this software without specific prior written permission.</span>00016 <span class="comment"> *</span>00017 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS</span>00018 <span class="comment"> * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>00019 <span class="comment"> * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS</span>00020 <span class="comment"> * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE</span>00021 <span class="comment"> * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,</span>00022 <span class="comment"> * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,</span>00023 <span class="comment"> * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS</span>00024 <span class="comment"> * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED</span>00025 <span class="comment"> * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,</span>00026 <span class="comment"> * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF</span>00027 <span class="comment"> * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span>00028 <span class="comment"> * SUCH DAMAGE.</span>00029 <span class="comment"> *</span>00030 <span class="comment"> * For additional information see http://www.ethernut.de/</span>00031 <span class="comment"> *</span>00032 <span class="comment"> */</span>00033 00034 <span class="preprocessor">#include <string.h></span>00035 <span class="preprocessor">#include <stdio.h></span>00036 <span class="preprocessor">#include <io.h></span>00037 00038 <span class="preprocessor">#include <dev/spidigio.h></span>00039 <span class="preprocessor">#include <pro/httpd.h></span>00040 00041 <span class="preprocessor">#include "db_shift.h"</span>00042 <span class="preprocessor">#include "<a class="code" href="webport_8h.html">webport.h</a>"</span>00043 <span class="comment"></span>00044 <span class="comment">/*!</span>00045 <span class="comment"> * \file cgi.c</span>00046 <span class="comment"> * \brief CGI Callbacks.</span>00047 <span class="comment"> */</span>00048 <span class="comment"></span>00049 <span class="comment">/*!</span>00050 <span class="comment"> * \addtogroup xgCGI</span>00051 <span class="comment"> */</span><span class="comment"></span>00052 <span class="comment">/*@{*/</span>00053 <a name="l00054"></a><a class="code" href="group__xg_c_g_i.html#ga0">00054</a> <span class="keyword">static</span> u_char <a class="code" href="group__xg_c_g_i.html#ga0">spi_ni</a> = 255; <span class="comment">/*!< \brief Number of detected opto inputs. */</span><a name="l00055"></a><a class="code" href="group__xg_c_g_i.html#ga1">00055</a> <span class="keyword">static</span> u_char <a class="code" href="group__xg_c_g_i.html#ga1">spi_no</a> = 255; <span class="comment">/*!< \brief Number of detected relays. */</span><a name="l00056"></a><a class="code" href="group__xg_c_g_i.html#ga2">00056</a> <span class="keyword">static</span> u_long <a class="code" href="group__xg_c_g_i.html#ga2">relay_status</a>; <span class="comment">/*!< \brief Relays status. */</span><a name="l00057"></a><a class="code" href="group__xg_c_g_i.html#ga3">00057</a> <span class="keyword">static</span> u_char <a class="code" href="group__xg_c_g_i.html#ga3">relay_known</a>; <span class="comment">/*!< \brief Equals zero as long as the relay status is unknown. */</span>00058 <span class="comment"></span>00059 <span class="comment">/*!</span>00060 <span class="comment"> * \brief Print HTML code for a row of LEDs.</span>00061 <span class="comment"> *</span>00062 <span class="comment"> * The resulting HTML code will present a row of LEDs. The color and</span>00063 <span class="comment"> * the lit state of each LED is determined by three bit values. The</span>00064 <span class="comment"> * required images are expected in the URL root of the urom flash</span>00065 <span class="comment"> * filesystem:</span>00066 <span class="comment"> *</span>00067 <span class="comment"> * - r0.gif Red LED not lit. Will be displayed if the corresponding</span>00068 <span class="comment"> * bit in the direction mask is set and the input and output</span>00069 <span class="comment"> * bits are both not set.</span>00070 <span class="comment"> * - r1.gif Red LED lit. Will be displayed if the corresponding</span>00071 <span class="comment"> * bit in the direction mask is set and the input and output</span>00072 <span class="comment"> * bits are both set.</span>00073 <span class="comment"> * - g0.gif Green LED not lit. Will be displayed if the corresponding</span>00074 <span class="comment"> * bit in the direction mask and the input value are both not set.</span>00075 <span class="comment"> * - g1.gif Green LED lit. Will be displayed if the corresponding</span>00076 <span class="comment"> * bit in the direction mask is not set and the input bit is set.</span>00077 <span class="comment"> * - y0.gif Yellow LED not lit. Will be displayed if the corresponding</span>00078 <span class="comment"> * bit in the direction mask is set, the output bit is set</span>00079 <span class="comment"> * but the input bit is not set.</span>00080 <span class="comment"> * - y1.gif Yellow LED lit. Will be displayed if the corresponding</span>00081 <span class="comment"> * bit in the direction mask is set, the output bit is not set</span>00082 <span class="comment"> * but the input bit is set.</span>00083 <span class="comment"> *</span>00084 <span class="comment"> * All LED images must be of the same size, 28 x 28 pixels.</span>00085 <span class="comment"> *</span>00086 <span class="comment"> * \param stream HTML code is printed to this stream device.</span>00087 <span class="comment"> * \param num The number of LEDs to print.</span>00088 <span class="comment"> * \param desc If not equal zero, bits are processed in descending order.</span>00089 <span class="comment"> * \param ival Input bit values.</span>00090 <span class="comment"> * \param oval Output bit values.</span>00091 <span class="comment"> * \param dir Data direction mask. Any bit set to one represents an output.</span>00092 <span class="comment"> */</span><a name="l00093"></a><a class="code" href="group__xg_c_g_i.html#ga4">00093</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__xg_c_g_i.html#ga4">HtmlLedRow</a>(FILE * stream, u_char num, u_char desc, u_long ival, u_long oval, u_long dir)00094 {00095 u_char i;00096 u_long mask;00097 00098 <span class="keywordflow">for</span> (i = 0; i < num; i++) {00099 <span class="keywordflow">if</span> (desc)00100 mask = 1UL << (num - i - 1);00101 <span class="keywordflow">else</span>00102 mask = 1UL << i;00103 fputs(<span class="stringliteral">"<td><img src=\"/"</span>, stream);00104 <span class="keywordflow">if</span> (dir & mask) {00105 <span class="keywordflow">if</span> (oval & mask) {00106 <span class="keywordflow">if</span> (ival & mask)00107 fputs(<span class="stringliteral">"r1"</span>, stream);00108 <span class="keywordflow">else</span>00109 fputs(<span class="stringliteral">"y0"</span>, stream);00110 } <span class="keywordflow">else</span> {00111 <span class="keywordflow">if</span> (ival & mask)00112 fputs(<span class="stringliteral">"y1"</span>, stream);00113 <span class="keywordflow">else</span>00114 fputs(<span class="stringliteral">"r0"</span>, stream);00115 }00116 } <span class="keywordflow">else</span> {00117 <span class="keywordflow">if</span> (ival & mask) {00118 fputs(<span class="stringliteral">"g1"</span>, stream);00119 } <span class="keywordflow">else</span> {00120 fputs(<span class="stringliteral">"g0"</span>, stream);00121 }00122 }00123 fputs(<span class="stringliteral">".gif\" width=\"28\" heigth=\"28\"></td>\r\n"</span>, stream);00124 }00125 }00126 <span class="comment"></span>00127 <span class="comment">/*!</span>00128 <span class="comment"> * \brief Print HTML code for a row of checkboxes.</span>00129 <span class="comment"> *</span>00130 <span class="comment"> * The resulting HTML code will present a row of checkboxes. </span>00131 <span class="comment"> *</span>00132 <span class="comment"> * \param stream HTML code is printed to this stream device.</span>00133 <span class="comment"> * \param num The number of checkboxes to print.</span>00134 <span class="comment"> * \param desc If not equal zero, bits are processed in descending order.</span>00135 <span class="comment"> * \param name Identifier of the checkboxes.</span>00136 <span class="comment"> * \param check The checkbox will be checked if the corresponding bit is set.</span>00137 <span class="comment"> * \param enable The checkbox will be created only, ff the corresponding bit </span>00138 <span class="comment"> * in this bitmask is set.</span>00139 <span class="comment"> */</span><a name="l00140"></a><a class="code" href="group__xg_c_g_i.html#ga5">00140</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__xg_c_g_i.html#ga5">HtmlCheckboxRow</a>(FILE * stream, u_char num, u_char desc, u_char * name, u_long check, u_long enable)00141 {00142 u_char i;00143 u_long mask;00144 <span class="keywordflow">for</span> (i = 0; i < num; i++) {00145 <span class="keywordflow">if</span> (desc)00146 mask = 1UL << (num - i - 1);00147 <span class="keywordflow">else</span>00148 mask = 1UL << i;00149 <span class="keywordflow">if</span> (enable & mask) {00150 fputs(<span class="stringliteral">"<td><input type=\"checkbox\" name=\""</span>, stream);00151 fprintf(stream, <span class="stringliteral">"%s\" value=\"%u\" "</span>, name, num - i - 1);00152 <span class="keywordflow">if</span> (check & mask)00153 fputs(<span class="stringliteral">" checked=\"checked\""</span>, stream);00154 fputs(<span class="stringliteral">"></td>\r\n"</span>, stream);00155 } <span class="keywordflow">else</span>00156 fputs(<span class="stringliteral">"<td></td>\r\n"</span>, stream);00157 }00158 }00159 00160 <span class="comment"></span>00161 <span class="comment">/*!</span>00162 <span class="comment"> * \brief Print HTML code for a separator row.</span>00163 <span class="comment"> *</span>00164 <span class="comment"> * The resulting HTML code will present a black row. </span>00165 <span class="comment"> *</span>00166 <span class="comment"> * \param stream HTML code is printed to this stream device.</span>00167 <span class="comment"> * \param width Separator width in columns.</span>00168 <span class="comment"> * \param height Separator width in pixels.</span>00169 <span class="comment"> */</span><a name="l00170"></a><a class="code" href="group__xg_c_g_i.html#ga6">00170</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__xg_c_g_i.html#ga6">HtmlSeparatorRow</a>(FILE * stream, u_char width, u_char height)00171 {00172 fprintf(stream, <span class="stringliteral">"<tr bgcolor=\"#000000\"><td colspan=\"%u\" "</span> <span class="comment">/* */</span>00173 <span class="stringliteral">"height=\"%u\"></td></tr>"</span>, width, height);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -