HTTPsimple.c File Reference

simple HTTP server example More...

#include <BoardSupport/inc/stdtypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#include <Libs/NETlib/net.h>
#include <Libs/NETlib/httplib.h>
#include <BoardSupport/inc/BoardSpecific.h>
#include <Common/Common.h>
#include <Common/uartio.h>
#include <Common/timer.h>
#include <Common/CPrintf.h>
#include <BoardSupport/config/netconfig.c>
#include ".\webpage\webpage.c"
#include ".\webpage\webpage.gen"

Functions

int32_t http_interpreter (httpserv_type *http_server)
 User defined callback function. More...
 
int main (void)
 

Variables

char * program_name = "HTTP-server"
 
char * authentication_key = "Albert:Einstein"
 

Detailed Description

                          _         _             _
                       __| |    ___(_) ____ _ __ | |_
                      / _` |   / __| |/ _` | '_ \| __|
                     | (_| | _ \__ \ | (_| | | | | |_
                      \__,_|(_) ___/_|\__, |_| |_|\__|
                     Signalprocessing |___/ Technology
Author
D.SignT GmbH & Co. KG, Claus Hermbusche
Date
2019-06-03

This program installs a HTTP server (port 80) with either fix IP 192.168.168.200 (configurable in netconfig.c) or DHCP assigned address (e.g. 192.168.168.143, host name mydemo).

To verify this program, first 'ping' the DSP:

>ping 192.168.168.200

or, if configured for DHCP

>ping mydemo

If the settings and network connections are correct, the pings will be replied.

To see the web page type in your browser:

>http://192.168.168.200/index.htm

or, if configured for DHCP

>http://mydemo/index.htm

All pages and messages are hard-coded via c-variables into the code, but can also be loaded from internal flash.

Function Documentation

int main ( void  )
Examples:
HTTPsimple.c.
258 {
259  /***************************************************************************
260  locals
261  ***************************************************************************/
262  int main_loop = 1; /* main loop switch, set to 0 to exit */
263  volatile int32_t http_serv;
264  timeval stamp1, stamp2, delta; /* used to determine startup time */
265 
266 
267  /***************************************************************************
268  initialize application (e.g. timer clocks, PLL settings, EMIF etc.)
269  (ref. \Common\Common.c)
270  ***************************************************************************/
271  AppInit (GET_CLOCK);
272 
273  /***************************************************************************
274  select output device for CPrintf (ref. \Common\cprintf.c)
275  possible settings:
276  CPRINTF_UART_OUTPUT -> output to UART
277  CPRINTF_CCS_OUTPUT -> output to CCS
278  CPRINTF_UART_OUTPUT | CPRINTF_CCS_OUTPUT -> output to UART and CCS
279  ***************************************************************************/
280  CPrintf_select_output (CPRINTF_DEFAULT_OUTPUT); /* default outputs */
281 
282  /***************************************************************************
283  print a start up message
284  ***************************************************************************/
285  START_UP_MESSAGE (BLANK_REV NETLIB_REV);
286 
287  /**************************************************************************/
288  // CPrintfProgress (" Heap check ");
289  // at least 0x10000 bytes required for this app
290  /**************************************************************************/
291  ASSERT_HEAP (initial_heap_size, 0x10000);
292  // CPrintfProgressSuccess();
293 
294  /**************************************************************************/
295  CPrintfProgress (" Setup system time ");
296  // 1 milli seconds resolution
297  /**************************************************************************/
300  CPrintf (" *** timer %d mapped to CPU int %d ***\r\n",
302 
303  /**************************************************************************/
304  CPrintfProgress (" Enable interrupts ");
305  /**************************************************************************/
308 
309  /**************************************************************************/
310  CPrintfProgress (" Start system timer ");
311  /**************************************************************************/
312  StartSystemTimer ();
314  CPrintf (" *** timer %d running at %"PRId32" Hz ***\r\n", SystemTimerDev, RES_SECONDS/GetSystemTimerRes());
315 
316  /***************************************************************************
317  measure network initialization time
318  ***************************************************************************/
319  stamp1 = GetTimeStamp();
320 
321  /**************************************************************************/
322  CPrintfProgress (" Initialize network ");
323  /**************************************************************************/
324  InitializeNetwork ( 64); // 64 bytes for ping
325 
326  /***************************************************************************
327  initialize http server; parameter is the specified user list
328  ***************************************************************************/
329  http_serv = http_server_init ( user, /* specified user list */
330  NULL, /* mmc not supported */
331  HTTP_NO_LIMIT); /* max parallel connections */
332  /* 0 == no limit (heap limit only) */
333 
334  if ( http_serv == FALSE )
335  {
336  prg_exit ("http_server_init() failed"); /* possibly insufficient heap */
337  }
338 
339  /***************************************************************************
340  define user callback function
341  ***************************************************************************/
343 
344  /***************************************************************************
345  set the authentication for the secure page
346  authentication key is Username:Password (case sensitive)
347  ***************************************************************************/
348  http_set_authentication ("Secure Webpage", authentication_key,
351  stamp2 = GetTimeStamp();
352 
353  tv_interval (&delta, &stamp1, &stamp2);
354  CPuts (" network startup time [sec]: ");
356  "%"PRId32".%03"PRId32"\r\n"
358  delta.tv_sec,
359  delta.tv_usec/1000);
360 
361  CPrintf (" secure webpage account is\r\n %s (Username:Password, case sensitive)\r\n ", authentication_key);
362 
363  /***************************************************************************
364  main program loop: set main_loop to 0 to exit loop
365  ***************************************************************************/
366  CPuts ("\r\n Entering main loop ...");
367  while ( main_loop )
368  {
369  /***********************************************************************
370  process net_isq()
371  ***********************************************************************/
372  net_isq (); // process ISQ
373 
374  /***********************************************************************
375  monitor link status
376  ***********************************************************************/
378 
379  /***********************************************************************
380  try to detect IP assignment
381  if DHCP is used, the assigned IP address may change
382  ***********************************************************************/
384 
385  /***********************************************************************
386  call http_server()
387  ***********************************************************************/
388  http_server ();
389 
390  /***********************************************************************
391  show that the program is running, perform symbol animation
392  ***********************************************************************/
394  }
395 
396  /***************************************************************************
397  exit program, shut down peripherals
398  ***************************************************************************/
399  return (0);
400 }
#define prg_exit(s)
Definition: Common.h:267
void BoardEnableInterrupts(void)
global enable interrupts
Definition: BoardSpecific.c:365
#define ANIMATE_SYMBOLS_COUNT
Definition: BoardSpecific.h:268
void StartSystemTimer(void)
start system timer
Definition: timer.c:447
#define RES_MSECONDS
Definition: timer.h:67
uint16_t CPrintf_select_output(uint16_t device)
Definition: cprintf.c:206
#define ASSERT_HEAP(i, h)
Definition: Common.h:262
#define NULL
Definition: net.h:126
time_t GetSystemTimerRes(void)
Definition: timer.c:160
#define GET_CLOCK
Definition: BoardSpecific.h:258
int CPrintf(const char *_format,...)
Custom printf function.
Definition: cprintf.c:708
#define VT100_DEFAULT
Definition: cprintf.h:150
void SetupSystemTime(int32_t cpuint, int port, time_t resolution)
Setup System Time.
Definition: timer.c:392
void AppInit(uint32_t dsp_clock)
Initialize application.
Definition: Common.c:230
uint32_t initial_heap_size
Definition: Common.c:140
direntry_type e401
Definition: webpage.c:46
#define CPRINTF_DEFAULT_OUTPUT
Definition: BoardSpecific.h:129
user_type user[]
Definition: FTPclient.c:168
#define EFS_TERMINATION
Definition: net.h:783
#define VT100_RED
Definition: cprintf.h:143
uint16_t CPrintAnimatedSymbol(char *c, time_t period, size_t size)
Definition: cprintf.c:816
int InitializeNetwork(uint16_t icmp_size)
Initialize MAC, sockets and protocols.
Definition: BoardSpecific.c:597
char sym_animate[]
Definition: BoardSpecific.c:129
void http_define_callback(int32_t(*callback_func)(httpserv_type *))
Define a user callback function for HTTP requests.
int32_t http_server_init(user_type *user, mmc_function_type *(*d8900_init_mmc)(void), int32_t max_connections)
Initialize HTTP server.
#define HTTP_NO_LIMIT
Definition: httplib.h:92
Definition: timer.h:75
#define GetTimeStamp()
Definition: timer.h:81
void tv_interval(timeval *e, timeval *t1, timeval *t2)
compute elapsed time
Definition: timer.c:336
#define SYSTEM_TIMER_INT
Definition: BoardSpecific.h:174
#define SYSTEM_TIMER
Definition: BoardSpecific.h:167
void http_set_authentication(char *auth_name, char *auth_key, direntry_type *err401, direntry_type *dir_list,...)
Initialize a secure web page.
char * authentication_key
Definition: HTTPsimple.c:152
int32_t http_interpreter(httpserv_type *http_server)
User defined callback function.
Definition: HTTPsimple.c:186
void net_isq(void)
The main polling function for processing sockets, must be periodically called in the main application...
#define BLANK_REV
Definition: BoardSpecific.h:191
Uint16 SystemTimerDev
int int32_t
Definition: stdint.h:46
uint16_t monitor_ip_address(tpOutputFunc pLog)
monitor IP assignment
Definition: BoardSpecific.c:545
#define START_UP_MESSAGE(rev)
Definition: BoardSpecific.h:192
int32_t http_server(void)
The main polling function for concurrent HTTP server.
#define RES_SECONDS
Definition: timer.h:70
uint16_t monitor_link_status(tpOutputFunc pLog)
monitor link status change
Definition: BoardSpecific.c:497
int CPuts(const char *_ptr)
Definition: cprintf.c:399
time_t tv_sec
Definition: timer.h:77
#define CPrintfProgress(s)
Definition: cprintf.h:230
direntry_type secure
Definition: webpage.c:158
time_t tv_usec
Definition: timer.h:78
#define CPrintfProgressSuccess()
Definition: cprintf.h:263

Variable Documentation

char* program_name = "HTTP-server"
Examples:
HTTPsimple.c.
char* authentication_key = "Albert:Einstein"
Examples:
HTTPsimple.c.