LLC2_API
example-dynamic.cpp
Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file example1-dynamic.cpp                                                                 */
00003 /* ------------------------------------------------------------------------- */
00004 /*   Copyright (C) 2011 Peter Milne, D-TACQ Solutions Ltd
00005  *                      <Peter dot Milne at D hyphen TACQ dot com>
00006  *  Created on: Sep 14, 2011
00007  *      Author: pgm
00008 
00009     http://www.d-tacq.com
00010 
00011     This program is free software; you can redistribute it and/or modify
00012     it under the terms of Version 2 of the GNU General Public License
00013     as published by the Free Software Foundation;
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
00023 /* ------------------------------------------------------------------------- */
00024 
00025 /** @file example-dynamic.cpp example with dynamic system load.
00026  *
00027  * Example usage:
00028  * @verbatim
00029 LL2_SYSFILE=xml/example1-krypton.xml LL_OUTPUTS=data/ai-ramps.dat ./example-dynamic -v 2 -n 10000 100
00030 
00031 
00032 LL2_SYSFILE : xml system definition
00033 LL_OUTPUTS  : data file for AO data. DO is alternating all 1's.
00034 
00035 ./example-dynamic : run this program
00036 -v 2                    : verbose
00037 -n 10000                : for 10k samples
00038 100                             : ECM 100 eg 100usec cycle with 1MHz SYSCLK
00039 
00040    @endverbatim
00041  */
00042 #include <stdio.h>
00043 #include <sys/types.h>
00044 #include <sys/stat.h>
00045 #include <unistd.h>
00046 #include <stdlib.h>
00047 #include <errno.h>
00048 #include <assert.h>
00049 
00050 #include "ll2.h"
00051 #include "testharness.h"
00052 
00053 /** environment variable defines config_file */
00054 #define LL2_SYSFILE     "LL2_SYSFILE"
00055 
00056 /** default config_file */
00057 #define LL2_SYSFILE_DEFAULT     "xml/example1.xml"
00058 
00059 /** example program with dynamic system instantiation from config_file*/
00060 int main(int argc, const char* argv[])
00061 {
00062         const char* sysfile =
00063                         getenv(LL2_SYSFILE)? getenv(LL2_SYSFILE): LL2_SYSFILE_DEFAULT;
00064         LL_ControlSystem& the_system = LL_ControlSystem::createFromFile(sysfile);
00065 
00066         the_system.init(argc, argv);
00067 
00068         const int SAMPLES = the_system.getSamples();
00069         Outputs outputs(the_system.getAO_count(), the_system.getDO_count());
00070         Inputs inputs(SAMPLES,
00071                         the_system.getAI_count(),
00072                         the_system.getDI_count(), the_system.getStatus_count());
00073 
00074         the_system.Arm(outputs.getAO(0), outputs.getDO(0));
00075 
00076         for (int ii = 0; ii < SAMPLES; ++ii){
00077                 int rc = the_system.IO(
00078                                 outputs.getAO(ii), outputs.getDO(ii),
00079                                 inputs.getAI(ii), inputs.getDI(ii), inputs.getStatus(ii));
00080         }
00081 
00082         the_system.Stop();
00083         LL_ControlSystem::closedown(the_system);
00084 }