CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 10281|回复: 6

cb网页控制

[复制链接]
发表于 2014-5-14 23:43:37 | 显示全部楼层 |阅读模式
首先写个C web server

拿 tinyhttpd改造:

具体参照TLL大侠的:http://forum.cubietech.com/forum.php?mod=viewthread&tid=668

html部分:

QQ截图20140514231807.jpg

cgi部分:
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <errno.h>
  4. #include <fcntl.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>



  8. int main(int narg,char **args)
  9. {
  10.         int fd;
  11.         int val = 0;
  12.         printf("jiangdou\n");
  13.         printf("jiangdou\n");
  14.         printf("jiangdou\n");
  15.         printf("jiangdou\n");
  16.         printf("jiangdou\n");
  17.        
  18.    //printf("the input parameter 0 is %s\n",args[0]);

  19.    //printf("the input parameter 1 is %s\n",args[1]);
  20.   
  21.          if(narg != 2)
  22.    {
  23.        printf("error,the input parameter must be one!\n");
  24.        return -1;
  25.    }
  26.    char *str = args[1];
  27.    //printf("the input parameter is %s\n",str);
  28.    char *temp;
  29.    char tmp1[512];
  30.    temp = strstr(args[1],"=");
  31.     if(temp!=NULL)
  32.     {
  33.         sprintf(tmp1,"%s",(temp + 1));
  34.     }
  35.         printf("%s\n",tmp1);
  36.         //是否ledon命令
  37.         if (strcasecmp(tmp1, "ledon") == 0)
  38.         {
  39.                 printf("jiangdou  -> ledon\n");
  40.                
  41.                 fd = open("/dev/jiangdou_led",0666);
  42.                 write(fd,&val,sizeof(int));
  43.                 close(fd);
  44.        
  45.         }
  46.         //是否ledoff命令
  47.         if (strcasecmp(tmp1, "ledoff") == 0)
  48.         {
  49.                 printf("jiangdou        -> ledoff\n");
  50.                 val = 1;
  51.                 fd = open("/dev/jiangdou_led",0666);
  52.                 write(fd,&val,sizeof(int));
  53.                 close(fd);
  54.         }


  55.         return;
  56.        
  57. }
复制代码
adb效果:

QQ截图20140514232700.jpg


回复

使用道具 举报

 楼主| 发表于 2014-5-14 23:43:38 | 显示全部楼层
