Commit 0bc3d15c authored by wasp's avatar wasp

update change

parent f661c84b
......@@ -19,7 +19,7 @@
#include "RealCaenFastpsDriver.h"
#include "CaenFastpsDriver.h"
#include "CaenFastpsDef.h"
#include <regex>
#include <boost/tokenizer.hpp>
#include <boost/format.hpp>
using namespace boost;
using namespace std;
......@@ -53,6 +53,7 @@ RealCaenFastpsDriver::RealCaenFastpsDriver(CaenFastpsDriver* owner) :
m_Errors[ALREADY_LOOP_MODE] = "Module is already in the selected loop mode";
m_Errors[NOT_LOOP_MODE] = "Module is not in the selected loop mode";
m_Errors[UNKNOWN_ERROR] = "Unknown error";
}
/*
......@@ -81,7 +82,9 @@ void RealCaenFastpsDriver::readStatus() {
vector<string> answer = writeCaenFastps(READ_STATUS_COMMAND);
if (answer.size() > 1) {
int32 status = NO_STATUS;
status = lexical_cast<int32>("0x" + answer[1]);
std::stringstream ss;
ss << std::hex << answer[1];
ss >> status;
status &= 0x3FFFFFFF;
// Test tolerance
if ((status & CV_STATUS) == 0) {
......@@ -89,8 +92,7 @@ void RealCaenFastpsDriver::readStatus() {
if (fabs(delta) <= owner()->currentTolerance()) {
status |= IN_TOLERANCE;
}
}
else if ((status & CV_STATUS) != 0) {
} else if ((status & CV_STATUS) != 0) {
float64 delta = owner()->wantedVoltage() - owner()->actualVoltage();
if (fabs(delta) <= owner()->voltageTolerance()) {
status |= IN_TOLERANCE;
......@@ -98,7 +100,7 @@ void RealCaenFastpsDriver::readStatus() {
}
if (owner()->startActivated() == true) {
// Start activated , wait for the current
if (status == IN_TOLERANCE) {
if (status & IN_TOLERANCE) {
// Finished
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
......@@ -114,8 +116,7 @@ void RealCaenFastpsDriver::readStatus() {
}
owner()->computeCurrentStatus(status);
}
}
catch(CaenError& e) {
} catch (CaenError& e) {
throw Exceptions(e.code, getStringError(e.code));
}
}
......@@ -133,8 +134,7 @@ void RealCaenFastpsDriver::read() {
if (answer.size() > 1) {
owner()->actualVoltage.update(lexical_cast<float64>(answer[1]));
}
}
catch(CaenError& e) {
} catch (CaenError& e) {
throw Exceptions(e.code, getStringError(e.code));
}
}
......@@ -145,11 +145,13 @@ void RealCaenFastpsDriver::read() {
void RealCaenFastpsDriver::readInfos() {
try {
vector<string> answer = writeCaenFastps(VERSION_COMMAND);
if (answer.size() > 1) {
owner()->version.update(answer[1]);
string tmp;
for(int32 i = 1; i < answer.size(); i++) {
tmp.append(answer[i]);
tmp.append(" ");
}
}
catch(CaenError& e) {
owner()->version.update(tmp);
} catch (CaenError& e) {
throw Exceptions(e.code, getStringError(e.code));
}
}
......@@ -161,21 +163,19 @@ void RealCaenFastpsDriver::start() {
try {
writeCaenFastps(RESET_STATUS_COMMAND);
// writeCaenFastps(RESET_STATUS_COMMAND);
ostringstream buf1;
buf1 << LOOP_COMMAND << SEPARATOR;
writeCaenFastps(buf1.str());
// ostringstream buf1;
// buf1 << LOOP_COMMAND << SEPARATOR;
if (owner()->mode() == current::CurrentCommon::CC_MODE) {
buf1 << CURRENT_LOOP_COMMAND;
writeCaenFastps(buf1.str());
// buf1 << CURRENT_LOOP_COMMAND;
// writeCaenFastps(buf1.str());
ostringstream buf2;
buf2 << WRITE_CURRENT_COMMAND << SEPARATOR << owner()->wantedCurrent();
writeCaenFastps(buf2.str());
}
else if (owner()->mode() == current::CurrentCommon::CV_MODE) {
buf1 << VOLTAGE_LOOP_COMMAND;
writeCaenFastps(buf1.str());
} else if (owner()->mode() == current::CurrentCommon::CV_MODE) {
// buf1 << VOLTAGE_LOOP_COMMAND;
// writeCaenFastps(buf1.str());
ostringstream buf2;
buf2 << WRITE_VOLTAGE_COMMAND << SEPARATOR << owner()->wantedVoltage();
writeCaenFastps(buf2.str());
......@@ -183,8 +183,7 @@ void RealCaenFastpsDriver::start() {
// Force on to activate power supply
on();
}
catch(CaenError& e) {
} catch (CaenError& e) {
if (e.code != POWER_SUPPLY_ALREADY) {
throw Exceptions(e.code, getStringError(e.code));
}
......@@ -199,8 +198,7 @@ void RealCaenFastpsDriver::on() {
if ((owner()->status() & ONOFF_STATUS) == 0) {
try {
writeCaenFastps(ON_COMMAND);
}
catch(CaenError& e) {
} catch (CaenError& e) {
if (e.code != POWER_SUPPLY_ALREADY) {
throw Exceptions(e.code, getStringError(e.code));
}
......@@ -216,8 +214,7 @@ void RealCaenFastpsDriver::off() {
if ((owner()->status() & ONOFF_STATUS) != 0) {
try {
writeCaenFastps(OFF_COMMAND);
}
catch(CaenError& e) {
} catch (CaenError& e) {
throw Exceptions(e.code, getStringError(e.code));
}
}
......@@ -235,21 +232,23 @@ void RealCaenFastpsDriver::stop() {
*/
vector<string> RealCaenFastpsDriver::writeCaenFastps(const string& aCommand) throw (CaenError) {
string buf_in;
owner()->write(aCommand);
owner()->read(buf_in);
ostringstream scom;
scom << aCommand << "\r";
owner()->write(scom.str());
buf_in = owner()->read("\r\n");
string separators = HASH;
separators.append(SEPARATOR);
std::regex sep(separators);
sregex_token_iterator pos(buf_in.cbegin(), buf_in.cend(), sep, -1);
sregex_token_iterator end;
separators.append("\r\n");
vector<string> ret;
for ( ; pos!=end; ++pos ) {
ret.push_back(pos->str());
typedef tokenizer<char_separator<char> > tokenizer;
char_separator<char> sep(separators.c_str());
tokenizer tok1(buf_in, sep);
for (tokenizer::iterator iter = tok1.begin(); iter != tok1.end(); ++iter) {
ret.push_back(*iter);
}
if (ret.size() > 1) {
if (ret[0].find(NAK) == string::npos) {
if (ret[0].find(NAK) != string::npos) {
// Error to do
cout << "writeCaenFastps error : " << buf_in << "!!!!" << endl;
throw CaenError(lexical_cast<int32>(ret[1]));
}
}
......@@ -263,8 +262,7 @@ string RealCaenFastpsDriver::getStringError(int32 code) {
map<int32, string>::iterator iter = m_Errors.find(code);
if (iter != m_Errors.end()) {
return iter->second;
}
else {
} else {
return "Unknown error";
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment