ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

GoAhead4.1.0 移植

2019-06-04 11:53:00  阅读:336  来源: 互联网

标签:GoAhead4.1 4.1 ifr 移植 linux arm goahead out


 

环境

官方文档:https://www.embedthis.com/goahead/doc/

源码下载: goahead-4.1.0-src.tgz

系统平台:Ubuntu 12.04.4

gcc version 4.6.3

移植步骤

1.解压与编译

前提:交叉编译工具 arm-none-linux-gnueabi-gcc 已经安装并配置了环境变量;

tar -zxvf goahead-4.1.0-src.tgz
cd goahead-4.1.0
// 交叉编译
make CC=arm-none-linux-gnueabi-gcc ARCH=arm

编译之后在 goahead-4.1.0/build  目录下生成了  linux-arm-default 文件夹

里面包含我们需要的 goahead 可执行文件和 库

2.开始测试

新建一个 goahead 文件夹,可nfs挂载,我们使用nfs挂载调试

将 goahead-4.1.0/build/linux-arm-default/bin 里面的  goahead  libgo.so 拷贝到 goahead 文件夹

目标arm板开启 mount 挂载

 cd /mnt/goahead

// 运行测试

./goahead -v ./web/  192.168.10.111:80 

这里出现不能获取本地IP地址

解决方案一:

修改源码 goahead-4.1.0/src/http.c

#else
{
#if 0
    struct hostent  *hp;
    if ((hp = gethostbyname(host)) == NULL) {
        error("Cannot get host address for host %s: errno %d", host, errno);
        return -1;
    }
    memcpy((char*) &intaddr, (char *) hp->h_addr_list[0], (size_t) hp->h_length);
    ipaddr = inet_ntoa(intaddr);
#else     // wangh 2019-6-4 换种方式获取ip地址 (ipv4)   
    int sockfd;    
    struct sockaddr_in sin;    
    struct ifreq ifr;          
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);       
    if (sockfd == -1)   
    {              
        return -1;             
    }          
    strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);    //网卡多的得修改下   
    ifr.ifr_name[IFNAMSIZ - 1] = 0;        
    if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0)    
    {              
        return -1;     
    }      
    memcpy(&sin, &ifr.ifr_addr, sizeof(sin));      
    ipaddr=inet_ntoa(sin.sin_addr); 
#endif
    websSetIpAddr(ipaddr);
    websSetHost(ipaddr);
}
#endif
    return 0;
}

修改源码后需重新编译,并重新将 goahead-4.1.0/build/linux-arm-default/bin 里面的  goahead  libgo.so 拷贝到 goahead 文件夹

 

再测试

拷贝 build/linux-arm-default/bin/self.crt  self.key  到 goahead

 

 

测试发现 不能打开 route.txt

拷贝 goahead-4.1.0/src/route.txt  到 goahead

拷贝 goahead-4.1.0/src/auth.txt  到 goahead

 

这里说明移植运行成功

再浏览器输入 目标板主机地址 192.168.1.124

这是因为网页的内容还没有添加

3 web内容添加

再 goahead 文件夹下 新建 web 文件夹

编写 测试 首页

<html>
<!- Copyright (C) HTGD Co.,Ltd. 2019 All Rights Reserved. ->
<head> <!- 文档包含的元数据 ->
    <title>M283 Web Application</title>      <!- 文档标题 ->
    <meta charset="UTF-8">                     <!- 中文编码 ->
    <link rel="stylesheet" href="style/normal_ws.css" type="text/css">
