Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cescalara committed May 24, 2018
2 parents bce40ca + fc91972 commit 5a3fd4f
Show file tree
Hide file tree
Showing 9 changed files with 805 additions and 54 deletions.
3 changes: 1 addition & 2 deletions CPU/CPUsoftware/src/instrument/RunInstrument.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include "RunInstrument.h"

std::atomic<bool> signal_shutdown{false};
Expand Down Expand Up @@ -186,7 +185,7 @@ int RunInstrument::DebugMode() {

std::cout << "THERMISTORS" << std::endl;
std::cout << "running an acquisition (takes ~10 s)..." << std::endl;
this->Daq.ThManager->PrintTemperature();
this->Daq.Thermistors->PrintTemperature();
std::cout << std::endl;

this->Lvps.SwitchOn(LvpsManager::CAMERAS);
Expand Down
20 changes: 10 additions & 10 deletions CPU/CPUsoftware/src/operations/DataAcquisition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int DataAcquisition::CreateCpuRun(RunType run_type, std::shared_ptr<Config> Conf
this->RunAccess = new Access(this->CpuFile);

/* access for ThermManager */
this->ThManager->RunAccess = new Access(this->CpuFile);
this->Thermistors->RunAccess = new Access(this->CpuFile);

/* set up the cpu file structure */
cpu_file_header->header = BuildCpuFileHeader(CPU_FILE_TYPE, CPU_FILE_VER);
Expand All @@ -217,8 +217,8 @@ int DataAcquisition::CreateCpuRun(RunType run_type, std::shared_ptr<Config> Conf

/* notify the ThermManager */
/* will this only work the first time? */
this->ThManager->cpu_file_is_set = true;
this->ThManager->cond_var.notify_all();
this->Thermistors->cpu_file_is_set = true;
this->Thermistors->cond_var.notify_all();

return 0;
}
Expand Down Expand Up @@ -732,11 +732,11 @@ int DataAcquisition::ProcessIncomingData(std::shared_ptr<Config> ConfigOut, CmdL
printf("PACKET COUNTER = %i\n", packet_counter);
printf("The packet %s was read out\n", zynq_file_name.c_str());

/* increment the packet counter */
/* increment the packet counter */
packet_counter++;
frm_num++;

/* leave loop for a single run file */
/* leave loop for a single run file */
if (packet_counter == CmdLine->acq_len && CmdLine->single_run) {
/* send shutdown signal to RunInstrument */
/* interrupt signal to main thread */
Expand Down Expand Up @@ -989,16 +989,16 @@ int DataAcquisition::CollectData(ZynqManager * ZqManager, std::shared_ptr<Config

/* add acquisition with the analog board */
std::thread analog (&AnalogManager::ProcessAnalogData, this->Analog);
analog.join();

/* add acquisition with thermistors if required */
if (CmdLine->therm_on) {
this->ThManager->Init();
std::thread collect_therm_data (&ThermManager::ProcessThermData, this->ThManager);
this->Thermistors->Init();
std::thread collect_therm_data (&ThermManager::ProcessThermData, this->Thermistors);
collect_therm_data.join();
}

/* wait for main data acquisition thread to join */

/* wait for other acquisition threads to join */
analog.join();
collect_main_data.join();


Expand Down
5 changes: 0 additions & 5 deletions CPU/CPUsoftware/src/operations/DataAcquisition.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ class DataAcquisition : public OperationMode {
*/
Access * RunAccess;

/**
* control of the thermistors
*/
ThermManager * ThManager = new ThermManager();

/**
* enum to define the CPU file type
*/
Expand Down
6 changes: 4 additions & 2 deletions CPU/CPUsoftware/src/operations/OperationMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ void OperationMode::Notify() {
} /* release mutex */
this->_cv_switch.notify_all();

/* also notify the analog acquisition */
/* also notify the analog and thermal acquisition */
this->Analog->Notify();
this->Thermistors->Notify();

}

Expand All @@ -35,8 +36,9 @@ void OperationMode::Reset() {
this->_switch = false;
} /* release mutex */

/* also reset the analog switch */
/* also reset the analog and thermal switch */
this->Analog->Reset();
this->Thermistors->Reset();


}
Expand Down
5 changes: 5 additions & 0 deletions CPU/CPUsoftware/src/operations/OperationMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <condition_variable>

#include "AnalogManager.h"
#include "ThermManager.h"

/**
* base class for an operational mode
Expand All @@ -15,6 +16,10 @@ class OperationMode {
* control of the analog subsystem
*/
AnalogManager * Analog = new AnalogManager();
/**
* control of the thermal subsystem
*/
ThermManager * Thermistors = new ThermManager();

OperationMode();

Expand Down
119 changes: 85 additions & 34 deletions CPU/CPUsoftware/src/subsystems/ThermManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
ThermManager::ThermManager() {

this->cpu_file_is_set = false;

this->inst_mode_switch = false;

}

/**
Expand Down Expand Up @@ -56,8 +57,8 @@ TemperatureAcq * ThermManager::GetTemperature() {
TemperatureAcq * temperature_result;
size_t found = output.find("Error 10:");
if (found != std::string::npos) {
clog << "error: " << logstream::error << "cannot connect to temprature sensors" << std::endl;
temperature_result = NULL;
clog << "error: " << logstream::error << "cannot connect to temprature sensors, writing 0 to output." << std::endl;
temperature_result = ParseDigitempOutput("output_error");
}
else {
/* parse the output */
Expand Down Expand Up @@ -102,22 +103,32 @@ TemperatureAcq * ThermManager::ParseDigitempOutput(std::string input_string) {
std::smatch match;
TemperatureAcq * temperature_result = new TemperatureAcq();

/* search for numbers with 2 decimal places */
std::string::const_iterator searchStart(input_string.cbegin());
int i = 0;
int j = 0;
while (std::regex_search(searchStart, input_string.cend(), match, num_with_two_dp)) {

/* fill the results for even values only (ignore Fahrenheit results) */
if (i % 2 == 0) {
temperature_result->val[j] = std::stof(match[0]);
j++;
/* check for null output */
int k = 0;
if (input_string == "output_error") {
for (k = 0; k < N_CHANNELS_THERM; k++) {
temperature_result->val[k] = 0;
}
}
else {

/* search for numbers with 2 decimal places */
std::string::const_iterator searchStart(input_string.cbegin());
int i = 0;
int j = 0;
while (std::regex_search(searchStart, input_string.cend(), match, num_with_two_dp)) {

/* fill the results for even values only (ignore Fahrenheit results) */
if (i % 2 == 0) {
temperature_result->val[j] = std::stof(match[0]);
j++;
}

i++;
searchStart += match.position() + match.length();
}

i++;
searchStart += match.position() + match.length();
}

return temperature_result;
}

Expand Down Expand Up @@ -159,29 +170,69 @@ int ThermManager::WriteThermPkt(TemperatureAcq * temperature_result) {
int ThermManager::ProcessThermData() {

std::mutex m;

/* start infinite loop */
while(1) {

/* collect data */
TemperatureAcq * temperature_result = GetTemperature();
time_t start_time = time(0);
time_t time_diff = 0;
bool first_run = true;


std::unique_lock<std::mutex> lock(this->m_mode_switch);
/* enter loop while instrument mode switching not requested */
while(!this->cv_mode_switch.wait_for(lock,
std::chrono::milliseconds(WAIT_PERIOD),
[this] { return this->inst_mode_switch; })) {

if ((time_diff > THERM_ACQ_SLEEP) || first_run) {
/* collect data */
TemperatureAcq * temperature_result = GetTemperature();

/* wait for CPU file to be set by DataAcqManager::ProcessIncomingData() */
std::unique_lock<std::mutex> lock(m);
this->cond_var.wait(lock, [this]{return cpu_file_is_set == true;});


/* wait for CPU file to be set by DataAcqManager::ProcessIncomingData() */
std::unique_lock<std::mutex> lock(m);
this->cond_var.wait(lock, [this]{return cpu_file_is_set == true;});


/* write to file */
if (temperature_result != NULL) {
WriteThermPkt(temperature_result);
/* write to file */
if (temperature_result != NULL) {
WriteThermPkt(temperature_result);
}

first_run = false;
start_time = time(0);
}

/* sleep */
sleep(THERM_ACQ_SLEEP);

sleep(THERM_ACQ_CHECK);
time_diff = time(0) - start_time;

}

return 0;
}


/**
* reset the mode switching after an instrument mode change
* used by OperationMode::Reset()
*/
int ThermManager::Reset() {

{
std::unique_lock<std::mutex> lock(this->m_mode_switch);
this->inst_mode_switch = false;
} /* release mutex */

return 0;
}

/**
* notify the object of an instrument mode switch
* used by OperationMode::Notify
*/
int ThermManager::Notify() {

{
std::unique_lock<std::mutex> lock(this->m_mode_switch);
this->inst_mode_switch = true;
} /* release mutex */

/* never reached */
return 0;
}
27 changes: 26 additions & 1 deletion CPU/CPUsoftware/src/subsystems/ThermManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _THERM_MANAGER_H

#include <regex>
#include <mutex>
#include <condition_variable>

#include "log.h"
Expand All @@ -12,6 +13,13 @@
/* number of seconds between temperature acquisitions */
#define THERM_ACQ_SLEEP 60

/* number of seconds between checking for switching */
#define THERM_ACQ_CHECK 2

/* for use with conditional variable */
#define WAIT_PERIOD 1 /* milliseconds */


/**
* acquisition structure for temperature readout
*/
Expand Down Expand Up @@ -45,8 +53,25 @@ class ThermManager {
TemperatureAcq * GetTemperature();
int WriteThermPkt(TemperatureAcq * temperature_results);
void PrintTemperature();


/* handle instrument mode switching */
int Notify();
int Reset();

private:
/*
* to notify the object of a mode switch
*/
bool inst_mode_switch;
/*
* to handle mode switching in a thread-safe way
*/
std::mutex m_mode_switch;
/*
* to wait for a mode switch
*/
std::condition_variable cv_mode_switch;

TemperatureAcq * ParseDigitempOutput(std::string input_string);
uint32_t BuildCpuPktHeader(uint32_t type, uint32_t ver);
uint32_t BuildCpuTimeStamp();
Expand Down
Empty file modified CPU/cameras/multiplecam/multiplecam.sh
100644 → 100755
Empty file.
Loading

0 comments on commit 5a3fd4f

Please sign in to comment.