-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tiny Protocol library fixes, and sketches for Arduino.
- Loading branch information
Showing
19 changed files
with
585 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
releases/arduino/TinyProto-Full/examples/sketch_echo/sketch_echo.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* This example sends back every packet received over UART. | ||
* To test this example, just compile it and upload to Arduino controller. | ||
* Open Serial Monitor in Arduino IDE. send anything typing data around | ||
* '~' chars (for example, ~Welcome~ ), and Arduino will send back the packet to you. | ||
* | ||
* TinyProtocol uses some special frame format, that means that it will ignore not valid | ||
* chars received over UART. Each packet should be in the following format: | ||
* ~[UID]DATA[FCS]~ | ||
* UID and FCS field are optional. In the example below, they are disabled. Nano versition | ||
* of Tiny protocol supports only simple 1-byte Checksum field. For CRC-16/CRC-32 use Micro and | ||
* Full versions of Tiny protocol. | ||
*/ | ||
#include <TinyProto-Nano.h> | ||
|
||
/* Creating protocol object is simple */ | ||
Tiny::Proto proto; | ||
|
||
void setup() { | ||
/* No timeout, since we want non-blocking UART operations. */ | ||
Serial.setTimeout(0); | ||
/* Initialize serial protocol for test purposes */ | ||
Serial.begin(9600); | ||
/* Redirect all protocol communication to Serial0 UART */ | ||
proto.beginToSerial(); | ||
/* We do not want to use crc */ | ||
proto.disableCrc(); | ||
} | ||
|
||
/* Specify buffer for packets to send and receive */ | ||
char g_buf[16]; | ||
|
||
/* Create special class, which simplifies the work with buffer */ | ||
Tiny::Packet g_packet(g_buf, sizeof(g_buf)); | ||
|
||
void loop() | ||
{ | ||
/* Check if some data are waiting for reading in UART */ | ||
/* If there is no delay in loop() cycle, there is no need to check for OUT_OF_SYNC error */ | ||
int len = proto.read(g_packet, TINY_FLAG_WAIT_FOREVER); | ||
/* Check if we received something with no error */ | ||
if (len > 0) | ||
{ | ||
/* Send received packet back to UART (echo) */ | ||
proto.write(g_packet, TINY_FLAG_WAIT_FOREVER); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
releases/arduino/TinyProto-Full/examples/sketch_tinyproto01/sketch_tinyproto01.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* This example sends <Hello> packet every second. | ||
* If some packet is received from remote side, it echos content back to the sender | ||
*/ | ||
#include <TinyProto-Nano.h> | ||
|
||
const int PIN_LED = 13; | ||
|
||
/* Creating protocol object is simple */ | ||
Tiny::Proto proto; | ||
|
||
void setup() { | ||
pinMode(PIN_LED, OUTPUT); | ||
/* No timeout, since we want non-blocking UART operations */ | ||
Serial.setTimeout(0); | ||
/* Initialize serial protocol for test purposes */ | ||
Serial.begin(9600); | ||
/* Redirect all protocol communication to Serial0 UART */ | ||
proto.beginToSerial(); | ||
/* We do not want to use crc */ | ||
proto.disableCrc(); | ||
} | ||
|
||
/* Specify buffer for packets to send and receive */ | ||
char g_inBuf[16]; | ||
char g_outBuf[16]; | ||
|
||
/* Create special class, which simplifies the work with buffer */ | ||
Tiny::Packet outPacket(g_outBuf, sizeof(g_outBuf)); | ||
Tiny::Packet inPacket(g_inBuf, sizeof(g_inBuf)); | ||
|
||
|
||
void loop() | ||
{ | ||
/* Create simple packet, containing only text */ | ||
outPacket.clear(); | ||
outPacket.put("\nHello\n"); | ||
|
||
/* Send packet over UART to other side */ | ||
proto.write(outPacket, TINY_FLAG_WAIT_FOREVER); | ||
|
||
/* Check if some data are waiting for reading in UART */ | ||
/* If there is no delay in loop() cycle, there is no need to check for OUT_OF_SYNC error */ | ||
int len; | ||
do { | ||
len = proto.read(inPacket, TINY_FLAG_NO_WAIT); | ||
} while (len == TINY_ERR_OUT_OF_SYNC); | ||
if (len > 0) | ||
{ | ||
/* Send received packet back to UART (echo) */ | ||
proto.write(inPacket, TINY_FLAG_WAIT_FOREVER); | ||
} | ||
delay(985); | ||
digitalWrite(PIN_LED, HIGH); | ||
delay(15); | ||
digitalWrite(PIN_LED, LOW); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=TinyProto-Full | ||
version=0.1.0 | ||
version=0.1.1 | ||
author=Alexey Dynda | ||
maintainer=Alexey Dynda <[email protected]> | ||
sentence=Allows to communicate other boards/PC via any physical connection. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
releases/arduino/TinyProto-Micro/examples/sketch_echo/sketch_echo.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* This example sends back every packet received over UART. | ||
* To test this example, just compile it and upload to Arduino controller. | ||
* Open Serial Monitor in Arduino IDE. send anything typing data around | ||
* '~' chars (for example, ~Welcome~ ), and Arduino will send back the packet to you. | ||
* | ||
* TinyProtocol uses some special frame format, that means that it will ignore not valid | ||
* chars received over UART. Each packet should be in the following format: | ||
* ~[UID]DATA[FCS]~ | ||
* UID and FCS field are optional. In the example below, they are disabled. Nano versition | ||
* of Tiny protocol supports only simple 1-byte Checksum field. For CRC-16/CRC-32 use Micro and | ||
* Full versions of Tiny protocol. | ||
*/ | ||
#include <TinyProto-Nano.h> | ||
|
||
/* Creating protocol object is simple */ | ||
Tiny::Proto proto; | ||
|
||
void setup() { | ||
/* No timeout, since we want non-blocking UART operations. */ | ||
Serial.setTimeout(0); | ||
/* Initialize serial protocol for test purposes */ | ||
Serial.begin(9600); | ||
/* Redirect all protocol communication to Serial0 UART */ | ||
proto.beginToSerial(); | ||
/* We do not want to use crc */ | ||
proto.disableCrc(); | ||
} | ||
|
||
/* Specify buffer for packets to send and receive */ | ||
char g_buf[16]; | ||
|
||
/* Create special class, which simplifies the work with buffer */ | ||
Tiny::Packet g_packet(g_buf, sizeof(g_buf)); | ||
|
||
void loop() | ||
{ | ||
/* Check if some data are waiting for reading in UART */ | ||
/* If there is no delay in loop() cycle, there is no need to check for OUT_OF_SYNC error */ | ||
int len = proto.read(g_packet, TINY_FLAG_WAIT_FOREVER); | ||
/* Check if we received something with no error */ | ||
if (len > 0) | ||
{ | ||
/* Send received packet back to UART (echo) */ | ||
proto.write(g_packet, TINY_FLAG_WAIT_FOREVER); | ||
} | ||
} |
Oops, something went wrong.