HTTPjava.c File Reference

java 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 (unsigned int led_nr)
 
int32_t http_interpreter (httpserv_type *http_server)
 User defined callback function. More...
 
int main (void)
 

Variables

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

Variable Documentation

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