The SoftWare And Technology TEAM of Syncor Systems, Inc.
Netburner Tips

Tod has dozens of  blog entries about the NetBurner on his blog site and is always adding more.   A few specific entries are: The low level mechanics of how to implement AJAX are still available in an application note, Using AJAX to Serve Dynamic Web Content on the NetBurner Platform is available in PDF format. pdf icon You can also download the old  zipped file containing the  sample html, JavaScript, NetBurner code, make files and project files. This was tested with NNDK 1.98 under DevC++. 

However, we highly recommend using the link above to Ajax and the NetBurner Round 2. The blog post has links to the updated source code as well as a video tutorial on using the new code. This later version was built with the Galileo version of Eclipse and the NNDK 24rc1 beta01

A screencast of an Ajax benchmark. Running the Ajax request every 100 ms.


Shutdown Hook


How to disable update capability from Ethernet port.
From a forum post by Paul Breed.

A shutdown hook function serves two purposes, it allows you to reject an update, and it also allows you to cleanup any "active" processes before rebooting.

#include "Autoupdate.h";
int MyShutdown()
   return 0; /* return 0 to not allow update */
   return 1; /* Return 1 to allow update */
Then in initialization add the following call BEFORE you call EnableAutoUpdate()
/*PLEASE NOTE no () at the end of MyShutdown */
update_shutdown_func =MyShutdown; 
You can also add a password to protect IPSETUP and Autoupdate as well....
/* First write your test function */
int TestPassword(const char* name, const char* passwd) 
	if (name and password is ok)return 1;
	else return 0;
	/* Then in initialization link to the function */ 
	update_authenticate_func = TestPassword;
	ipsetup_authenticate_func= TestPassword;
Optimizing Small Tcp Packets


The Netburner can wait for the Maximum Segment Size(MSS) number of bytes before doing a write. If you send very small packets this may cause too much delay.
From a forum post by Paul Breed.

Usage: Using setsockoption you can enable send fewer than MSS bytes as a single write. With the socket (fd) returned from when you set up the communication channel do the following:

#include <tcp.h>
setsockoption( int fd, SO_NONAGLE);
This tells TCP to send immediately not wait for an ACK. The SO_NOPUSH option, does the opposite and tells TCP to hold off on the send until a full MSS sized packet is available. In effect setting SO_NONAGL turns SO_NOPUSH off. When SO_NOPUSH is active it will send data for the following 3 reasons:
  • It has to send an ACK packet to acknowledge data coming the other way.
  • The amount of data accumulated to be sent is greater than or equal to the MSS. MSS can vary but typically is 512 bytes for a distant destination or about 1460 bytes for a local connection.
  • SO_NOPUSH is turned off and there is data waiting to be sent
Making NetBurner Serve up proper MIME types for CSS and JS in version <=1.98 

The Problem

If you use proper <!DOCTYPE...>  headers in your HTML files, Firefox (any maybe other browsers) won't load your css style sheets.You'll get an error that states the .css file has a MIME type of "text/plain" not "text/css". You can remove the DOCTYPE and the error becomes a warning and the stylesheets load. However this puts certain browsers in the wrong mode (quirks mode, comaptability mode etc) when the DOCTYPE isn't correct.

The Solution

Harald Johnsen of Eltek Energy solved this problem by modifying the source code for comphtml.exe. He has uploaded the new file to the files section of the yahoo groups. Someone from NetBurner posted and said they would fix this in 1.99. Until then you have to take three steps.
  • 1. Get the new comphtml.exe (you may need to log into the Yahoo Groups first) and rename the NetBurner version (just to be safe) and put this version in the nburn/pcbin folder to replace the existing one.
  • 2. UpdateNburn/include/htmlfiles.h by replacing the existing file_type enum with this one
  • enum file_type { eTypeText,
         eTypeWBMP };
  • 3. Modify Nburn/system/htmldecomp.cpp starting around line 217, you need to replace the case for XML, shown in red below, and insert the two for CSS and JSS shown in blue below. The rebuild the system and happy times will be here again.
    case eTypePNG:
           SendHeader( sock, "image/png", fr->siz );
         case eTypeJar:
           SendHeader( sock, "application/x-zip-compressed", fr->siz );
         case eTypeXML:
           SendHeader( sock, "text/xml", fr->siz );
         case eTypeCSS:
           SendHeader( sock, "text/css", fr->siz );
         case eTypeJS:
           SendHeader( sock, "text/javascript", fr->siz );
         case eTypeWBMP:
           SendHeader( sock, "image/wbmp", fr->siz );
         case eTypeText:
         case eTypeOther:
           SendTextHeader( sock );
The original NetBurner Message.
Fast TCP (AKA no copy mode)


How to speed up TCP to the 14-18 MBit range by avoiding an extra copy of the data to send.
From a forum post by Paul Breed.


Instead of using write or writeall to copy from your buffer to a intermediate buffer, then from there to the ethernet packet we take a short cut and write directly to the packet. We also gain by calculating the checksum as we go rather than after the fact.


  1. #define SPEED_TCP in predef.h and recompile the system files (In Eclipse use the NBEclipse menu Rebuild system files item.
  2. in constants.h set BUFFER_POOL_SIZE to 256 or larger. (In NNDK 2.0 this is already done)
  3. Establish your TCP connection in the usual way.
  4. Find out what the negotiated maximum segment size is... call the function WORD GetMSSData( int fd ) remember this number, if it is less than 1500 bytes, you need to change the way your are making the connection to maximize this value. I'll call this value connection_mss (Syncor note: in all our tests this came out to be 1460)
  5. Increase the maximum number of buffers you can queue up.
    SetSocketTxBuffers( int fd, int n );  Where n should be 45
  6. Now to send data...

  7. Get a buffer to copy your data into......
    PBYTE GetTcpTxBuffer() /* Returns a buffer that may use up to connection_mss in length */
  8. Copy up to connection_mss bytes of data into the buffer.
  9. While copying the data in keep a DWORD checksum of the copied data. This is the most critical step to maximize speed. If you can only copy DWORDS then your performance is maximized. If your block of data exists as a block of memory in an external device then you can call the function
    DWORD memcpysum( void *to, const void *frm, int len );
    You will first have to declare it....
    extern "C"
       	DWORD memcpysum( void *to, const void *frm, int len ); 
    This function is written in assembly language to maximize speed. See ucosmcfa.s for the source.
  10. Submit this packet for transmit
    int SubmitTcpBuffer4Tx( int fd, DWORD csum32bit, WORD length, PBYTE  pBuffer )
    If the function returns length then it was sent and you are done with that packet.If the function returns 0 it means the other side of the TCP connection has flow controlled off.You probably want to sleep for awhile in this case and try again. If the function returns <0 then there is an error on the socket. IF you got any return value other than the length passed in then the buffer is still your responsibility and you must free it. Do this by calling
    void FreeTcpTxBuffer( PBYTE  pBuffer ) 
    or by sleeping and trying again.
That's it. Just do steps 6-8 over and over.