jiangdou 发表于 2014-5-14 23:43:37

cb网页控制

首先写个C web server

拿 tinyhttpd改造:

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

html部分:



cgi部分:#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



int main(int narg,char **args)
{
        int fd;
        int val = 0;
        printf("jiangdou\n");
        printf("jiangdou\n");
        printf("jiangdou\n");
        printf("jiangdou\n");
        printf("jiangdou\n");
       
   //printf("the input parameter 0 is %s\n",args);

   //printf("the input parameter 1 is %s\n",args);

       if(narg != 2)
   {
       printf("error,the input parameter must be one!\n");
       return -1;
   }
   char *str = args;
   //printf("the input parameter is %s\n",str);
   char *temp;
   char tmp1;
   temp = strstr(args,"=");
    if(temp!=NULL)
    {
      sprintf(tmp1,"%s",(temp + 1));
    }
        printf("%s\n",tmp1);
        //是否ledon命令
        if (strcasecmp(tmp1, "ledon") == 0)
        {
                printf("jiangdou-> ledon\n");
               
                fd = open("/dev/jiangdou_led",0666);
                write(fd,&val,sizeof(int));
                close(fd);
       
        }
        //是否ledoff命令
        if (strcasecmp(tmp1, "ledoff") == 0)
        {
                printf("jiangdou        -> ledoff\n");
                val = 1;
                fd = open("/dev/jiangdou_led",0666);
                write(fd,&val,sizeof(int));
                close(fd);
        }


        return;
       
}
adb效果:




jiangdou 发表于 2014-5-14 23:43:38

html代码部分:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>嵌入式安防系统 by jiangdou</title>
<style>
*{
          margin:0px;
          padding:0px;
          border:0px;
          text-align:center;
}
li{
                    list-style:none;
}
table{
          width:100%;
          text-align:center;
}

a{
          text-decoration:none;
}

#logo{
          height:80px;
          background-image:url(images/banner.jpg);
          background-repeat:repeat-x;
}
#logo li{
          padding-top:28px;
}
#menu{
          height:32px;
      background-image:url(images/menu_bg.jpg);
          background-repeat:repeat-x;           
}
#menu ul li{
          float:left;
          width:82px;
          margin-left:15px;
          margin-right:10px;
          padding-top:8px;
          text-align:center;
}
#menu ul li:hover{
          background-image:url(images/menu.jpg);
}
.btn{
          cursor:pointer;
          width:100px;
          height:30px;
          margin-top:5px;
          padding-top:8px;
          background-repeat:no-repeat;
}
#btnPai{
          width:100px;
          height:35px;
          cursor:pointer;
          margin-top:80px;
          padding-top:8px;
          background-image:url(images/paizhao.gif);
          background-repeat:no-repeat;
}
.baojing{
          font-size:24px;
          width:220px;
          margin-top:5px;
          margin-bottom:20px;
}
.baojing input{
          text-align:right;
}
</style>
<script language="JavaScript">
<!--
function FP_preloadImgs() {//v1.0
var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
for(var i=0; i<a.length; i++) { d.FP_imgs=new Image; d.FP_imgs.src=a; }
}

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

