MOD5441X Factory Application
Overview
This comprehensive demonstration application showcases the complete feature set of the NetBurner MOD5441X platform. It serves as the factory-installed application and provides a full-featured example of web server functionality, file system management, interactive GPIO control, and network services. This application demonstrates how to build a complete embedded web-based control system with both static and dynamic content.
Supported Platform
- MOD5441X - MOD54415/MOD54417 core modules only
Hardware Requirements
Essential Components
- MOD5441X core module - Factory-installed application platform
- MOD-DEV-70CR development board - For complete functionality including LEDs, switches, and flash card access
- Network connection - Ethernet for web server access
- Flash card - SD or microSD for file system demonstrations (optional)
Development Board Features Utilized
- 8 LEDs - Interactive web-controlled indicators on J2 pins
- 8 DIP switches - Analog switch reading on J2 pins
- Flash card socket - External storage for FTP and file operations
- Serial debugging - Console interface for system monitoring
LED and Switch Pin Mapping
MOD-DEV-70 Board GPIO Assignments:
LEDs (J2 pins): 15, 16, 31, 23, 37, 19, 20, 24
Switches (A/D pins): 8, 6, 7, 10, 9, 11, 12, 13
Features
Comprehensive Web Server
- Multi-page website - Complete navigation structure with header/footer
- Static content - HTML, CSS, JavaScript, and image resources
- Dynamic content - Real-time data generation using CPPCALL tags
- Interactive controls - Web-based LED control and switch monitoring
- Modern web support - jQuery integration and responsive design
- WebSocket communication - Real-time bidirectional data exchange
File System Services
- FTP Server - Full FTP daemon for file transfer operations
- EFFS Integration - Flash card file system access
- Multi-drive support - On-board and external flash card management
- File operations - Create, read, write, delete file operations
- Directory navigation - Complete directory structure management
Network Services
- HTTP Server - Full-featured web server on port 80
- FTP Server - File Transfer Protocol server on port 21
- WebSocket Server - Real-time communication support
- Network diagnostics - ARP cache, IP addresses, counters display
Interactive Hardware Control
- LED Control - Web-based LED pattern control and display
- Switch Reading - Real-time DIP switch position monitoring
- Analog-to-Digital - Switch position detection via ADC
- GPIO Management - Direct hardware pin control and configuration
Entertainment and Testing
- Tic-Tac-Toe Game - Interactive game demonstrating AI algorithms
- System Diagnostics - Memory usage, task status, network statistics
- Test Functions - Manufacturing test routines and validation
- Debug Interface - Serial console command system
Web Interface Structure
Main Navigation Pages
Home Page (index.html)
- Welcome interface - Introduction to MOD5441X capabilities
- Feature overview - Description of available demonstrations
- Hardware images - Visual representation of module and development board
- Getting started guide - Basic usage instructions
LED Control (led.html)
- Interactive LED grid - 8 LEDs with clickable on/off control
- Visual indicators - Green (ON) and red (OFF) LED status images
- URL encoding - LED state encoded in URL parameters
- Instant feedback - Immediate hardware response to web clicks
- DIP switch display - Real-time switch position indicators
Dynamic Web (dynamicweb.html)
- Real-time data - Live system information display
- Switch status - Current DIP switch positions
- System uptime - Elapsed time since boot
- Memory usage - Available RAM and system resources
- Network statistics - Traffic counters and connection status
FTP Access (ftp.html)
- File transfer - Instructions for FTP client connection
- Directory listing - Flash card file and folder display
- Upload/download - Bidirectional file transfer capabilities
- File management - Create, delete, rename file operations
Tic-Tac-Toe Game (tt.html)
- Interactive game - Play against embedded AI opponent
- Game logic - Complete tic-tac-toe rule implementation
- AI opponent - Intelligent move selection algorithm
- Score tracking - Win/loss statistics maintenance
Technical Support (support.html)
- Contact information - NetBurner support resources
- Documentation links - Additional learning resources
- Troubleshooting - Common issue resolution guides
- Community forums - User support community access
Technical Implementation
Web Server Architecture
Dynamic Content Generation
void WebLeds(int sock, PCSTR url) {
int32_t urlEncodeOffset = 9;
int v;
if ((*(url + urlEncodeOffset)) == '?') {
v = atoi((char *)(url + urlEncodeOffset + 1));
} else {
v = 0xAA;
}
WriteLeds((uint8_t)v & 0xFF);
for (int i = 1; i < 256; i = i << 1) {
char buffer[80];
if (v & i) {
sniprintf(buffer, 80,
"<td><A href=\"LED.HTML?%d\"><img src=\"images/ON.GIF\"></a></td>",
v & (~i));
} else {
sniprintf(buffer, 80,
"<td><A href=\"LED.HTML?%d\"><img src=\"images/OFF.GIF\"></a></td>",
v | i);
}
}
}
int writestring(int fd, const char *str)
Write a null terminated ascii string to the stream associated with a file descriptor (fd)....
LED Hardware Control
void WriteLeds(uint8_t LedMask) {
static BOOL bLedGpioInit = FALSE;
const uint8_t PinNumber[8] = {15, 16, 31, 23, 37, 19, 20, 24};
if (!bLedGpioInit) {
for (int i = 0; i < 8; i++) {
J2[PinNumber[i]].function(PIN_GPIO);
}
bLedGpioInit = TRUE;
}
uint8_t BitMask = 0x01;
for (int i = 0; i < 8; i++) {
if ((LedMask & BitMask) == 0) {
J2[PinNumber[i]] = 1;
} else {
J2[PinNumber[i]] = 0;
}
BitMask <<= 1;
}
}
Switch Reading via ADC
uint8_t ReadSwitch() {
static bool bReadSwitchInit = FALSE;
const uint8_t PinNumber[8] = {7, 6, 5, 3, 4, 1, 0, 2};
uint8_t BitMask = 0;
if (!bReadSwitchInit) {
InitSingleEndAD();
bReadSwitchInit = TRUE;
}
for (int i = 0; i < 8; i++) {
uint16_t adcValue = GetADResult(PinNumber[i]);
if (adcValue > SWITCH_THRESHOLD) {
BitMask |= (1 << i);
}
}
return BitMask;
}
File System Integration
Multi-Drive Flash Card Support
void doSingleMemCardTest(int mmc_drive) {
const char *driveLabel;
int rv;
if (mmc_drive == MMC_OFF_BOARD) {
driveLabel = "Off-board Card Reader";
rv = f_mountfat(mmc_drive, mmc_initfunc, F_MMC_DRIVE0);
} else {
driveLabel = "On-board Card Reader";
rv = f_mountfat(mmc_drive, mmc_initfunc, F_MMC_DRIVE1);
}
if (rv == F_NO_ERROR) {
rv = f_chdrive(mmc_drive);
if (rv == F_NO_ERROR) {
F_FILE *fp =
f_open(
"TestFile.txt",
"w+");
if (fp) {
const char *content = "Hello Memory Card!";
f_write(content, 1, strlen(content), fp);
printf("PASS - %s test successful\n", driveLabel);
}
}
}
}
#define f_write(buf, size, size_st, filehandle)
Write data to the file at the current position.
Definition api_f.h:538
#define f_close(filehandle)
Closes an opened file.
Definition api_f.h:487
#define f_open(filename, mode)
Opens a file in the file system.
Definition api_f.h:512
Network Services
Main Application Loop
void UserMain(void *pd) {
showIpAddressesSerial();
RegisterWebFuncs();
printf("%s\n", FirmwareVersion);
displayMenu();
char buffer[255];
while (1) {
SendWebSocketData();
fgets(buffer, 255, stdin);
processCommand(buffer);
}
OSTimeDly(2);
}
}
#define TICKS_PER_SECOND
System clock ticks per second.
Definition constants.h:49
#define MAIN_PRIO
Recommend UserMain priority.
Definition constants.h:130
int f_enterFS(void)
Adds a new task priority to the task list used by the file system.
int FTPDStart(uint16_t port, uint8_t server_priority)
Starts the FTP Server task (non-SSL/TLS) Listens for incoming connections. Only one instance of the F...
int charavail()
Checks to see if data is available for read on stdin. By default, stdin is the boot/debug serial port...
void StartHttp(uint16_t port, bool RunConfigMirror)
Start the HTTP web server. Further documentation in the Initialization section Initialization - Syste...
void init()
System initialization. Ideally called at the beginning of all applications, since the easiest Recover...
void EnableSystemDiagnostics()
Turn on the diagnostic reports from the config page.
bool WaitForActiveNetwork(uint32_t ticks_to_wait=120 *TICKS_PER_SECOND, int interface=-1)
Wait for an active network connection on at least one interface.
WebSocket Communication
void SendWebSocketData() {
static uint32_t lastSendTime = 0;
sniprintf(ReportBuffer, ReportBufSize,
"{"
"\"uptime\":%lu,"
"\"switches\":%d,"
"\"freemem\":%lu"
"}",
Secs, ReadSwitch(), GetFreeRam());
if (wsFdList[i] != -1) {
ws_send(wsFdList[i], ReportBuffer, strlen(ReportBuffer));
}
}
lastSendTime = TimeTick;
}
}
#define WS_MAX_SOCKS
Maximum number of simultaneous WebSocket connections supported.
Definition websockets.h:59
Usage Instructions
Initial Setup
- Hardware assembly
- Mount MOD5441X on MOD-DEV-70CR development board
- Connect Ethernet cable to network
- Insert flash card in external card socket (optional)
- Power up system
- Network configuration
- Note IP address from serial console output
- Verify network connectivity with ping test
- Configure firewall if necessary for HTTP/FTP access
- Web browser access
- Open web browser to
http://<device_ip>
- Navigate through demonstration pages
- Test interactive features (LEDs, switches)
Web Interface Operations
LED Control Testing
- Access LED page - Navigate to LED control page from main menu
- Click LEDs - Click individual LED images to toggle state
- Observe hardware - Watch physical LEDs change on development board
- Pattern testing - Create different LED patterns using web interface
- Switch monitoring - Observe DIP switch positions update automatically
Dynamic Content Monitoring
- Access dynamic page - Navigate to dynamic web content
- Real-time updates - Page displays live system information
- Switch changes - Move DIP switches on development board
- System statistics - Monitor uptime, memory usage, network counters
FTP File Operations
- FTP client connection
Host: <device_ip>
Port: 21
Username: (none required)
Password: (none required)
- File operations
- Upload files - Transfer files from PC to flash card
- Download files - Retrieve files from flash card to PC
- Directory navigation - Browse folder structure
- File management - Create, delete, rename operations
Tic-Tac-Toe Game
- Start game - Navigate to tic-tac-toe page
- Make moves - Click squares to place X marks
- AI response - System automatically makes O moves
- Game completion - Play until win, loss, or draw
- Reset game - Start new game after completion
Serial Console Interface
Debug Commands
----- Main Menu -----
B - Show IP Addresses
C - Show Counters
E - Show Ethernet Registers
W - Show OS Seconds Counter
? - Display Menu
Address Resolution Protocol packet structure.
Definition arp.h:1035
Network Diagnostics
- ARP Cache - Display Address Resolution Protocol table
- IP Addresses - Show current network configuration
- Counters - Network traffic and error statistics
- Ethernet Registers - Low-level hardware status
- System Uptime - OS tick counter and elapsed time
Manufacturing Test Commands
Special Commands:
~ - Manufacturing Test Sequence
` - Dual Memory Card Test
Expected Console Output
Startup Sequence
MOD54415 Factory Demo
IP Address: 192.168.1.100
Subnet Mask: 255.255.255.0
Gateway: 192.168.1.1
DNS Server: 192.168.1.1
NetBurner Release Version: 3.x.x
----- Main Menu -----
B - Show IP Addresses
C - Show Counters
E - Show Ethernet Registers
W - Show OS Seconds Counter
? - Display Menu
Link Status: Connected at 100 Mbps Full Duplex
LED Control Feedback
[Web browser LED click generates URL with parameter]
LED Pattern: 0xAA (binary: 10101010)
Hardware LEDs updated to match web interface
Advanced Features
WebSocket Real-Time Communication
Client-Side JavaScript
// Example WebSocket connection for real-time updates
var ws = new WebSocket('ws://' + window.location.host + '/ws');
ws.onmessage = function(event) {
var data = JSON.parse(event.data);
// Update switch display
updateSwitchDisplay(data.switches);
// Update system information
document.getElementById('uptime').innerHTML = data.uptime + ' seconds';
document.getElementById('freemem').innerHTML = data.freemem + ' bytes';
};
function updateSwitchDisplay(switchValue) {
for (var i = 0; i < 8; i++) {
var checkbox = document.getElementById('cbox' + (i + 1));
checkbox.checked = (switchValue & (1 << i)) !== 0;
}
}
Server-Side WebSocket Handler
void RegisterWebFuncs() {
SetNewWSCallback(WSCallback);
RegisterPost("LED.HTML", WebLeds);
RegisterGet("dynamicweb.html", WebDynamicContent);
}
int WSUpgrade(HTTP_Request *req, int sock)
Upgrade an HTTP connection to a WebSocket connection.
Manufacturing Test System
Comprehensive Hardware Testing
void doManfTest() {
printf("Starting Manufacturing Test Sequence...\n");
printf("Testing LEDs... ");
for (int i = 0; i < 8; i++) {
WriteLeds(1 << i);
}
printf("PASS\n");
printf("Testing switches... ");
uint8_t switches = ReadSwitch();
printf("Switch pattern: 0x%02X - ", switches);
printf("PASS\n");
printf("Testing network... ");
if (GetInterfaceStatus() == INTERFACE_UP) {
printf("PASS\n");
} else {
printf("FAIL\n");
}
printf("Manufacturing test complete.\n");
}
Dual Memory Card Testing
void doDualMemCardTest() {
printf("Testing both memory card slots...\n");
doSingleMemCardTest(MMC_ON_BOARD);
doSingleMemCardTest(MMC_OFF_BOARD);
printf("Memory card testing complete.\n");
}
Performance and Scalability
Web Server Performance
- Concurrent connections - Supports multiple simultaneous users
- Page load times - <1 second for static content
- Dynamic content - Real-time generation with minimal delay
- Image serving - Efficient binary content delivery
Memory Usage
- Static allocation - ~64KB for web content and resources
- Dynamic buffers - 512 bytes for JSON WebSocket data
- File system - EFFS buffers scale with flash card usage
- Network stacks - Standard NetBurner TCP/IP overhead
Network Throughput
- HTTP traffic - 10+ Mbps sustained throughput
- FTP transfers - Limited by flash card write speed
- WebSocket updates - 1 Hz real-time data refresh
- Concurrent users - 5-10 simultaneous web browsers supported
Troubleshooting
Common Issues
Web Page Not Loading
Symptoms**: Browser cannot connect to device Solutions**:
- Verify IP address from serial console
- Check network connectivity with ping
- Confirm firewall settings allow HTTP traffic
- Verify Ethernet cable connection
- Check power supply stability
LEDs Not Responding
Symptoms**: Web clicks don't change hardware LEDs Solutions**:
- Verify MOD5441X is properly seated on development board
- Check development board power connections
- Confirm LED functionality with manual GPIO test
- Verify web page URL encoding is working
- Check GPIO pin configuration in code
FTP Connection Failures
Symptoms**: FTP client cannot connect Solutions**:
- Verify FTP server is running (check serial console)
- Confirm port 21 is not blocked by firewall
- Try passive mode in FTP client
- Check flash card insertion and formatting
- Verify file system initialization
Switch Reading Errors
Symptoms**: DIP switches not reading correctly Solutions**:
- Verify ADC initialization completed successfully
- Check switch physical connections to development board
- Adjust ADC threshold values if necessary
- Test with different switch positions
- Verify power supply voltage stability
Debug Procedures
Network Diagnostics
if (GetInterfaceStatus() == INTERFACE_UP) {
printf("Network interface is UP\n");
printf("IP: %s\n", GetCurrentIP().AsString());
printf("Netmask: %s\n", GetCurrentNetmask().AsString());
printf("Gateway: %s\n", GetCurrentGateway().AsString());
} else {
printf("Network interface is DOWN\n");
}
GPIO Testing
void TestLEDs() {
const uint8_t PinNumber[8] = {15, 16, 31, 23, 37, 19, 20, 24};
for (int i = 0; i < 8; i++) {
J2[PinNumber[i]].function(PIN_GPIO);
J2[PinNumber[i]] = 0;
J2[PinNumber[i]] = 1;
}
}
File System Verification
if (get_cd(MMC_OFF_BOARD)) {
printf("External flash card detected\n");
if (!get_wp(MMC_OFF_BOARD)) {
printf("Card is writable\n");
} else {
printf("Card is write-protected\n");
}
} else {
printf("No external flash card detected\n");
}
File Structure
Mod5441xFactoryApp/
|-- src/
| |-- main.cpp # Main application and command system
| |-- webfuncs.cpp # Web server dynamic content functions
| |-- webfuncs.h # Web function declarations
| |-- tests.cpp # Manufacturing and diagnostic tests
| |-- tests.h # Test function declarations
| |-- ip_util.cpp # Network utility functions
| |-- ip_util.h # Network utility declarations
| |-- ftps.cpp # FTP server extensions
| |-- SimpleAD.cpp # Analog-to-digital converter utilities
| |-- SimpleAD.h # ADC function declarations
| |-- FileSystemUtils.cpp # EFFS file system utilities
| |-- FileSystemUtils.h # File system utility declarations
| +-- cardtype.h # Flash card type definitions
|-- html/
| |-- index.html # Main welcome page
| |-- led.html # LED control and switch display
| |-- dynamicweb.html # Real-time system information
| |-- ftp.html # FTP access instructions
| |-- tt.html # Tic-tac-toe game
| |-- support.html # Technical support resources
| |-- header.html # Common navigation header
| |-- style.css # Cascading style sheet
| |-- script.js # JavaScript functionality
| |-- jquery-3.0.0.min.js # jQuery library
| +-- images/ # Web graphics and icons
| |-- logo.jpg # NetBurner logo
| |-- mod5441X.jpg # Module image
| |-- devBoard.jpg # Development board image
| |-- on.gif # LED ON indicator
| |-- off.gif # LED OFF indicator
| +-- [other graphics] # Additional UI elements
|-- makefile # Build configuration with FatFile library
|-- nbeclipse-rules.json # IDE integration settings
+-- README.md # This comprehensive guide
Dependencies
- NetBurner NNDK - Network Development Kit with full web server support
- FatFile Library - EFFS FAT file system support for flash cards
- jQuery Library - Modern web interface functionality
- Development Board - MOD-DEV-70CR for complete hardware feature access
Learning Objectives
This comprehensive example demonstrates:
- Complete web application development - Full-stack embedded web development
- Multi-service architecture - HTTP, FTP, and WebSocket servers
- Hardware abstraction patterns - GPIO, ADC, and file system integration
- Real-time web interfaces - WebSocket communication and dynamic content
- Production application structure - Modular code organization and scalability
- Manufacturing test integration - Automated hardware validation procedures
- Network service coordination - Multiple simultaneous network protocols
Related Examples
For additional learning and development, see:
- Individual MOD5441X examples for focused feature demonstrations
- Web server examples for advanced HTTP functionality
- File system examples for EFFS and storage management
- Network protocol examples for custom service development