tinyproto
Arduino related API (C++)

Table of Contents

This is Tiny protocol implementation for microcontrollers (Arduino, Stellaris).

Simple Tiny Protocol examples

Simple Tiny Protocol examples section is applicable only when working with Tiny light protocol API functions.

Initialization

void setup()
{
proto.beginToSerial();
}

Sending/Receiving data over protocol

Variant 1

First variant: without using any helpers to work with data

/* The buffer must be defined globally */
uint8_t g_buffer[16];
void loop()
{
if (needToSend)
{
/* define buffer, you want to use */
uint8_t buffer[16];
/* Prepare data you want to send here */
buffer[0] = 10;
buffer[1] = 20;
/* Send 2 bytes to remote side */
proto.write( buffer, 2 );
}
int length;
length = proto.read( g_buffer, sizeof(g_buffer), TINY_FLAG_NO_WAIT );
if ( length > 0 )
{
/* Parse your data received from remote side here. */
}
}

Variant 2

Second variant: with using special helper to pack the data being sent

/* The buffer must be defined globally */
void loop()
{
if (needToSend)
{
/* Create helper object to simplify packing of data being sent */
/* Pack data you want to send here */
packet.put( "message" );
/* Send message to remote side */
proto.write( packet );
}
int length;
length = proto.read( packet, TINY_FLAG_NO_WAIT );
if ( length > 0 )
{
/* Parse your data received from remote side here. */
/* For example, read sent ealier in example above "message" */
char * str = packet.getString();
}
}

Stopping communication

void loop()
{
...
if ( needToStop )
{
proto.end();
}
}