00001 #ifndef TRIMRANGETEST_H
00002 #define TRIMRANGETEST_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 <Sct/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 TrimRangeTest : public TestRequestImpl {
00029 private:
00030 static const bool registeredInTestLibrary;
00031
00032 public:
00033 static Sct_CalibrationController::TestRequest_ptr instance() {
00034 static TrimRangeTest tr;
00035 tr.setFitAlgorithm("Threshold");
00036 tr.setAnalysisAlgorithm("TrimRangeTest");
00037 return tr._this();
00038 }
00039
00040 virtual void startTestRealImpl(Sct_SctApi::SctApiIPC_ptr inapi, string& name, unsigned short& testVariable, unsigned long& nScans, vector<double>& testPoints) {
00041 this->api = Sct_SctApi::SctApiIPC::_duplicate(inapi);
00042
00043
00044 APICALL(api, modifyABCDVar(ST_COMPRESSION, 1), "TrimRangeTest::startTest can't set compression")
00045
00046
00047 APICALL(api, modifyABCDVar(ST_EDGE_DETECT, 0), "TrimRangeTest::startTest can't set edge detect")
00048
00049
00050 APICALL(api, modifyABCDVar(ST_SEND_MASK, 0), "TrimRangeTest::startTest can't set send mask")
00051
00052
00053 APICALL(api, modifyABCDVar(ST_QCAL, 1), "TrimRangeTest::startTest can't set qcal")
00054
00055 name = "TrimRangeTest";
00056 testVariable=ST_TRIM_RANGE;
00057 for (unsigned int i=0; i<28; ++i) {
00058 testPoints.push_back(getValue(i));
00059 }
00060 nScans = testPoints.size();
00061 }
00062
00063 virtual Sct_CalibrationController::ScanRequest_ptr getNextScanRealImpl(unsigned long index) {
00064 if (isFirstPoint(index)) {
00065
00066 APICALL(api, modifyABCDVar(ST_TRIM_RANGE, getRange(index)), "TrimRangeTest::getNextScan")
00067 }
00068
00069 APICALL(api, modifyABCDVar(ST_TRIM, getValue(index)), "TrimRangeTest::getNextScan")
00070
00071 Sct_CalibrationController::ScanLibrary_var sl = CalibrationControllerImpl::instance()->getScanLibrary();
00072 double offset = ranges[getRange(index)] * getValue(index);
00073 return sl->thresholdScanfCOffset(400, 1.0, offset);
00074 }
00075
00076 unsigned int getRange(unsigned int index) {
00077 if (index<16) return 0;
00078 else return (index-16)/4+1;
00079 }
00080
00081 bool isFirstPoint(unsigned int index) {
00082 return (index-16)%4 == 0;
00083 }
00084
00085 unsigned int getValue(unsigned int index) {
00086 if (index < 16) return index;
00087 unsigned int pointInRange = (index-16)%4;
00088 return (pointInRange+1)*4-1;
00089 }
00090
00091 virtual bool canFeedbackRealImpl() {
00092 return true;
00093 }
00094
00095 virtual void endTestRealImpl() {
00096 api = Sct_SctApi::SctApiIPC::_nil();
00097 }
00098
00099 private:
00100 TrimRangeTest() {}
00101 Sct_SctApi::SctApiIPC_var api;
00102 static double ranges[4];
00103 };
00104 }
00105 }
00106 #endif //TRIMRANGETEST_H