OpenCores
URL https://opencores.org/ocsvn/gecko3/gecko3/trunk

Subversion Repositories gecko3

[/] [gecko3/] [trunk/] [GECKO3COM/] [gecko3com-fw/] [examples/] [scpi_parser_full_spec.re] - Blame information for rev 14

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 nussgipfel
/* GECKO3COM
2
 *
3
 * Copyright (C) 2009 by
4
 *   ___    ____  _   _
5
 *  (  _`\ (  __)( ) ( )
6
 *  | (_) )| (_  | |_| |   Berne University of Applied Sciences
7
 *  |  _ <'|  _) |  _  |   School of Engineering and
8
 *  | (_) )| |   | | | |   Information Technology
9
 *  (____/'(_)   (_) (_)
10
 *
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation, either version 3 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program.  If not, see .
23
 */
24
 
25
/*********************************************************************/
26
/** \cond EXAMPLE \file     scpi_parser.re
27
 *********************************************************************
28
 * \brief     Parser for the SCPI commands. Excecutes the necessary
29
 *            Function.
30
 *
31
 *            The SCPI Parser is developed as a set of regular
32
 *            expressions and blocks of C code to excecute. \n
33
 *            We use the opensource programm re2c (http://re2c.org/) to
34
 *            generate the parser. With solution we have an easy to
35
 *            maintain and extend parser definitions without the hassle
36
 *            of optimizing the parser sourcecode by hand. \n \n
37
 *            Don't forget to use the "-s" option with re2c to generate
38
 *            nested ifs for some switches because sdcc hates long
39
 *            switch case structures.
40
 *
41
 * \todo      use newer re2c to generate state event diagramm to include here
42
 *
43
 * \author    Christoph Zimmermann bfh.ch
44
 * \date      2009-02-04
45
 *
46
 * \endcond
47
*/
48
 
49
#include 
50
#include 
51
 
52
#include "scpi_parser.h"
53
#include "debugprint.h"
54
 
55
 
56
#define YYCTYPE         uint8_t
57
#define YYCURSOR        s->cur
58
#define YYLIMIT         s->lim
59
#define YYMARKER        s->ptr
60
#define YYFILL(n)       {YYCURSOR = fill(s, buffer, n);}
61
/*!max:re2c */          /* this will define YYMAXFILL */
62
 
63
 
64
uint8_t* fill(Scanner *s, int16_t *buffer, uint8_t n){
65
  uint8_t i = 0;
66
 
67
  for(i;i
68
    buffer[i] = tolower(*(s->source));
69
    s->source++;
70
  }
71
 
72
  s->cur = buffer;
73
  s->lim = &buffer[n];
74
 
75
  return s->cur;
76
}
77
 
78
 
79
int8_t scpi_scan(Scanner *s){
80
 
81
  int8_t buffer[YYMAXFILL];
82
 
83
  /** \cond SCANNER
84
   * this is a ugly hack to avoid that the regular expressions are included in
85
   * the doxygen documentation
86
  */
87
 
88
  /*!re2c
89
 
90
  /* place here the regular expressions to detect the end of a message */
91
 
92
  /* FIXME end detection missing */
93
  "\n"                                  { /* end of message reached */
94
                                          return 99;
95
                                        }
96
 
97
  /* this set of regular expressions are for the mandatory IEEE488 commands */
98
 
99
  "*cls"                                { /* clear status command */
100
 
101
                                          return 1;
102
                                        }
103
 
104
  "*ese"                                { /* standard event status enable command */
105
 
106
                                          return 1;
107
                                        }
108
 
109
  "*ese?"                               { /* standard event status enable query */
110
 
111
                                          return 1;
112
                                        }
113
 
114
  "*esr?"                               { /* standard event status register query */
115
 
116
                                          return 1;
117
                                        }
118
 
119
  "*idn?"                               { /* identification query */
120
 
121
                                          return 1;
122
                                        }
123
 
124
  "*opc"                                { /* operation complete command */
125
 
126
                                          return 1;
127
                                        }
128
 
129
  "*opc?"                               { /* operation complete query */
130
 
131
                                          return 1;
132
                                        }
133
 
134
  "*rst"                                { /* reset command */
135
 
136
                                          return 1;
137
                                        }
138
 
139
  "*sre"                                { /* service request enable command */
140
 
141
                                          return 1;
142
                                        }
143
 
144
  "*sre?"                               { /* service request enable query */
145
 
146
                                          return 1;
147
                                        }
148
 
149
  "*stb?"                               { /* read status byte query */
150
 
151
                                          return 1;
152
                                        }
153
 
154
  "*tst?"                               { /* self-test query */
155
 
156
                                          return 1;
157
                                        }
158
 
159
  "*wai"                                { /* wait-to-continue command */
160
 
161
                                          return 1;
162
                                        }
163
 
164
 
165
 
166
  /* this set of regular expressions are for the mandatory SCPI 99 commands */
167
 
168
  "syst:err?"|"syst:err:next?"          { /* gets an error message if ther is one */
169
 
170
                                          return 1;
171
                                        }
172
 
173
  "syst:vers"                           { /* returns the firmware version number */
174
 
175
                                          return 1;
176
                                        }
177
 
178
  "stat:oper?"|"stat:oper:even?"        { /* dfsg */
179
 
180
                                          return 1;
181
                                        }
182
 
183
  "stat:oper:cond?"                     { // fsdgsg
184
 
185
                                          return 1;
186
                                        }
187
 
188
  "stat:oper:enab"                      { // sfgsdf
189
 
190
                                          return 1;
191
                                        }
192
 
193
  "stat:oper:enab?"                     { // sfgfsdg
194
 
195
                                          return 1;
196
                                        }
197
 
198
  "stat:ques?"|"stat:ques:even?"        { // sfgfsdg
199
 
200
                                          return 1;
201
                                        }
202
 
203
  "stat:ques:cond?"                     { // sfgsdfg
204
 
205
                                          return 1;
206
                                        }
207
 
208
  "stat:ques:enab"                      { // sfgsdfg
209
 
210
                                          return 1;
211
                                        }
212
 
213
  "stat:ques:enab?"                     { // sfgfg
214
 
215
                                          return 1;
216
                                        }
217
 
218
  "stat:pres"                           { // sfgfg
219
 
220
                                          return 1;
221
                                        }
222
 
223
 
224
 
225
  /* this set of regular expressions are for the device functions */
226
 
227
 
228
  "diag:mes?"                           { /* ask if there is a message to read available */
229
                                          print_info("scpi: diag:mes?\n");
230
                                          return 1;
231
                                        }
232
 
233
  "diag:mes"                            { /* reads the message from the message buffer */
234
                                          print_info("scpi: diag:mes\n");
235
                                          return 1;
236
                                        }
237
 
238
  "diag:gpif?"                          { /* reads the GPIF state */
239
                                          print_info("scpi: diag:gpif?\n");
240
                                          return 1;
241
                                        }
242
 
243
*/
244
 
245
/** \endcond */
246
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.