Skip to content

Commit 2637fc4

Browse files
astronomerdaveDavid Hale
andauthored
adds ADC gain control, issue #55 (#56)
Co-authored-by: David Hale <[email protected]>
1 parent e4e50de commit 2637fc4

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

camerad/archon.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7404,6 +7404,110 @@ namespace Archon {
74047404
/**************** Archon::Interface::bias ***********************************/
74057405

74067406

7407+
/***** Archon::Interface::preampgain ****************************************/
7408+
/**
7409+
* @brief set/get the ADC preamp gain
7410+
* @param args contains: gain {low|high}
7411+
* @return ERROR or NO_ERROR
7412+
*
7413+
*/
7414+
long Interface::preampgain(std::string args, std::string &retstring) {
7415+
const std::string function("Archon::Interface::preampgain");
7416+
std::stringstream message;
7417+
int gain;
7418+
long error = NO_ERROR;
7419+
7420+
// must have loaded firmware
7421+
//
7422+
if ( ! this->firmwareloaded ) {
7423+
this->camera.log_error( function, "firmware not loaded" );
7424+
return ERROR;
7425+
}
7426+
7427+
// make a list of installed AD modules
7428+
//
7429+
std::vector<int> admodules;
7430+
for ( int i=0; i<nmods; i++ ) {
7431+
if ( this->modtype[i] == 2 ) admodules.push_back(i);
7432+
}
7433+
if (admodules.size()==0) {
7434+
this->camera.log_error( function, "no AD modules found" );
7435+
return ERROR;
7436+
}
7437+
7438+
// no args is read gain
7439+
//
7440+
if ( args.empty() ) {
7441+
std::vector<int> gains;
7442+
7443+
// read gain of all AD modules into gains vecctor
7444+
for ( const auto &mod : admodules ) {
7445+
std::string key ( "MOD" + std::to_string(mod) + "/PREAMPGAIN" );
7446+
error |= this->get_configmap_value(key, gain);
7447+
gains.push_back(gain);
7448+
}
7449+
7450+
if ( error != NO_ERROR || gains.size() < 1 ) {
7451+
this->camera.log_error( function, "reading PREAMPGAIN or no AD modules found" );
7452+
return ERROR;
7453+
}
7454+
7455+
// are they all the same?
7456+
if ( ! std::equal(gains.begin()+1, gains.end(), gains.begin()) ) {
7457+
logwrite( function, "NOTICE: AD gains not the same" );
7458+
message.str(""); message << "gains =";
7459+
for ( const auto &gain : gains ) message << " " << (gain==0?"low":"high");
7460+
retstring = message.str();
7461+
}
7462+
else {
7463+
retstring = gains.front()==0 ? "low" : "high";
7464+
}
7465+
return NO_ERROR;
7466+
}
7467+
7468+
// if not read-only then get the arg is the requested gain level
7469+
//
7470+
if ( caseCompareString(args, "low") ) gain=0;
7471+
else
7472+
if ( caseCompareString(args, "high") ) gain=1;
7473+
else {
7474+
this->camera.log_error( function, "bad arguments: expected {low|high}" );
7475+
return ERROR;
7476+
}
7477+
7478+
// write preamp gain configuration to each AD module
7479+
//
7480+
for ( const auto &mod : admodules ) {
7481+
bool changed = false;
7482+
std::string key ( "MOD" + std::to_string(mod) + "/PREAMPGAIN" );
7483+
std::string val ( gain==0 ? "0" : "1" );
7484+
7485+
// write the config line
7486+
error |= this->write_config_key(key.c_str(), val.c_str(), changed);
7487+
7488+
// send the APPLYMODx command
7489+
std::stringstream applystr;
7490+
applystr << "APPLYMOD"
7491+
<< std::setfill('0')
7492+
<< std::setw(2)
7493+
<< std::hex
7494+
<< (mod-1);
7495+
if (error==NO_ERROR) error |= this->archon_cmd(applystr.str());
7496+
7497+
if (error==NO_ERROR) {
7498+
logwrite( function, "applied preamp gain="+args+" to AD "+std::to_string(mod) );
7499+
}
7500+
else {
7501+
this->camera.log_error( function, "applying preamp gain="+args+" to AD "+std::to_string(mod) );
7502+
}
7503+
}
7504+
7505+
retstring = gain==0?"LOW":"HIGH";
7506+
return error;
7507+
}
7508+
/***** Archon::Interface::preampgain ****************************************/
7509+
7510+
74077511
/**************** Archon::Interface::cds ************************************/
74087512
/**
74097513
* @fn cds

camerad/archon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ namespace Archon {
274274

275275
long bias(std::string args, std::string &retstring);
276276

277+
long preampgain(std::string args, std::string &retstring);
278+
277279
long cds(std::string args, std::string &retstring);
278280

279281
long inreg(std::string args);

camerad/camerad.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,15 @@ void doit(Network::TcpSocket sock) {
785785
sock.Write(retstring);
786786
sock.Write(" ");
787787
}
788-
} else if (cmd == "echo") {
788+
}
789+
else if (cmd == "preampgain") {
790+
ret = server.preampgain(args, retstring);
791+
if (!retstring.empty()) {
792+
sock.Write(retstring);
793+
sock.Write(" ");
794+
}
795+
}
796+
else if (cmd == "echo") {
789797
sock.Write(args);
790798
sock.Write("\n");
791799
} else if (cmd == "interface") {

0 commit comments

Comments
 (0)