#include <stdio.h>
#include <string.h>
#include "inetfile.hh"
#include "inifile.h"
#include "rcs_prnt.hh"
#include <math.h>
#include "amplifier.h"
Include dependency graph for amplifier.c:
Go to the source code of this file.
Defines | |
#define | GAIN_SET 0x01 |
#define | MAX_OUTPUT_CURRENT_SET 0x02 |
#define | LOAD_RESISTANCE_SET 0x04 |
#define | ALL_SET (GAIN_SET | MAX_OUTPUT_CURRENT_SET | LOAD_RESISTANCE_SET) |
Functions | |
char | __attribute__ ((unused)) ident[]="$Id |
int | amplifierSetGain (AMPLIFIER_STRUCT *amp, double gain) |
double | amplifierGetGain (AMPLIFIER_STRUCT *amp) |
int | amplifierSetMaxOutputCurrent (AMPLIFIER_STRUCT *amp, double maxOutputCurrent) |
double | amplifierGetMaxOutputCurrent (AMPLIFIER_STRUCT *amp) |
int | amplifierSetLoadResistance (AMPLIFIER_STRUCT *amp, double loadResistance) |
double | amplifierGetLoadResistance (AMPLIFIER_STRUCT *amp) |
int | amplifierEnable (AMPLIFIER_STRUCT *amp) |
int | amplifierDisable (AMPLIFIER_STRUCT *amp) |
int | amplifierIsEnabled (AMPLIFIER_STRUCT *amp) |
int | amplifierReset (AMPLIFIER_STRUCT *amp) |
int | amplifierIsTripped (AMPLIFIER_STRUCT *amp) |
double | amplifierRunCycle (AMPLIFIER_STRUCT *amp, double input) |
int | amplifierIniLoad (AMPLIFIER_STRUCT *amplifier, const char *filename, const char *section) |
|
|
|
|
|
|
|
|
|
Definition at line 35 of file amplifier.c. 00035 : amplifier.c,v 1.2 2000/10/27 20:34:42 terrylr Exp $"; 00036 00037 #define GAIN_SET 0x01 00038 #define MAX_OUTPUT_CURRENT_SET 0x02 00039 #define LOAD_RESISTANCE_SET 0x04 00040 #define ALL_SET (GAIN_SET | MAX_OUTPUT_CURRENT_SET | LOAD_RESISTANCE_SET) 00041 00042 int amplifierInit(AMPLIFIER_STRUCT * amp) 00043 { 00044 /* parameters */ 00045 if (0 == amp) 00046 { 00047 return -1; 00048 } 00049 00050 amp->gain = 0.0; 00051 amp->maxOutputCurrent = 0.0; 00052 amp->loadResistance = 1.0; /* not zero-- it's a denominator */ 00053 00054 /* internal vars */ 00055 amp->configured = 0; 00056 amp->enabled = 0; 00057 amp->tripped = 0; 00058 00059 return 0; 00060 } |
|
Definition at line 156 of file amplifier.c. 00157 { 00158 if (0 == amp) 00159 { 00160 return -1; 00161 } 00162 00163 amp->enabled = 0; 00164 00165 return 0; 00166 } |
|
Definition at line 139 of file amplifier.c. 00140 { 00141 if (0 == amp) 00142 { 00143 return -1; 00144 } 00145 00146 if (! amp->tripped && 00147 amp->configured == ALL_SET) 00148 { 00149 amp->enabled = 1; 00150 } 00151 00152 return 0; 00153 } |
|
Definition at line 76 of file amplifier.c. 00077 { 00078 if (0 == amp || 00079 ! (amp->configured & GAIN_SET)) 00080 { 00081 return 0.0; 00082 } 00083 00084 return amp->gain; 00085 } |
|
Definition at line 127 of file amplifier.c. 00128 { 00129 if (0 == amp || 00130 ! (amp->configured & LOAD_RESISTANCE_SET)) 00131 { 00132 return 0.0; 00133 } 00134 00135 return amp->loadResistance; 00136 } |
|
Definition at line 102 of file amplifier.c. 00103 { 00104 if (0 == amp || 00105 ! (amp->configured & MAX_OUTPUT_CURRENT_SET)) 00106 { 00107 return 0.0; 00108 } 00109 00110 return amp->maxOutputCurrent; 00111 } |
|
Definition at line 241 of file amplifier.c. 00242 { 00243 #ifndef NO_STDIO_SUPPORT 00244 00245 AMPLIFIER_STRUCT amp; 00246 int retval = 0; 00247 const char *inistring; 00248 00249 #ifndef UNDER_CE 00250 FILE *fp; 00251 00252 if (NULL == (fp = fopen(filename, "r"))) 00253 { 00254 rcs_print_error( "can't open ini file %s\n", filename); 00255 return -1; 00256 } 00257 #else 00258 INET_FILE *fp; 00259 00260 if (NULL == (fp = inet_file_open(filename, "r"))) 00261 { 00262 rcs_print_error( "can't open ini file %s\n", filename); 00263 return -1; 00264 } 00265 #endif 00266 00267 memset(&,0,sizeof(amp)); 00268 if (NULL != (inistring = iniFind(fp, "AMPLIFIER_GAIN", section))) 00269 { 00270 #ifndef UNDER_CE 00271 if (1 != sscanf((char *) inistring, "%lf", &.gain)) 00272 { 00273 /* found, but invalid */ 00274 rcs_print_error( "invalid GAIN: %s\n", inistring); 00275 retval = -1; 00276 } 00277 else 00278 { 00279 amplifierSetGain(amplifier, amp.gain); 00280 } 00281 #else 00282 amp.gain = RCS_CE_ATOF(inistring); 00283 amplifierSetGain(amplifier, amp.gain); 00284 #endif 00285 } 00286 00287 if (NULL != (inistring = iniFind(fp, "MAX_OUTPUT_CURRENT", section))) 00288 { 00289 #ifndef UNDER_CE 00290 if (1 != sscanf((char *) inistring, "%lf", &.maxOutputCurrent)) 00291 { 00292 /* found, but invalid */ 00293 rcs_print_error( "invalid MAX_OUTPUT_CURRENT: %s\n", inistring); 00294 retval = -1; 00295 } 00296 else 00297 { 00298 amplifierSetMaxOutputCurrent(amplifier, amp.maxOutputCurrent); 00299 } 00300 #else 00301 amp.maxOutputCurrent = RCS_CE_ATOF(inistring); 00302 amplifierSetMaxOutputCurrent(amplifier, amp.maxOutputCurrent); 00303 #endif 00304 } 00305 00306 if (NULL != (inistring = iniFind(fp, "LOAD_RESISTANCE", section))) 00307 { 00308 #ifndef UNDER_CE 00309 if (1 != sscanf((char *) inistring, "%lf", &.loadResistance)) 00310 { 00311 /* found, but invalid */ 00312 rcs_print_error( "invalid LOAD_RESISTANCE: %s\n", inistring); 00313 retval = -1; 00314 } 00315 else 00316 { 00317 amplifierSetLoadResistance(amplifier, amp.loadResistance); 00318 } 00319 #else 00320 amp.loadResistance = RCS_CE_ATOF(inistring); 00321 amplifierSetLoadResistance(amplifier, amp.loadResistance); 00322 #endif 00323 } 00324 00325 /* close inifile */ 00326 #ifndef UNDER_CE 00327 fclose(fp); 00328 #else 00329 inet_file_close(fp); 00330 #endif 00331 00332 00333 return retval; 00334 00335 #else 00336 00337 return -1; 00338 00339 #endif 00340 } |
|
Definition at line 169 of file amplifier.c. 00170 { 00171 if (0 == amp) 00172 { 00173 return -1; 00174 } 00175 00176 return amp->enabled; 00177 } |
|
Definition at line 197 of file amplifier.c. 00198 { 00199 if (0 == amp) 00200 { 00201 return -1; 00202 } 00203 00204 return amp->tripped; 00205 } |
|
Definition at line 180 of file amplifier.c. 00181 { 00182 if (0 == amp) 00183 { 00184 return -1; 00185 } 00186 00187 if (amp->configured == ALL_SET) 00188 { 00189 amp->enabled = 0; 00190 amp->tripped = 0; 00191 } 00192 00193 return 0; 00194 } |
|
Definition at line 207 of file amplifier.c. 00208 { 00209 double output; 00210 double outputCurrent; 00211 00212 /* check for configured */ 00213 if (0 == amp || 00214 amp->configured != ALL_SET) 00215 { 00216 return 0.0; 00217 } 00218 00219 /* check state for allowing output */ 00220 if (! amp->enabled || 00221 amp->tripped) 00222 { 00223 return 0.0; /* disabled-- hold output at 0.0 */ 00224 } 00225 00226 /* finally-- do the simple math */ 00227 output = amp->gain * input; 00228 outputCurrent = fabs(output / amp->loadResistance); 00229 00230 /* check output */ 00231 if (outputCurrent > amp->maxOutputCurrent) 00232 { 00233 amp->tripped = 1; 00234 amp->enabled = 0; 00235 output = 0.0; 00236 } 00237 00238 return output; 00239 } |
|
Definition at line 62 of file amplifier.c. 00063 { 00064 if (0 == amp || 00065 gain <= 0.0) 00066 { 00067 return -1; 00068 } 00069 00070 amp->gain = gain; 00071 amp->configured |= GAIN_SET; 00072 00073 return 0; 00074 } |
|
Definition at line 113 of file amplifier.c. 00114 { 00115 if (0 == amp || 00116 loadResistance <= 0.0) 00117 { 00118 return -1; 00119 } 00120 00121 amp->loadResistance = loadResistance; 00122 amp->configured |= LOAD_RESISTANCE_SET; 00123 00124 return 0; 00125 } |
|
Definition at line 87 of file amplifier.c. 00089 { 00090 if (0 == amp || 00091 maxOutputCurrent <= 0.0) 00092 { 00093 return -1; 00094 } 00095 00096 amp->maxOutputCurrent = maxOutputCurrent; 00097 amp->configured |= MAX_OUTPUT_CURRENT_SET; 00098 00099 return 0; 00100 } |