LLC2_API
ll2-api.cpp
Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file ll2-api.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 ll2-api.cpp C wrapper for LOWLATENCY2 API.
00026  *
00027  */
00028 
00029 #include <stdio.h>
00030 #include <assert.h>
00031 #include "ll2.h"
00032 #include "ll2-api.h"
00033 
00034 #define RETOK(fun)      do { return (fun) == 0? OK: ERR; } while (0)
00035 
00036 /** singleton */
00037 class DynamicSystem {
00038         LL_ControlSystem& the_system;
00039         DynamicSystem(LL_ControlSystem& _the_system)  :
00040                 the_system(_the_system)
00041         {}
00042 public:
00043         static LL_ControlSystem& instance(const char* config_file = 0);
00044 };
00045 
00046 
00047 
00048 
00049 LL_ControlSystem& DynamicSystem::instance(const char* config_file)
00050 {
00051         static DynamicSystem* instance;
00052 
00053         assert(!(instance == 0 && config_file == 0));
00054         assert(!(instance != 0 && config_file != 0));
00055 
00056         if (instance == 0){
00057                 instance = new DynamicSystem(LL_ControlSystem::createFromFile(config_file));
00058         }
00059         return instance->the_system;
00060 }
00061 
00062 /** instantiate system
00063  * @param config_file .xml file with system definition
00064  * @param argc  pass in argc argv for optional command line initialization set zero if not required
00065  * @param argv  optional command line argv array
00066  */
00067 STATUS_OK RtSetup(const char* config_file, int argc, const char* argv[])
00068 {
00069         DynamicSystem::instance(config_file).init(argc, argv);
00070         return OK;
00071 }
00072 
00073 /** arm the capture
00074  * @param ao_values initial ao values
00075  * @param do_values initial do_values
00076  */
00077 STATUS_OK RtArm(
00078                 const short* ao_values,
00079                 const unsigned* do_values)
00080 {
00081         RETOK(DynamicSystem::instance().Arm(ao_values, do_values));
00082 }
00083 
00084 /** set next outputs, wait for and return next sample
00085  * @param ao_values next ao_values
00086  * @param do_values next do_values
00087  * @param ai_values latest ai sample
00088  * @param di_values latest di sample
00089  * @param status_values latest status values
00090  */
00091 STATUS_OK RtIO(
00092                 const short* ao_values,
00093                 const unsigned* do_values,
00094                 short* ai_values,
00095                 unsigned* di_values,
00096                 unsigned* status_values)
00097 {
00098         RETOK(DynamicSystem::instance().IO(
00099                         ao_values, do_values, ai_values, di_values, status_values));
00100 }
00101 
00102 /** stop and cleanup. */
00103 STATUS_OK RtDone(void)
00104 {
00105         DynamicSystem::instance().Stop();
00106         LL_ControlSystem::closedown(DynamicSystem::instance());
00107         return OK;
00108 }