00001 #ifndef QUICKTRIMTEST_H
00002 #define QUICKTRIMTEST_H
00003
00004 #include "../ipc/TestRequest.h"
00005 #include "../ipc/CalibrationController.h"
00006 #include "../ipc/ScanLibrary.h"
00007 #include "../ipc/CalibrationController.hh"
00008 #include "../CalibrationControllerImpl.h"
00009
00010 #include "../SctApiAccessException.h"
00011 #include "Sct/LogicErrors.h"
00012 #include "../SctApiCall.h"
00013
00014 #include <CommonWithDsp/ABCD/ABCDscans.h>
00015 #include <iostream>
00016 #include <vector>
00017
00018 using namespace std;
00019 using namespace SctCalibrationController::Ipc;
00020 using namespace SctCalibrationController;
00021 using namespace Sct;
00022
00023 namespace SctCalibrationController {
00024 namespace Scripts {
00025
00028 class QuickTrimTest : public TestRequestImpl {
00029 private:
00030 static const bool registeredInTestLibrary;
00031
00032 public:
00033 static Sct_CalibrationController::TestRequest_ptr instance() {
00034 static QuickTrimTest tr;
00035 return tr._this();
00036 }
00037
00038 virtual void startTestRealImpl(Sct_SctApi::SctApiIPC_ptr inapi, string& name, unsigned short& testVariable, unsigned long& nScans, vector<double>& testPoints) {
00039 this->api = Sct_SctApi::SctApiIPC::_duplicate(inapi);
00040
00041
00042 APICALL(api, modifyABCDVar(ST_COMPRESSION, 1), "QuickTrimTest::startTest can't set compression")
00043
00044
00045 APICALL(api, modifyABCDVar(ST_EDGE_DETECT, 0), "QuickTrimTest::startTest can't set edge detect")
00046
00047
00048 APICALL(api, modifyABCDVar(ST_SEND_MASK, 0), "QuickTrimTest::startTest can't set send mask")
00049
00050
00051 APICALL(api, modifyABCDVar(ST_QCAL, 1), "QuickTrimTest::startTest can't set qcal")
00052
00053 name = "TrimRangeTest";
00054 testVariable=ST_TRIM_RANGE;
00055 for (unsigned int i=0; i<13; ++i) {
00056 testPoints.push_back(getValue(i));
00057 }
00058 nScans = testPoints.size();
00059 }
00060
00061 virtual Sct_CalibrationController::ScanRequest_ptr getNextScanRealImpl(unsigned long index) {
00062 if (isFirstPoint(index)) {
00063
00064 APICALL(api, modifyABCDVar(ST_TRIM_RANGE, getRange(index)), "QuickTrimTest::getNextScan")
00065 }
00066
00067 APICALL(api, modifyABCDVar(ST_TRIM, getValue(index)), "QuickTrimTest::getNextScan")
00068
00069 Sct_CalibrationController::ScanLibrary_var sl = CalibrationControllerImpl::instance()->getScanLibrary();
00070 double offset = ranges[getRange(index)] * getValue(index);
00071 return sl->thresholdScanfCOffset(400, 1.0, offset);
00072 }
00073
00074 unsigned int getRange(unsigned int index) {
00075 if (index<4) return 0;
00076 else return (index-1)/3+1;
00077 }
00078
00079 bool isFirstPoint(unsigned int index) {
00080 return (index==0 || (index-1)%3) == 0;
00081 }
00082
00083 unsigned int getValue(unsigned int index) {
00084 if (index ==0 ) return 0;
00085 switch ((index-1)%3){
00086 case 0: return 2;
00087 case 1: return 5;
00088 case 2: return 8;
00089 default:
00090 throw IllegalStateError("This index should never happen!", __FILE__, __LINE__);
00091 }
00092 }
00093
00094 virtual bool canFeedbackRealImpl() {
00095 return true;
00096 }
00097
00098 virtual void endTestRealImpl() {
00099 api = Sct_SctApi::SctApiIPC::_nil();
00100 }
00101
00102 private:
00103 QuickTrimTest() {}
00104 Sct_SctApi::SctApiIPC_var api;
00105 static double ranges[4];
00106 };
00107 double QuickTrimTest::ranges[4] = {3.5, 6.5, 10, 13};
00108 }
00109 }
00110 #endif //QUICKTRIMTEST_H