Return board status string at request. Add sprintf module.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 21 Sep 2011 16:38:52 +0000 (16:38 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 21 Sep 2011 16:38:52 +0000 (16:38 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5081 38d2e660-2303-0410-9eaa-f027e97ec537

boards/sam3x-ek/examples/sam3x-ek_http_server/main.c
boards/sam3x-ek/examples/sam3x-ek_http_server/project.bertos
boards/sam3x-ek/examples/sam3x-ek_http_server/sam3x-ek_http_server.mk

index 9a1282330b4a8c05703a20c5ad53d6d4a11218dc..276265a66418f804a839fefa8766cd32298a4df3 100644 (file)
@@ -38,6 +38,8 @@
 #include "bertos.c"
 
 #include "hw/hw_sd.h"
+#include "hw/hw_adc.h"
+#include "hw/hw_sdram.h"
 
 #include <cfg/debug.h>
 
@@ -48,6 +50,7 @@
 #include <drv/ser.h>
 #include <drv/sd.h>
 #include <drv/dmac_sam3.h>
+#include <drv/adc.h>
 
 #include <kern/proc.h>
 #include <kern/monitor.h>
 
 #include <fs/fat.h>
 
+#include <stdio.h>
 #include <string.h>
 
 /* Network interface global variables */
 static struct ip_addr ipaddr, netmask, gw;
 static struct netif netif;
 
-
 // SD fat filesystem context
 static Sd sd;
 static FATFS fs;
 static FatFile in_file;
 
+typedef struct BoardStatus
+{
+       char local_ip[sizeof("123.123.123.123")];
+       char last_connected_ip[sizeof("123.123.123.123")];
+       uint16_t internal_temp;
+       ticks_t up_time;
+       size_t tot_req;
+} BoardStatus;
+
+static BoardStatus status;
+
 static void init(void)
 {
        /* Enable all the interrupts */
@@ -89,6 +103,7 @@ static void init(void)
         * processes using proc_new()).
         */
        proc_init();
+       sdram_init();
 
        /* Initialize TCP/IP stack */
        tcpip_init(NULL, NULL);
@@ -99,20 +114,19 @@ static void init(void)
        netif_set_up(&netif);
 
        dmac_init();
-}
 
-static int tot_req;
+       adc_init();
+       /* Enable the adc to read internal temperature sensor */
+       hw_enableTempRead();
+}
 
-static NORETURN void monitor_process(void)
+static NORETURN void status_process(void)
 {
-       int start = tot_req;
-
        while (1)
        {
-               //monitor_report();
-               kprintf("tot_req=%d [%d reqs/s]\n", tot_req, tot_req - start);
-               start = tot_req;
-               timer_delay(10000);
+               status.internal_temp = hw_convertToDegree(adc_read(ADC_TEMPERATURE_CH));
+               status.up_time++;
+               timer_delay(1000);
        }
 }
 
