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/Sct_CalibrationController.hh"
00008 #include "../CalibrationControllerImpl.h"
00009
00010 #include "../SctApiException.h"
00011 #include "Sct/LogicErrors.h"
00012
00013 #include <CommonWithDsp/ABCD/ABCDscans.h>
00014 #include <iostream>
00015 #include <vector>
00016
00017 using namespace std;
00018 using namespace SctCalibrationController::Ipc;
00019 using namespace SctCalibrationController;
00020 using namespace Sct;
00021
00022 namespace SctCalibrationController {
00023 namespace Scripts {
00024
00025 class TrimRangeTest : public TestRequestImpl {
00026 public:
00027 static TrimRangeTest& instance() {
00028 static TrimRangeTest tr;
00029 return tr;
00030 }
00031
00032 virtual void startTest(Sct_SctApi_T_SctApi& inapi, string& name, unsigned short& testVariable, unsigned long& nScans, vector<double>& testPoints) {
00033 this->api = &inapi;
00034
00035 Sct_SctApiStatus status;
00036 api->modifyABCDVar(&status, ST_COMPRESSION, 1);
00037 if (status.returnCode != 0)
00038 throw SctApiException(status.returnCode, "TrimRangeTest::startTest can't set compression", __FILE__, __LINE__);
00039
00040 api->modifyABCDVar(&status, ST_EDGE_DETECT, 0);
00041 if (status.returnCode != 0)
00042 throw SctApiException(status.returnCode, "TrimRangeTest::startTest can't set edge detect", __FILE__, __LINE__);
00043
00044 api->modifyABCDVar(&status, ST_SEND_MASK, 0);
00045 if (status.returnCode != 0)
00046 throw SctApiException(status.returnCode, "TrimRangeTest::startTest can't set send mask", __FILE__, __LINE__);
00047
00048 api->modifyABCDVar(&status, ST_QCAL, 1);
00049 if (status.returnCode != 0)
00050 throw SctApiException(status.returnCode, "TrimRangeTest::startTest can't set qcal", __FILE__, __LINE__);
00051
00052 name = "TrimRangeTest";
00053 testVariable=ST_TRIM_RANGE;
00054 for (unsigned int i=0; i<28; ++i) {
00055 testPoints.push_back(getValue(i));
00056 }
00057 nScans = testPoints.size();
00058 }
00059
00060 virtual Sct_SctApi_T_Scan* getNextScan(unsigned long index) {
00061 Sct_SctApiStatus status;
00062
00063 if (isFirstPoint(index)) {
00064 api->modifyABCDVar(&status, ST_TRIM_RANGE, getRange(index));
00065 if (status.returnCode != 0)
00066 throw SctApiException(status.returnCode, "TrimRangeTest::getNextScan", __FILE__, __LINE__);
00067 }
00068 api->modifyABCDVar(&status, ST_TRIM, getValue(index));
00069 if (status.returnCode != 0)
00070 throw SctApiException(status.returnCode, "TrimRangeTest::getNextScan", __FILE__, __LINE__);
00071
00072
00073 ScanLibrary& sl = CalibrationControllerImpl::instance().getScanLibrary();
00074 return &sl.thresholdScanfC(1000, 1.0);
00075 }
00076
00077 unsigned int getRange(unsigned int index) {
00078 if (index<16) return 0;
00079 else return (index-16)/4+1;
00080 }
00081
00082 bool isFirstPoint(unsigned int index) {
00083 return (index-16)%4 == 0;
00084 }
00085
00086 unsigned int getValue(unsigned int index) {
00087 if (index < 16) return index;
00088 unsigned int pointInRange = (index-16)%4;
00089 return (pointInRange+1)*4-1;
00090 }
00091
00092 virtual bool canFeedback() {
00093 return true;
00094 }
00095
00096 virtual void endTest() {
00097 api = 0;
00098 }
00099
00100 private:
00101 TrimRangeTest() {}
00102 Sct_SctApi_T_SctApi* api;
00103 };
00104 }
00105 }
00106 #endif //TRIMRANGETEST_H