Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
gc_format.h File Reference

Go to the source code of this file.

Functions

 DECLARE_CONST (gc_generate_newlines)
 Whether gridconnect format should create newline characters at the end of packets.
 
int gc_format_parse (const char *buf, struct can_frame *can_frame)
 Parses a GridConnect packet.
 
char * gc_format_generate (const struct can_frame *can_frame, char *buf, int double_format)
 Formats a can frame in the GridConnect protocol.
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Headers for conversion to gridconnect format.

Author
Balazs Racz
Date
20 May 2013

Definition in file gc_format.h.

Function Documentation

◆ gc_format_generate()

char * gc_format_generate ( const struct can_frame *  can_frame,
char *  buf,
int  double_format 
)

Formats a can frame in the GridConnect protocol.

If requested, it can create the double protocol with leading !!, trailing ;; and all the characters doubled.

If the input frame is an error frame, then does not output anything and returns the input pointer.

Parameters
can_frameis the input frame.
bufis the output buffer. The caller must ensure this is big enough to hold the resulting frame (28 or 56 bytes).
double_formatif non-zero, the doubling format will be generated.
Returns
the pointer to the buffer character after the formatted can frame.

Definition at line 199 of file gc_format.cxx.

◆ gc_format_parse()

int gc_format_parse ( const char *  buf,
struct can_frame *  can_frame 
)

Parses a GridConnect packet.

Parameters
bufpoints to a character buffer that contains the packet. The leading ":" must be already removed, the tailing ';' must be replaced by a \0 char.
can_frameis the CAN frame that will be filled based on the source packet.
Returns
0 in case of success, -1 if there was a packet format error (in this case the frame is set to an error frame).

Definition at line 82 of file gc_format.cxx.