HTTPdynamic.c File Reference

Dynamic 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

void UpdateLedStates (void)
 
void toggle_led (direntry_type *fp, unsigned int led_nr)
 
int32_t http_interpreter (httpserv_type *http_server)
 User defined callback function. More...
 
int main (void)
 

Variables

char * program_name = "dynamic HTTP server"
 
direntry_type led1 = {"led1" , "led1.gif" , sizeof(ledoff_gif) , FTP_RW | FTP_RAM, 'B', (uint32_t)ledoff_gif }
 
direntry_type led2 = {"led2" , "led2.gif" , sizeof(ledoff_gif) , FTP_RW | FTP_RAM, 'B', (uint32_t)ledoff_gif }
 
direntry_type led3 = {"led3" , "led3.gif" , sizeof(ledoff_gif) , FTP_RW | FTP_RAM, 'B', (uint32_t)ledoff_gif }
 
direntry_type led4 = {"led4" , "led4.gif" , sizeof(ledoff_gif) , FTP_RW | FTP_RAM, 'B', (uint32_t)ledoff_gif }
 

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

void UpdateLedStates ( void  )
Examples:
HTTPdynamic.c.
185 {
186  /***************************************************************************
187  locals
188  ***************************************************************************/
189  uint16_t led_mask = 1, i;
190  direntry_type *fp;
191  uint16_t leds = LED_state();
192 
193  CPuts ("\r ");
194  for ( i=0; i<4; i++ )
195  {
196  fp = user[0].dir[led1.index+i];
197 
198  if ( leds & led_mask )
199  {
200  /*******************************************************************
201  change file to ledon.gif
202  *******************************************************************/
203  fp-> offset = (uint32_t)ledon_gif;
204  fp-> size = sizeof(ledon_gif);
205  fp-> max_offset = (uint32_t)ledon_gif + fp->size;
207  " * "
208  VT100_DEFAULT);
209  }
210  else
211  {
212  /*******************************************************************
213  change file to ledoff.gif
214  *******************************************************************/
215  fp-> offset = (uint32_t)ledoff_gif;
216  fp-> size = sizeof(ledoff_gif);
217  fp-> max_offset = (uint32_t)ledoff_gif + fp-> size;
218  CPuts (" o ");
219  }
220  led_mask <<= 1;
221  }
222 }
Embedded File System directory.
Definition: net.h:796
int32_t index
Definition: net.h:813
unsigned short uint16_t
Definition: stdint.h:45
direntry_type led1
Definition: HTTPdynamic.c:164
#define VT100_DEFAULT
Definition: cprintf.h:150
direntry_type * dir[MAX_DIR]
Definition: net.h:828
uint16_t LED_state(void)
Definition: BoardSpecific.c:1342
user_type user[]
Definition: FTPclient.c:168
unsigned int uint32_t
Definition: stdint.h:47
#define VT100_GREEN
Definition: cprintf.h:144
int32_t size
Definition: net.h:800
int CPuts(const char *_ptr)
Definition: cprintf.c:399
void toggle_led ( direntry_type fp,
unsigned int  led_nr 
)
Examples:
HTTPdynamic.c.
234 {
235  /***************************************************************************
236  locals
237  ***************************************************************************/
238  uint16_t led_mask = 1 << led_nr;
239  uint16_t leds = LED_state();
240 
241  (void)fp;
242 
243  if ( leds & led_mask )
244  {
245  /***********************************************************************
246  switch LED off
247  ***********************************************************************/
248  LED_off (led_nr);
249  }
250  else
251  {
252  /***********************************************************************
253  switch LED on
254  ***********************************************************************/
255  LED_on (led_nr);
256  }
257 }
void LED_on(unsigned int ledNum)
Definition: BoardSpecific.c:1302
unsigned short uint16_t
Definition: stdint.h:45
void LED_off(unsigned int ledNum)
Definition: BoardSpecific.c:1284
uint16_t LED_state(void)
Definition: BoardSpecific.c:1342
int main ( void  )
Examples:
HTTPdynamic.c.
384 {
385  /***************************************************************************
386  locals
387  ***************************************************************************/
388  int main_loop = 1; /* main loop switch, set to 0 to exit */
389  volatile int32_t http_serv;
390 
391  /***************************************************************************
392  initialize application (e.g. timer clocks, PLL settings, EMIF etc.)
393  (ref. \Common\Common.c)
394  ***************************************************************************/
395  AppInit (GET_CLOCK);
396 
397  /***************************************************************************
398  select output device for CPrintf (ref. \Common\cprintf.c)
399  possible settings:
400  CPRINTF_UART_OUTPUT -> output to UART
401  CPRINTF_CCS_OUTPUT -> output to CCS
402  CPRINTF_UART_OUTPUT | CPRINTF_CCS_OUTPUT -> output to UART and CCS
403  ***************************************************************************/
404  CPrintf_select_output (CPRINTF_DEFAULT_OUTPUT); /* default outputs */
405 
406  /***************************************************************************
407  print a start up message
408  ***************************************************************************/
409  START_UP_MESSAGE (BLANK_REV NETLIB_REV);
410 
411  /**************************************************************************/
412  // CPrintfProgress (" Heap check ");
413  // at least 0x10000 bytes required for this app
414  /**************************************************************************/
415  ASSERT_HEAP (initial_heap_size, 0x10000);
416  // CPrintfProgressSuccess();
417 
418  /**************************************************************************/
419  CPrintfProgress (" Setup system time ");
420  // 1 milli seconds resolution
421  /**************************************************************************/
424  CPrintf (" *** timer %d mapped to CPU int %d ***\r\n",
426 
427  /**************************************************************************/
428  CPrintfProgress (" Enable interrupts ");
429  /**************************************************************************/
432 
433  /**************************************************************************/
434  CPrintfProgress (" Start system timer ");
435  /**************************************************************************/
436  StartSystemTimer ();
438  CPrintf (" *** timer %d running at %"PRId32" Hz ***\r\n", SystemTimerDev, RES_SECONDS/GetSystemTimerRes());
439 
440  /**************************************************************************/
441  CPrintfProgress (" Initialize network ");
442  /**************************************************************************/
443  InitializeNetwork ( 64); // 64 bytes for ping
444 
445  /***************************************************************************
446  initialize http server; parameter is the specified user list
447  ***************************************************************************/
448  http_serv = http_server_init ( user, /* specified user list */
449  NULL, /* mmc not supported */
450  HTTP_NO_LIMIT); /* max parallel connections */
451  /* 0 == no limit (heap limit only) */
452 
453  if ( http_serv == FALSE )
454  {
455  prg_exit ("http_server_init() failed"); /* possibly insufficient heap */
456  }
457 
458  /***************************************************************************
459  add some dynamic pages
460  ***************************************************************************/
461  http_add_page (&led1);
462  http_add_page (&led2);
463  http_add_page (&led3);
464  http_add_page (&led4);
465 
466  /***************************************************************************
467  define user callback function
468  ***************************************************************************/
471 
472  /***************************************************************************
473  main program loop: set main_loop to 0 to exit loop
474  ***************************************************************************/
475  while ( main_loop )
476  {
477  /***********************************************************************
478  try to detect IP assignment
479  if DHCP is used, the assigned IP address may change
480  ***********************************************************************/
482  {
483  /*******************************************************************
484  print leds
485  *******************************************************************/
486  CPuts ("\r\n LED1 LED2 LED3 LED4");
487  CPuts ("\r\n o o o o");
488  }
489 
490  /***********************************************************************
491  call net_isq() and http_server()
492  ***********************************************************************/
493  net_isq ();
494  http_server ();
495 
496  /***********************************************************************
497  monitor link status
498  ***********************************************************************/
500 
501  /***********************************************************************
502  show that the program is running, perform symbol animation
503  ***********************************************************************/
505  }
506 
507  /***************************************************************************
508  exit program, shut down peripherals
509  ***************************************************************************/
510  return (0);
511 }
#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
direntry_type led1
Definition: HTTPdynamic.c:164
#define GET_CLOCK
Definition: BoardSpecific.h:258
direntry_type led3
Definition: HTTPdynamic.c:166
int CPrintf(const char *_format,...)
Custom printf function.
Definition: cprintf.c:708
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
#define CPRINTF_DEFAULT_OUTPUT
Definition: BoardSpecific.h:129
direntry_type led4
Definition: HTTPdynamic.c:167
user_type user[]
Definition: FTPclient.c:168
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
direntry_type led2
Definition: HTTPdynamic.c:165
#define SYSTEM_TIMER_INT
Definition: BoardSpecific.h:174
#define SYSTEM_TIMER
Definition: BoardSpecific.h:167
int32_t http_interpreter(httpserv_type *http_server)
User defined callback function.
Definition: HTTPdynamic.c:274
int32_t http_add_page(direntry_type *uri)
Dynamically add a webpage during runtime.
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
#define CPrintfProgress(s)
Definition: cprintf.h:230
#define CPrintfProgressSuccess()
Definition: cprintf.h:263

Variable Documentation

char* program_name = "dynamic HTTP server"
Examples:
HTTPdynamic.c.
direntry_type led1 = {"led1" , "led1.gif" , sizeof(ledoff_gif) , FTP_RW | FTP_RAM, 'B', (uint32_t)ledoff_gif }
Examples:
HTTPdynamic.c.
direntry_type led2 = {"led2" , "led2.gif" , sizeof(ledoff_gif) , FTP_RW | FTP_RAM, 'B', (uint32_t)ledoff_gif }
Examples:
HTTPdynamic.c.
direntry_type led3 = {"led3" , "led3.gif" , sizeof(ledoff_gif) , FTP_RW | FTP_RAM, 'B', (uint32_t)ledoff_gif }
Examples:
HTTPdynamic.c.
direntry_type led4 = {"led4" , "led4.gif" , sizeof(ledoff_gif) , FTP_RW | FTP_RAM, 'B', (uint32_t)ledoff_gif }
Examples:
HTTPdynamic.c.