Skip to content

Commit b24dc85

Browse files
committed
Merge pull request #33 from pixie16/dev
Merge of dev work from pixie16 group.
2 parents 28658ae + cdac7e2 commit b24dc85

25 files changed

Lines changed: 1078 additions & 458 deletions

CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ if (CMAKE_COMPILER_IS_GNUCXX)
1010
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=auto")
1111
endif()
1212

13-
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
14-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
15-
endif()
16-
13+
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
14+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
15+
endif()
16+
1717
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
1818
endif()
1919

@@ -89,7 +89,12 @@ if (NOT ${CORE_ONLY})
8989
link_directories(${PXI_LIBRARY_DIR})
9090
#The following configuration file path is hardcoded into the PXI software :-(
9191
install(FILES ${PXI_ROOT_DIR}/test/pxisys.ini DESTINATION ${CMAKE_INSTALL_PREFIX})
92-
install(FILES Setup/source/pixie.cfg DESTINATION ${CMAKE_INSTALL_PREFIX})
92+
93+
#Create pixie.cfg and copy slot_def.set as well as default.set to current.set
94+
PXI_CONFIG()
95+
#Use the cmake script created by PXI_CONFIG to install the files it created when make config is typed
96+
add_custom_target(config ${CMAKE_COMMAND} -P pixie_cfg.cmake)
97+
9398
endif()
9499

95100
add_subdirectory(Core)
@@ -99,14 +104,14 @@ if (NOT ${CORE_ONLY})
99104
include_directories(Interface/include)
100105
add_subdirectory(Interface/source)
101106

107+
include_directories(MCA/include)
108+
add_subdirectory(MCA)
109+
102110
if (USE_SETUP)
103111
include_directories(Setup/include)
104112
add_subdirectory(Setup/source)
105113
endif()
106114

107-
include_directories(MCA/include)
108-
add_subdirectory(MCA)
109-
110115
add_subdirectory(Poll)
111116

112117
add_subdirectory(PxiDump/source)

Core/include/CTerminal.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*
88
* \author Cory R. Thornsberry
99
*
10-
* \date May 13th, 2015
10+
* \date Oct. 1st, 2015
1111
*
12-
* \version 1.1.06
12+
* \version 1.2.02
1313
*/
1414

1515
#ifndef CTERMINAL_H
@@ -23,13 +23,11 @@
2323
///Default size of terminal scroll back buffer in lines.
2424
#define SCROLLBACK_SIZE 1000
2525

26-
#define CTERMINAL_VERSION "1.1.06"
27-
#define CTERMINAL_DATE "May 13th, 2015"
26+
#define CTERMINAL_VERSION "1.2.02"
27+
#define CTERMINAL_DATE "Oct. 2nd, 2015"
2828

2929
#include <curses.h>
3030

31-
extern bool SIGNAL_INTERRUPT;
32-
3331
extern std::string CPP_APP_VERSION;
3432

3533
template <typename T>
@@ -219,6 +217,7 @@ class Terminal{
219217
std::string prompt;
220218
///The tab complete flag
221219
bool enableTabComplete;
220+
float commandTimeout_; ///<Time in seconds to wait for command.
222221

223222
short tabCount;
224223

@@ -289,6 +288,9 @@ class Terminal{
289288
void EnableTabComplete(bool enable = true);
290289
void TabComplete(std::vector<std::string> matches);
291290

291+
///Enable a timeout while waiting fro a command.
292+
void EnableTimeout(float timeout = 0.5);
293+
292294
/** Set the command filename for storing previous commands This command will
293295
* clear all current commands from the history if overwrite_ is set to true. */
294296
void SetCommandFilename(std::string input_, bool overwrite_=false);

Core/include/Unpacker.hpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class Unpacker{
1717

1818
unsigned int event_width; /// The width of the raw event in pixie clock ticks (8 ns).
1919

20-
bool raw_event_mode; /// Placeholder bool for dumping raw events to file.
21-
bool use_hires_time; /// Placeholder bool for using high resolution pulse fitting.
22-
2320
bool debug_mode; /// True if debug mode is set.
2421
bool init; /// True if the class has been properly initialized.
2522

@@ -74,7 +71,7 @@ class Unpacker{
7471
/** Initialize the Unpacker object. Does nothing useful if not overloaded
7572
* by a derived class.
7673
*/
77-
virtual bool Initialize();
74+
virtual bool Initialize(std::string prefix_="");
7875

7976
/** Initialize the root output. Does nothing useful if not overloaded
8077
* by a derived class.
@@ -86,7 +83,7 @@ class Unpacker{
8683

8784
/// Toggle debug mode on / off.
8885
bool SetDebugMode(bool state_=true){ return (debug_mode = state_); }
89-
86+
9087
/// Set the width of events in pixie16 clock ticks.
9188
unsigned int SetEventWidth(unsigned int width_){ return (event_width = width_); }
9289

@@ -96,9 +93,22 @@ class Unpacker{
9693
*/
9794
bool ReadSpill(unsigned int *data, unsigned int nWords, bool is_verbose=true);
9895

99-
virtual bool SetRawEventMode(bool state_=true){ return (raw_event_mode = state_); }
96+
/// Return the syntax string for this program.
97+
virtual void SyntaxStr(const char *name_, std::string prefix_=""){ std::cout << prefix_ << "SYNTAX: " << std::string(name_) << " <options> <input>\n"; }
98+
99+
/// Print a help dialogue.
100+
virtual void Help(std::string prefix_=""){}
100101

101-
virtual bool SetHiResMode(bool state_=true){ return (use_hires_time = state_); }
102+
/// Scan input arguments and set class variables.
103+
virtual bool SetArgs(std::deque<std::string> &args_, std::string &filename_){ return true; }
104+
105+
/// Print a status message.
106+
virtual void PrintStatus(std::string prefix_=""){}
107+
108+
/// Empty the raw event and the event list.
109+
void Close();
102110
};
103111

112+
extern Unpacker *GetCore(); /// External function which returns a pointer to a class derived from Unpacker.
113+
104114
#endif

Core/include/hribf_buffers.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
*
1515
* \author Cory R. Thornsberry
1616
*
17-
* \date June 27th, 2015
17+
* \date Sept. 29th, 2015
1818
*
19-
* \version 1.2.03
19+
* \version 1.2.04
2020
*/
2121

2222
#ifndef HRIBF_BUFFERS_H
@@ -25,8 +25,10 @@
2525
#include <fstream>
2626
#include <vector>
2727

28-
#define HRIBF_BUFFERS_VERSION "1.2.03"
29-
#define HRIBF_BUFFERS_DATE "June 27th, 2015"
28+
#define HRIBF_BUFFERS_VERSION "1.2.04"
29+
#define HRIBF_BUFFERS_DATE "Sept. 29th, 2015"
30+
31+
class Client;
3032

3133
class BufferType{
3234
protected:
@@ -324,7 +326,7 @@ class PollOutputFile{
324326

325327
/** Build a data spill notification message for broadcast onto the network
326328
* Return the total number of bytes in the packet upon success, and -1 otherwise */
327-
int BuildPacket(char *&output);
329+
int SendPacket(Client *cli_);
328330

329331
/// Close the current file, if one is open, and open a new file for data output
330332
bool OpenNewFile(std::string title_, int &run_num_, std::string prefix, std::string output_dir="./", bool continueRun = false);

Core/source/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ add_library(PixieCoreObjects OBJECT ${PixieCore_SOURCES})
77

88
add_library(PixieCore SHARED $<TARGET_OBJECTS:PixieCoreObjects>)
99

10+
target_link_libraries(PixieCore ${CMAKE_THREAD_LIBS_INIT})
11+
1012
add_library(PixieCoreStatic STATIC $<TARGET_OBJECTS:PixieCoreObjects>)
1113

14+
target_link_libraries(PixieCoreStatic ${CMAKE_THREAD_LIBS_INIT})
15+
1216
if (${CURSES_FOUND})
1317
target_link_libraries(PixieCore ${CURSES_LIBRARIES})
1418
target_link_libraries(PixieCoreStatic ${CURSES_LIBRARIES})

Core/source/CTerminal.cpp

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
*
88
* \author Cory R. Thornsberry
99
*
10-
* \date May 13th, 2015
10+
* \date Oct. 2nd, 2015
1111
*
12-
* \version 1.1.06
12+
* \version 1.2.02
1313
*/
1414

1515
#include <iostream>
1616
#include <fstream>
1717
#include <unistd.h>
1818
#include <vector>
19+
#include <ctime>
1920

2021
#ifdef USE_NCURSES
2122

@@ -30,7 +31,9 @@
3031

3132
#ifdef USE_NCURSES
3233

34+
bool SIGNAL_SEGFAULT = false;
3335
bool SIGNAL_INTERRUPT = false;
36+
bool SIGNAL_TERMSTOP = false;
3437
bool SIGNAL_RESIZE = false;
3538

3639
#endif
@@ -273,26 +276,48 @@ void CommandString::Pop(unsigned int index_){
273276
// Terminal
274277
///////////////////////////////////////////////////////////////////////////////
275278

279+
void sig_segv_handler(int ignore_){
280+
SIGNAL_SEGFAULT = true;
281+
}
282+
276283
void sig_int_handler(int ignore_){
277284
SIGNAL_INTERRUPT = true;
278285
}
279286

287+
void sig_tstp_handler(int ignore_){
288+
SIGNAL_TERMSTOP = true;
289+
}
290+
280291
void signalResize(int ignore_) {
281292
SIGNAL_RESIZE = true;
282293
}
283294

284295

285296
// Setup the interrupt signal intercept
286297
void setup_signal_handlers(){
298+
// Handle segmentation faults press (SIGSEGV)
299+
if(signal(SIGSEGV, SIG_IGN) != SIG_IGN){
300+
if(signal(SIGSEGV, sig_segv_handler) == SIG_ERR){
301+
throw std::runtime_error(" Error setting up SIGSEGV signal handler!");
302+
}
303+
}
304+
305+
// Handle ctrl-c press (SIGINT)
287306
if(signal(SIGINT, SIG_IGN) != SIG_IGN){
288307
if(signal(SIGINT, sig_int_handler) == SIG_ERR){
289-
throw std::runtime_error(" Error setting up signal handler!");
308+
throw std::runtime_error(" Error setting up SIGINT signal handler!");
309+
}
310+
}
311+
312+
// Handle ctrl-z press (SIGTSTP)
313+
if(signal(SIGTSTP, SIG_IGN) != SIG_IGN){
314+
if(signal(SIGTSTP, sig_tstp_handler) == SIG_ERR){
315+
throw std::runtime_error(" Error setting up SIGTSTP signal handler!");
290316
}
291317
}
292318

293319
//Handle resize signal
294320
signal(SIGWINCH, signalResize);
295-
296321
}
297322
void Terminal::resize_() {
298323
//end session and then refresh to get new window sizes.
@@ -524,6 +549,7 @@ bool Terminal::save_commands_(){
524549
Terminal::Terminal() :
525550
status_window(NULL),
526551
_statusWindowSize(0),
552+
commandTimeout_(0),
527553
_scrollbackBufferSize(SCROLLBACK_SIZE),
528554
_scrollPosition(0)
529555
{
@@ -721,6 +747,17 @@ void Terminal::EnableTabComplete(bool enable) {
721747
enableTabComplete = enable;
722748
}
723749

750+
/**By enabling the timeout the GetCommand() routine returns after a set
751+
* timesout period has passed. The current typed text is stored for the next
752+
* GetCommand call.
753+
*
754+
* \param[in] timeout The amount of time to wait before timeout in seconds
755+
* defaults to 0.5 s.
756+
*/
757+
void Terminal::EnableTimeout(float timeout/*=0.5*/) {
758+
commandTimeout_ = timeout;
759+
}
760+
724761
/**Take the list of matching tab complete values and output resulting tab completion.
725762
* If the list is empty nothing happens, if a unique value is given the command is completed. If there are multiple
726763
* matches the common part of the matches is determined and printed to the input. If there is no common part of the
@@ -780,6 +817,9 @@ void Terminal::TabComplete(std::vector<std::string> matches) {
780817

781818
std::string Terminal::GetCommand(){
782819
std::string output = "";
820+
time_t commandRequestTime;
821+
time_t currentTime;
822+
time(&commandRequestTime);
783823

784824
//Update status message
785825
if (status_window) {
@@ -788,40 +828,58 @@ std::string Terminal::GetCommand(){
788828
}
789829

790830
while(true){
831+
if(SIGNAL_SEGFAULT){ // segmentation fault (SIGSEGV)
832+
Close();
833+
return "_SIGSEGV_";
834+
}
791835
if(SIGNAL_INTERRUPT){ // ctrl-c (SIGINT)
792836
SIGNAL_INTERRUPT = false;
793837
output = "CTRL_C";
794838
text_length = 0;
795839
break;
796840
}
841+
else if(SIGNAL_TERMSTOP){ // ctrl-z (SIGTSTP)
842+
SIGNAL_TERMSTOP = false;
843+
output = "CTRL_Z";
844+
text_length = 0;
845+
break;
846+
}
797847

798848
flush(); // If there is anything in the stream, dump it to the screen
849+
850+
//Time out if there is no command within the set interval (default 0.5 s).
851+
if (commandTimeout_ > 0) {
852+
time(&currentTime);
853+
//If the timeout has passed we simply return the empty output string.
854+
if (currentTime > commandRequestTime + commandTimeout_) {
855+
break;
856+
}
857+
}
799858

800859
int keypress = wgetch(input_window);
801860

802861
// Check for internal commands
803-
if(keypress == 10){ // Enter key (10)
862+
if(keypress == ERR){ } // No key was pressed in the interval
863+
else if(keypress == 10){ // Enter key (10)
804864
std::string temp_cmd = cmd.Get();
805-
if(temp_cmd != ""){
806-
//Reset the position in the history.
807-
commands.Reset();
808-
if(temp_cmd != commands.PeekPrev()){ // Only save this command if it is different than the previous command
809-
commands.Push(temp_cmd);
810-
}
811-
output = temp_cmd;
812-
std::cout << prompt.c_str() << output << "\n";
813-
flush();
814-
text_length = 0;
815-
_scrollPosition = 0;
816-
clear_();
817-
tabCount = 0;
818-
return output;
865+
//Reset the position in the history.
866+
commands.Reset();
867+
if(temp_cmd != "" && temp_cmd != commands.PeekPrev()){ // Only save this command if it is different than the previous command
868+
commands.Push(temp_cmd);
819869
}
870+
output = temp_cmd;
871+
std::cout << prompt << output << "\n";
872+
flush();
873+
text_length = 0;
874+
_scrollPosition = 0;
875+
clear_();
876+
tabCount = 0;
877+
break;
820878
}
821879
else if(keypress == '\t' && enableTabComplete) {
822880
tabCount++;
823881
output = cmd.Get().substr(0,cursX - offset) + "\t";
824-
return output;
882+
break;
825883
}
826884
else if(keypress == 4){ // ctrl-d (EOT)
827885
output = "CTRL_D";
@@ -893,7 +951,6 @@ std::string Terminal::GetCommand(){
893951
else if(keypress == KEY_RESIZE) {
894952
//Do nothing with the resize key
895953
}
896-
else if(keypress == ERR){ } // No key was pressed in the interval
897954
else{
898955
in_char_((char)keypress);
899956
cmd.Put((char)keypress, cursX - offset - 1);

0 commit comments

Comments
 (0)