function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all; if(el) return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c); if(el) return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f.elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els); if(el) return el; } }
return null;
}
// -->
</script>
</head>
<body onkeydown="submitFormKeydown()" onkeyup="submitFormKeyup()"
         </ul>
       </div>
       </td>
   </tr>
   <tr>
       <td>
         <table >
         <tr>
             <td style="width:30%; height:500px; background-color:#066;">
               <li class="baojing">
                     
                  烟雾报警<input type="checkbox"value="" />
                </li>
                <li class="baojing">
                   非法入侵报警<input type="checkbox"value="" />
                </li>
                <li class="baojing"> 当前温度:48°</li>
             </td>
             <td style="width:70%; height:500px; background-color:#666;">
                       <!--//注释掉-><! - - ... -->
               <li style="float:left; margin-left:50px;"><img src="http://192.168.1.102:8080/?action=stream" align="暂无图片" style="width:480px; height:377px;"/></li>
                          
               <li style="float:left; margin-top:100px; margin-left:20px">
                  <table style="border-width:25px; width:150px; height:150px" bordercolor="#000000">
                     <iframe name="server" style="display:none;"></iframe>
                                       
                                       <!--//document.getElementById("my_form_id").submit();   提交:GET /cgi-bin/my_cgi?bValue=STOP HTTP/1.1   ... -->
                                       <!--   -->
                                        <form method="GET" target="server"action="../../../../cgi-bin/my_cgi"name="myform" id ="my_form_id">
                                                <tr>
                     <td></td>
                     <td>
                                                <img border="0" id="img7" src="http://192.168.1.4:8100/images/button10.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="向上" onmouseover="FP_swapImg(1,0,/*id*/'img7',/*url*/'images/button11.jpg')"
                                                onmouseout="FP_swapImg(0,0,/*id*/'img7',/*url*/'images/button10.jpg')"
                                                onmousedown="FP_swapImg(1,0,/*id*/'img7',/*url*/'images/button12.jpg'); submitFormgoup()"
                                                onmouseup="FP_swapImg(0,0,/*id*/'img7',/*url*/'images/button11.jpg'); submitFormup()"></td>
                     <td> </td>
                                           <td>
                                           <input type="hidden" name="bValue" id="bValue"></td>
                     </tr>
                     <tr>
                     <td>
                                                <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')"
                                                onmouseout="FP_swapImg(0,0,/*id*/'img9',/*url*/'images/button16.jpg')"
                                                onmousedown="FP_swapImg(1,0,/*id*/'img9',/*url*/'images/button18.jpg'); submitFormgoleft()"
                                                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>
                     <td> </td>
                     <td>
                                                <img border="0" id="img8" src="images/button13.jpg" height="40" width="100" alt="向右"
                                                onmouseover="FP_swapImg(1,0,/*id*/'img8',/*url*/'images/button14.jpg')"
                                                onmouseout="FP_swapImg(0,0,/*id*/'img8',/*url*/'images/button13.jpg')"
                                                onmousedown="FP_swapImg(1,0,/*id*/'img8',/*url*/'images/button15.jpg');submitFormgoright()"
                                                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>
                     </tr>
                     <tr>
                     <td></td>
                     <td>
                                                <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="向下"
                                                onmouseover="FP_swapImg(1,0,/*id*/'img10',/*url*/'images/button1A.jpg')"
                                                onmouseout="FP_swapImg(0,0,/*id*/'img10',/*url*/'images/button19.jpg')"
                                                onmousedown="FP_swapImg(1,0,/*id*/'img10',/*url*/'images/button1B.jpg');submitFormgodown()"
                                                onmouseup="FP_swapImg(0,0,/*id*/'img10',/*url*/'images/button1A.jpg');submitFormup()"></td>
                     <td></td>
                     </tr>
                     <tr>
                     <td>
                        <p> </p>
                                                        <p> </p>
                                                        <p> </p>
                                                        <p> </p>
                                                        <p> </p>
                                                        <p>

</html>

<script language="JavaScript">

var key_u = 1;

function submitFormgledon()
{
//将按钮的值赋给隐藏的输入框
document.getElementById("bValue").value="ledon";
document.getElementById("my_form_id").submit();
}
function submitFormgledoff()
{
//将按钮的值赋给隐藏的输入框
document.getElementById("bValue").value="ledoff";
document.getElementById("my_form_id").submit();
}
function submitFormgoup()
{
//将按钮的值赋给隐藏的输入框
document.getElementById("bValue").value="UP";
document.getElementById("my_form_id").submit();
}
function submitFormgodown()
{
//将按钮的值赋给隐藏的输入框
document.getElementById("bValue").value="DOWN";
document.getElementById("my_form_id").submit();
}
function submitFormgoright()
{
//将按钮的值赋给隐藏的输入框
document.getElementById("bValue").value="RIGHT";
document.getElementById("my_form_id").submit();
}
function submitFormgoleft()
{
//将按钮的值赋给隐藏的输入框
document.getElementById("bValue").value="LEFT";//bValue = "id=bValue"
document.getElementById("my_form_id").submit();
}

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

//键盘方向按键onkeydown do
function submitFormKeydown()
{
        var keycode=event.keyCode;      
        if((keycode == 37) || (keycode == 38) || (keycode == 39) || (keycode == 40))
        {
                if(key_u == 1)
                {         
                           if(keycode == 38)
                          document.getElementById("bValue").value="UP";
                  if(keycode == 37)
                          document.getElementById("bValue").value="LEFT";
                        if(keycode == 39)
                          document.getElementById("bValue").value="RIGHT";
                           if(keycode == 40)
                          document.getElementById("bValue").value="DOWN";
                           document.getElementById("my_form_id").submit();//GET /cgi-bin/my_cgi?bValue=DOWN HTTP/1.1
                           key_u = 0;
          }
        }
}
//键盘方向按键onkeyup do
function submitFormKeyup()
{
        var keycode=event.keyCode;               
    if((keycode == 37) || (keycode == 38) || (keycode == 39) || (keycode == 40))
    {
            key_u = 1;
            document.getElementById("bValue").value="STOP";
            document.getElementById("my_form_id").submit();//GET /cgi-bin/my_cgi?bValue=STOP HTTP/1.1
    }
}

//-->
</script>

Sugar 发表于 2014-5-15 09:21:38

不错,有想法:P

SUNROC1 发表于 2014-5-15 16:45:56

赞一个

flyword 发表于 2014-5-20 19:08:22

不错不错!

webyxm 发表于 2014-5-20 21:17:03

不错不错!

yongxiangu 发表于 2014-5-23 09:08:50

有空很想试试
页: [1]
查看完整版本: cb网页控制