NetBurner 3.1
Application Wizard Project

We will start with a basic application created with the NBEclipse Application Wizard. If you are not familiar with creating an application or NBEclipse please refer to the NBEclipse Getting Started Guide before continuing. When running the Application Wizard select the Standard Initialization and Web server options. Once the project is complete, you should have a main.cpp file as shown below:

#include <predef.h> // System level options and definitions
#include <stdio.h> // Standard I/O functions
#include <nbrtos.h> // NetBurner Real Time Operating System (RTOS)
#include <http.h> // HTTP functions
#include <init.h> // Initialization functions
const char * AppName = "AppWizard"; // Name of application. Will be displayed by discovery programs
void UserMain(void * pd)
{
init(); // Initialize system
WaitForActiveNetwork(TICKS_PER_SECOND * 5); // Wait up to 5 seconds for active network activity
StartHttp(); // Start HTTP web server. Note StartHttps() starts secure web server
iprintf("Application %s started\n", AppName ); // Print message to stdout, which is the debug serial port by default
while (1) // Infinite loop
{
OSTimeDly(TICKS_PER_SECOND);
}
}

The system will automatically start the RTOS and UserMain() as a its own task. This simple application is a fully functional network application with a web server.

The init() function will do the following:

  • Initialize stdio to be the debug/console port.
  • Read and process the system configuration information. This includes things such as network interface settings, serial port settings and boot options.
  • Initialize the network stack.
  • Set the RTOS task priority of UserMain() to MAIN_PRIO.
  • Enable the Task Monitor utility support.
  • Whenever the project is built in debug mode, enable the GDB debugger.

The WaitForActiveNetwork() function will wait for an active network link before proceeding, up until the specified timeout.

StartHttp() starts the web server. The default port is 80. If you wish to start on a different port you can specify the port number as a parameter to the function.

The system supports printf() and iprintf(). The iprintf() function (i = integer only) will consume less system resources if you do not need floating point support.

Your application should never return from UserMain(); the while() loop will run forever. The #define TICKS_PER_SECOND should be used with the delay function in case the system ticks per second value is ever modified.