html代码部分:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>嵌入式安防系统 by jiangdou</title>
  6. <style>
  7.   *{
  8.           margin:0px;
  9.           padding:0px;
  10.           border:0px;
  11.           text-align:center;
  12.   }
  13.   li{
  14.                     list-style:none;
  15.   }
  16.   table{
  17.           width:100%;
  18.           text-align:center;
  19.   }
  20.   
  21.   a{
  22.           text-decoration:none;
  23.   }
  24.   
  25.   #logo{
  26.           height:80px;
  27.           background-image:url(images/banner.jpg);
  28.           background-repeat:repeat-x;
  29.   }
  30.   #logo li{
  31.           padding-top:28px;
  32.   }
  33.   #menu{
  34.           height:32px;
  35.       background-image:url(images/menu_bg.jpg);
  36.           background-repeat:repeat-x;           
  37.   }
  38.   #menu ul li{
  39.           float:left;
  40.           width:82px;
  41.           margin-left:15px;
  42.           margin-right:10px;
  43.           padding-top:8px;
  44.           text-align:center;
  45.   }
  46.   #menu ul li:hover{
  47.           background-image:url(images/menu.jpg);
  48.   }
  49.   .btn{
  50.           cursor:pointer;
  51.           width:100px;
  52.           height:30px;
  53.           margin-top:5px;
  54.           padding-top:8px;
  55.           background-repeat:no-repeat;
  56.   }
  57.   #btnPai{
  58.           width:100px;
  59.           height:35px;
  60.           cursor:pointer;
  61.           margin-top:80px;
  62.           padding-top:8px;
  63.           background-image:url(images/paizhao.gif);
  64.           background-repeat:no-repeat;
  65.   }
  66.   .baojing{
  67.           font-size:24px;
  68.           width:220px;
  69.           margin-top:5px;
  70.           margin-bottom:20px;
  71.   }
  72.   .baojing input{
  73.           text-align:right;
  74.   }
  75. </style>
  76. <script language="JavaScript">
  77. <!--
  78. function FP_preloadImgs() {//v1.0
  79. var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
  80. for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
  81. }

  82. function FP_swapImg() {//v1.0
  83. var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
  84. n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
  85. elm.$src=elm.src; elm.src=args[n+1]; } }
  86. }

  87. function FP_getObjectByID(id,o) {//v1.0
  88. var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
  89. else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
  90. if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
  91. for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
  92. f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
  93. for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
  94. return null;
  95. }
  96. // -->
  97. </script>
  98. </head>
  99. <body onkeydown="submitFormKeydown()" onkeyup="submitFormKeyup()"
  100.          </ul>
  101.        </div>
  102.        </td>
  103.      </tr>
  104.      <tr>
  105.        <td>
  106.          <table >
  107.            <tr>
  108.              <td style="width:30%; height:500px; background-color:#066;">
  109.                <li class="baojing">
  110.                        
  111.                     烟雾报警<input type="checkbox"  value="" />
  112.                 </li>
  113.                 <li class="baojing">
  114.                    非法入侵报警<input type="checkbox"  value="" />
  115.                 </li>
  116.                 <li class="baojing"> 当前温度:48°</li>
  117.              </td>
  118.              <td style="width:70%; height:500px; background-color:#666;">
  119.                          <!--  //注释掉-><! - - ... -->
  120.                <li style="float:left; margin-left:50px;"><img src="http://192.168.1.102:8080/?action=stream" align="暂无图片" style="width:480px; height:377px;"/></li>
  121.                           
  122.                <li style="float:left; margin-top:100px; margin-left:20px">
  123.                   <table style="border-width:25px; width:150px; height:150px" bordercolor="#000000">
  124.                      <iframe name="server" style="display:none;"></iframe>
  125.                                          
  126.                                          <!--  //document.getElementById("my_form_id").submit();   提交:GET /cgi-bin/my_cgi?bValue=STOP HTTP/1.1   ... -->
  127.                                          <!--   -->
  128.                                         <form method="GET" target="server"  action="../../../../cgi-bin/my_cgi"  name="myform" id ="my_form_id">
  129.                                                 <tr>
  130.                        <td></td>
  131.                        <td>
  132.                                                 <img border="0" id="img7" src="http://192.168.1.4:8100/images/button10.jpg" height="40" width="100" alt="向上"
  133.                                                 fp-style="fp-btn: Embossed Rectangle 1; fp-font: 楷体; fp-font-style: Bold; fp-font-size: 16; fp-proportional: 0" fp-title="向上" onmouseover="FP_swapImg(1,0,/*id*/'img7',/*url*/'images/button11.jpg')"
  134.                                                 onmouseout="FP_swapImg(0,0,/*id*/'img7',/*url*/'images/button10.jpg')"
  135.                                                 onmousedown="FP_swapImg(1,0,/*id*/'img7',/*url*/'images/button12.jpg'); submitFormgoup()"
  136.                                                 onmouseup="FP_swapImg(0,0,/*id*/'img7',/*url*/'images/button11.jpg'); submitFormup()"></td>
  137.                        <td> </td>
  138.                                            <td>
  139.                                            <input type="hidden" name="bValue" id="bValue"></td>
  140.                        </tr>
  141.                      <tr>
  142.                        <td>
  143.                                                 <img border="0" id="img9" src="images/button16.jpg" height="40" width="100" alt="向左" onmouseover="FP_swapImg(1,0,/*id*/'img9',/*url*/'images/button17.jpg')"  
  144.                                                 onmouseout="FP_swapImg(0,0,/*id*/'img9',/*url*/'images/button16.jpg')"
  145.                                                 onmousedown="FP_swapImg(1,0,/*id*/'img9',/*url*/'images/button18.jpg'); submitFormgoleft()"
  146.                                                 onmouseup="FP_swapImg(0,0,/*id*/'img9',/*url*/'images/button17.jpg'); submitFormup()" fp-style="fp-btn: Embossed Rectangle 1; fp-font: 楷体; fp-font-style: Bold; fp-font-size: 16; fp-proportional: 0" fp-title="向左"></td>
  147.                        <td> </td>
  148.                        <td>
  149.                                                 <img border="0" id="img8" src="images/button13.jpg" height="40" width="100" alt="向右"
  150.                                                 onmouseover="FP_swapImg(1,0,/*id*/'img8',/*url*/'images/button14.jpg')"
  151.                                                 onmouseout="FP_swapImg(0,0,/*id*/'img8',/*url*/'images/button13.jpg')"
  152.                                                 onmousedown="FP_swapImg(1,0,/*id*/'img8',/*url*/'images/button15.jpg');submitFormgoright()"
  153.                                                 onmouseup="FP_swapImg(0,0,/*id*/'img8',/*url*/'images/button14.jpg'); submitFormup()" fp-style="fp-btn: Embossed Rectangle 1; fp-font: 楷体; fp-font-style: Bold; fp-font-size: 16; fp-proportional: 0" fp-title="向右"></td>
  154.                      </tr>
  155.                      <tr>
  156.                        <td></td>
  157.                        <td>
  158.                                                 <img border="0" id="img10" src="images/button19.jpg" height="40" width="100" alt="向下" fp-style="fp-btn: Embossed Rectangle 1; fp-font: 楷体; fp-font-style: Bold; fp-font-size: 16; fp-proportional: 0" fp-title="向下"
  159.                                                 onmouseover="FP_swapImg(1,0,/*id*/'img10',/*url*/'images/button1A.jpg')"
  160.                                                 onmouseout="FP_swapImg(0,0,/*id*/'img10',/*url*/'images/button19.jpg')"
  161.                                                 onmousedown="FP_swapImg(1,0,/*id*/'img10',/*url*/'images/button1B.jpg');submitFormgodown()"
  162.                                                 onmouseup="FP_swapImg(0,0,/*id*/'img10',/*url*/'images/button1A.jpg');submitFormup()"></td>
  163.                        <td></td>
  164.                      </tr>
  165.                      <tr>
  166.                        <td>
  167.                           <p> </p>
  168.                                                         <p> </p>
  169.                                                         <p> </p>
  170.                                                         <p> </p>
  171.                                                         <p> </p>
  172.                                                         <p>

  173. </html>

  174. <script language="JavaScript">

  175. var key_u = 1;

  176. function submitFormgledon()
  177. {
  178.   //将按钮的值赋给隐藏的输入框
  179.   document.getElementById("bValue").value="ledon";
  180.   document.getElementById("my_form_id").submit();
  181. }
  182. function submitFormgledoff()
  183. {
  184.   //将按钮的值赋给隐藏的输入框
  185.   document.getElementById("bValue").value="ledoff";
  186.   document.getElementById("my_form_id").submit();
  187. }
  188. function submitFormgoup()
  189. {
  190.   //将按钮的值赋给隐藏的输入框
  191.   document.getElementById("bValue").value="UP";
  192.   document.getElementById("my_form_id").submit();
  193. }
  194. function submitFormgodown()
  195. {
  196.   //将按钮的值赋给隐藏的输入框
  197.   document.getElementById("bValue").value="DOWN";
  198.   document.getElementById("my_form_id").submit();
  199. }
  200. function submitFormgoright()
  201. {
  202.   //将按钮的值赋给隐藏的输入框
  203.   document.getElementById("bValue").value="RIGHT";
  204.   document.getElementById("my_form_id").submit();
  205. }
  206. function submitFormgoleft()
  207. {
  208.   //将按钮的值赋给隐藏的输入框
  209.   document.getElementById("bValue").value="LEFT";//bValue = "id=bValue"
  210.   document.getElementById("my_form_id").submit();
  211. }

  212. function submitFormup()
  213. {
  214.   //将按钮的值赋给隐藏的输入框
  215.   document.getElementById("bValue").value="STOP";//赋值->value=STOP
  216.   document.getElementById("my_form_id").submit();//提交my_form_id= <form>体
  217. }

  218. //键盘方向按键onkeydown do
  219. function submitFormKeydown()
  220. {
  221.         var keycode=event.keyCode;      
  222.         if((keycode == 37) || (keycode == 38) || (keycode == 39) || (keycode == 40))
  223.         {
  224.                 if(key_u == 1)
  225.                 {           
  226.                            if(keycode == 38)
  227.                             document.getElementById("bValue").value="UP";
  228.                     if(keycode == 37)
  229.                             document.getElementById("bValue").value="LEFT";
  230.                         if(keycode == 39)
  231.                             document.getElementById("bValue").value="RIGHT";
  232.                            if(keycode == 40)
  233.                             document.getElementById("bValue").value="DOWN";
  234.                            document.getElementById("my_form_id").submit();//GET /cgi-bin/my_cgi?bValue=DOWN HTTP/1.1
  235.                            key_u = 0;
  236.             }
  237.         }
  238. }
  239. //键盘方向按键onkeyup do
  240. function submitFormKeyup()
  241. {
  242.         var keycode=event.keyCode;                 
  243.     if((keycode == 37) || (keycode == 38) || (keycode == 39) || (keycode == 40))
  244.     {
  245.             key_u = 1;
  246.             document.getElementById("bValue").value="STOP";
  247.             document.getElementById("my_form_id").submit();//GET /cgi-bin/my_cgi?bValue=STOP HTTP/1.1
  248.     }
  249. }

  250. //-->
  251. </script>
复制代码
回复 支持 反对

使用道具 举报

发表于 2014-5-15 09:21:38 | 显示全部楼层
不错,有想法
回复 支持 反对

使用道具 举报

发表于 2014-5-15 16:45:56 | 显示全部楼层
赞一个
回复 支持 反对

使用道具 举报

发表于 2014-5-20 19:08:22 | 显示全部楼层
不错不错!
回复 支持 反对

使用道具 举报

发表于 2014-5-20 21:17:03 | 显示全部楼层
不错不错!
回复 支持 反对

使用道具 举报

发表于 2014-5-23 09:08:50 | 显示全部楼层
有空很想试试
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-5-3 04:07 , Processed in 0.023106 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部