GoAhead4.1.0 開發總結一(移植)


 

環境

官方文檔: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  其他頁面直接寫名稱

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM