Initial commit of files
This commit is contained in:
61
include/CAN_Packet.h
Normal file
61
include/CAN_Packet.h
Normal file
@ -0,0 +1,61 @@
|
||||
#ifndef __CAN_PACKET_INCLUDE__
|
||||
#define __CAN_PACKET_INCLUDE__
|
||||
|
||||
/******************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
// all data is network byte order (big endian)
|
||||
typedef struct _CAN_Packet {
|
||||
uint32_t dwCounter; // incrementing counter
|
||||
|
||||
// J2735 Part 1 floating point
|
||||
float fSpeed; // meters/sec (m/s)
|
||||
float fSteering; // degrees/sec
|
||||
float fAccelLongitudinal; // meters/sec^2
|
||||
float fAccelLateral; // meters/sec^2
|
||||
float fAccelVertical; // meters/sec^2
|
||||
float fYawRate; // degrees/sec
|
||||
float fVehicleWidth;
|
||||
float fVehicleLength;
|
||||
// J2735 Part 2 floating point
|
||||
float fThrottle; // %
|
||||
|
||||
// J2735 Part 1/2 integer
|
||||
uint16_t wBrakeSystemStatus;
|
||||
uint8_t byTransmission;
|
||||
uint8_t byExteriorLights;
|
||||
// J2735 Part 2 integer
|
||||
uint16_t wEventFlags;
|
||||
uint8_t byFrontWipers;
|
||||
} __attribute__((packed)) CAN_Packet;
|
||||
|
||||
/******************************************************************************
|
||||
* function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/******************************************************************************
|
||||
* Macros
|
||||
* ***************************************************************************/
|
||||
|
||||
#endif
|
||||
|
||||
77
include/asn1common.h
Normal file
77
include/asn1common.h
Normal file
@ -0,0 +1,77 @@
|
||||
#ifndef __ASN1COMMON_INCLUDE__
|
||||
#define __ASN1COMMON_INCLUDE__
|
||||
|
||||
/******************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "embtypes.h"
|
||||
|
||||
/******************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
#define ASN1_UPER_ALIGNED 0
|
||||
#define ASN1_APER_ALIGNED 1
|
||||
#define ASN1_OER_ALIGNED 2
|
||||
|
||||
#define asn1_get_error(S) ((S)->error)
|
||||
|
||||
#define asn1_get_bits_consumed(O) ((O)->consumed)
|
||||
#define asn1_get_bytes_consumed(O) ((O)->consumed?(((O)->consumed-1)/8+1):0)
|
||||
|
||||
#define asn1_init_extension(E) memset((E),0,sizeof(ASN1_Extension))
|
||||
#define asn1_init_bitstream(E) memset((E),0,sizeof(ASN1_BitStream))
|
||||
|
||||
/******************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
typedef struct _asn1_stream {
|
||||
uint8_t *buf; // pointer to first byte
|
||||
uint8_t *ptr; // pointer to current byte
|
||||
uint8_t alloc; // set if alloc'd
|
||||
uint8_t align; // alignment
|
||||
uint8_t error; // set if error
|
||||
uint16_t bit; // current bit in byte
|
||||
uint16_t max; // maximum bits
|
||||
uint16_t consumed;// bits consumed
|
||||
} ASN1_Stream;
|
||||
|
||||
typedef struct _asn1_bitstream {
|
||||
uint64_t value; // value
|
||||
uint16_t max; // maximum bits
|
||||
} ASN1_BitStream;
|
||||
|
||||
typedef struct _asn1_extension {
|
||||
uint64_t value; // extension+option bits
|
||||
uint8_t ellipses; // 0 or 1
|
||||
uint8_t options; // # options
|
||||
uint16_t length; // length of extension
|
||||
} ASN1_Extension;
|
||||
|
||||
/******************************************************************************
|
||||
* function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void asn1_set_debug(uint8_t flag);
|
||||
extern uint8_t _asn1_debug_on_;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/******************************************************************************
|
||||
* Macros
|
||||
* ***************************************************************************/
|
||||
|
||||
#endif
|
||||
111
include/asn1oer.h
Normal file
111
include/asn1oer.h
Normal file
@ -0,0 +1,111 @@
|
||||
#ifndef __ASN1OER_INCLUDE__
|
||||
#define __ASN1OER_INCLUDE__
|
||||
|
||||
/******************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "embtypes.h"
|
||||
#include "asn1common.h"
|
||||
|
||||
/******************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
#define oer_get_error(O) ((O)->error)
|
||||
#define oer_get_bytes_consumed(O) asn1_get_bytes_consumed(O)
|
||||
|
||||
#define oer_init_extension(E) asn1_init_extension(E)
|
||||
#define oer_init_bitstream(E) asn1_init_bitstream(E)
|
||||
|
||||
#define oer_get_signed_value(U,B,O) (((int64_t)uper_get_bits_stream(U,B))-O)
|
||||
#define oer_get_unsigned_value(U,B) uper_get_bits_stream(U,B)
|
||||
|
||||
#define oer_get_char_value(O) ((int8_t)(oer_get_value(O,1)))
|
||||
#define oer_get_int8_value(O) ((int8_t)(oer_get_value(O,1)))
|
||||
#define oer_get_byte_value(O) ((uint8_t)(oer_get_value(O,1)))
|
||||
#define oer_get_uint8_value(O) ((uint8_t)(oer_get_value(O,1)))
|
||||
|
||||
#define oer_get_short_value(O) ((int16_t)(oer_get_value(O,2)))
|
||||
#define oer_get_int16_value(O) ((int16_t)(oer_get_value(O,2)))
|
||||
#define oer_get_word_value(O) ((uint16_t)(oer_get_value(O,2)))
|
||||
#define oer_get_uint16_value(O) ((uint16_t)(oer_get_value(O,2)))
|
||||
|
||||
#define oer_get_long_value(O) ((int32_t)(oer_get_value(O,4)))
|
||||
#define oer_get_int32_value(O) ((int32_t)(oer_get_value(O,4)))
|
||||
#define oer_get_dword_value(O) ((uint32_t)(oer_get_value(O,4)))
|
||||
#define oer_get_uint32_value(O) ((uint32_t)(oer_get_value(O,4)))
|
||||
|
||||
#define oer_get_llong_value(O) ((int64_t)oer_get_value(O,8))
|
||||
#define oer_get_int64_value(O) ((int64_t)oer_get_value(O,8))
|
||||
#define oer_get_qword_value(O) ((uint64_t)oer_get_value(O,8))
|
||||
#define oer_get_uint64_value(O) ((uint64_t)oer_get_value(O,8))
|
||||
|
||||
#define oer_get_string(O,B,N,X) oer_get_octet_stream(O,B,N,X)
|
||||
#define oer_put_string(O,B,L,N,X) oer_put_octet_stream(O,B,L,N,X)
|
||||
|
||||
#define OER_Stream ASN1_Stream
|
||||
#define OER_Extension ASN1_Extension
|
||||
#define OER_BitStream ASN1_BitStream
|
||||
|
||||
/******************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void oer_init_stream(OER_Stream *strm, uint8_t *ptr, uint max);
|
||||
OER_Stream *uper_alloc_stream(uint8_t *ptr, uint max);
|
||||
void oer_free_stream(OER_Stream *oer);
|
||||
|
||||
// DECODE
|
||||
uint oer_get_length(OER_Stream *oer, uint *value);
|
||||
uint64_t oer_get_value(OER_Stream *oer, uint size);
|
||||
uint oer_get_data(OER_Stream *oer, uint8_t *data, uint max);
|
||||
|
||||
// ENCODE
|
||||
uint oer_put_length(OER_Stream *oer, uint value);
|
||||
void oer_put_value(OER_Stream *oer, uint64_t value, uint size);
|
||||
void oer_put_data(OER_Stream *oer, uint8_t *data, uint length);
|
||||
|
||||
// EXTENSIONS
|
||||
uint oer_get_extension(OER_Stream *uper, OER_Extension *ext, uint nbits, uint ellipses);
|
||||
uint oer_get_ext_ellipses(OER_Extension *ext);
|
||||
uint oer_get_ext_optional(OER_Extension *ext, uint bit);
|
||||
uint oer_get_ext_length(OER_Stream *uper, OER_Extension *ext);
|
||||
uint oer_get_ext_skip(OER_Stream *uper, OER_Extension *ext);
|
||||
void oer_put_extension(OER_Stream *uper, OER_Extension *ext);
|
||||
void oer_set_ext_ellipses(OER_Extension *ext);
|
||||
void oer_set_ext_length(OER_Extension *ext, uint len);
|
||||
void oer_set_ext_optional(OER_Extension *ext, uint option, uint val, uint nbits);
|
||||
|
||||
// OCTET
|
||||
uint oer_get_octet_stream(OER_Stream *ptr, uint8_t *buf, uint min, uint max);
|
||||
void oer_put_octet_stream(OER_Stream *ptr, uint8_t *buf, uint len, uint min, uint max);
|
||||
|
||||
// BIT STREAM
|
||||
uint64_t oer_get_bitstream(OER_Stream *ptr, OER_BitStream *bs, uint max);
|
||||
uint64_t oer_get_bit_bitstream(OER_BitStream *bs, uint bit);
|
||||
void oer_put_bitstream(OER_Stream *ptr, OER_BitStream *bs);
|
||||
void oer_set_bit_bitstream(OER_BitStream *bs, uint bit, uint max);
|
||||
void oer_set_bits_bitstream(OER_BitStream *bs, uint64_t value, uint max);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/******************************************************************************
|
||||
* Macros
|
||||
* ***************************************************************************/
|
||||
|
||||
#endif
|
||||
118
include/asn1uper.h
Normal file
118
include/asn1uper.h
Normal file
@ -0,0 +1,118 @@
|
||||
#ifndef __ASN1UPER_INCLUDE__
|
||||
#define __ASN1UPER_INCLUDE__
|
||||
|
||||
/******************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "embtypes.h"
|
||||
#include "asn1common.h"
|
||||
|
||||
/******************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
#define uper_get_error(S) ((S)->error)
|
||||
#define uper_get_bits_consumed(U) asn1_get_bits_consumed(U)
|
||||
#define uper_get_bytes_consumed(U) asn1_get_bytes_consumed(U)
|
||||
|
||||
#define uper_get_bits_length(U,S) (uper_get_bits_stream(U,S)+1)
|
||||
#define uper_put_bits_length(U,L,S) uper_put_bits_stream(U,(L)-1,S)
|
||||
|
||||
#define uper_init_extension(E) asn1_init_extension(E)
|
||||
#define uper_init_bitstream(E) asn1_init_bitstream(E)
|
||||
|
||||
#define uper_get_signed_value(U,B,O) (((int64_t)uper_get_bits_stream(U,B))-O)
|
||||
#define uper_get_unsigned_value(U,B) uper_get_bits_stream(U,B)
|
||||
|
||||
#define uper_get_char_value(O) ((int8_t)(uper_get_value(O,1)))
|
||||
#define uper_get_int8_value(O) ((int8_t)(uper_get_value(O,1)))
|
||||
#define uper_get_byte_value(O) ((uint8_t)(uper_get_value(O,1)))
|
||||
#define uper_get_uint8_value(O) ((uint8_t)(uper_get_value(O,1)))
|
||||
|
||||
#define uper_get_short_value(O) ((int16_t)(uper_get_value(O,2)))
|
||||
#define uper_get_int16_value(O) ((int16_t)(uper_get_value(O,2)))
|
||||
#define uper_get_word_value(O) ((uint16_t)(uper_get_value(O,2)))
|
||||
#define uper_get_uint16_value(O) ((uint16_t)(uper_get_value(O,2)))
|
||||
|
||||
#define uper_get_long_value(O) ((int32_t)(uper_get_value(O,4)))
|
||||
#define uper_get_int32_value(O) ((int32_t)(uper_get_value(O,4)))
|
||||
#define uper_get_dword_value(O) ((uint32_t)(uper_get_value(O,4)))
|
||||
#define uper_get_uint32_value(O) ((uint32_t)(uper_get_value(O,4)))
|
||||
|
||||
#define uper_get_llong_value(O) ((int64_t)uper_get_value(O,8))
|
||||
#define uper_get_int64_value(O) ((int64_t)uper_get_value(O,8))
|
||||
#define uper_get_qword_value(O) ((uint64_t)uper_get_value(O,8))
|
||||
#define uper_get_uint64_value(O) ((uint64_t)uper_get_value(O,8))
|
||||
|
||||
#define uper_get_string(O,B,N,X) uper_get_octet_stream(O,B,N,X)
|
||||
#define uper_put_string(O,B,L,N,X) uper_put_octet_stream(O,B,L,N,X)
|
||||
|
||||
#define UPER_Stream ASN1_Stream
|
||||
#define UPER_Extension ASN1_Extension
|
||||
#define UPER_BitStream ASN1_BitStream
|
||||
|
||||
/******************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void uper_init_stream(UPER_Stream *strm, uint8_t *ptr, uint max);
|
||||
UPER_Stream *uper_alloc_stream(uint8_t *ptr, uint max);
|
||||
void uper_free_stream(UPER_Stream *oer);
|
||||
|
||||
// DECODE
|
||||
uint uper_get_bit_direct(const uint8_t *pkt, uint bit);
|
||||
uint64_t uper_get_bits_direct(const uint8_t *pkt, uint bit, uint bits);
|
||||
uint64_t uper_get_bits_stream(UPER_Stream *ptr, uint bits);
|
||||
uint64_t uper_get_bits_stream_reverse(UPER_Stream *ptr, uint nbits);
|
||||
uint uper_get_bytes_stream(UPER_Stream *uper, uint8_t *buf, uint nbytes);
|
||||
|
||||
// ENCODE
|
||||
void uper_put_bit_direct(uint8_t *pkt, uint val, uint bit);
|
||||
void uper_put_bits_direct(uint8_t *pkt, uint64_t value, uint bit, uint bits);
|
||||
void uper_put_bits_stream(UPER_Stream *uper, uint64_t value, uint bits);
|
||||
void uper_put_bytes_stream(UPER_Stream *uper, uint8_t *buf, uint nbytes);
|
||||
|
||||
// EXTENSIONS
|
||||
uint uper_get_extension(UPER_Stream *uper, UPER_Extension *ext, uint nbits, uint ellipses);
|
||||
uint uper_get_ext_ellipses(UPER_Extension *ext);
|
||||
uint uper_get_ext_optional(UPER_Extension *ext, uint bit);
|
||||
uint uper_get_ext_length(UPER_Stream *uper, UPER_Extension *ext);
|
||||
uint uper_get_ext_skip(UPER_Stream *uper, UPER_Extension *ext);
|
||||
void uper_put_extension(UPER_Stream *uper, UPER_Extension *ext);
|
||||
void uper_set_ext_ellipses(UPER_Extension *ext);
|
||||
void uper_set_ext_length(UPER_Extension *ext, uint len);
|
||||
void uper_set_ext_optional(UPER_Extension *ext, uint option, uint val, uint nbits);
|
||||
|
||||
// OCTET
|
||||
uint uper_get_octet_stream(UPER_Stream *ptr, uint8_t *buf, uint min, uint max);
|
||||
void uper_put_octet_stream(UPER_Stream *uper, uint8_t *buf, uint len, uint min, uint max);
|
||||
|
||||
// BIT STREAM
|
||||
uint64_t uper_get_bitstream(UPER_Stream *uper, UPER_BitStream *bs, uint max);
|
||||
uint64_t uper_get_bit_bitstream(UPER_BitStream *bs, uint bit);
|
||||
void uper_put_bitstream(UPER_Stream *uper, UPER_BitStream *bs);
|
||||
void uper_set_bit_bitstream(UPER_BitStream *bs, uint bit, uint max);
|
||||
void uper_set_bits_bitstream(UPER_BitStream *bs, uint64_t value, uint max);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/******************************************************************************
|
||||
* Macros
|
||||
* ***************************************************************************/
|
||||
|
||||
#endif
|
||||
46
include/asnlib.h
Normal file
46
include/asnlib.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef __ASNLIB_INCLUDE__
|
||||
#define __ASNLIB_INCLUDE__
|
||||
|
||||
/******************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <memory.h>
|
||||
|
||||
/******************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
typedef struct _bit_struct {
|
||||
const uint8_t *ptr;
|
||||
int bit;
|
||||
int max;
|
||||
int consumed;
|
||||
} UPER_Stream;
|
||||
|
||||
/******************************************************************************
|
||||
* function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int uper_get_bit(const uint8_t *pkt, int bit);
|
||||
uint64_t uper_get_bits_direct(const uint8_t *pkt, int bit, int bits);
|
||||
uint64_t uper_get_bits_stream(UPER_Stream *ptr, int bits)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/******************************************************************************
|
||||
* Macros
|
||||
* ***************************************************************************/
|
||||
|
||||
#endif
|
||||
52
include/bitlib.h
Normal file
52
include/bitlib.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef __BITLIB_INCLUDE__
|
||||
#define __BITLIB_INCLUDE__
|
||||
|
||||
/******************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "embtypes.h"
|
||||
|
||||
/******************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
typedef struct _bit_struct {
|
||||
const uint8_t *ptr;
|
||||
int bit;
|
||||
int max;
|
||||
int consumed;
|
||||
} BIT_Stream;
|
||||
|
||||
/******************************************************************************
|
||||
* function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
BYTE reverseByteBits(BYTE b);
|
||||
|
||||
void enableBitDebug(int flag);
|
||||
int getBitDirect(const uint8_t *pkt, int bit);
|
||||
uint64_t getBitsDirect(const uint8_t *pkt, int bit, int bits);
|
||||
uint64_t getBitsStream(BIT_Stream *ptr, int bits);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/******************************************************************************
|
||||
* Macros
|
||||
* ***************************************************************************/
|
||||
|
||||
#endif
|
||||
112
include/bytequeue.h
Normal file
112
include/bytequeue.h
Normal file
@ -0,0 +1,112 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (C) 2008
|
||||
* ProbeStar Telematics, LLC
|
||||
* All Rights Reserved. Proprietary and Confidential.
|
||||
*============================================================================
|
||||
* BYTE Queue
|
||||
*****************************************************************************/
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __EMBEDDED_BYTEQUEUE__
|
||||
#define __EMBEDDED_BYTEQUEUE__
|
||||
|
||||
/*****************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include "embtypes.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* macros
|
||||
*****************************************************************************/
|
||||
|
||||
#define _QueuePut(Q,D) \
|
||||
{ \
|
||||
*((Q).pbyBuf+((Q).byFront++)) = (D); \
|
||||
(Q).byCount++; \
|
||||
if ( (Q).byFront == (Q).bySize ) \
|
||||
(Q).byFront = 0; \
|
||||
}
|
||||
|
||||
#define _QueueUnput(Q) \
|
||||
{ \
|
||||
if ( (Q).byFront == 0 ) \
|
||||
(Q).byFront = (Q).bySize; \
|
||||
*((Q).pbyBuf+(--(Q).byFront)) = (0); \
|
||||
(Q).byCount--; \
|
||||
}
|
||||
|
||||
#define _QueueGet(Q,D) \
|
||||
{ \
|
||||
(D) = *((Q).pbyBuf+((Q).byRear++)); \
|
||||
(Q).byCount--; \
|
||||
if ( (Q).byRear == (Q).bySize ) \
|
||||
(Q).byRear = 0; \
|
||||
}
|
||||
|
||||
#define _QueueUnget(Q,D) \
|
||||
{ \
|
||||
if ( (Q).byRear == 0 ) \
|
||||
(Q).byRear = (Q).bySize; \
|
||||
*((Q).pbyBuf+(--(Q).byRear)) = (D); \
|
||||
(Q).byCount++; \
|
||||
}
|
||||
|
||||
#define _QueueAlloc(Q,B,N) (Q).pbyBuf=(B);(Q).bySize=(N)
|
||||
#define _QueueClear(Q) (Q).byCount=(Q).byFront=(Q).byRear=0
|
||||
#define _QueueCount(Q) (Q).byCount
|
||||
#define _QueueSize(Q) (Q).bySize
|
||||
#define _QueueEmpty(Q) ((Q).byCount==0)
|
||||
#define _QueueFull(Q) ((Q).byCount>=(Q).bySize)
|
||||
|
||||
#define QueueCount(Q) (Q)->byCount
|
||||
#define QueueSize(Q) (Q)->bySize
|
||||
#define QueueEmpty(Q) ((Q)->byCount==0)
|
||||
#define QueueFull(Q) ((Q)->byCount>=(Q)->bySize)
|
||||
|
||||
/*****************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
typedef struct _Queue {
|
||||
BYTE byCount;
|
||||
BYTE byFront;
|
||||
BYTE byRear;
|
||||
BYTE bySize;
|
||||
BYTE *pbyBuf;
|
||||
} Queue;
|
||||
|
||||
/*****************************************************************************
|
||||
* global constants
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* global variables
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* C function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void QueueAlloc( Queue *pQ, BYTE *pbyData, BYTE bySize );
|
||||
void QueueClear( Queue *pQ );
|
||||
|
||||
BYTE QueueGet( Queue *pQ, BYTE *pbyData );
|
||||
BYTE QueuePut( Queue *pQ, BYTE *pbyData );
|
||||
|
||||
BYTE QueueUnget( Queue *pQ, BYTE byData );
|
||||
BYTE QueueUnput( Queue *pQ );
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
81
include/bytestack.h
Normal file
81
include/bytestack.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (C) 2004-2005
|
||||
* ProbeStar Telematics, LLC
|
||||
* All Rights Reserved. Proprietary and Confidential.
|
||||
*============================================================================
|
||||
* BYTE Stack
|
||||
*****************************************************************************/
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __EMBEDDED_BYTESTACK__
|
||||
#define __EMBEDDED_BYTESTACK__
|
||||
|
||||
/*****************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include "embtypes.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* macros
|
||||
*****************************************************************************/
|
||||
|
||||
#define _StackPush(S,D) \
|
||||
if ( (S).byCount < (S).bySize ) \
|
||||
*((S).pbyBuf+((S).byCount++)) = (D);
|
||||
|
||||
#define _StackPop(S) ((S).byCount ? *((S).pbyBuf+(--(S).byCount)) : 0)
|
||||
|
||||
#define _StackAlloc(S,B,N) (S).pbyBuf=(B);(S).bySize=(N)
|
||||
#define _StackClear(S) (S).byCount=0
|
||||
#define _StackCount(S) (S).byCount
|
||||
#define _StackSize(S) (S).bySize
|
||||
#define _StackEmpty(S) ((S).byCount==0)
|
||||
#define _StackFull(S) ((S).byCount>=(S).bySize)
|
||||
|
||||
#define StackClear(S) (S)->byCount=0
|
||||
#define StackCount(S) (S)->byCount
|
||||
#define StackSize(S) (S)->bySize
|
||||
#define StackEmpty(S) ((S)->byCount==0)
|
||||
#define StackFull(S) ((S)->byCount>=(S)->bySize)
|
||||
|
||||
/*****************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
typedef struct _Stack {
|
||||
BYTE byCount;
|
||||
BYTE bySize;
|
||||
BYTE *pbyBuf;
|
||||
} Stack;
|
||||
|
||||
/*****************************************************************************
|
||||
* global constants
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* global variables
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* C function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void StackAlloc( Stack *pS, BYTE *pbyBuf, BYTE bySize );
|
||||
|
||||
BYTE StackPush( Stack *pS, BYTE *pbyData );
|
||||
BYTE StackPop( Stack *pS, BYTE *pbyData );
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
74
include/emblib.h
Normal file
74
include/emblib.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (C) 2008
|
||||
* ProbeStar Telematics, LLC
|
||||
* All Rights Reserved. Proprietary and Confidential.
|
||||
*============================================================================
|
||||
* Multiplatform Embedded Data Types and Conversion
|
||||
* Checksum and CRC Routines
|
||||
*****************************************************************************/
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef _EMBLIB_H_
|
||||
#define _EMBLIB_H_
|
||||
|
||||
/*****************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include "embtypes.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* macros
|
||||
*****************************************************************************/
|
||||
|
||||
/* useful one to have */
|
||||
#define bin2bcd(d) (((((d)/10)<<4|(d)%10)))
|
||||
#define bcd2bin(b) ((((b)>>4)*10)+((b)&0xf))
|
||||
|
||||
/*****************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* global constants
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* global variables
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* C function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int chomp(char *s);
|
||||
void base64(const unsigned char *in, char *out, int len);
|
||||
int unbase64(const char *in, unsigned char *out, int max);
|
||||
|
||||
extern BYTE doCheckSum( const BYTE *pbyData, BYTE nBytes );
|
||||
extern WORD doCheckSumW( const WORD *pwData, WORD nBytes );
|
||||
|
||||
extern BYTE doCRC8( BYTE byCrc, BYTE byData );
|
||||
extern BYTE strCRC8( BYTE *pbyData, WORD nBytes, BYTE byInit );
|
||||
|
||||
extern WORD doCRC16( WORD wCrc, BYTE byData );
|
||||
extern WORD strCRC16( BYTE *pbyData, WORD nBytes, WORD wInit );
|
||||
|
||||
short InterpolateShortTable( const short *psTbl, BYTE nPairs, short sData );
|
||||
long InterpolateLongTable( const long *plTbl, BYTE nPairs, long lData );
|
||||
|
||||
BYTE reverseByteBits(BYTE b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
47
include/embstruct.h
Normal file
47
include/embstruct.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (C) 2008
|
||||
* ProbeStar Telematics, LLC
|
||||
* All Rights Reserved. Proprietary and Confidential.
|
||||
*============================================================================
|
||||
* Multiplatform Embedded Data Types and Conversion
|
||||
* Checksum and CRC Routines
|
||||
*****************************************************************************/
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef _EMBSTRUCT_H_
|
||||
#define _EMBSTRUCT_H_
|
||||
|
||||
/*****************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include "embtypes.h"
|
||||
|
||||
#include "bytequeue.h"
|
||||
#include "bytestack.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* macros
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* global constants
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* global variables
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* C function prototypes
|
||||
*****************************************************************************/
|
||||
|
||||
#endif
|
||||
291
include/embtypes.h
Normal file
291
include/embtypes.h
Normal file
@ -0,0 +1,291 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (C) 2008
|
||||
* ProbeStar Telematics, LLC
|
||||
* All Rights Reserved. Proprietary and Confidential.
|
||||
*============================================================================
|
||||
* Multiplatform Embedded Data Types and Conversion
|
||||
* Checksum and CRC Routines
|
||||
*****************************************************************************/
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef _EMBTYPES_H_
|
||||
#define _EMBTYPES_H_
|
||||
|
||||
/*****************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef ON
|
||||
#define ON 1
|
||||
#define OFF 0
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
/* take out those keywords */
|
||||
#define interrupt
|
||||
#define near
|
||||
#define far
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
* macros
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
// data types
|
||||
#ifdef __linux__
|
||||
typedef unsigned char bit;
|
||||
#else
|
||||
typedef bit BOOL;
|
||||
#endif
|
||||
|
||||
// ProbeStar Standard
|
||||
typedef signed char CHAR;
|
||||
typedef signed short SHORT;
|
||||
typedef signed int INT;
|
||||
typedef signed long LONG;
|
||||
typedef signed long long LLONG;
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned int UINT;
|
||||
typedef unsigned long DWORD;
|
||||
typedef unsigned long long QWORD;
|
||||
|
||||
typedef signed char int8;
|
||||
typedef signed short int16;
|
||||
typedef signed long int32;
|
||||
typedef signed long long int64;
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned long uint32;
|
||||
typedef unsigned long long uint64;
|
||||
|
||||
typedef signed char S8;
|
||||
typedef signed short S16;
|
||||
typedef signed long S32;
|
||||
typedef signed long long S64;
|
||||
typedef unsigned char U8;
|
||||
typedef unsigned short U16;
|
||||
typedef unsigned long U32;
|
||||
typedef unsigned long long U64;
|
||||
|
||||
#ifdef BIG_ENDIAN
|
||||
|
||||
typedef union
|
||||
{
|
||||
WORD w;
|
||||
SHORT s;
|
||||
struct
|
||||
{
|
||||
BYTE h;
|
||||
BYTE l;
|
||||
}
|
||||
b;
|
||||
BYTE c[2];
|
||||
} __attribute__((__packed__)) short_word;
|
||||
|
||||
typedef union
|
||||
{
|
||||
DWORD dw;
|
||||
LONG l;
|
||||
struct
|
||||
{
|
||||
WORD h;
|
||||
WORD l;
|
||||
}
|
||||
w;
|
||||
short s[2];
|
||||
struct
|
||||
{
|
||||
short_word h;
|
||||
short_word l;
|
||||
}
|
||||
sw;
|
||||
struct
|
||||
{
|
||||
BYTE hh;
|
||||
BYTE hl;
|
||||
BYTE lh;
|
||||
BYTE ll;
|
||||
}
|
||||
b;
|
||||
BYTE c[4];
|
||||
} __attribute__((__packed__)) long_dword;
|
||||
|
||||
typedef union
|
||||
{
|
||||
QWORD qw;
|
||||
LLONG ll;
|
||||
struct
|
||||
{
|
||||
DWORD h;
|
||||
DWORD l;
|
||||
} dw;
|
||||
long l[2];
|
||||
struct
|
||||
{
|
||||
WORD hh;
|
||||
WORD hl;
|
||||
WORD lh;
|
||||
WORD ll;
|
||||
}
|
||||
w;
|
||||
short s[4];
|
||||
struct
|
||||
{
|
||||
short_word hh;
|
||||
short_word hl;
|
||||
short_word lh;
|
||||
short_word ll;
|
||||
}
|
||||
sw;
|
||||
struct
|
||||
{
|
||||
BYTE hhh;
|
||||
BYTE hhl;
|
||||
BYTE hlh;
|
||||
BYTE hll;
|
||||
BYTE lhh;
|
||||
BYTE lhl;
|
||||
BYTE llh;
|
||||
BYTE lll;
|
||||
}
|
||||
b;
|
||||
BYTE c[8];
|
||||
} __attribute__((__packed__)) llong_qword;
|
||||
|
||||
#elif defined(LITTLE_ENDIAN)
|
||||
|
||||
// new
|
||||
typedef union
|
||||
{
|
||||
WORD w;
|
||||
SHORT s;
|
||||
struct
|
||||
{
|
||||
BYTE l;
|
||||
BYTE h;
|
||||
}
|
||||
b;
|
||||
BYTE c[2];
|
||||
} __attribute__((__packed__)) short_word;
|
||||
|
||||
typedef union
|
||||
{
|
||||
DWORD dw;
|
||||
LONG l;
|
||||
struct
|
||||
{
|
||||
WORD l;
|
||||
WORD h;
|
||||
}
|
||||
w;
|
||||
short s[2];
|
||||
struct
|
||||
{
|
||||
short_word l;
|
||||
short_word h;
|
||||
}
|
||||
sw;
|
||||
struct
|
||||
{
|
||||
BYTE ll;
|
||||
BYTE lh;
|
||||
BYTE hl;
|
||||
BYTE hh;
|
||||
}
|
||||
b;
|
||||
BYTE c[4];
|
||||
} __attribute__((__packed__)) long dword;
|
||||
|
||||
typedef union
|
||||
{
|
||||
QWORD qw;
|
||||
LLONG ll;
|
||||
struct
|
||||
{
|
||||
DWORD l;
|
||||
DWORD h;
|
||||
} dw;
|
||||
long l[2];
|
||||
struct
|
||||
{
|
||||
WORD ll;
|
||||
WORD lh;
|
||||
WORD hl;
|
||||
WORD hh;
|
||||
}
|
||||
w;
|
||||
short s[4];
|
||||
struct
|
||||
{
|
||||
short_word ll;
|
||||
short_word lh;
|
||||
short_word hl;
|
||||
short_word hh;
|
||||
}
|
||||
sw;
|
||||
struct
|
||||
{
|
||||
BYTE lll;
|
||||
BYTE llh;
|
||||
BYTE lhl;
|
||||
BYTE lhh;
|
||||
BYTE hll;
|
||||
BYTE hlh;
|
||||
BYTE hhl;
|
||||
BYTE hhh;
|
||||
}
|
||||
b;
|
||||
BYTE c[8];
|
||||
} __attribute__((__packed__)) llong_qword;
|
||||
|
||||
#endif
|
||||
|
||||
typedef union
|
||||
{
|
||||
BYTE byte;
|
||||
struct {
|
||||
unsigned b0:1;
|
||||
unsigned b1:1;
|
||||
unsigned b2:1;
|
||||
unsigned b3:1;
|
||||
unsigned b4:1;
|
||||
unsigned b5:1;
|
||||
unsigned b6:1;
|
||||
unsigned b7:1;
|
||||
} bits;
|
||||
} byte_bits;
|
||||
|
||||
/*****************************************************************************
|
||||
* global constants
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* global variables
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* C function prototypes
|
||||
*****************************************************************************/
|
||||
|
||||
#endif
|
||||
63
include/libcan++/CanDatabase.h
Normal file
63
include/libcan++/CanDatabase.h
Normal file
@ -0,0 +1,63 @@
|
||||
//****************************************************************************
|
||||
// Copyright (C) 2007
|
||||
// Nissan North America
|
||||
// All Rights Reserved. Proprietary and Confidential.
|
||||
//============================================================================
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __CanDatabase__
|
||||
#define __CanDatabase__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
#include "CanSignal.h"
|
||||
#include "CanSocket.h"
|
||||
#include "DbcParser.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
/**
|
||||
* CAN class to handle database of CAN signals from DBC (.dbc) file
|
||||
*/
|
||||
class CanDatabase : public DbcParser {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
CanDatabase();
|
||||
|
||||
// destructor
|
||||
virtual ~CanDatabase();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int FormatHeader( char *buf, int max );
|
||||
int FormatMessage( char *buf, int max );
|
||||
|
||||
int SubscribeCan( CanSocket *pCan );
|
||||
int ReadCan( CanSocket *pCan );
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
74
include/libcan++/CanMessage.h
Normal file
74
include/libcan++/CanMessage.h
Normal file
@ -0,0 +1,74 @@
|
||||
//****************************************************************************
|
||||
// Copyright (C) 2007
|
||||
// Nissan North America
|
||||
// All Rights Reserved. Proprietary and Confidential.
|
||||
//============================================================================
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __CanMessage__
|
||||
#define __CanMessage__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "CanSignal.h"
|
||||
#include "CanSocket.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
// based on .dbc data
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||
//
|
||||
class CanMessage {
|
||||
// public data
|
||||
public:
|
||||
std::string Name; // Signal Name
|
||||
std::string Module; // Module Name
|
||||
u_int32_t Address; // 29 bits (standard or extended)
|
||||
u_int8_t Data[64]; // Data
|
||||
u_int Size; // DLC (CAN-FD > 8)
|
||||
|
||||
|
||||
// list of signals in the message
|
||||
std::vector<CanSignal *> Signals;
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
CanMessage();
|
||||
|
||||
// destructor
|
||||
virtual ~CanMessage();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int Read(CanFrame *frame);
|
||||
int Write(CanFrame *frame);
|
||||
int Convert(CanFrame *frame) {return Read(frame);};
|
||||
int Subscribe(void);
|
||||
int Unsubscribe(void);
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
116
include/libcan++/CanSignal.h
Normal file
116
include/libcan++/CanSignal.h
Normal file
@ -0,0 +1,116 @@
|
||||
//****************************************************************************
|
||||
// Copyright (C) 2007
|
||||
// Nissan North America
|
||||
// All Rights Reserved. Proprietary and Confidential.
|
||||
//============================================================================
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __CanSignal__
|
||||
#define __CanSignal__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
//#include "BaseSignal.h"
|
||||
//#include "VoltType.h"
|
||||
|
||||
#include "CanSocket.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
// based on .dbc data
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||
//
|
||||
#ifdef __BaseSignal__
|
||||
class CanSignal : public BaseSignal, public VoltType {
|
||||
#else
|
||||
class CanSignal {
|
||||
#endif
|
||||
// public data
|
||||
public:
|
||||
std::string Name; // Signal Name
|
||||
std::string Units; // Signal Units
|
||||
u_int32_t Address; // 29 bits (standard or extended)
|
||||
|
||||
// data conversion (from .dbc file)
|
||||
u_char StartBit; // 0..63
|
||||
u_char NumBits; // 1..32
|
||||
u_char BigEndian; // 0 = little endian (intel), 1 = big endian (moto)
|
||||
u_char IsSigned; // 0 = unsigned, 1 = 2's Complement
|
||||
double Scale; // scale
|
||||
double Offset; // offset
|
||||
|
||||
// conversion help
|
||||
u_char StartByte; // 0..7
|
||||
u_char NumBytes; // 1..4
|
||||
u_char HighBit; // 0..7
|
||||
u_char LowBit; // #bits after
|
||||
u_int64_t Mask; // 64 bit mask
|
||||
u_int64_t Sign; // 64 bit sign mask
|
||||
|
||||
// status, data
|
||||
u_char doSubscribe; // CanSocket filter
|
||||
u_char isNew;
|
||||
u_char isValid;
|
||||
int32_t rawValue;
|
||||
int64_t currValue;
|
||||
int64_t lastValue;
|
||||
double realValue;
|
||||
|
||||
// misc
|
||||
u_int64_t activity; // activity counter
|
||||
void *userData; // user data
|
||||
int userIndex; // user index
|
||||
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
CanSignal();
|
||||
|
||||
// destructor
|
||||
virtual ~CanSignal();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int Init( void );
|
||||
int Convert(CanFrame *frame) {return Read(frame->data);};
|
||||
int Read(CanFrame *frame) {return Read(frame->data);};
|
||||
int Read(const u_char *pbyData, long *ldata=NULL, double *ddata=NULL);
|
||||
int Write(CanFrame *frame) {return Write(frame->data);};
|
||||
int Write(u_char *pbyData);
|
||||
int Write(long value, u_char *pbyData);
|
||||
long Write(double value, u_char *pbyData);
|
||||
void Subscribe(void) {doSubscribe=1;};
|
||||
void Unsubscribe(void) {doSubscribe=0;};
|
||||
|
||||
#ifndef __VoltType__
|
||||
void SetScaling( double scale=1.0, double offset=0.0 ) { Scale=scale; Offset=offset; };
|
||||
double GetScale( void ) { return Scale; };
|
||||
double GetOffset( void ) { return Offset; };
|
||||
#endif
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
101
include/libcan++/CanSocket.h
Normal file
101
include/libcan++/CanSocket.h
Normal file
@ -0,0 +1,101 @@
|
||||
//****************************************************************************
|
||||
// Copyright (C) 2007
|
||||
// Nissan North America
|
||||
// All Rights Reserved. Proprietary and Confidential.
|
||||
//============================================================================
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __CanSocket__
|
||||
#define __CanSocket__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include <linux/can.h>
|
||||
#include <linux/can/raw.h>
|
||||
#include <linux/can/bcm.h>
|
||||
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
#define CAN_MAX_FILTER 31
|
||||
#define CAN_MAX_ADDRESSES 256
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
typedef struct can_filter CanFilter;
|
||||
typedef struct can_frame CanFrame;
|
||||
|
||||
typedef struct _BcmFrame {
|
||||
struct bcm_msg_head head;
|
||||
struct can_frame frame;
|
||||
} BcmFrame;
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||
//
|
||||
class CanSocket {
|
||||
// public data
|
||||
public:
|
||||
int m_sock;
|
||||
int m_proto;
|
||||
|
||||
// private data
|
||||
private:
|
||||
// device
|
||||
int m_flags;
|
||||
|
||||
// errors
|
||||
bool m_logerrs;
|
||||
long m_errcount;
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
CanSocket();
|
||||
|
||||
// destructor
|
||||
virtual ~CanSocket();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
void AddrFlags( u_long f ) { m_flags = f; };
|
||||
int GetSock(void) {return m_sock;};
|
||||
int GetSocket(void) {return m_sock;};
|
||||
int GetProto(void) {return m_proto;};
|
||||
int CanOpen( const char *dev="can0", int proto=CAN_RAW, int flags=0 );
|
||||
void CanClose(void);
|
||||
|
||||
// misc
|
||||
int ClearFilters( void );
|
||||
int Blocking(bool block=true);
|
||||
int NonBlocking(void) { return Blocking(false); };
|
||||
int Loopback(bool loop=true);
|
||||
int NoLoopback(void) { return Loopback(false); };
|
||||
void LogErrors(bool logerrs=true) {m_logerrs = logerrs;};
|
||||
|
||||
// rx filter
|
||||
int CanAddRx( u_int32_t addr );
|
||||
int CanAddRx( const CanFilter *filter, int max=1 );
|
||||
int CanDelRx( u_int32_t addr );
|
||||
|
||||
// raw
|
||||
int CanRawRead( CanFrame *buf, int max=1 );
|
||||
int CanRawWrite( const CanFrame *buf, int max=1 );
|
||||
|
||||
// bcm
|
||||
int CanBcmRead( BcmFrame *msg, int max=1 );
|
||||
int CanBcmWrite( BcmFrame *msg, int max=1 );
|
||||
};
|
||||
|
||||
#endif
|
||||
87
include/libcan++/DbcParser.h
Normal file
87
include/libcan++/DbcParser.h
Normal file
@ -0,0 +1,87 @@
|
||||
//****************************************************************************
|
||||
// Copyright (C) 2007
|
||||
// Nissan North America
|
||||
// All Rights Reserved. Proprietary and Confidential.
|
||||
//============================================================================
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __DbcParser__
|
||||
#define __DbcParser__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <regex.h>
|
||||
#include <vector>
|
||||
|
||||
#include "CanMessage.h"
|
||||
#include "CanSignal.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
// based on .dbc data
|
||||
typedef struct _DbcFilter {
|
||||
// signal information
|
||||
char Name[32]; // Signal name
|
||||
regex_t preg;
|
||||
|
||||
// address range
|
||||
u_int32_t CanAddrLo; // 29 bits
|
||||
u_int32_t CanAddrHi;
|
||||
|
||||
// data conversion
|
||||
u_char StartBit; // 0..63
|
||||
u_char NumBits; // 1..32
|
||||
|
||||
int found;
|
||||
} DbcFilter;
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||
//
|
||||
class DbcParser {
|
||||
// public data
|
||||
public:
|
||||
std::vector<DbcFilter *> MsgFilters; // message filter
|
||||
std::vector<DbcFilter *> SigFilters; // signal filter
|
||||
std::vector<CanMessage *> Messages;
|
||||
std::vector<CanSignal *> Signals;
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// private methods
|
||||
DbcFilter *AddFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
DbcParser();
|
||||
|
||||
// destructor
|
||||
virtual ~DbcParser();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int AddMsgFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
||||
int AddSigFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
|
||||
int AddMessage( char *name, u_int32_t addr, u_int32_t size, char *module );
|
||||
int AddSignal( char *name, char *units, u_int32_t addr, char start, char num, char endian, char sign, float scale, float offset );
|
||||
|
||||
int LoadDatabase( const char *file );
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
62
include/libgps++/ApplanixParser.h
Normal file
62
include/libgps++/ApplanixParser.h
Normal file
@ -0,0 +1,62 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __ApplanixParser__
|
||||
#define __ApplanixParser__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "GpsListener.h"
|
||||
#include "GpsParser.h"
|
||||
|
||||
#include "NmeaParser.h"
|
||||
#include "NmeaProtocol.h"
|
||||
//#include "ApplanixProtocol.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
class ApplanixParser : public NmeaParser {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
// data
|
||||
u_char state; // parser state
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
ApplanixParser();
|
||||
|
||||
// destructor
|
||||
virtual ~ApplanixParser();
|
||||
|
||||
// virtual functions
|
||||
int GpsDecode( const char *buf, int max ) { return ApplanixDecode( (const u_char *)buf, max); };
|
||||
int GpsParse( const char *buf, int max ) { return ApplanixParse( buf, max ); };
|
||||
|
||||
// public methods
|
||||
int ApplanixDecode( const u_char *buf, int max );
|
||||
int ApplanixParse( const char *buf, int max );
|
||||
};
|
||||
|
||||
#endif
|
||||
56
include/libgps++/DgpsClient.h
Normal file
56
include/libgps++/DgpsClient.h
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __DgpsClient__
|
||||
#define __DgpsClient__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "TcpClient.h"
|
||||
#include "netlib.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class DgpsClient : public TcpClient {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
unsigned long count;
|
||||
|
||||
// private methods
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
DgpsClient();
|
||||
|
||||
// destructor
|
||||
virtual ~DgpsClient();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int DgpsConnect( const char *host, const char *service );
|
||||
void DgpsClose(void) {Close();};
|
||||
|
||||
int DgpsRead( char *buf, int max );
|
||||
int DgpsWrite( const char *buf, int max );
|
||||
};
|
||||
|
||||
#endif
|
||||
73
include/libgps++/FastraxParser.h
Normal file
73
include/libgps++/FastraxParser.h
Normal file
@ -0,0 +1,73 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __FastraxParser__
|
||||
#define __FastraxParser__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "GpsListener.h"
|
||||
#include "GpsParser.h"
|
||||
|
||||
#include "NmeaParser.h"
|
||||
#include "NmeaProtocol.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
// Fastrax iTrax03
|
||||
class NmeaSentencePFST : public NmeaSentence {
|
||||
public:
|
||||
char msg[4];
|
||||
|
||||
NmeaSentencePFST();
|
||||
~NmeaSentencePFST();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class FastraxParser : public NmeaParser {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
// Fastrax iTrax03
|
||||
NmeaSentencePFST PFST;
|
||||
|
||||
// private data
|
||||
private:
|
||||
// data
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
FastraxParser();
|
||||
|
||||
// destructor
|
||||
virtual ~FastraxParser();
|
||||
|
||||
// virtual functions
|
||||
int GpsDecode( const char *buf, int max ) { return FastraxDecode( (const u_char *)buf, max); };
|
||||
int GpsParse( const char *buf, int max ) { return FastraxParse( buf, max ); };
|
||||
|
||||
// public methods
|
||||
int FastraxDecode( const u_char *buf, int max );
|
||||
int FastraxParse( const char *buf, int max );
|
||||
};
|
||||
|
||||
#endif
|
||||
125
include/libgps++/GarminParser.h
Normal file
125
include/libgps++/GarminParser.h
Normal file
@ -0,0 +1,125 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __GarminParser__
|
||||
#define __GarminParser__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "GpsListener.h"
|
||||
#include "GpsParser.h"
|
||||
|
||||
#include "NmeaParser.h"
|
||||
#include "NmeaProtocol.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
|
||||
// Garmin
|
||||
class NmeaSentencePGRME : public NmeaSentence {
|
||||
public:
|
||||
float horizontal;
|
||||
char horizontal_unit[4];
|
||||
float vertical;
|
||||
char vertical_unit[4];
|
||||
float three_dimensions;
|
||||
char three_dimensions_unit[4];
|
||||
|
||||
NmeaSentencePGRME();
|
||||
~NmeaSentencePGRME();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentencePGRMF : public NmeaSentence {
|
||||
public:
|
||||
int week;
|
||||
int seconds;
|
||||
struct timespec utctime;
|
||||
int leap;
|
||||
double latitude;
|
||||
double longitude;
|
||||
char mode;
|
||||
int type;
|
||||
double speed;
|
||||
double course;
|
||||
double position_dilution;
|
||||
double time_dilution;
|
||||
|
||||
NmeaSentencePGRMF();
|
||||
~NmeaSentencePGRMF();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentencePGRMM : public NmeaSentence {
|
||||
public:
|
||||
char datum[256];
|
||||
|
||||
NmeaSentencePGRMM();
|
||||
~NmeaSentencePGRMM();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentencePGRMZ : public NmeaSentence {
|
||||
public:
|
||||
|
||||
NmeaSentencePGRMZ();
|
||||
~NmeaSentencePGRMZ();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
// main class
|
||||
class GarminParser : public NmeaParser {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
// Garmin
|
||||
NmeaSentencePGRME PGRME;
|
||||
NmeaSentencePGRMF PGRMF;
|
||||
NmeaSentencePGRMM PGRMM;
|
||||
|
||||
// private data
|
||||
private:
|
||||
// data
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
GarminParser();
|
||||
|
||||
// destructor
|
||||
virtual ~GarminParser();
|
||||
|
||||
// virtual functions
|
||||
int GpsDecode( const char *buf, int max ) { return GarminDecode( (const u_char *)buf, max); };
|
||||
int GpsParse( const char *buf, int max ) { return GarminParse( buf, max ); };
|
||||
|
||||
// public methods
|
||||
int GarminDecode( const u_char *buf, int max );
|
||||
int GarminParse( const char *buf, int max );
|
||||
};
|
||||
|
||||
#endif
|
||||
52
include/libgps++/GpsDevice.h
Normal file
52
include/libgps++/GpsDevice.h
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __GpsDevice__
|
||||
#define __GpsDevice__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "SerialIO.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class GpsDevice : public SerialIO {
|
||||
// public data
|
||||
public:
|
||||
// parser
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
GpsDevice();
|
||||
|
||||
// destructor
|
||||
virtual ~GpsDevice();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int GpsOpen( const char *dev, int baud=38400 );
|
||||
int GpsRead( char *buf, int max ) {return Read(buf,max); };
|
||||
int GpsWrite( const char *buf, int max ) {return Write(buf,max); };
|
||||
void GpsClose(void) { Close(); };
|
||||
};
|
||||
|
||||
#endif
|
||||
95
include/libgps++/GpsListener.h
Normal file
95
include/libgps++/GpsListener.h
Normal file
@ -0,0 +1,95 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __GpsListener__
|
||||
#define __GpsListener__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "GpsPoint.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
#define NMEA_MAX_SATELLITE 32
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
typedef struct _ErrorInfo {
|
||||
// GPGSA dilution of precision (DOP)
|
||||
double PositionDilution; // PDOP
|
||||
double HorizontalDilution; // HDOP
|
||||
double VerticalDilution; // VDOP
|
||||
|
||||
// GPGST standard deviation of error
|
||||
double HorizontalDeviation; // largest
|
||||
double VerticalDeviation;
|
||||
|
||||
// PUBX-01
|
||||
double HorizontalAccuracy;
|
||||
double VerticalAccuracy;
|
||||
double TimeDilution; // TDOP
|
||||
} ErrorInfo;
|
||||
|
||||
typedef struct _SatelliteInfo {
|
||||
// GPGSV, PUBX-03
|
||||
u_int Satellites;
|
||||
struct {
|
||||
char Id;
|
||||
char Status;
|
||||
double Elevation;
|
||||
double Azimuth;
|
||||
double Signal2noise;
|
||||
} Satellite[NMEA_MAX_SATELLITE];
|
||||
} SatelliteInfo;
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
class GpsListener {
|
||||
// public data
|
||||
public:
|
||||
// Position Data
|
||||
GpsPoint PosData;
|
||||
|
||||
// Accuracy, Dilution, Error
|
||||
ErrorInfo ErrInfo;
|
||||
|
||||
// Satellite info
|
||||
SatelliteInfo SatInfo;
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// private methods
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
GpsListener();
|
||||
|
||||
// destructor
|
||||
virtual ~GpsListener();
|
||||
|
||||
// virtual functions
|
||||
virtual void PositionListener( const GpsPoint &Pos, const ErrorInfo &Err );
|
||||
virtual void TimeListener( const struct timespec &Time );
|
||||
|
||||
// public methods
|
||||
int GpsTime( struct timespec *tv ) {*tv=PosData.TimeStamp;return PosData.Fix;};
|
||||
int GpsFix(void) {return PosData.Fix;};
|
||||
};
|
||||
|
||||
#endif
|
||||
81
include/libgps++/GpsMath.h
Normal file
81
include/libgps++/GpsMath.h
Normal file
@ -0,0 +1,81 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __GpsMath__
|
||||
#define __GpsMath__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include "netlib.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
// degrees <-> radians
|
||||
#define DEG2RAD(X) ((X)*M_PI/180.0)
|
||||
#define RAD2DEG(X) ((X)*180.0/M_PI)
|
||||
|
||||
// (nautical mile to km) to meters per degree
|
||||
#define MPERDEG (111.13285*1000.0)
|
||||
#define EARTHRADIUS 6378100.0 // meters
|
||||
|
||||
// speed conversions
|
||||
#define KNOTS_KPH 1.85200
|
||||
#define KNOTS_METERSPERSEC (KNOTS_KPH*1000.0/3600.0)
|
||||
|
||||
#define KPH2MSEC(X) ((X)*0.277777778)
|
||||
#define MSEC2KPH(X) ((X)/0.277777778)
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
|
||||
//
|
||||
class GpsMath {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// parser
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
// static data
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
GpsMath();
|
||||
|
||||
// destructor
|
||||
virtual ~GpsMath();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
|
||||
// static methods
|
||||
static double Minutes2Degrees(char *value, char *side = NULL);
|
||||
static void Degrees2Minutes(double deg, char *buf, int max, bool lat);
|
||||
static timespec String2Time(const char *hhmmss, const char *ddmmyy);
|
||||
|
||||
static double Bearing( double lat1, double lon1, double lat2, double lon2 );
|
||||
static double Distance( double lat1, double lon1, double lat2, double lon2 );
|
||||
static double DistanceX( double lat1, double lon1, double lat2, double lon2 );
|
||||
static double DistanceY( double lat1, double lon1, double lat2, double lon2 );
|
||||
static double DistanceXY(double lat1, double lon1, double lat2, double lon2, double &x, double &y );
|
||||
static double Travel( double *lat, double *lon, double *ele, double x, double y, double z);
|
||||
};
|
||||
|
||||
#endif
|
||||
93
include/libgps++/GpsParser.h
Normal file
93
include/libgps++/GpsParser.h
Normal file
@ -0,0 +1,93 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __GpsParser__
|
||||
#define __GpsParser__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "GpsListener.h"
|
||||
#include "NmeaProtocol.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
class GpsParser : public NmeaProtocol {
|
||||
// public data
|
||||
public:
|
||||
char Vendor[32];
|
||||
char Product[32];
|
||||
|
||||
// Position Data
|
||||
GpsPoint PosData;
|
||||
|
||||
// Accuracy, Dilution, Error
|
||||
ErrorInfo ErrInfo;
|
||||
|
||||
// Satellite info
|
||||
SatelliteInfo SatInfo;
|
||||
|
||||
protected:
|
||||
// protected data
|
||||
std::vector<GpsListener *> GpsListeners;
|
||||
|
||||
// incoming data buffer
|
||||
u_char data[2048];
|
||||
u_char lastc;
|
||||
u_short numbytes; // current byte count
|
||||
u_short totbytes; // expect byte count
|
||||
u_short checksum;
|
||||
u_long counter; // # parsed
|
||||
|
||||
// private data
|
||||
private:
|
||||
// private methods
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
GpsParser();
|
||||
|
||||
// destructor
|
||||
virtual ~GpsParser();
|
||||
|
||||
// virtual functions
|
||||
virtual void GpsInit( void ) {};
|
||||
virtual int GpsDecode( const char *buf, int max );
|
||||
virtual int GpsParse( const char *buf, int max );
|
||||
|
||||
// public methods
|
||||
|
||||
// subscribe/unsubscribe
|
||||
void Subscribe( GpsListener *ear ) {
|
||||
GpsInit();
|
||||
if (ear)
|
||||
GpsListeners.push_back(ear);
|
||||
};
|
||||
|
||||
int GetNumParsed(void) {return counter;};
|
||||
|
||||
// misc
|
||||
int GpsTime( struct timespec *tv ) {*tv=PosData.TimeStamp;return PosData.Fix;};
|
||||
int GpsFix(void) {return PosData.Fix;};
|
||||
int Gps2Vii( char *buf, int max );
|
||||
|
||||
// static functions
|
||||
};
|
||||
|
||||
#endif
|
||||
123
include/libgps++/GpsPoint.h
Normal file
123
include/libgps++/GpsPoint.h
Normal file
@ -0,0 +1,123 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __GpsPoint__
|
||||
#define __GpsPoint__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "GpsMath.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// Gps Point on the planet
|
||||
//
|
||||
class GpsPoint : public GpsMath {
|
||||
// public data
|
||||
public:
|
||||
timespec TimeStamp;
|
||||
double Latitude;
|
||||
double Longitude;
|
||||
double Altitude;
|
||||
double Speed; // m/sec
|
||||
double Heading; // deg
|
||||
|
||||
// fix information (GpsListener) for point
|
||||
int Fix; // GPGGA
|
||||
int Mode; // GPGSA
|
||||
int Type; // GPGSA
|
||||
double Accel; // m/sec2
|
||||
double Yaw; // deg/sec (-left, +right)
|
||||
|
||||
// parser
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
// static data
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
GpsPoint();
|
||||
GpsPoint( double lat, double lon );
|
||||
GpsPoint(const GpsPoint ©);
|
||||
|
||||
// destructor
|
||||
virtual ~GpsPoint();
|
||||
|
||||
// operators
|
||||
GpsPoint &operator=(const GpsPoint &rhs);
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
double GetLatitude(void) {return Latitude;};
|
||||
double GetLongitude(void) {return Longitude;};
|
||||
double GetAltitude(void) {return Altitude;};
|
||||
double GetElevation(void) {return Altitude;};
|
||||
void GetPosition( double *lat, double *lon, double *elev=NULL );
|
||||
double GetSpeed(void) {return Speed;};
|
||||
double GetHeading(void) {return Heading;};
|
||||
timespec GetTimeVal(void) {return TimeStamp;};
|
||||
uint64_t GetTimeStamp(void) {return (TimeStamp.tv_sec*1000L)+(TimeStamp.tv_nsec/1000000L);};
|
||||
time_t GetTimeStampSec(void) {return TimeStamp.tv_sec;};
|
||||
|
||||
void SetLatitude(double lat) {Latitude = lat;};
|
||||
void SetLongitude(double lon) {Longitude = lon;};
|
||||
void SetAltitude(double alt) {Altitude = alt;};
|
||||
void SetElevation(double ele) {Altitude = ele;};
|
||||
void SetPosition(double lat, double lon, double ele = 0.0)
|
||||
{Latitude=lat;Longitude=lon;Altitude=ele;};
|
||||
void SetSpeed(double spd) {Speed = spd;}; // kph
|
||||
void SetHeading(double hdg) {Heading = hdg;};
|
||||
void SetTimeStamp(timespec &tv) {TimeStamp=tv;};
|
||||
void SetTimeStamp(time_t t) {TimeStamp.tv_sec=t;TimeStamp.tv_nsec=0;};
|
||||
void SetTimeStamp(uint64_t t);
|
||||
void SetTimeStamp(double t);
|
||||
void SetTimeStamp(const char *str);
|
||||
|
||||
void AddMeters( double x, double y ); // add meters
|
||||
void Extrapolate( double speed, double accel, double yaw, double time );
|
||||
|
||||
double Bearing( const GpsPoint &gpt ); // bearing to point
|
||||
double Distance( const GpsPoint &gpt ); // distance to point
|
||||
double Distance( double lat, double lon );
|
||||
double Travel( double x, double y, double z );
|
||||
|
||||
double DistanceX( const GpsPoint &gpt )
|
||||
{ return GpsMath::DistanceX(Latitude, Longitude, gpt.Latitude, gpt.Longitude); };
|
||||
double DistanceY( const GpsPoint &gpt )
|
||||
{ return GpsMath::DistanceY(Latitude, Longitude, gpt.Latitude, gpt.Longitude); };
|
||||
double DistanceX(double lat, double lon)
|
||||
{ return GpsMath::DistanceX(Latitude, Longitude, Latitude, lon); };
|
||||
double DistanceY(double lat, double lon)
|
||||
{ return GpsMath::DistanceY(Latitude, Longitude, lat, Longitude); };
|
||||
double DistanceX(double lon)
|
||||
{ return GpsMath::DistanceX(Latitude, Longitude, Latitude, lon); };
|
||||
double DistanceY(double lat)
|
||||
{ return GpsMath::DistanceY(Latitude, Longitude, lat, Longitude); };
|
||||
|
||||
double DistanceXY( const GpsPoint &gpt1, const GpsPoint &gpt2, double &x, double &y );
|
||||
double DistanceXY( const GpsPoint &gpt1, double lat, double lon, double &x, double &y );
|
||||
|
||||
bool Inside( const GpsPoint polygon[], int num );
|
||||
bool Traversed( GpsPoint &gpt, const GpsPoint polygon[], int num );
|
||||
|
||||
// static methods
|
||||
};
|
||||
|
||||
#endif
|
||||
70
include/libgps++/GpsTrack.h
Normal file
70
include/libgps++/GpsTrack.h
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __GpsTrack__
|
||||
#define __GpsTrack__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "GpsPoint.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
typedef std::vector<GpsPoint> GpsTrack_t;
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
|
||||
//
|
||||
class GpsTrack {
|
||||
// public data
|
||||
public:
|
||||
char Name[64];
|
||||
GpsTrack_t Points;
|
||||
|
||||
// parser
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
// static data
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
GpsTrack();
|
||||
GpsTrack(const char *name);
|
||||
GpsTrack(const GpsTrack ©);
|
||||
|
||||
// destructor
|
||||
virtual ~GpsTrack();
|
||||
|
||||
// operators
|
||||
GpsTrack &operator=(const GpsTrack &rhs);
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
void SetName( const char *name ) { strncpy(Name,name,sizeof(Name)-1); };
|
||||
int AddPoint( const GpsPoint &Pt );
|
||||
|
||||
int GenerateKML( const char *kmlfile );
|
||||
int ParseKML( const char *kmlfile );
|
||||
|
||||
// static methods
|
||||
};
|
||||
|
||||
#endif
|
||||
70
include/libgps++/GpsdClient.h
Normal file
70
include/libgps++/GpsdClient.h
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __GpsdClient__
|
||||
#define __GpsdClient__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "TcpClient.h"
|
||||
#include "netlib.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// Connect to http://gpsd.berlios.de/ GPSD
|
||||
//
|
||||
class GpsdClient : public TcpClient {
|
||||
// public data
|
||||
public:
|
||||
int Fix;
|
||||
int Satellites;
|
||||
|
||||
struct timespec Time;
|
||||
double Latitude;
|
||||
double Longitude;
|
||||
double Elevation;
|
||||
double Heading;
|
||||
double Speed;
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
GpsdClient();
|
||||
GpsdClient( const char *host );
|
||||
|
||||
// destructor
|
||||
virtual ~GpsdClient();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int GpsdParse( char *msg );
|
||||
int GpsdConnect( const char *host = "localhost" );
|
||||
|
||||
int GpsdRead( void );
|
||||
int GpsdWrite( const char *msg, int max );
|
||||
|
||||
int Gpsd2Vii( char *buf, int max );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
73
include/libgps++/KmlFile.h
Normal file
73
include/libgps++/KmlFile.h
Normal file
@ -0,0 +1,73 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __KmlFile__
|
||||
#define __KmlFile__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "GpsTrack.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
|
||||
//
|
||||
class KmlFile {
|
||||
// public data
|
||||
public:
|
||||
xmlDocPtr xmlDoc;
|
||||
xmlNodePtr xmlRoot;
|
||||
|
||||
// folders we're interested in
|
||||
xmlNodePtr xmlRoutes;
|
||||
xmlNodePtr xmlTracks;
|
||||
xmlNodePtr xmlWaypoints;
|
||||
|
||||
// parser
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
FILE *fileKml;
|
||||
|
||||
// private data
|
||||
private:
|
||||
// static data
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
KmlFile();
|
||||
|
||||
// destructor
|
||||
virtual ~KmlFile();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int Open( const char *file );
|
||||
void Close( void );
|
||||
int Create( const char *file );
|
||||
|
||||
GpsTrack *GetTracks(void);
|
||||
|
||||
// static methods
|
||||
static time_t ParseTime( const char *time );
|
||||
};
|
||||
|
||||
#endif
|
||||
86
include/libgps++/NmeaParser.h
Normal file
86
include/libgps++/NmeaParser.h
Normal file
@ -0,0 +1,86 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
// NMEA Parser code stolen from Pascal Martin's RoadMap
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __NmeaParser__
|
||||
#define __NmeaParser__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "GpsListener.h"
|
||||
#include "GpsParser.h"
|
||||
|
||||
#include "NmeaProtocol.h"
|
||||
#include "NmeaSentence.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
class NmeaParser : public GpsParser {
|
||||
// public data
|
||||
public:
|
||||
|
||||
protected:
|
||||
// private data
|
||||
std::vector<NmeaSentence *> NmeaSentences;
|
||||
|
||||
// Standard
|
||||
NmeaSentenceGPRMC GPRMC;
|
||||
NmeaSentenceGPVTG GPVTG;
|
||||
NmeaSentenceGPGGA GPGGA;
|
||||
NmeaSentenceGPGSA GPGSA;
|
||||
NmeaSentenceGPGSV GPGSV;
|
||||
NmeaSentenceGPGLL GPGLL;
|
||||
NmeaSentenceGPGST GPGST;
|
||||
NmeaSentenceGPZDA GPZDA;
|
||||
|
||||
// private data
|
||||
private:
|
||||
// incoming data buffer
|
||||
|
||||
// NMEA record for notification
|
||||
char posfixnmea[8];
|
||||
char timefixnmea[8];
|
||||
|
||||
// private methods
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
NmeaParser();
|
||||
|
||||
// destructor
|
||||
virtual ~NmeaParser();
|
||||
|
||||
// virtual functions
|
||||
int GpsDecode( const char *buf, int max ) { return NmeaDecode( buf, max ); };
|
||||
int GpsParse( const char *buf, int max ) { return NmeaParse( buf, max ); };
|
||||
|
||||
// public methods
|
||||
int NmeaDecode( const char *msg, int max );
|
||||
int NmeaParse( const char *msg, int max );
|
||||
|
||||
// misc
|
||||
void NmeaPosFix( const char *str )
|
||||
{ strncpy(posfixnmea,str,sizeof(posfixnmea)-1);};
|
||||
|
||||
// static functions
|
||||
static int CsvSplit( char *buf, char *field[], int max );
|
||||
};
|
||||
|
||||
#endif
|
||||
50
include/libgps++/NmeaProtocol.h
Normal file
50
include/libgps++/NmeaProtocol.h
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __NmeaProtocol__
|
||||
#define __NmeaProtocol__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
|
||||
//
|
||||
class NmeaProtocol {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
NmeaProtocol();
|
||||
|
||||
// destructor
|
||||
virtual ~NmeaProtocol();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
static int NmeaChecksum( char *msg, int len, int max = 0 );
|
||||
};
|
||||
|
||||
#endif
|
||||
197
include/libgps++/NmeaSentence.h
Normal file
197
include/libgps++/NmeaSentence.h
Normal file
@ -0,0 +1,197 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
// NMEA Parser code stolen from Pascal Martin's RoadMap
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __NmeaSentence__
|
||||
#define __NmeaSentence__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "GpsMath.h"
|
||||
#include "GpsListener.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
#define NMEA_MAX_SATELLITE 32
|
||||
|
||||
#define NMEA_FIX_INVALID 0
|
||||
#define NMEA_FIX_NOFIX 0
|
||||
#define NMEA_FIX_GPS 1
|
||||
#define NMEA_FIX_DGPS 2
|
||||
#define NMEA_FIX_PPS 3
|
||||
#define NMEA_FIX_RTK_FIXED 4
|
||||
#define NMEA_FIX_RTK_FLOAT 5
|
||||
#define NMEA_FIX_DEAD_RECKONING 6
|
||||
#define NMEA_FIX_MANUAL 7
|
||||
#define NMEA_FIX_SIMULATION 8
|
||||
|
||||
#define NMEA_MODE_AUTOMATIC 'A'
|
||||
#define NMEA_MODE_DIFFERENTIAL 'D'
|
||||
#define NMEA_MODE_ESTIMATED 'E' // dead reckoning
|
||||
#define NMEA_MODE_MANUAL 'M'
|
||||
#define NMEA_MODE_SIMULATED 'S'
|
||||
#define NMEA_MODE_INVALID 'N'
|
||||
|
||||
#define NMEA_TYPE_INVALID 0
|
||||
#define NMEA_TYPE_NOFIX 1
|
||||
#define NMEA_TYPE_2D 2
|
||||
#define NMEA_TYPE_3D 3
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
#define DecodeCoordinate(A,B) GpsMath::Minutes2Degrees(A,B)
|
||||
#define DecodeTime(A,B) GpsMath::String2Time(A,B)
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class NmeaSentence {
|
||||
public:
|
||||
char name[8];
|
||||
char argc;
|
||||
char parsed; // just parsed flag
|
||||
u_long counter;
|
||||
timespec timestamp;
|
||||
|
||||
NmeaSentence();
|
||||
virtual ~NmeaSentence();
|
||||
|
||||
virtual int Decode( int argc, char *argv[] );
|
||||
virtual void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentenceGPGGA : public NmeaSentence {
|
||||
public:
|
||||
timespec fixtime;
|
||||
double latitude; // decimal degrees
|
||||
double longitude;
|
||||
int quality;
|
||||
int satellites;
|
||||
float horizontal_dilution;
|
||||
double altitude; // meters
|
||||
double geoid;
|
||||
|
||||
NmeaSentenceGPGGA();
|
||||
~NmeaSentenceGPGGA();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentenceGPGLL : public NmeaSentence {
|
||||
public:
|
||||
double latitude;
|
||||
double longitude;
|
||||
timespec utctime;
|
||||
char status;
|
||||
char mode;
|
||||
|
||||
NmeaSentenceGPGLL();
|
||||
~NmeaSentenceGPGLL();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentenceGPGSA : public NmeaSentence {
|
||||
public:
|
||||
char mode;
|
||||
char type;
|
||||
char satellite[NMEA_MAX_SATELLITE];
|
||||
float position_dilution;
|
||||
float horizontal_dilution;
|
||||
float vertical_dilution;
|
||||
|
||||
NmeaSentenceGPGSA();
|
||||
~NmeaSentenceGPGSA();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentenceGPGST : public NmeaSentence {
|
||||
public:
|
||||
timespec utctime;
|
||||
// standard deviation of error
|
||||
float rms_deviation;
|
||||
float semimajor_deviation;
|
||||
float semiminor_deviation;
|
||||
float semimajor_orientation;
|
||||
float latitude_deviation;
|
||||
float longitude_deviation;
|
||||
float altitude_deviation;
|
||||
|
||||
NmeaSentenceGPGST();
|
||||
~NmeaSentenceGPGST();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentenceGPGSV : public NmeaSentence {
|
||||
public:
|
||||
char total;
|
||||
char sequence;
|
||||
char satellites;
|
||||
struct {
|
||||
char id;
|
||||
char elevation;
|
||||
short azimuth;
|
||||
short signal2noise;
|
||||
} satellite[NMEA_MAX_SATELLITE];
|
||||
|
||||
NmeaSentenceGPGSV();
|
||||
~NmeaSentenceGPGSV();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentenceGPRMC : public NmeaSentence {
|
||||
public:
|
||||
timespec utctime;
|
||||
char status;
|
||||
double latitude;
|
||||
double longitude;
|
||||
double speed; // convert knots to kph
|
||||
double course;
|
||||
double variation;
|
||||
|
||||
NmeaSentenceGPRMC();
|
||||
~NmeaSentenceGPRMC();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentenceGPVTG : public NmeaSentence {
|
||||
public:
|
||||
double course;
|
||||
double speed;
|
||||
char mode;
|
||||
|
||||
NmeaSentenceGPVTG();
|
||||
~NmeaSentenceGPVTG();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class NmeaSentenceGPZDA : public NmeaSentence {
|
||||
public:
|
||||
timespec utctime;
|
||||
|
||||
NmeaSentenceGPZDA();
|
||||
~NmeaSentenceGPZDA();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
#endif
|
||||
65
include/libgps++/NtripClient.h
Normal file
65
include/libgps++/NtripClient.h
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __NtripClient__
|
||||
#define __NtripClient__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "TcpClient.h"
|
||||
#include "netlib.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
|
||||
//
|
||||
class NtripClient : public TcpClient {
|
||||
// public data
|
||||
public:
|
||||
char Uri[1024];
|
||||
|
||||
protected:
|
||||
unsigned long count;
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// private methods
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
NtripClient();
|
||||
|
||||
// destructor
|
||||
virtual ~NtripClient();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int NtripConnect( const char *host, const char *service,
|
||||
const char *user = "anonymous", const char *pass = "",
|
||||
const char *path = "" );
|
||||
int NtripConnect( const char *uri );
|
||||
int NtripReconnect( void ) {return NtripConnect( Uri ); };
|
||||
void NtripClose(void) {Close();};
|
||||
|
||||
int NtripRead( unsigned char *buf, int max );
|
||||
int NtripWrite( const unsigned char *buf, int max )
|
||||
{return TcpClient::Send((const char *)buf,max);};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
62
include/libgps++/RtcmDevice.h
Normal file
62
include/libgps++/RtcmDevice.h
Normal file
@ -0,0 +1,62 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __RtcmDevice__
|
||||
#define __RtcmDevice__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "TcpClient.h"
|
||||
#include "netlib.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class RtcmDevice {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
int SerialFd; // serial port
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// private methods
|
||||
int SerialOpen( const char *dev, int baud );
|
||||
int SerialRead( char *buf, int max );
|
||||
void SerialClose( void );
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
RtcmDevice();
|
||||
|
||||
// destructor
|
||||
virtual ~RtcmDevice();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
int GetFd(void) {return SerialFd;};
|
||||
|
||||
int RtcmOpen( const char *dev, int baud ) {return SerialOpen(dev,baud); };
|
||||
void RtcmClose(void) {SerialClose();};
|
||||
|
||||
int RtcmRead( char *buf, int max );
|
||||
int RtcmWrite( const char *buf, int max );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
62
include/libgps++/SirfParser.h
Normal file
62
include/libgps++/SirfParser.h
Normal file
@ -0,0 +1,62 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __SirfParser__
|
||||
#define __SirfParser__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "GpsListener.h"
|
||||
#include "GpsParser.h"
|
||||
|
||||
#include "NmeaParser.h"
|
||||
#include "NmeaProtocol.h"
|
||||
#include "SirfProtocol.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
class SirfParser : public NmeaParser, public SirfProtocol {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
// data
|
||||
u_char state; // parser state
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
SirfParser();
|
||||
|
||||
// destructor
|
||||
virtual ~SirfParser();
|
||||
|
||||
// virtual functions
|
||||
int GpsDecode( const char *buf, int max ) { return SirfDecode( (const u_char *)buf, max); };
|
||||
int GpsParse( const char *buf, int max ) { return SirfParse( buf, max ); };
|
||||
|
||||
// public methods
|
||||
int SirfDecode( const u_char *buf, int max );
|
||||
int SirfParse( const char *buf, int max );
|
||||
};
|
||||
|
||||
#endif
|
||||
53
include/libgps++/SirfProtocol.h
Normal file
53
include/libgps++/SirfProtocol.h
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __SirfProtocol__
|
||||
#define __SirfProtocol__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "NmeaProtocol.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
|
||||
//
|
||||
class SirfProtocol {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
SirfProtocol();
|
||||
|
||||
// destructor
|
||||
virtual ~SirfProtocol();
|
||||
|
||||
// virtual functions
|
||||
|
||||
// public methods
|
||||
static void SirfChecksum( unsigned char *buf, int len );
|
||||
static void SirfBinary2Nmea( int baud, unsigned char *buf, int max );
|
||||
};
|
||||
|
||||
#endif
|
||||
111
include/libgps++/UbloxParser.h
Normal file
111
include/libgps++/UbloxParser.h
Normal file
@ -0,0 +1,111 @@
|
||||
//
|
||||
// Linux GPS
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UbloxParser__
|
||||
#define __UbloxParser__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
#include "GpsListener.h"
|
||||
#include "GpsParser.h"
|
||||
|
||||
#include "NmeaParser.h"
|
||||
#include "NmeaProtocol.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class NmeaSentencePUBX : public NmeaSentence {
|
||||
public:
|
||||
int id;
|
||||
timespec utctime;
|
||||
// 00
|
||||
double latitude;
|
||||
double longitude;
|
||||
double altitude_ref;
|
||||
char navstat[4];
|
||||
double horizontal_accuracy;
|
||||
double vertical_accuracy;
|
||||
double speed;
|
||||
double course;
|
||||
double vvel;
|
||||
double agec;
|
||||
double horizontal_dilution;
|
||||
double vertical_dilution;
|
||||
double time_dilution;
|
||||
int gps;
|
||||
int glonass;
|
||||
int dead_reckoning;
|
||||
|
||||
// 01
|
||||
|
||||
// 03
|
||||
int satellites;
|
||||
struct {
|
||||
int prn;
|
||||
char status;
|
||||
double azimuth;
|
||||
double elevation;
|
||||
int signal2noise;
|
||||
int locktime;
|
||||
} satellite[NMEA_MAX_SATELLITE];
|
||||
|
||||
// 04
|
||||
double utc_tow;
|
||||
int week;
|
||||
int clk_b;
|
||||
double clk_d;
|
||||
int granularity;
|
||||
|
||||
NmeaSentencePUBX();
|
||||
~NmeaSentencePUBX();
|
||||
|
||||
int Decode( int argc, char *argv[] );
|
||||
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
|
||||
};
|
||||
|
||||
class UbloxParser : public NmeaParser {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
// u-Blox
|
||||
NmeaSentencePUBX PUBX;
|
||||
|
||||
// private data
|
||||
private:
|
||||
// data
|
||||
u_char state; // parser state
|
||||
|
||||
// private methods
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UbloxParser();
|
||||
|
||||
// destructor
|
||||
virtual ~UbloxParser();
|
||||
|
||||
// virtual functions
|
||||
int GpsDecode( const char *buf, int max ) { return UbloxDecode( (const u_char *)buf, max); };
|
||||
int GpsParse( const char *buf, int max ) { return UbloxParse( buf, max ); };
|
||||
|
||||
// public methods
|
||||
int UbloxDecode( const u_char *buf, int max );
|
||||
int UbloxParse( const char *buf, int max );
|
||||
};
|
||||
|
||||
#endif
|
||||
63
include/libnet++/Client.h
Normal file
63
include/libnet++/Client.h
Normal file
@ -0,0 +1,63 @@
|
||||
//
|
||||
// Client
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __Client__
|
||||
#define __Client__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Socket.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class Client {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
Client();
|
||||
|
||||
// destructor
|
||||
virtual ~Client();
|
||||
|
||||
// public methods
|
||||
int ConnectUri( const char *uri );
|
||||
int ListenUri( const char *uri );
|
||||
|
||||
// virtual functions
|
||||
virtual int Connect( const char *host, const char *service=NULL )
|
||||
{return -1;};
|
||||
virtual int Listen( const char *host, const char *service=NULL )
|
||||
{return 0;};
|
||||
|
||||
// exceptions
|
||||
class ClientException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
79
include/libnet++/Clock.h
Normal file
79
include/libnet++/Clock.h
Normal file
@ -0,0 +1,79 @@
|
||||
//
|
||||
// Linux Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __Clock__
|
||||
#define __Clock__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class Clock {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
struct timespec Time;
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
Clock();
|
||||
Clock( time_t tic );
|
||||
|
||||
// destructor
|
||||
virtual ~Clock();
|
||||
|
||||
Clock( const Clock& );
|
||||
const Clock& operator=( const Clock& );
|
||||
|
||||
// public methods
|
||||
time_t GetUtc( void ) { return Time.tv_sec; };
|
||||
struct timespec GetTimeSpec() { return Time; };
|
||||
|
||||
int Format( char *buf, int max );
|
||||
struct timespec Parse( const char *buf );
|
||||
|
||||
void SetTime( void );
|
||||
void SetTime( time_t sec, suseconds_t usec=0L );
|
||||
void SetTime( const struct timespec &tv ) { Time = tv; };
|
||||
|
||||
// microsecond time stamp
|
||||
unsigned long long GetTimeStamp();
|
||||
void SetTimeStamp( unsigned long long ts );
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
|
||||
// static methods
|
||||
static int Format( const struct timespec &tv, char **buf, int *max );
|
||||
|
||||
// private methods
|
||||
private:
|
||||
|
||||
// signal catchers (do not override)
|
||||
};
|
||||
|
||||
#endif
|
||||
64
include/libnet++/ClockTimer.h
Normal file
64
include/libnet++/ClockTimer.h
Normal file
@ -0,0 +1,64 @@
|
||||
//
|
||||
// Linux Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __ClockTimer__
|
||||
#define __ClockTimer__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Timer.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class ClockTimer : public Timer {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
long m_timeout; // usec
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
ClockTimer();
|
||||
ClockTimer(unsigned long usec);
|
||||
|
||||
// destructor
|
||||
virtual ~ClockTimer();
|
||||
|
||||
ClockTimer( const ClockTimer& );
|
||||
const ClockTimer& operator=( const ClockTimer& );
|
||||
|
||||
// public methods
|
||||
int Restart(void);
|
||||
int Start( unsigned long usec );
|
||||
void Stop(void);
|
||||
unsigned long Remaining(void);
|
||||
int Wait(void);
|
||||
int Sync(void); // Wait()+Restart()
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
|
||||
// signal catchers (do not override)
|
||||
};
|
||||
|
||||
#endif
|
||||
89
include/libnet++/Daemon.h
Normal file
89
include/libnet++/Daemon.h
Normal file
@ -0,0 +1,89 @@
|
||||
//
|
||||
// Linux Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __Daemon__
|
||||
#define __Daemon__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "LogData.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class Daemon {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
char m_name[32];
|
||||
bool m_debug;
|
||||
int m_pid;
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
Daemon();
|
||||
Daemon( const char *name, int debug, int noclose );
|
||||
|
||||
// destructor
|
||||
virtual ~Daemon();
|
||||
|
||||
// public methods
|
||||
int Daemonize( const char *name, int debug=0, int noclose=0 );
|
||||
void Die( int code );
|
||||
|
||||
void SetDebug(bool debug) {m_debug = debug;};
|
||||
bool GetDebug(void) {return m_debug;};
|
||||
bool IsDebug(void) {return m_debug;};
|
||||
void Dprintf( const char *fmt, ... );
|
||||
|
||||
void SetName(const char *s) {strncpy(m_name,s,sizeof(m_name)-1);};
|
||||
char *GetName(void) {return m_name;};
|
||||
|
||||
int GetPid(void) {return m_pid;};
|
||||
|
||||
// virtual functions
|
||||
virtual void DaemonStartup(void) {};
|
||||
virtual void DaemonShutdown(void) {};
|
||||
virtual void DaemonReload(void) {};
|
||||
|
||||
// exceptions
|
||||
class DaemonException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods to override
|
||||
static int SignalAlarm(void) {return 1;};
|
||||
static int SignalDeath(void) {return 1;};
|
||||
static int SignalInterrupt(void) {return 1;};
|
||||
static void SignalHup(void) {;};
|
||||
|
||||
// private methods
|
||||
private:
|
||||
// signal catchers (do not override)
|
||||
static void signal_alarm(int signum);
|
||||
static void signal_child(int signum);
|
||||
static void signal_death(int signum);
|
||||
static void signal_intrp(int signum);
|
||||
static void signal_hup(int signum);
|
||||
};
|
||||
|
||||
#endif
|
||||
91
include/libnet++/LogData.h
Normal file
91
include/libnet++/LogData.h
Normal file
@ -0,0 +1,91 @@
|
||||
//
|
||||
// GPS Daemon
|
||||
// Neal Probert
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __LogData__
|
||||
#define __LogData__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "UdpClient.h"
|
||||
|
||||
#ifdef MYSQL_LOGGING
|
||||
#include "mysql/mysql.h"
|
||||
#endif
|
||||
#ifdef BZIP2_LOGGING
|
||||
#include "bzlib.h"
|
||||
#endif
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
#define LOGD_PORT "2940"
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
|
||||
//
|
||||
class LogData : public UdpClient {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// private data
|
||||
private:
|
||||
// MySQL logging
|
||||
int nfields;
|
||||
char myfields[2048];
|
||||
FILE *pFile;
|
||||
#ifdef MYSQL_LOGGING
|
||||
MYSQL *myconn;
|
||||
char mytable[256];
|
||||
MYSQL_RES *myres;
|
||||
#endif
|
||||
long nrecords;
|
||||
|
||||
// formats
|
||||
bool m_logging;
|
||||
bool m_syslog;
|
||||
bool m_binary;
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
LogData();
|
||||
|
||||
// destructor
|
||||
virtual ~LogData();
|
||||
|
||||
// public methods
|
||||
FILE *LogOpen( const char *log = NULL, int bz2=0 );
|
||||
int LogRead( timeval *tv, char *buf, int max );
|
||||
int LogPrintf( const char *fmt, ... );
|
||||
int LogWrite( const char *buf, int max );
|
||||
void LogClose( void );
|
||||
void LogRotate( void );
|
||||
|
||||
// text only csv logging
|
||||
void LogFields( const char *flds );
|
||||
int CsvSplit( char *buf, char *field[], int max );
|
||||
|
||||
// logging control
|
||||
bool IsLogging(void) {return m_logging;};
|
||||
void SetBinary(void) { m_binary=true; };
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
59
include/libnet++/Logging.h
Normal file
59
include/libnet++/Logging.h
Normal file
@ -0,0 +1,59 @@
|
||||
//
|
||||
// Linux Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __Logging__
|
||||
#define __Logging__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "LogData.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class Logging {
|
||||
// public data
|
||||
public:
|
||||
LogData Log;
|
||||
|
||||
protected:
|
||||
// logfile
|
||||
|
||||
// pid
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
Logging();
|
||||
|
||||
// destructor
|
||||
virtual ~Logging();
|
||||
|
||||
// public methods
|
||||
FILE *LogOpen( const char *log, int bz2 )
|
||||
{ return Log.LogOpen( log, bz2 ); };
|
||||
FILE *LogOpen( const char *log )
|
||||
{ return Log.LogOpen( log ); };
|
||||
bool IsLogging(void) {return Log.IsLogging();};
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
72
include/libnet++/Mutex.h
Normal file
72
include/libnet++/Mutex.h
Normal file
@ -0,0 +1,72 @@
|
||||
//
|
||||
// Linux Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __Mutex__
|
||||
#define __Mutex__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class Mutex {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
pthread_mutexattr_t m_attr;
|
||||
pthread_mutex_t m_mutex;
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
Mutex();
|
||||
|
||||
// destructor
|
||||
virtual ~Mutex();
|
||||
|
||||
Mutex( const Mutex& );
|
||||
const Mutex& operator=( const Mutex& );
|
||||
|
||||
// public methods
|
||||
void Init( void );
|
||||
int Lock( void );
|
||||
int TryLock( void );
|
||||
int Unlock( void );
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
class MutexException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods to override
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
66
include/libnet++/PosixTimer.h
Normal file
66
include/libnet++/PosixTimer.h
Normal file
@ -0,0 +1,66 @@
|
||||
//
|
||||
// Linux Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __PosixTimer__
|
||||
#define __PosixTimer__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Timer.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class PosixTimer : public Timer {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
timer_t m_timerid;
|
||||
struct itimerspec m_value;
|
||||
int m_signal; // signal used
|
||||
bool m_running;
|
||||
bool m_oneshot;
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
PosixTimer();
|
||||
PosixTimer(unsigned long usec);
|
||||
|
||||
// destructor
|
||||
virtual ~PosixTimer();
|
||||
|
||||
// public methods
|
||||
int Restart(void);
|
||||
int Start( unsigned long usec, bool one_shot=true );
|
||||
void Stop(void);
|
||||
unsigned long Remaining(void);
|
||||
int Wait(void);
|
||||
int Sync(void); // Wait()+Restart()
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
void Init(void);
|
||||
|
||||
// signal catchers (do not override)
|
||||
};
|
||||
|
||||
#endif
|
||||
67
include/libnet++/QueryString.h
Normal file
67
include/libnet++/QueryString.h
Normal file
@ -0,0 +1,67 @@
|
||||
//
|
||||
// URI Parser
|
||||
// Neal Probert
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __QueryString__
|
||||
#define __QueryString__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// Chop up the URI into it's component parts
|
||||
//
|
||||
class QueryString {
|
||||
// public data
|
||||
public:
|
||||
std::string Name;
|
||||
std::string Value;
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
QueryString();
|
||||
QueryString(const QueryString ©);
|
||||
|
||||
// destructor
|
||||
virtual ~QueryString();
|
||||
|
||||
// operators
|
||||
QueryString &operator=(const QueryString &rhs);
|
||||
|
||||
// access methods
|
||||
void setName( const char *s );
|
||||
void setValue( const char *s );
|
||||
void setValue( int v );
|
||||
void Set( const char *name, const char *value=NULL );
|
||||
|
||||
const char *getName(void) { return Name.c_str(); };
|
||||
int getLength(void) { return Value.length(); };
|
||||
const char *getValue(void) { return Value.c_str(); };
|
||||
const char *Get(void) { return Value.c_str(); };
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
78
include/libnet++/RawSocket.h
Normal file
78
include/libnet++/RawSocket.h
Normal file
@ -0,0 +1,78 @@
|
||||
//
|
||||
// Socket
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __RawSocket__
|
||||
#define __RawSocket__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Socket.h"
|
||||
|
||||
#include<netinet/ip_icmp.h> //Provides declarations for icmp header
|
||||
#include<netinet/udp.h> //Provides declarations for udp header
|
||||
#include<netinet/tcp.h> //Provides declarations for tcp header
|
||||
#include<netinet/ip.h> //Provides declarations for ip header
|
||||
#include<sys/socket.h>
|
||||
#include<arpa/inet.h>
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class RawSocket : public Socket {
|
||||
// public data
|
||||
public:
|
||||
struct sockaddr_storage sock_addr;
|
||||
socklen_t sock_len;
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
RawSocket();
|
||||
|
||||
// destructor
|
||||
virtual ~RawSocket();
|
||||
|
||||
// copy constructor
|
||||
RawSocket( const RawSocket &src ) ;
|
||||
const RawSocket& operator=( const RawSocket &src );
|
||||
|
||||
// public methods
|
||||
int Socket();
|
||||
int RecvFrom( void *buf, int max );
|
||||
|
||||
// control
|
||||
|
||||
// status
|
||||
int GetIPHdrLen( const void *buf );
|
||||
int GetProtocol( const void *buf );
|
||||
struct iphdr *GetIPHeader( const void *buf ) {return (struct iphdr*)buf;};
|
||||
struct tcphdr *GetTcpHeader( const void *buf );
|
||||
struct udphdr *GetUdpHeader( const void *buf );
|
||||
unsigned char *GetData( const void *buf, int *length, int proto=0 );
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
94
include/libnet++/SerialIO.h
Normal file
94
include/libnet++/SerialIO.h
Normal file
@ -0,0 +1,94 @@
|
||||
//
|
||||
// Socket
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __SerialIO__
|
||||
#define __SerialIO__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <termios.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
/** \class
|
||||
*
|
||||
* Serial I/O wrapper and support class, Linux only
|
||||
*/
|
||||
|
||||
class SerialIO {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
int m_fd; // handle
|
||||
unsigned long m_sentcnt; // # bytes sent
|
||||
unsigned long m_recvcnt; // # bytes recv
|
||||
|
||||
// serial config
|
||||
struct termios termios;
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
SerialIO();
|
||||
|
||||
// destructor
|
||||
virtual ~SerialIO();
|
||||
|
||||
// public methods
|
||||
|
||||
// control
|
||||
int GetFd( void ) { return m_fd; };
|
||||
|
||||
void SetBaud( int baud );
|
||||
void SetCanonical( bool canonical, int bs=0, int wt=0 );
|
||||
void Canonical(void) { SetCanonical(true); };
|
||||
void NonCanonical(void) { SetCanonical(false); };
|
||||
|
||||
// i/o
|
||||
int Open( const char *dev, int baud );
|
||||
int Read( void *buf, int len );
|
||||
int Write( const void *buf, int len );
|
||||
void Close( void );
|
||||
|
||||
// status
|
||||
unsigned long GetBytesSent(void) {return m_sentcnt;};
|
||||
unsigned long GetBytesRecv(void) {return m_recvcnt;};
|
||||
|
||||
// virtual functions (must be overridden!)
|
||||
|
||||
// exceptions
|
||||
class SerialIOException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
82
include/libnet++/Server.h
Normal file
82
include/libnet++/Server.h
Normal file
@ -0,0 +1,82 @@
|
||||
//
|
||||
// Server
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __Server__
|
||||
#define __Server__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Socket.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class Server {
|
||||
// public data
|
||||
public:
|
||||
|
||||
protected:
|
||||
// socket
|
||||
int m_nfds; /* number of descriptors */
|
||||
fd_set m_rfds; /* set of open sockets */
|
||||
|
||||
// select
|
||||
fd_set m_sfds;
|
||||
struct timeval m_timeout;
|
||||
struct timeval m_seltime;
|
||||
|
||||
bool m_client_to; // reset timeout on client
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
Server();
|
||||
|
||||
// destructor
|
||||
virtual ~Server();
|
||||
|
||||
// public methods
|
||||
// control
|
||||
void SetTimeout(time_t to);
|
||||
void SetTimeout(timeval &tv);
|
||||
void ResetTimeout(void);
|
||||
void ResetClientTimeout(void) {if(m_client_to)ResetTimeout();};
|
||||
void ResetServerTimeout(void) {ResetTimeout();};
|
||||
void SetClientTimeout(bool ct) {m_client_to=ct;};
|
||||
|
||||
// select
|
||||
void AddFd(int sock) {if(sock>=0)m_nfds=fd_add(sock,&m_rfds,m_nfds);};
|
||||
void DelFd(int sock) {if(sock>=0)FD_CLR(sock,&m_rfds);};
|
||||
bool IsSet(int sock) {if(sock>=0)return FD_ISSET(sock,&m_sfds);return 0;};
|
||||
int Select( void );
|
||||
|
||||
// service
|
||||
int ServiceUri( const char *uri );
|
||||
|
||||
// virtual functions
|
||||
virtual int Service( const char *host, const char *service=NULL ) {return -1;};
|
||||
virtual int Listen( void ) {return 0;};
|
||||
virtual int ServerTimeout(void) {return 0;};
|
||||
virtual int ServerSocket(void) {return 0;}; // other socket
|
||||
|
||||
// exceptions
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
165
include/libnet++/Socket.h
Normal file
165
include/libnet++/Socket.h
Normal file
@ -0,0 +1,165 @@
|
||||
//
|
||||
// Socket
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __Socket__
|
||||
#define __Socket__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <byteswap.h>
|
||||
#include <netdb.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <linux/sockios.h>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
#if defined(__BIG_ENDIAN)
|
||||
# define ntohll(x) (x)
|
||||
# define htonll(x) (x)
|
||||
#elif defined(__LITTLE_ENDIAN)
|
||||
# define ntohll(x) bswap_64(x)
|
||||
# define htonll(x) bswap_64(x)
|
||||
#endif
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class Socket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
// socket
|
||||
int m_family; // AF_UNIX, AF_INET or AF_INET6
|
||||
int m_proto; // protocol
|
||||
int m_sock; // socket
|
||||
|
||||
void LogSocket( const char *str );
|
||||
|
||||
// private data
|
||||
private:
|
||||
// reference
|
||||
static char g_hostname[256];
|
||||
char m_host[256];
|
||||
char m_port[32];
|
||||
|
||||
// stats
|
||||
unsigned long m_sentcnt;
|
||||
unsigned long m_recvcnt;
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
Socket();
|
||||
|
||||
// destructor
|
||||
virtual ~Socket();
|
||||
|
||||
// copy constructor
|
||||
Socket( const Socket& );
|
||||
const Socket& operator=( const Socket& );
|
||||
|
||||
// public methods
|
||||
int ClientUri( const char *uri );
|
||||
int ServerUri( const char *uri );
|
||||
|
||||
// control
|
||||
void SetFamily( int family ) {m_family = family;};
|
||||
void SetProto( int proto ) {m_proto = proto;};
|
||||
void SetHost(const char *host) {if(host)strncpy(m_host,host,sizeof(m_host)-1);};
|
||||
void SetPort(const char *port) {if(port)strncpy(m_port,port,sizeof(m_port)-1);};
|
||||
void SetHostPort(const char *host, const char *port)
|
||||
{SetHost(host);SetPort(port);};
|
||||
void SetSocket( int sock ) {m_sock=sock;};
|
||||
|
||||
// i/o
|
||||
int Bind( const struct sockaddr_storage *sa, int len )
|
||||
{return Bind(m_sock,sa,len);};
|
||||
void Close( void );
|
||||
|
||||
int Recv( void *buf, int len );
|
||||
int Send( const void *buf, int len );
|
||||
int RecvFrom( void *buf, int max, struct sockaddr_storage *sa, socklen_t *len );
|
||||
int SendTo( const void *buf, int max, const struct sockaddr_storage *sa, socklen_t len );
|
||||
|
||||
// status
|
||||
unsigned long GetBytesSent(void) {return m_sentcnt;};
|
||||
unsigned long GetBytesRecv(void) {return m_recvcnt;};
|
||||
const char *GetHostName(void) {return g_hostname;};
|
||||
const char *GetHost(void) {return m_host;};
|
||||
const char *GetPort(void) {return m_port;};
|
||||
|
||||
int GetFamily(void) {return m_family;};
|
||||
int GetProto(void) {return m_proto;};
|
||||
int GetSock(void) {return m_sock;};
|
||||
int GetSocket(void) {return m_sock;};
|
||||
int SockAddr( struct sockaddr_storage *sa ) {return SockAddr(m_sock,sa);};
|
||||
int SockName( char *buf, int max ) {return SockName(m_sock,buf,max); };
|
||||
|
||||
// virtual functions (must be overridden!)
|
||||
virtual int Client( const char *host, const char *port ) {return -1;};
|
||||
virtual int Server( const char *host, const char *port ) {return -1;};
|
||||
virtual void Closed(void) {;};
|
||||
|
||||
// exceptions
|
||||
class SocketException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
static int Bind( int sock, const struct sockaddr_storage *sa, socklen_t len );
|
||||
static int Recv( int sock, void *buf, int max );
|
||||
static int Send( int sock, const void *buf, int len );
|
||||
static int RecvFrom( int sock, void *buf, int n,
|
||||
struct sockaddr_storage *sa, socklen_t *len );
|
||||
static int SendTo( int sock, const void *buf, int len,
|
||||
const struct sockaddr_storage *sa, int salen );
|
||||
|
||||
static int Host2Addr(const char *host, const char *service,
|
||||
struct sockaddr_storage *sa, socklen_t *len);
|
||||
static const char *Host2Name( const struct sockaddr_storage *sa,
|
||||
char *buf, int max );
|
||||
static int Name2Host( const char *buf, struct sockaddr_storage *sa );
|
||||
static int SockAddr( int sock, struct sockaddr_storage *sa );
|
||||
static int SockName( int sock, char *buf, int max );
|
||||
|
||||
static int String2Mac( const char *str, unsigned char *mac );
|
||||
static int Mac2String( const unsigned char *mac, char *str );
|
||||
static int Interface2MacAddr( const char *name, unsigned char *mac );
|
||||
static int Service2Port( const char *service, int port, const char *proto );
|
||||
|
||||
// protected methods
|
||||
protected:
|
||||
void Copy( const Socket &sock );
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
56
include/libnet++/TcpArchdaemon.h
Normal file
56
include/libnet++/TcpArchdaemon.h
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// TCP Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __TcpArchdaemon__
|
||||
#define __TcpArchdaemon__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "TcpDaemon.h"
|
||||
#include "TcpThread.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class TcpArchdaemon : public TcpDaemon {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
TcpArchdaemon();
|
||||
|
||||
// destructor
|
||||
virtual ~TcpArchdaemon();
|
||||
|
||||
// public methods
|
||||
int StartService(const char *n,const char *h,const char *p,int d=0,int c=0);
|
||||
int RunService(void);
|
||||
|
||||
// overidden methods
|
||||
int Listen( void *arg=NULL );
|
||||
virtual TcpThread *ClientThread( void **parg ) {return NULL;};
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
64
include/libnet++/TcpClient.h
Normal file
64
include/libnet++/TcpClient.h
Normal file
@ -0,0 +1,64 @@
|
||||
//
|
||||
// TCP Client
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __TcpClient__
|
||||
#define __TcpClient__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "TcpSocket.h"
|
||||
#include "Client.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class TcpClient : public Client, public TcpSocket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
TcpClient();
|
||||
TcpClient( const char *host, const char *service=NULL );
|
||||
|
||||
// destructor
|
||||
virtual ~TcpClient();
|
||||
|
||||
// public methods
|
||||
int ConnectUri( const char *uri );
|
||||
int Connect( const char *host, const char *service=NULL );
|
||||
int Reconnect(void) { Close();return Connect(GetHost(),GetPort()); };
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
class TcpClientException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
void Init( void );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
52
include/libnet++/TcpDaemon.h
Normal file
52
include/libnet++/TcpDaemon.h
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// TCP Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __TcpDaemon__
|
||||
#define __TcpDaemon__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Daemon.h"
|
||||
#include "TcpServer.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class TcpDaemon : public TcpServer, public Daemon {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
TcpDaemon();
|
||||
|
||||
// destructor
|
||||
virtual ~TcpDaemon();
|
||||
|
||||
// public methods
|
||||
int StartService(const char *n,const char *h,const char *p,int d=0,int c=0);
|
||||
int RunService(void);
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
81
include/libnet++/TcpServer.h
Normal file
81
include/libnet++/TcpServer.h
Normal file
@ -0,0 +1,81 @@
|
||||
//
|
||||
// TCP Server
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __TcpServer__
|
||||
#define __TcpServer__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "TcpSocket.h"
|
||||
#include "Daemon.h"
|
||||
#include "Server.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class TcpServer : public Server, public TcpSocket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
// logfile
|
||||
|
||||
// private data
|
||||
private:
|
||||
// socket
|
||||
int m_clients;
|
||||
fd_set m_cfds; /* client sockets */
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
TcpServer();
|
||||
TcpServer( const char *host, const char *service );
|
||||
|
||||
// destructor
|
||||
virtual ~TcpServer();
|
||||
|
||||
// public methods
|
||||
int ServiceUri( const char *uri );
|
||||
int Service( const char *host, const char *service=NULL );
|
||||
int Listen( void );
|
||||
int Restart( void );
|
||||
int NumClients(void) {return m_clients;};
|
||||
|
||||
// virtual functions
|
||||
virtual int ServerTimeout(void) {return 0;};
|
||||
virtual int ServerSocket(void) {return 0;}; // other socket (not client)
|
||||
|
||||
virtual int ClientUp( int sock ) { return 1; };
|
||||
virtual void ClientDown( int sock ) {;};
|
||||
virtual int ClientSock( int sock ) {return 0;};
|
||||
virtual int ClientIn( int client, const char *buf, int n );
|
||||
virtual int ClientOut( int client, char *buf, int max );
|
||||
virtual void ClientCast( const char *buf, int len );
|
||||
|
||||
// exceptions
|
||||
class TcpServerException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
void Init(void);
|
||||
|
||||
private:
|
||||
void ClientAdd(int sock);
|
||||
};
|
||||
|
||||
#endif
|
||||
69
include/libnet++/TcpSocket.h
Normal file
69
include/libnet++/TcpSocket.h
Normal file
@ -0,0 +1,69 @@
|
||||
//
|
||||
// Socket
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __TcpSocket__
|
||||
#define __TcpSocket__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Socket.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class TcpSocket : public Socket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
protected:
|
||||
// socket
|
||||
|
||||
// stats
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
TcpSocket();
|
||||
|
||||
// destructor
|
||||
virtual ~TcpSocket();
|
||||
|
||||
// copy constructor
|
||||
TcpSocket( const TcpSocket &src ) {Copy(src);};
|
||||
const TcpSocket& operator=( const TcpSocket &src ) {this->Copy(src);return *this;};
|
||||
|
||||
// public methods
|
||||
int Client( const char *host, const char *port );
|
||||
int Server( const char *host, const char *port );
|
||||
int Accept( struct sockaddr_storage *sa );
|
||||
int SendStr( const char *str );
|
||||
|
||||
// control
|
||||
int Nagle( int flag ) {return Nagle(m_sock,flag);};
|
||||
|
||||
// status
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
|
||||
// static methods
|
||||
static int Nagle( int sock, int flag );
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
60
include/libnet++/TcpThread.h
Normal file
60
include/libnet++/TcpThread.h
Normal file
@ -0,0 +1,60 @@
|
||||
//
|
||||
// TCP Thread
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __TcpThread__
|
||||
#define __TcpThread__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "TcpClient.h"
|
||||
#include "Thread.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class TcpThread : public TcpClient, public Thread {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
TcpThread();
|
||||
|
||||
// destructor
|
||||
virtual ~TcpThread();
|
||||
|
||||
// public methods
|
||||
void SetSocket( int sock ) {Socket::SetSocket(sock);};
|
||||
int Detach(void) {return pthread_detach(pthread_self());};
|
||||
|
||||
// virtual functions
|
||||
virtual void *Run(void *);
|
||||
|
||||
// exceptions
|
||||
class TcpThreadException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
81
include/libnet++/Thread.h
Normal file
81
include/libnet++/Thread.h
Normal file
@ -0,0 +1,81 @@
|
||||
//
|
||||
// Linux Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __Thread__
|
||||
#define __Thread__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class Thread {
|
||||
// public data
|
||||
public:
|
||||
void *m_arg;
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
pthread_t m_thread;
|
||||
pthread_attr_t m_attr;
|
||||
|
||||
// private data
|
||||
private:
|
||||
bool m_join;
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
Thread();
|
||||
|
||||
// destructor
|
||||
virtual ~Thread();
|
||||
|
||||
Thread( const Thread& );
|
||||
const Thread& operator=( const Thread& );
|
||||
|
||||
// public methods
|
||||
void Init(void);
|
||||
int Start( void *arg = NULL, bool detach = false );
|
||||
int Stop( void );
|
||||
int Join( void **pptr = NULL );
|
||||
|
||||
pthread_t GetTid(void) {return m_thread;};
|
||||
|
||||
// virtual functions
|
||||
virtual bool Prep(void);
|
||||
virtual void *Run(void *) = 0; // {return NULL;};
|
||||
|
||||
// exceptions
|
||||
class ThreadException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods to override
|
||||
|
||||
// private methods
|
||||
private:
|
||||
// signal catchers (do not override)
|
||||
};
|
||||
|
||||
#endif
|
||||
80
include/libnet++/Timer.h
Normal file
80
include/libnet++/Timer.h
Normal file
@ -0,0 +1,80 @@
|
||||
//
|
||||
// Linux Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __Timer__
|
||||
#define __Timer__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "netlib.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class Timer {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
struct timespec m_timespec;
|
||||
bool m_running;
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
Timer();
|
||||
|
||||
// destructor
|
||||
virtual ~Timer();
|
||||
|
||||
// public methods
|
||||
|
||||
// virtual functions
|
||||
virtual int Restart(void);
|
||||
virtual int Start( unsigned long usec );
|
||||
virtual void Stop(void);
|
||||
virtual unsigned long Remaining(void);
|
||||
virtual int Wait(void);
|
||||
virtual int Sync(void); // Wait()+Restart()
|
||||
|
||||
// exceptions
|
||||
class TimerException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
static void Sleep( unsigned int sec ) { sleep(sec); };
|
||||
static void MilliSleep( unsigned long msec ) { msleep(msec); };
|
||||
static void MicroSleep( unsigned long usec ) { usleep(usec); };
|
||||
static void NanoSleep( unsigned long nsleep );
|
||||
|
||||
// private methods
|
||||
private:
|
||||
|
||||
// signal catchers (do not override)
|
||||
};
|
||||
|
||||
#endif
|
||||
56
include/libnet++/UdpArchdaemon.h
Normal file
56
include/libnet++/UdpArchdaemon.h
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// TCP Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdpArchdaemon__
|
||||
#define __UdpArchdaemon__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "UdpDaemon.h"
|
||||
#include "UdpThread.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdpArchdaemon : public UdpDaemon {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdpArchdaemon();
|
||||
|
||||
// destructor
|
||||
virtual ~UdpArchdaemon();
|
||||
|
||||
// public methods
|
||||
int StartService(const char *n,const char *h,const char *p,int d=0,int c=0);
|
||||
int RunService(void);
|
||||
|
||||
// overidden methods
|
||||
int Listen( void *arg=NULL );
|
||||
virtual UdpThread *ClientThread( void **parg ) {return NULL;};
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
65
include/libnet++/UdpCaster.h
Normal file
65
include/libnet++/UdpCaster.h
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// UDP Caster
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdpCaster__
|
||||
#define __UdpCaster__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "UdpSocket.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdpCaster : public UdpSocket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdpCaster();
|
||||
UdpCaster( const char *host, const char *service );
|
||||
|
||||
// destructor
|
||||
virtual ~UdpCaster();
|
||||
|
||||
// public methods
|
||||
int BroadcasterUri( const char *uri );
|
||||
int Broadcaster( const char *host, const char *service=NULL );
|
||||
int CasterUri( const char *uri );
|
||||
int Caster( const char *host, const char *service=NULL );
|
||||
int Restart( void );
|
||||
|
||||
// virtual functions
|
||||
virtual int SendTo( const void *buf, int max );
|
||||
|
||||
// exceptions
|
||||
class UdpCasterException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
void Init( void );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
63
include/libnet++/UdpClient.h
Normal file
63
include/libnet++/UdpClient.h
Normal file
@ -0,0 +1,63 @@
|
||||
//
|
||||
// TCP Client
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdpClient__
|
||||
#define __UdpClient__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "UdpSocket.h"
|
||||
#include "Client.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdpClient : public Client, public UdpSocket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdpClient();
|
||||
UdpClient( const char *host, const char *service );
|
||||
|
||||
// destructor
|
||||
virtual ~UdpClient();
|
||||
|
||||
// public methods
|
||||
int ConnectUri( const char *uri );
|
||||
int Connect( const char *host, const char *service=NULL );
|
||||
int Reconnect() { Close();return Connect(GetHost(),GetPort()); };
|
||||
int ListenUri( const char *uri );
|
||||
int Listen( const char *host, const char *port );
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
class UdpClientException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
52
include/libnet++/UdpDaemon.h
Normal file
52
include/libnet++/UdpDaemon.h
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// TCP Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdpDaemon__
|
||||
#define __UdpDaemon__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Daemon.h"
|
||||
#include "UdpServer.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdpDaemon : public UdpServer, public Daemon {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdpDaemon();
|
||||
|
||||
// destructor
|
||||
virtual ~UdpDaemon();
|
||||
|
||||
// public methods
|
||||
int StartService(const char *n,const char *h,const char *p,int d=0,int c=0);
|
||||
int RunService(void);
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
65
include/libnet++/UdpServer.h
Normal file
65
include/libnet++/UdpServer.h
Normal file
@ -0,0 +1,65 @@
|
||||
//
|
||||
// TCP Server
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdpServer__
|
||||
#define __UdpServer__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "UdpSocket.h"
|
||||
#include "Daemon.h"
|
||||
#include "Server.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdpServer : public Server, public UdpSocket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdpServer();
|
||||
UdpServer( const char *host, const char *service );
|
||||
|
||||
// destructor
|
||||
virtual ~UdpServer();
|
||||
|
||||
// public methods
|
||||
int ServiceUri( const char *uri );
|
||||
int Service( const char *host, const char *service=NULL );
|
||||
int Listen( void );
|
||||
int Restart( void );
|
||||
|
||||
// virtual functions
|
||||
virtual int ClientSock( int sock ) {return 0;};
|
||||
virtual int ClientInOut( char *buf, int n, int max ) {return n;};
|
||||
|
||||
// exceptions
|
||||
class UdpServerException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
74
include/libnet++/UdpSocket.h
Normal file
74
include/libnet++/UdpSocket.h
Normal file
@ -0,0 +1,74 @@
|
||||
//
|
||||
// Socket
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdpSocket__
|
||||
#define __UdpSocket__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Socket.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdpSocket : public Socket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
struct sockaddr_storage sock_addr;
|
||||
socklen_t sock_len;
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdpSocket();
|
||||
|
||||
// destructor
|
||||
virtual ~UdpSocket();
|
||||
|
||||
// copy constructor
|
||||
UdpSocket( const UdpSocket &src ) ;
|
||||
const UdpSocket& operator=( const UdpSocket &src );
|
||||
|
||||
// public methods
|
||||
int Socket( const char *host, const char *port );
|
||||
int Client( const char *host, const char *port );
|
||||
int Server( const char *host, const char *port );
|
||||
int Broadcast( const char *host, const char *port,
|
||||
struct sockaddr_storage *sa, socklen_t *len );
|
||||
int Listener( const char *host, const char *port );
|
||||
int Multicast( const char *host, const char *port,
|
||||
struct sockaddr_storage *sa, socklen_t *len );
|
||||
|
||||
int RecvFrom( void *buf, int max );
|
||||
int SendTo( const void *buf, int len );
|
||||
|
||||
// control
|
||||
|
||||
// status
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
59
include/libnet++/UdpThread.h
Normal file
59
include/libnet++/UdpThread.h
Normal file
@ -0,0 +1,59 @@
|
||||
//
|
||||
// UDP Thread
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdpThread__
|
||||
#define __UdpThread__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "UdpClient.h"
|
||||
#include "Thread.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdpThread : public UdpClient, public Thread {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdpThread();
|
||||
|
||||
// destructor
|
||||
virtual ~UdpThread();
|
||||
|
||||
// public methods
|
||||
void SetSocket( int sock ) {Socket::SetSocket(sock);};
|
||||
|
||||
// virtual functions
|
||||
virtual void *Run(void *);
|
||||
|
||||
// exceptions
|
||||
class UdpThreadException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
59
include/libnet++/UdsClient.h
Normal file
59
include/libnet++/UdsClient.h
Normal file
@ -0,0 +1,59 @@
|
||||
//
|
||||
// TCP Client
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdsClient__
|
||||
#define __UdsClient__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "UdsSocket.h"
|
||||
#include "Client.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdsClient : public Client, public UdsSocket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdsClient();
|
||||
UdsClient( const char *file );
|
||||
|
||||
// destructor
|
||||
virtual ~UdsClient();
|
||||
|
||||
// public methods
|
||||
int Connect( const char *file );
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
class UdsClientException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
52
include/libnet++/UdsDaemon.h
Normal file
52
include/libnet++/UdsDaemon.h
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// TCP Daemon
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdsDaemon__
|
||||
#define __UdsDaemon__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Daemon.h"
|
||||
#include "UdsServer.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdsDaemon : public UdsServer, public Daemon {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdsDaemon();
|
||||
|
||||
// destructor
|
||||
virtual ~UdsDaemon();
|
||||
|
||||
// public methods
|
||||
int StartService(const char *f,int d=0,int c=0);
|
||||
int RunService(void);
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
64
include/libnet++/UdsServer.h
Normal file
64
include/libnet++/UdsServer.h
Normal file
@ -0,0 +1,64 @@
|
||||
//
|
||||
// TCP Server
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdsServer__
|
||||
#define __UdsServer__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "UdsSocket.h"
|
||||
#include "Daemon.h"
|
||||
#include "Server.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdsServer : public Server, public UdsSocket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdsServer();
|
||||
UdsServer( const char *file );
|
||||
|
||||
// destructor
|
||||
virtual ~UdsServer();
|
||||
|
||||
// public methods
|
||||
int Service( const char *file );
|
||||
int Listen( void );
|
||||
int Restart( void );
|
||||
|
||||
// virtual functions
|
||||
virtual int ClientSock( int sock ) {return 0;};
|
||||
virtual int ClientInOut( char *buf, int n, int max ) {return n;};
|
||||
|
||||
// exceptions
|
||||
class UdsServerException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
70
include/libnet++/UdsSocket.h
Normal file
70
include/libnet++/UdsSocket.h
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// Socket
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdsSocket__
|
||||
#define __UdsSocket__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "Socket.h"
|
||||
#include <sys/un.h>
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
#define MAX_UDS_CLIENTS 10
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdsSocket : public Socket {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
char m_file[1024];
|
||||
struct sockaddr_storage sock_addr;
|
||||
socklen_t sock_len;
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdsSocket();
|
||||
|
||||
// destructor
|
||||
virtual ~UdsSocket();
|
||||
|
||||
// copy constructor
|
||||
UdsSocket( const UdsSocket &src ) ;
|
||||
const UdsSocket& operator=( const UdsSocket &src );
|
||||
|
||||
// public methods
|
||||
int Socket( const char *file );
|
||||
int Client( const char *file );
|
||||
int Server( const char *file );
|
||||
|
||||
// control
|
||||
|
||||
// status
|
||||
|
||||
// virtual functions
|
||||
|
||||
// exceptions
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
59
include/libnet++/UdsThread.h
Normal file
59
include/libnet++/UdsThread.h
Normal file
@ -0,0 +1,59 @@
|
||||
//
|
||||
// UDP Thread
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UdsThread__
|
||||
#define __UdsThread__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include "UdsClient.h"
|
||||
#include "Thread.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
class UdsThread : public UdsClient, public Thread {
|
||||
// public data
|
||||
public:
|
||||
|
||||
// protected data
|
||||
protected:
|
||||
|
||||
// private data
|
||||
private:
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UdsThread();
|
||||
|
||||
// destructor
|
||||
virtual ~UdsThread();
|
||||
|
||||
// public methods
|
||||
void SetSocket( int sock ) {Socket::SetSocket(sock);};
|
||||
|
||||
// virtual functions
|
||||
virtual void *Run(void *);
|
||||
|
||||
// exceptions
|
||||
class UdsThreadException
|
||||
{
|
||||
char *toString(void) { return strerror(errno); };
|
||||
};
|
||||
|
||||
// static methods
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
91
include/libnet++/UriParse.h
Normal file
91
include/libnet++/UriParse.h
Normal file
@ -0,0 +1,91 @@
|
||||
//
|
||||
// URI Parser
|
||||
// Neal Probert
|
||||
//
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __UriParse__
|
||||
#define __UriParse__
|
||||
|
||||
/* includes *****************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "QueryString.h"
|
||||
|
||||
/* defines ******************************************************************/
|
||||
|
||||
/* macros *******************************************************************/
|
||||
|
||||
/* structs & typedefs *******************************************************/
|
||||
|
||||
/* c class definitions ******************************************************/
|
||||
|
||||
//
|
||||
// Chop up the URI into it's component parts
|
||||
//
|
||||
class UriParse {
|
||||
// public data
|
||||
public:
|
||||
std::string Proto;
|
||||
std::string User;
|
||||
std::string Pass;
|
||||
std::string Host;
|
||||
std::string Port;
|
||||
std::string Path;
|
||||
std::vector<QueryString> Queries;
|
||||
|
||||
// private data
|
||||
private:
|
||||
int Rate;
|
||||
|
||||
// static data
|
||||
|
||||
// public methods
|
||||
public:
|
||||
// constructors
|
||||
UriParse();
|
||||
UriParse( const char *uri );
|
||||
|
||||
// destructor
|
||||
virtual ~UriParse();
|
||||
|
||||
// access methods
|
||||
int setUri( const char *uri ); // parse
|
||||
int getUri( char *buf, int size );
|
||||
|
||||
void setProto( const char *s ) { Proto = s; };
|
||||
void setUser( const char *s ) { User = s; };
|
||||
void setPassword( const char *s ) { Pass = s; };
|
||||
void setHost( const char *s ) { Host = s; };
|
||||
void setService( const char *s ){ Port = s; };
|
||||
void setPort( int p ) { Port = p; };
|
||||
void setPath( const char *s ) { Path = s; };
|
||||
void setRate( int r ) { Rate = r; };
|
||||
|
||||
const char *getProto(void) { return Proto.c_str(); };
|
||||
const char *getUser(void) { return User.c_str(); };
|
||||
const char *getPassword(void) { return Pass.c_str(); };
|
||||
const char *getHost(void) { return Host.c_str(); };
|
||||
const char *getService(void) { return Port.c_str(); };
|
||||
int getPort(void);
|
||||
const char *getPath(void) { return Path.c_str(); };
|
||||
int getRate(void) { return Rate; };
|
||||
|
||||
void setQuery( const char *name, const char *value );
|
||||
const char *getQuery( const char *name );
|
||||
|
||||
// static methods
|
||||
|
||||
// private methods
|
||||
private:
|
||||
void Init(void);
|
||||
int Parse( const char *uri );
|
||||
};
|
||||
|
||||
#endif
|
||||
39
include/memlib.h
Normal file
39
include/memlib.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef __MEMLIB_INCLUDE__
|
||||
#define __MEMLIB_INCLUDE__
|
||||
|
||||
/******************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <memory.h>
|
||||
|
||||
//#pragma deprecated (memcpy, memmove)
|
||||
|
||||
/******************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void memcpy_s(void *dest, size_t max, const void *src, size_t count);
|
||||
void memmove_s(void *dest, size_t max, const void *src, size_t count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/******************************************************************************
|
||||
* Macros
|
||||
* ***************************************************************************/
|
||||
|
||||
#endif
|
||||
143
include/netlib.h
Normal file
143
include/netlib.h
Normal file
@ -0,0 +1,143 @@
|
||||
#ifndef __NETLIB_INCLUDE__
|
||||
#define __NETLIB_INCLUDE__
|
||||
|
||||
/******************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <netdb.h>
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "strlib.h"
|
||||
|
||||
/******************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
#define VAR_LOG_RUN_NAME "cnomicon"
|
||||
|
||||
/******************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
typedef struct _uri_parts {
|
||||
char proto[8];
|
||||
char user[16];
|
||||
char pass[16];
|
||||
char host[256];
|
||||
char port[16];
|
||||
char path[1204];
|
||||
int rate;
|
||||
} uri_parts;
|
||||
|
||||
/******************************************************************************
|
||||
* function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* File */
|
||||
int fd_add( int sock, fd_set *pfds, int nfds );
|
||||
int fd_count( fd_set *pfds );
|
||||
int selector( int *nfds, fd_set *rfds, fd_set *wfds, long usec );
|
||||
|
||||
/* Runtime */
|
||||
void log_path( const char * );
|
||||
FILE *log_open( const char * );
|
||||
void log_write( const char * );
|
||||
void log_printf( const char *, ... );
|
||||
void log_error( const char * );
|
||||
void log_on(void);
|
||||
void log_off(void);
|
||||
void pid_path( const char * );
|
||||
int pid_create( const char * );
|
||||
void pid_delete( void );
|
||||
|
||||
/* Serial I/O */
|
||||
int serial_open( char *tty, int baud, int vmin, int vwait );
|
||||
|
||||
/* Signals */
|
||||
int sigrt_alloc(void);
|
||||
void sigrt_free(int sig);
|
||||
|
||||
/* TCP/IP Basics */
|
||||
int ip_host2addr( const char *host, const char *service, struct sockaddr_storage *ss, socklen_t *len );
|
||||
const char *ip_host2name( char *buf, int max, const struct sockaddr_storage *ss);
|
||||
int ip_name2host( const char *buf, struct sockaddr_storage *ss);
|
||||
int ip_service2port( const char *service, int port, const char *proto );
|
||||
int ip_sockname( int sock, struct sockaddr_storage *ss );
|
||||
|
||||
/* MAC Address */
|
||||
int mac_interface2macaddr( const char *, unsigned char * );
|
||||
int mac_string2mac( const char *str, unsigned char *mac );
|
||||
int mac_mac2string( const unsigned char *mac, char *str );
|
||||
|
||||
/* TCP Server */
|
||||
int tcp_server( const char *host, const char *service );
|
||||
int tcp_accept( int sock, struct sockaddr_storage *ss );
|
||||
|
||||
/* TCP Client */
|
||||
int tcp_client( const char *host, const char *service );
|
||||
int tcp_nagle( int sock, int flag );
|
||||
|
||||
/* TCP I/O */
|
||||
int tcp_recv( int sock, void *buf, int len );
|
||||
int tcp_send( int sock, const char *buf, int len );
|
||||
int tcp_sendstr( int sock, const char *str );
|
||||
|
||||
/* UDP Server */
|
||||
int udp_server( const char *host, const char *service );
|
||||
int udp_client( const char *host, const char *service );
|
||||
int udp_socket( const char *host, const char *service );
|
||||
|
||||
/* UDP Broadcast */
|
||||
int udp_broadcast( const char *host, const char *service, struct sockaddr_storage *, socklen_t *);
|
||||
int udp_multicast( const char *host, const char *service, struct sockaddr_storage *, socklen_t *);
|
||||
int udp_listener( const char *host, const char *service );
|
||||
|
||||
/* UDP I/O */
|
||||
int udp_recvfrom( int sock, void *buf, int n, struct sockaddr_storage *, socklen_t *len );
|
||||
int udp_sendto( int sock, const char *buf, int n, const struct sockaddr_storage *, int len );
|
||||
int udp_sendstr( int sock, const char *buf, const struct sockaddr_storage *, int len );
|
||||
|
||||
/* Unix Domain Socket (UDS) */
|
||||
int uds_client( const char *file );
|
||||
int uds_server( const char *file );
|
||||
|
||||
/* URI */
|
||||
void uri_clear( uri_parts *parsed );
|
||||
void uri_defaults( uri_parts *parsed );
|
||||
int uri_parse( const char *uri, uri_parts *parsed );
|
||||
|
||||
/* misc */
|
||||
int chomp(char *s);
|
||||
void base64(const unsigned char *in, char *out, int len);
|
||||
int unbase64(const char *in, unsigned char *out, int max);
|
||||
int msleep(unsigned long msec);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/******************************************************************************
|
||||
* Macros
|
||||
* ***************************************************************************/
|
||||
|
||||
// connected udp socket
|
||||
#define udp_send(S,B,L) tcp_send(S,B,L)
|
||||
#define uds_recv(S,B,L) tcp_recv(S,B,L)
|
||||
#define uds_send(S,B,L) tcp_send(S,B,L)
|
||||
|
||||
#endif
|
||||
40
include/strlib.h
Normal file
40
include/strlib.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef __STRLIB_INCLUDE__
|
||||
#define __STRLIB_INCLUDE__
|
||||
|
||||
/******************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
//#pragma deprecated (strcpy, strcat)
|
||||
|
||||
/******************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/******************************************************************************
|
||||
* Macros
|
||||
* ***************************************************************************/
|
||||
|
||||
#endif
|
||||
55
include/utillib.h
Normal file
55
include/utillib.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (C) 2008
|
||||
* ProbeStar Telematics, LLC
|
||||
* All Rights Reserved. Proprietary and Confidential.
|
||||
*============================================================================
|
||||
* Multiplatform Embedded Data Types and Conversion
|
||||
* Checksum and CRC Routines
|
||||
*****************************************************************************/
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef _UTILLIB_H_
|
||||
#define _UTILLIB_H_
|
||||
|
||||
/*****************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*****************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* macros
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* global constants
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* global variables
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* C function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void hex_print(FILE *pHexFile, const u_char *packet, int length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user