c9d1a3c8f8709a339aa62c15b584a7d21dfe94f1
[bertos.git] / bertos / net / nmeap / inc / nmeap_def.h
1 /*
2 Copyright (c) 2005, David M Howard (daveh at dmh2000.com)
3 All rights reserved.
4
5 This product is licensed for use and distribution under the BSD Open Source License.
6 see the file COPYING for more details.
7
8 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
9 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
10 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
11 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
12 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
13 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
14 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
15 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
16 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
17 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
18 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
19
20 */
21
22 #ifndef __NMEAP_DEF_H__
23 #define __NMEAP_DEF_H__
24
25 /**
26  * context for a single sentence 
27  */
28 typedef struct nmeap_sentence {
29     char                    name[NMEAP_MAX_SENTENCE_NAME_LENGTH + 1];
30         int                     id;
31     nmeap_sentence_parser_t parser;
32     nmeap_callout_t         callout;
33     void                   *data;
34 } nmeap_sentence_t;
35
36 /** 
37  * parser context
38  */
39 struct nmeap_context {
40         /** support up to 8 sentences */
41         nmeap_sentence_t sentence[NMEAP_MAX_SENTENCES];         /* sentence descriptors */
42         int              sentence_count;                                                /* number of initialized descriptors */
43         
44         /** sentence input buffer */
45         char             input[NMEAP_MAX_SENTENCE_LENGTH + 1];   /* input line buffer */
46         int              input_count;                           /* index into 'input */
47         int              input_state;                           /* current lexical scanner state */
48         char             input_name[6];                        /* sentence name */
49         char             icks;                                          /* input checksum    */
50         char             ccks;                                          /* computed checksum */
51         
52         /* tokenization */
53         char            *token[NMEAP_MAX_TOKENS];              /* list of delimited tokens */
54         int              tokens;                                                             /* list of tokens */
55         
56         /** errors and debug. optimize these as desired */
57         unsigned long    msgs;    /* count of good messages */
58         unsigned long    err_hdr; /* header error */                                                    
59         unsigned long    err_ovr; /* overrun error */
60         unsigned long    err_unk; /* unknown error */
61         unsigned long    err_id;  /* bad character in id */
62         unsigned long    err_cks; /* bad checksum */
63         unsigned long    err_crl; /* expecting cr or lf, got something else */
64         char             debug_input[NMEAP_MAX_SENTENCE_LENGTH + 1];     /* input line buffer for debug */
65         
66         /** opaque user data */
67         void *user_data;
68 };
69
70 typedef struct nmeap_context nmeap_context_t;
71
72 #endif /* __NMEAP_DEF_H__ */