@@ -121,6 +135,7 @@ static void get_fileName(char *revc_buf, char *name, size_t len)
        char *p = strstr(revc_buf, "GET");
        if (p)
        {
+               //skip the "/" in get string request
                p += sizeof("GET") + 1;
                for (size_t i = 0; *p != ' '; i++,p++)
                {
@@ -168,7 +183,7 @@ int main(void)
        /* Hardware initialization */
        init();
 
-       proc_new(monitor_process, NULL, KERN_MINSTACKSIZE * 2, NULL);
+       proc_new(status_process, NULL, KERN_MINSTACKSIZE * 2, NULL);
 
        dhcp_start(&netif);
        while (!netif.ip_addr.addr)
@@ -181,20 +196,20 @@ int main(void)
 
        while (1)
        {
-
                struct netconn *client;
                struct netbuf *rx_buf_conn;
                char *rx_buf;
                u16_t len;
 
                client = netconn_accept(server);
-               kprintf("remote ip = %d.%d.%d.%d\n", IP_ADDR_TO_INT_TUPLE(client->pcb.ip->remote_ip.addr));
-               kprintf("local ip = %d.%d.%d.%d\n", IP_ADDR_TO_INT_TUPLE(client->pcb.ip->local_ip.addr));
-
                if (!client)
                        continue;
 
-               tot_req++;
+               //Update board status.
+               sprintf(status.local_ip, "%d.%d.%d.%d", IP_ADDR_TO_INT_TUPLE(client->pcb.ip->remote_ip.addr));
+               sprintf(status.last_connected_ip, "%d.%d.%d.%d", IP_ADDR_TO_INT_TUPLE(client->pcb.ip->local_ip.addr));
+               status.tot_req++;
+
                rx_buf_conn = netconn_recv(client);
                if (rx_buf_conn)
                {
@@ -202,6 +217,8 @@ int main(void)
                        if (rx_buf)
                        {
                                memset(file_name, 0, sizeof(file_name));
+                               memset(tx_buf, 0, sizeof(tx_buf));
+
                                get_fileName(rx_buf, file_name, sizeof(file_name));
 
                                kprintf("%s\n", file_name);
@@ -212,6 +229,14 @@ int main(void)
                                {
                                        netconn_write(client, bertos_jpg, sizeof(bertos_jpg), NETCONN_NOCOPY);
                                }
+                               else if (!strcmp("status", file_name))
+                               {
+                                       sprintf((char *)tx_buf, "[ %s, %s, %d.%d, %ld, %d ]", status.local_ip, status.last_connected_ip,
+                                                                                                                               status.internal_temp / 10, status.internal_temp % 10,
+                                                                                                                               status.up_time, status.tot_req);
+
+                                       netconn_write(client, tx_buf, strlen((char *)tx_buf), NETCONN_COPY);
+                               }
                                else if (SD_CARD_PRESENT())
                                {
                                        bool sd_ok = sd_init(&sd, NULL, 0);
@@ -228,8 +253,6 @@ int main(void)
 
                                                if (sd_ok)
                                                {
-                                                       memset(tx_buf, 0, sizeof(tx_buf));
-
                                                        result = fatfile_open(&in_file, file_name,  FA_OPEN_EXISTING | FA_READ);
 
                                                        size_t count = 0;
index 56916fb44baac8fb333aee3a8bccf460fa026017..26e0bc8056ed8cae30f2c7f8be6a3d1e39b8a70f 100644 (file)
@@ -60,30 +60,32 @@ aS'sd'
 p30
 aS'signal'
 p31
-aS'timer'
+aS'sprintf'
 p32
-asS'CPU_NAME'
+aS'timer'
 p33
-VSAM3X8
+asS'CPU_NAME'
 p34
-sS'PROJECT_HW_PATH'
+VSAM3X8
 p35
-S'../..'
+sS'PROJECT_HW_PATH'
 p36
-sS'PROJECT_SRC_PATH'
+S'../..'
 p37
-S'.'
+sS'PROJECT_SRC_PATH'
 p38
-sS'PRESET'
+S'.'
 p39
+sS'PRESET'
+p40
 I01
 sS'PROJECT_SRC_PATH_FROM_MAKEFILE'
-p40
-Vboards/sam3x-ek/examples/sam3x-ek_http_server
 p41
-sS'OUTPUT'
+Vboards/sam3x-ek/examples/sam3x-ek_http_server
 p42
-(lp43
+sS'OUTPUT'
+p43
+(lp44
 S'codelite'
-p44
+p45
 as.
\ No newline at end of file
index 665af34454951f0c4fd4512660262260b08d81ba..e1a4102df1ac205614d2932ec9c2332b26dc758d 100644 (file)
@@ -41,6 +41,7 @@ sam3x-ek_http_server_WIZARD_CSRC = \
        bertos/mware/event.c \
        bertos/mware/formatwr.c \
        bertos/mware/hex.c \
+       bertos/mware/sprintf.c \
        bertos/net/lwip.c \
        bertos/struct/heap.c \
        $(sam3x-ek_http_server_HW_PATH)/hw/hw_eth.c \