📄 cgi_8c-source.html
字号:
00174 }00175 <span class="comment"></span>00176 <span class="comment">/*!</span>00177 <span class="comment"> * \brief Print HTML code to display a single I/O port.</span>00178 <span class="comment"> *</span>00179 <span class="comment"> * The resulting HTML code will present a row of LEDs and two rows of</span>00180 <span class="comment"> * checkboxes. While the LEDs show the current port status, the checkboxes</span>00181 <span class="comment"> * may be used to modify the port output and the data direction register.</span>00182 <span class="comment"> *</span>00183 <span class="comment"> * See HtmlLedRow() for further details about how LEDs are displayed.</span>00184 <span class="comment"> * The checkboxes are created by calling HtmlCheckboxRow().</span>00185 <span class="comment"> *</span>00186 <span class="comment"> * \param stream HTML code is printed to this stream device.</span>00187 <span class="comment"> * \param name Port identifier, typically 'A' for Port A, 'B' for port B etc.</span>00188 <span class="comment"> * \param pin Contents of the PIN register.</span>00189 <span class="comment"> * \param port Contents of the PORT register.</span>00190 <span class="comment"> * \param ddr Contents of the data direction register.</span>00191 <span class="comment"> * \param enable If a bit is not set in this bit mask, then the corresponding</span>00192 <span class="comment"> * checkboxes are not created and the port bits and data direction</span>00193 <span class="comment"> * can't be modified.</span>00194 <span class="comment"> */</span><a name="l00195"></a><a class="code" href="group__xg_c_g_i.html#ga7">00195</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__xg_c_g_i.html#ga7">HtmlInOutPortRow</a>(FILE * stream, <span class="keywordtype">char</span> name, u_char pin, u_char port, u_char ddr, u_char enable)00196 {00197 <span class="keywordtype">char</span> ditem[3] = { <span class="charliteral">'D'</span>, <span class="charliteral">'X'</span>, 0 };00198 <span class="keywordtype">char</span> pitem[3] = { <span class="charliteral">'P'</span>, <span class="charliteral">'X'</span>, 0 };00199 00200 ditem[1] = name;00201 pitem[1] = name;00202 fputs(<span class="stringliteral">"<tr><th rowspan=\"4\">"</span>, stream);00203 fprintf(stream, <span class="stringliteral">"%c"</span>, name);00204 fputs(<span class="stringliteral">"</th><td>Status</td>"</span>, stream);00205 <a class="code" href="group__xg_c_g_i.html#ga4">HtmlLedRow</a>(stream, 8, 1, pin, port, ddr);00206 fputs(<span class="stringliteral">"</tr>\r\n<tr><td>Output</td>"</span>, stream);00207 <a class="code" href="group__xg_c_g_i.html#ga5">HtmlCheckboxRow</a>(stream, 8, 1, ditem, ddr, enable);00208 fputs(<span class="stringliteral">"</tr>\r\n<tr><td>Pull up</td>"</span>, stream);00209 <a class="code" href="group__xg_c_g_i.html#ga5">HtmlCheckboxRow</a>(stream, 8, 1, pitem, port, enable);00210 fputs(<span class="stringliteral">"</tr>\r\n"</span>, stream);00211 }00212 <span class="comment"></span>00213 <span class="comment">/*!</span>00214 <span class="comment"> * \brief Process request parameters for CPU port control.</span>00215 <span class="comment"> *</span>00216 <span class="comment"> * Parse the CGI query and perform the corresponding action:</span>00217 <span class="comment"> *</span>00218 <span class="comment"> * - Dx=y will set bit y in the data direction register of port x.</span>00219 <span class="comment"> * - Px=y will set bit y in the port output register of port x.</span>00220 <span class="comment"> *</span>00221 <span class="comment"> * All other bits are switched off.</span>00222 <span class="comment"> *</span>00223 <span class="comment"> * \param query CGI query string.</span>00224 <span class="comment"> */</span><a name="l00225"></a><a class="code" href="group__xg_c_g_i.html#ga8">00225</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__xg_c_g_i.html#ga8">ProcessCgiPortRequest</a>(REQUEST * req)00226 {00227 u_char ddrb = 0;00228 u_char portb = 0;00229 u_char ddrd = 0;00230 u_char portd = 0;00231 u_char ddre = 0;00232 u_char porte = 0;00233 <span class="keywordtype">int</span> mods = 0;00234 <span class="keywordtype">int</span> i;00235 <span class="keywordtype">int</span> pcount = NutHttpGetParameterCount(req);00236 <span class="keywordtype">char</span> *name;00237 <span class="keywordtype">char</span> *value;00238 00239 <span class="keywordflow">for</span> (i = 0; i < pcount; i++) {00240 name = NutHttpGetParameterName(req, i);00241 value = NutHttpGetParameterValue(req, i);00242 <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">"DB"</span>) == 0) {00243 ddrb |= BV(*value - <span class="charliteral">'0'</span>);00244 mods++;00245 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">"PB"</span>) == 0) {00246 portb |= BV(*value - <span class="charliteral">'0'</span>);00247 mods++;00248 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">"DD"</span>) == 0) {00249 ddrd |= BV(*value - <span class="charliteral">'0'</span>);00250 mods++;00251 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">"PD"</span>) == 0) {00252 portd |= BV(*value - <span class="charliteral">'0'</span>);00253 mods++;00254 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">"DE"</span>) == 0) {00255 ddre |= BV(*value - <span class="charliteral">'0'</span>);00256 ddre &= ~_BV(5);00257 mods++;00258 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(name, <span class="stringliteral">"PE"</span>) == 0) {00259 porte |= BV(*value - <span class="charliteral">'0'</span>);00260 porte &= ~_BV(5);00261 mods++;00262 }00263 }00264 <span class="keywordflow">if</span> (mods) {00265 outb(DDRB, ddrb);00266 outb(PORTB, portb);00267 outb(DDRD, ddrd);00268 outb(PORTD, portd);00269 outb(DDRE, ddre);00270 outb(PORTE, porte);00271 }00272 }00273 <span class="comment"></span>00274 <span class="comment">/*!</span>00275 <span class="comment"> * \brief Process request parameters for relay output control.</span>00276 <span class="comment"> *</span>00277 <span class="comment"> * Parse the CGI query and switch the corresponding relays.</span>00278 <span class="comment"> * 'S=y' will switch on relay y. All other relays are switched off.</span>00279 <span class="comment"> *</span>00280 <span class="comment"> * Note, that before calling this function is called for the first time,</span>00281 <span class="comment"> * the status of the relays is unknown.</span>00282 <span class="comment"> *</span>00283 <span class="comment"> * \param query CGI query string.</span>00284 <span class="comment"> */</span><a name="l00285"></a><a class="code" href="group__xg_c_g_i.html#ga9">00285</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__xg_c_g_i.html#ga9">ProcessCgiRelayRequest</a>(<span class="keywordtype">char</span> *query)00286 {00287 u_char *item = query;00288 u_char *val;00289 00290 <a class="code" href="group__xg_c_g_i.html#ga2">relay_status</a> = 0;00291 <span class="keywordflow">for</span> (;;) {00292 <span class="keywordflow">if</span> ((val = strchr(item, <span class="charliteral">'='</span>)) == 0)00293 <span class="keywordflow">break</span>;00294 *val++ = 0;00295 <span class="keywordflow">if</span> (item[0] == <span class="charliteral">'S'</span>)00296 <a class="code" href="group__xg_c_g_i.html#ga2">relay_status</a> |= 1UL << (7 - (*val - <span class="charliteral">'0'</span>));00297 <span class="keywordflow">if</span> ((item = strchr(val, <span class="charliteral">'&'</span>)) == 0)00298 <span class="keywordflow">break</span>;00299 item++;00300 }00301 SpiDigitalSet(<a class="code" href="group__xg_c_g_i.html#ga1">spi_no</a>, <a class="code" href="group__xg_c_g_i.html#ga2">relay_status</a>);00302 <a class="code" href="group__xg_c_g_i.html#ga3">relay_known</a> = 1;00303 }00304 <span class="comment"></span>00305 <span class="comment">/*!</span>00306 <span class="comment"> * \brief CGI callback function to control the CPU ports.</span>00307 <span class="comment"> *</span>00308 <span class="comment"> * Creates HTML code to show the status of CPU ports B, D, E and F</span>00309 <span class="comment"> * plus a HTML form to modify the port and data direction registers </span>00310 <span class="comment"> * of ports B, D and E by checkboxes. </span>00311 <span class="comment"> *</span>00312 <span class="comment"> * The resulting HTML code is send back to the browser. If the submit</span>00313 <span class="comment"> * button is clicked on this page, this function will be called again</span>00314 <span class="comment"> * to process the checkboxes.</span>00315 <span class="comment"> *</span>00316 <span class="comment"> * \image html cport.gif</span>00317 <span class="comment"> *</span>00318 <span class="comment"> *</span>00319 <span class="comment"> *</span>00320 <span class="comment"> * This function is called by the HTTP module when a browser requests</span>00321 <span class="comment"> * a CGI function, for which this routine has been registered via</span>00322 <span class="comment"> * NutRegisterCgi().</span>00323 <span class="comment"> *</span>00324 <span class="comment"> * \param stream Stream of the HTTP connection.</span>00325 <span class="comment"> * \param req Pointer to the CGI REQUEST structure. Detailed information</span>00326 <span class="comment"> * is available in the Nut/OS API documentation.</span>00327 <span class="comment"> *</span>00328 <span class="comment"> * \return 0 on success or -1 in case of any failure.</span>00329 <span class="comment"> */</span><a name="l00330"></a><a class="code" href="group__xg_c_g_i.html#ga10">00330</a> <span class="keywordtype">int</span> <a class="code" href="group__xg_c_g_i.html#ga10">CpuPortControl</a>(FILE * stream, REQUEST * req)00331 {00332 <span class="keyword">static</span> prog_char head[] = <span class="stringliteral">"<html>"</span> <span class="comment">/* */</span>00333 <span class="stringliteral">"<head>"</span> <span class="comment">/* */</span>00334 <span class="stringliteral">"<meta http-equiv=\"expires\" content=\"0\">"</span> <span class="comment">/* */</span>00335 <span class="stringliteral">"<title>Ethernut CPU Port Control</title>"</span> <span class="comment">/* */</span>00336 <span class="stringliteral">"</head>"</span> <span class="comment">/* */</span>00337 <span class="stringliteral">"<body bgcolor=\"#C7D0D9\"><a href=\"/\">"</span> <span class="comment">/* */</span>00338 <span class="stringliteral">"<img src=\"/enmini.gif\" border=\"0\" width=\"70\" height=\"17\">"</span> <span class="comment">/* */</span>00339 <span class="stringliteral">"</a><div align=\"center\">"</span>;00340 <span class="keyword">static</span> prog_char thdr[] = <span class="stringliteral">"<form action=\""</span> <a class="code" href="group__xg_w_p_defs.html#ga8">PORT_CONTROL_CGI</a> <span class="comment">/* */</span>00341 <span class="stringliteral">"\" enctype=\"text/plain\">"</span> <span class="comment">/* */</span>00342 <span class="stringliteral">"<table border=\"1\" cellspacing=\"0\">\r\n"</span> <span class="comment">/* */</span>00343 <span class="stringliteral">"<thead><tr><th rowspan=\"2\"> PORT </th>"</span> <span class="comment">/* */</span>00344 <span class="stringliteral">"<th rowspan=\"2\"> Type </th>"</span> <span class="comment">/* */</span>00345 <span class="stringliteral">"<th colspan=\"8\">Bit</th></tr>"</span> <span class="comment">/* */</span>00346 <span class="stringliteral">"<tr><th>7</th><th>6</th><th>5</th><th>4</th><th>3</th>"</span> <span class="comment">/* */</span>00347 <span class="stringliteral">"<th>2</th><th>1</th><th>0</th></tr>"</span> <span class="comment">/* */</span>00348 <span class="stringliteral">"</thead><tfoot>\r\n"</span>;00349 <span class="keyword">static</span> prog_char foot[] = <span class="stringliteral">"</tfoot></table><br>"</span> <span class="comment">/* */</span>00350 <span class="stringliteral">" <input type=\"submit\" value=\" Set \"> "</span> <span class="comment">/* */</span>00351 <span class="stringliteral">" <input type=\"reset\" value=\" Cancel \"> "</span> <span class="comment">/* */</span>00352 <span class="stringliteral">"</form>\r\n</div></body>\r\n</html>"</span>;00353 00354 NutHttpSendHeaderTop(stream, req, 200, <span class="stringliteral">"Ok"</span>);00355 NutHttpSendHeaderBot(stream, <span class="stringliteral">"text/html"</span>, -1);00356 00357 fputs_P(head, stream);00358 <span class="keywordflow">if</span> (req->req_url)00359 <a class="code" href="group__xg_c_g_i.html#ga8">ProcessCgiPortRequest</a>(req);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -