Skip to content

Commit

Permalink
Merge branch 'dev' into dev-sim
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredmales committed Nov 2, 2024
2 parents a3bebf9 + 439cfbe commit 801d227
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 38 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,10 @@ vm/
# Python caches, etc
*.egg-info
__pycache__
libMagAOX/doc/diag/Makefile
libMagAOX/doc/diag/xwcapp_fsm.drawio
libMagAOX/doc/diag/xwcapp.drawio
libMagAOX/doc/diag/xwcapps_connections.drawio
libMagAOX/doc/diag/png/xwcapp_fsm.png
libMagAOX/doc/diag/png/xwcapp.png
libMagAOX/doc/diag/png/xwcapps_connections.png
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ utils_to_build = \
xrif2shmim \
xrif2fits

scripts_to_install = magaox \
scripts_to_install = \
query_seeing \
sync_cacao \
xctrl \
Expand Down
47 changes: 38 additions & 9 deletions apps/dbIngest/dbIngest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import xconf
from magaox.indi.device import XDevice
from magaox.db.config import BaseDeviceConfig
from magaox.db import Telem, FileOrigin
from magaox.db import Telem, FileOrigin, UserLog
from magaox.db import ingest
from magaox.utils import parse_iso_datetime_as_utc, creation_time_from_filename

import json
import orjson
import xconf
import subprocess
import queue
Expand Down Expand Up @@ -63,7 +64,8 @@ def on_modified(self, event):
CREATE_CONNECTION_TIMEOUT_SEC = 2
EXIT_TIMEOUT_SEC = 2

def _run_logdump_thread(logger_name, logdump_dir, logdump_args, name, message_queue):
def _run_logdump_thread(logger_name, logdump_dir, logdump_args, name, message_queue, record_class):
# filter what content from user_logs gets put into db
log = logging.getLogger(logger_name)
glob_pat = logdump_dir + f'/{name}_*'
has_no_logs = len(glob.glob(glob_pat)) == 0
Expand All @@ -77,7 +79,8 @@ def _run_logdump_thread(logger_name, logdump_dir, logdump_args, name, message_qu
log.debug(f"Running logdump command {repr(' '.join(args))} for {name} in follow mode")
p = subprocess.Popen(args, stdout=subprocess.PIPE, stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL, text=True)
for line in p.stdout:
message = Telem.from_json(name, line)
log.debug(f"Log line read: {line}")
message = record_class.from_json(name, line)
message_queue.put(message)
if p.returncode != 0:
raise RuntimeError(f"{name} logdump exited with {p.returncode} ({repr(' '.join(args))})")
Expand All @@ -92,20 +95,32 @@ class dbIngestConfig(BaseDeviceConfig):
class dbIngest(XDevice):
config : dbIngestConfig
telem_threads : list[tuple[str, threading.Thread]]
fs_observer : BaseObserverSubclassCallable
telem_queue : queue.Queue
fs_observer : BaseObserverSubclassCallable
fs_queue : queue.Queue
last_update_ts_sec : float
startup_ts_sec : float
records_since_startup : float

def launch_follower(self, dev):
args = self.log.name + '.' + dev, '/opt/MagAOX/telem', (self.config.logdump_exe, '--ext=.bintel'), dev, self.telem_queue
telem_thread = threading.Thread(target=_run_logdump_thread, args=args, daemon=True)

#add user_log support here
user_log_threads : list[tuple[str, threading.Thread]]
user_log_queue : queue.Queue

def launch_followers(self, dev):
telem_args = self.log.name + '.' + dev, '/opt/MagAOX/telem', (self.config.logdump_exe, '--ext=.bintel'), dev, self.telem_queue, Telem
telem_thread = threading.Thread(target=_run_logdump_thread, args=telem_args, daemon=True)
telem_thread.start()
self.log.debug(f"Watching {dev} for incoming telem")
self.telem_threads.append((dev, telem_thread))

#userLog support here
if dev == "observers":
ULog_args = self.log.name + '.' + dev, '/opt/MagAOX/logs', (self.config.logdump_exe, '--ext=.binlog'), dev, self.user_log_queue, UserLog
user_log_thread = threading.Thread(target=_run_logdump_thread, args= ULog_args, daemon=True)
user_log_thread.start()
self.log.debug(f"Watching {dev} for incoming user logs")
self.user_log_threads.append((dev, user_log_thread))

def refresh_properties(self):
self.properties['last_update']['timestamp'] = self.last_update_ts_sec
self.update_property(self.properties['last_update'])
Expand Down Expand Up @@ -161,10 +176,14 @@ def setup(self):
raise RuntimeError(f"Got malformed proclist line: {repr(line)}")
device_names.add(parts[0])

#setup user log here too
self.user_log_queue = queue.Queue()
self.user_log_threads = []

self.telem_queue = queue.Queue()
self.telem_threads = []
for dev in device_names:
self.launch_follower(dev)
self.launch_followers(dev)

self.startup_ts_sec = time.time()

Expand Down Expand Up @@ -206,10 +225,20 @@ def loop(self):
except queue.Empty:
pass

#update for userlog here too
user_logs = []
try:
while rec := self.user_log_queue.get(timeout=0.1):
user_logs.append(rec)
self.records_since_startup += 1
except queue.Empty:
pass

with self.conn.transaction():
cur = self.conn.cursor()
ingest.batch_telem(cur, telems)
ingest.batch_file_origins(cur, fs_events)
ingest.batch_user_log(cur, user_logs)

this_ts_sec = time.time()
self.last_update_ts_sec = this_ts_sec
Expand Down
27 changes: 24 additions & 3 deletions apps/smc100ccCtrl/smc100ccCtrl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class smc100ccCtrl : public MagAOXApp<>, public tty::usbDevice, public dev::ioDe
*@{
*/
double m_homingOffset {0};

double m_opDelta {0}; ///< The threshold for switching to OPERATING

///@}

Expand All @@ -70,6 +72,7 @@ class smc100ccCtrl : public MagAOXApp<>, public tty::usbDevice, public dev::ioDe

bool m_powerOnHomed{false};

bool m_moveOp {true}; ///< Flag indicating that OPERATING should not be set for a move, because it's less than m_opDelta.
public:

INDI_NEWCALLBACK_DECL(smc100ccCtrl, m_indiP_position);
Expand Down Expand Up @@ -189,7 +192,8 @@ inline smc100ccCtrl::smc100ccCtrl() : MagAOXApp(MAGAOX_CURRENT_SHA1, MAGAOX_REPO
void smc100ccCtrl::setupConfig()
{
config.add("stage.homingOffset", "", "stage.homingOffset", argType::Required, "stage", "homingOffset", false, "float", "Homing offset, a.k.a. default starting position.");

config.add("stage.opDelta", "", "stage.opDelta", argType::Required, "stage", "opDelta", false, "float", "Threshold move size for switching to OPERATING.");

tty::usbDevice::setupConfig(config);
dev::ioDevice::setupConfig(config);
dev::stdMotionStage<smc100ccCtrl>::setupConfig(config);
Expand All @@ -200,6 +204,7 @@ void smc100ccCtrl::loadConfig()
{

config(m_homingOffset, "stage.homingOffset");
config(m_opDelta, "stage.opDelta");

this->m_baudRate = B57600; //default for SMC100CC controller. Will be overridden by any config setting.

Expand Down Expand Up @@ -496,7 +501,10 @@ int smc100ccCtrl::appLogic()
else if (axState[0] == '2')
{
m_moving = 1;
state(stateCodes::OPERATING);
if(m_moveOp)
{
state(stateCodes::OPERATING);
}
}
else if (axState[0] == '3' && isdigit(axState[1]))
{
Expand All @@ -510,6 +518,7 @@ int smc100ccCtrl::appLogic()
{
m_moving = 0;
state(stateCodes::READY);
m_moveOp = true;
}
}
else if (axState[0] == '3')
Expand Down Expand Up @@ -1059,6 +1068,15 @@ int smc100ccCtrl::moveTo(double position)
recordStage(true);
recordPosition(true);

if(fabs(position-m_position) > m_opDelta)
{
m_moveOp = true;
}
else
{
m_moveOp = false;
}

std::string buffer{"1PA"};
buffer = buffer + std::to_string(position) + "\r\n";

Expand All @@ -1074,7 +1092,10 @@ int smc100ccCtrl::moveTo(double position)
std::string errorString;
if (getLastError(errorString) == 0)
{
state(stateCodes::OPERATING);
if(m_moveOp)
{
state(stateCodes::OPERATING);
}
updateIfChanged(m_indiP_position, "target", position);
return 0;
}
Expand Down
20 changes: 20 additions & 0 deletions apps/zaberLowLevel/zaberLowLevel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class zaberLowLevel : public MagAOXAppT, public tty::usbDevice
///Current temperature of the stage.
pcf::IndiProperty m_indiP_temp;

///Current temperature of the stage.
pcf::IndiProperty m_indiP_warn;

///Target raw position of the stage.
pcf::IndiProperty m_indiP_tgt_pos;

Expand Down Expand Up @@ -395,6 +398,14 @@ int zaberLowLevel::appStartup()
m_indiP_temp.add (pcf::IndiElement(m_stages[n].name()));
}

REG_INDI_NEWPROP_NOCB(m_indiP_warn, "warning", pcf::IndiProperty::Switch);
m_indiP_warn.setRule(pcf::IndiProperty::AnyOfMany);
for(size_t n=0; n< m_stages.size(); ++n)
{
m_indiP_warn.add (pcf::IndiElement(m_stages[n].name()));
m_indiP_warn[m_stages[n].name()].setSwitchState(pcf::IndiElement::Off);
}

REG_INDI_NEWPROP(m_indiP_tgt_pos, "tgt_pos", pcf::IndiProperty::Number);
for(size_t n=0; n< m_stages.size(); ++n)
{
Expand Down Expand Up @@ -608,6 +619,15 @@ int zaberLowLevel::appLogic()
}
else updateIfChanged(m_indiP_curr_state, m_stages[i].name(), std::string("NODEVICE"));

if(m_stages[i].warn())
{
updateIfChanged(m_indiP_warn, m_stages[i].name(), pcf::IndiElement::On);
}
else
{
updateIfChanged(m_indiP_warn, m_stages[i].name(), pcf::IndiElement::Off);
}

m_stages[i].updateTemp(m_port);
updateIfChanged(m_indiP_temp, m_stages[i].name(), m_stages[i].temp());

Expand Down
Loading

0 comments on commit 801d227

Please sign in to comment.