# SFBSerial.h File Reference

Support for high-level packet exchange over serial lines. More...

`#include "SFBConstants.h"`
`#include "SFBAlarm.h"`
`#include "SFBReactor.h"`
`#include "SFBHWSerial.h"`
`#include "SFBPrint.h"`

Include dependency graph for SFBSerial.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures
class | SFBSerial
| A serial communications "endpoint", implementing the SFB packet protocol, including baud rate negotiation (BRN). More...
## Defines
#define | NorthFace Faces[NORTH]
| The SFBSerial object representing the NORTH face.
#define | SouthFace Faces[SOUTH]
| The SFBSerial object representing the SOUTH face.
#define | EastFace Faces[EAST]
| The SFBSerial object representing the EAST face.
#define | WestFace Faces[WEST]
| The SFBSerial object representing the WEST face.
#define | Serial NorthFace
| An alias for NorthFace, for Arduino compatibility.
#define | Serial1 SouthFace
| An alias for SouthFace, for Arduino Mega compatibility.
#define | Serial2 EastFace
| An alias for EastFace, for Arduino Mega compatibility.
#define | Serial3 WestFace
| An alias for WestFace, for Arduino Mega compatibility.
## Enumerations
enum | StandardBaudRateCodes { SFBAUD300 = 0, SFBAUD1200 = 1, SFBAUD9600 = 2, SFBAUD57600 = 3, SFBAUD115200 = 4, SFBAUD230400 = 5, SFBAUD500000 = 6, SFBAUD1000000 = 7, SFBAUD2000000 = 8, SFBAUD3000000 = 9, SFBAUD_CODE_COUNT = 10, SFBAUD_RENDEZVOUS = 2 }
| Single digit numeric codes for the "standard baud rates" for interSFB communications. More...
## Functions
int | getStandardBaudCode (u32 baudCodeOrRate)
| What standard baud code does baudCodeOrRate correspond to, if any?
u32 | getStandardBaudRate (u32 baudCode)
| What is the baud rate associated with standard baud code baudCode?
void | serial_startup_initialization ()
bool | zPacketPrefix (u8 *p1, const char *to)
bool | packetPrefix (u8 *p1, const u8 *to, const u32 len)
## Variables
SFBSerial | Faces [FACE_COUNT]
| The array of SFBSerial objects.

## Detailed Description

Support for high-level packet exchange over serial lines.

Author:
  David H. Ackley.

Date:
  (C) 2008 All rights reserved.

Code License:
  The GNU Lesser General Public License

License Note:
  All code samples shown in documentation are placed into the public domain.

## Enumeration Type Documentation

enum StandardBaudRateCodes

Single digit numeric codes for the "standard baud rates" for interSFB communications.

Although the SFB serial hardware and software is capable of communicating at a wide range of standard and non-standard baud rates (see begin(int,bool)), only the rates described here are used in the "SB" and "SS" packets sent between SFB's during the "baud rate negotiation" (BRN) protocol, and thus only one of these rates can be selected by that process.

Enumerator:

  SFBAUD300 | 300 baud.
  SFBAUD1200 | 1200 baud.
  SFBAUD9600 | 9600 baud; the "rendezvous rate" (see SFBAUD_RENDEZVOUS).
  SFBAUD57600 | 57600 baud.
  SFBAUD115200 | 115200 baud; a common rate for communications between SFBs.
  SFBAUD230400 | 230400 baud; often achievable by SFBs (depending on interrupt load).
  SFBAUD500000 | 500000 baud; may be achievable by SFBs, but usually not reliable.
  SFBAUD1000000 | 1000000 baud; future use; unachievable by existing SFBs.
  SFBAUD2000000 | 2000000 baud; future use; unachievable by existing SFBs.
  SFBAUD3000000 | 3000000 baud; future use; unachievable by existing SFBs.
  SFBAUD_CODE_COUNT | The number of possible SFB BRN baud codes.
  SFBAUD_RENDEZVOUS | Code 2 (SFBAUD9600) is the "rendezvous speed" used for initial interSFB communications. The baud rade indicated by this code must be supported by every "SFB-communications-aware" device. (On the other hand, it is the _only_ baud rate that is so required; support for any of the other baud rate codes is optional.)

## Function Documentation

int getStandardBaudCode | ( | u32 | baudCodeOrRate | ) |

What standard baud code does baudCodeOrRate correspond to, if any?

Returns:
  0..9 if baudCodeOrRate is either in the range 0..9 (assumed to be a baud code), or is of the 10 standard baud rates supported by the BRN (in which case the corresponding code is returned), and returns -1 otherwise.

Since:
  0.9.7

u32 getStandardBaudRate | ( | u32 | baudCode | ) |

What is the baud rate associated with standard baud code baudCode?

Returns:
  0 if baudCode is not a legal baud code, otherwise returns the baud rate specified by baudCode.

Since:
  0.9.7

## Variable Documentation

SFBSerial Faces[FACE_COUNT]

The array of SFBSerial objects.

There is one entry each for NORTH, SOUTH, EAST, and WEST. A reference to, e.g., NorthFace, is a shorthand for `Faces`[NORTH]. The Faces array is the most general mechanism for referring to a face given its direction.

Example:

        void myHandler(u8 * packet) {
          Faces[packetSource(packet)].println("roger"); // Send a packet back to wherever it came from
        }