</head>
<body> <!- 元素包含了可见的页面内容 ->
    <h1>M283 Web Application</h1> <!- 一级标题 ->
    <h2>The Simplified I/O Device Control</h2> <!- 二级标题 ->
    <form id="gpio-2-4" action="/goform/gpio_p24" method="post">
    <input type="hidden" name="lab_gpio_p2.4" value="gpio-p2.4" />
        <table border="0">
            <tr>
                <td width=100><b>DeviceName </b></td>
                <td width=100><b>Direction </b></td>
                <td width=100><b>Value </b></td>
                <td width=100><b>Setting</b></td>
            </tr>
            <tr>
                <td width=100> Gpio P2.4 </td>
                <td width=100>
                    <input type="checkbox" name="dir24" title="out" />out</td>
                <td width=100>
                    <input type="checkbox" name="val24" /></td>
                <td width=100><input type="submit" value="set" /></td>
            </tr>
        </table>
    </form>
    <form id="gpio-2-5" action="/goform/gpio_p25" method="post">
    <input type="hidden" name="lab_gpio_p2.5" value="gpio-p2.5" />
        <table>
            <tr>
                <td width=100>
                    Gpio P2.5</td>
                <td width=100>
                    <input type="checkbox" name="dir25" title="out" />out</td>
                <td width=100>
                    <input type="checkbox" name="val25" /></td>
                <td width=100><input type="submit" value="set" /></td>
            </tr>
        </table>
    </form>
    <form id="gpio-2-6" action="/goform/gpio_p26" method="post">
    <input type="hidden" name="lab_gpio_p2.6" value="gpio-p2.6" />
        <table>
            <tr>
                <td width=100>
                    Gpio P2.6</td>
                <td width=100>
                    <input type="checkbox" name="dir26" title="out" />out</td>
                <td width=100>
                    <input type="checkbox" name="val26" /></td>
                <td width=100><input type="submit" value="set" /></td>
            </tr>
        </table>
    </form>
    <form id="gpio-2-7" action="/goform/gpio_p27" method="post">
    <input type="hidden" name="lab_gpio_p2.7" value="gpio-p2.7" />
        <table>
            <tr>
                <td width=100>
                    Gpio P2.7</td>
                <td width=100>
                    <input type="checkbox" name="dir27" title="out" />out</td>
                <td width=100>
                    <input type="checkbox" name="val27" /></td>
                <td width=100><input type="submit" value="set" /></td>
            </tr>
        </table>
    </form>
    <form id="gpio-led" action="/goform/led" method="post">
    <input type="hidden" name="lab_led" value="led-err" />
        <table>
            <tr>
                <td width=100>
                    LED-ERR</td>
                <td width=100>
                    <input type="checkbox" name="dir_led" checked disabled title="out" />out</td>
                <td width=100>
                    <input type="checkbox" name="val_led" /></td>
                <td width=100><input type="submit" value="set" /></td>
            </tr>
        </table>
    </form>
    <form id="gpio-buzzer" action="/goform/buzzer" method="post">
    <input type="hidden" name="lab_buzzer" value="buzzer" />
        <table>
            <tr>
                <td width=100>
                    BUZZER</td>
                <td width=100>
                    <input type="checkbox" name="dir_buz" checked disabled title="out" />out</td>
                <td width=100>
                    <input type="checkbox" name="val_buz" /></td>
                <td width=100><input type="submit" value="set" /></td>
            </tr>
        </table>
    </form>
    
    <p> <!- 元素定义一个段落 ->
       About the GPIO P2.4(,5,6,7), we assume the pin(s) are exported previously<br />
       and they can work as GPIO.<br /><br />
       The buzzer must connect JP1(BZ) on the board, else it does not buzze<br />
       when the control signal is valid.
    </p>
    <h2>
        System LCD Backlight Control</h2>
    <form id="lcdbkl" action="/goform/lcdbkl" method="post">
    <input type="hidden" name="lab_bkl" value="lab_bkl" />
       <table>
            <tr>
                <td><b>backlight(0-100): </b></td>
                <td><input type="text" name="bkl_val" value="80" size="3" maxlength="3" />%</td>
                <td><input type="submit" name="lcd_bk" value="set"/></td>
            </tr>
        </table>
    <hr/>
        <p align="center"><b> &copy; 2019 HTGD Co.,Ltd.</b> <a href="http://www.htgd.com.cn">公司主页</a></p>
</body>
</html>

然后执行 ./goahead -v ./web/

默认打开 index.html  其他页面直接写名称

 

标签:GoAhead4.1,4.1,ifr,移植,linux,arm,goahead,out
来源: https://www.cnblogs.com/silencehuan/p/10972610.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有