Back Midas Rome Roody Rootana
  Midas DAQ System, Page 129 of 138  Not logged in ELOG logo
New entries since:Wed Dec 31 16:00:00 1969
ID Date Author Topic Subjectdown
  2665   03 Jan 2024 Stefan RittBug ReportCompilation error on RPi
> > git pull
> > git submodule update
> 
> confirmed. just run into this myself. I think "make" should warn about out of 
> date git modules. Also check that the build git version is tagged with "-dirty".
> 
> K.O.

The submodule business becomes kind of annoying. I updated the documentation at

https://daq00.triumf.ca/MidasWiki/index.php/Quickstart_Linux#MIDAS_Package_Installatio
n

to tell people to use 

1) "git clone ... --recurse-submodules" during the first clone
2) "git submodule update --init --recursive" in case they forgot 1)
3) "git pull --recurse-submodules" for each update or to use
4) "git config submodule.recurse true" to make the --recurse-submodules the default

I use 4) since a while and it works nicely, so one does not have to remember to pull 
recursively each time.

Stefan
  178   14 Dec 2004 Konstantin OlchanskiInfoCommit local TWIST modifications
I am commiting MIDAS modification accumulated during the last few months of running TWIST:
1) system.c::ss_shm_open() fail if trying to map a file that is smaller than we expect.
2) midas.c::bm_lock_buffer(), el_submit(), el_delete_message(): do not wait for mutexes forever, use a 5 
minute timeout. If we can't get the lock, cm_msg()/abort().
The above helps dealing with complete midas freezes. I also have code to keep track of "who locked
the mutex *and* is still holding it?!?" but it is way too ugly to commit. I wish we had a "lockedByPid"
entry for all lockable objects.
K.O.
 
  179   14 Dec 2004 Konstantin OlchanskiInfoCommit local TWIST modifications
> I am commiting MIDAS modification accumulated during the last few months of running TWIST:

More:
- mfe.c: in error messages "cannot find statistics record", also print
  the name of the record we are looking for.
- mlogger.c: in warning message "Write operation took N ms", report the name
  of the offending data stream.
- system.c: do not chdir("/") in ss_daemon_init()- it prevents us from ever
  getting core dumps from midas daemons. The old behaviour is trivially
  restored by "cd /" before starting the daemon; or by "limit coredumpsize 0".
- odb.c: db_validate_db() detect and break infinite looping on free list corruption.

K.O.
  182   15 Dec 2004 Stefan RittInfoCommit local TWIST modifications
> - system.c: do not chdir("/") in ss_daemon_init()- it prevents us from ever
>   getting core dumps from midas daemons. The old behaviour is trivially
>   restored by "cd /" before starting the daemon; or by "limit coredumpsize 0".

The chdir("/") is from one of the unix text books. They say you HAVE to do it. If you start a
daemon on an NFS file system, you cannot unmount that file system as long as the daemon is
running. I'm sure the same code is inside most other daemons (apache, ...). So if we go away
from that standard, we have to be aware of the consequences.
  2062   18 Dec 2020 Stefan RittSuggestionCode formatting
May I ask for your quick opinion on code formatting. MIDAS had a coding style 
which pretty much followed the ROOT coding style described at

https://root.cern/contribute/coding_conventions/

so we followed the "3 spaces indent" convention, braces according to Kernigham & 
Ritchie and a few other things. I see however that code written by different 
people still is formatted differently, like spaces before and after comparators 
etc. I wonder if it would make sense to keep a consistent code formatting through 
the whole midas repository.

Looking again at what the ROOT guys doe (see link above), they have a ClangFormat 
file, which I attached to this post. Putting this file into the root of midas 
ensures that all files are formatted in exactly the same way, which would increase 
readability largely.

The nice thing with ClangFormat is that can be integrated into my editor (Clion) as 
well as in emacs and vim:

https://clang.llvm.org/docs/ClangFormat.html

This would also make the emacs settings in our files obsolete:

/* emacs
 * Local Variables:
 * tab-width: 8
 * c-basic-offset: 3
 * indent-tabs-mode: nil
 * End:
 */

I don't like these because they are only for people using emacs. If everybody would 
put statements into the files with their favourite editor, all our source files 
would be cluttered quite a bit.

So the question is now how style to use? I attached different trials with a simple 
file from the distribution, so you can see the differences. They use the style from

- LLVM
- ROOT
- GNU
- Google

I consciously skipped the "Microsoft" style ;-)

Which one should we settle on? Any opinion? If I don't hear anything, I will pick a 
style at the end of this year 2020. I have a slight favour of the ROOT style, although 
I don't like that the "case" is not indented there under the opening brace of the 
switch statement which seems inconsistent to me. The only one doing that right is the 
Google format, but that one has an indentation of 2 chars instead our usual 3 chars. 
At the end of the day I think it's not so important on which style we agree, as long 
as we DO have a common style for all midas files.

Best,
Stefan
Attachment 1: .clang-format
---
Language:        Cpp
# BasedOnStyle:  LLVM
AccessModifierOffset: -3
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
# This would be nice to have but seems to also (mis)align function parameters
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: true
AlignOperands:   true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
# This option is "deprecated and is retained for backwards compatibility."
# AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
  AfterClass:      false
  AfterControlStatement: false
  AfterEnum:       false
  AfterFunction:   true
  AfterNamespace:  false
  AfterObjCDeclaration: false
  AfterStruct:     false
  AfterUnion:      false
  BeforeCatch:     false
  BeforeElse:      false
  IndentBraces:    false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit:     120
CommentPragmas:  '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 3
ContinuationIndentWidth: 3
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat:   false
ExperimentalAutoDetectBinPacking: false
ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
  - Regex:           '^("|<)T'
    Priority:        4
  - Regex:           '^("|<)ROOT/'
    Priority:        5
  - Regex:           '^<.*\.h>'
    Priority:        1
  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
    Priority:        2
  - Regex:           '^(<|"(gtest|isl|json)/)'
    Priority:        3
  - Regex:           '.*'
    Priority:        6
IndentCaseLabels: false
IndentWidth:     3
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd:   ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 3
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60000
PointerAlignment: Right
ReflowComments:  true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles:  false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard:        Cpp11
TabWidth:        3
UseTab:          Never
...
Attachment 2: cnaf_callback_llvm.cxx
/********************************************************************\

  Name:         cnaf_callback.c
  Created by:   Stefan Ritt
  Created by:   moved here from mfe.c by Konstantin Olchanski

  Contents:     The system part of the MIDAS frontend. Has to be
                linked with user code to form a complete frontend

  $Id$

\********************************************************************/

#include <stdio.h>
#include <assert.h>
#include "midas.h"
#include "msystem.h"
#include "mcstd.h"

/*------------------------------------------------------------------*/

static int cnaf_debug = 0;

INT cnaf_callback(INT index, void *prpc_param[]) {
  DWORD cmd, b, c, n, a, f, *pdword, *size, *x, *q, dtemp;
  WORD *pword, *pdata, temp;
  INT i, count;

  /* Decode parameters */
  cmd = CDWORD(0);
  b = CDWORD(1);
  c = CDWORD(2);
  n = CDWORD(3);
  a = CDWORD(4);
  f = CDWORD(5);
  pdword = CPDWORD(6);
  pword = CPWORD(6);
  pdata = CPWORD(6);
  size = CPDWORD(7);
  x = CPDWORD(8);
  q = CPDWORD(9);

  /* determine repeat count */
  if (index == RPC_CNAF16)
    count = *size / sizeof(WORD); /* 16 bit */
  else
    count = *size / sizeof(DWORD); /* 24 bit */

  switch (cmd) {
    /*---- special commands ----*/

  case CNAF_INHIBIT_SET: cam_inhibit_set(c);
    break;
  case CNAF_INHIBIT_CLEAR: cam_inhibit_clear(c);
    break;
  case CNAF_CRATE_CLEAR: cam_crate_clear(c);
    break;
  case CNAF_CRATE_ZINIT: cam_crate_zinit(c);
    break;

  case CNAF_TEST: break;

  case CNAF:
    if (index == RPC_CNAF16) {
      for (i = 0; i < count; i++)
        if (f < 16)
          cam16i_q(c, n, a, f, pword++, (int *) x, (int *) q);
        else if (f < 24)
          cam16o_q(c, n, a, f, pword[i], (int *) x, (int *) q);
        else
          cam16i_q(c, n, a, f, &temp, (int *) x, (int *) q);
    } else {
      for (i = 0; i < count; i++)
        if (f < 16)
          cam24i_q(c, n, a, f, pdword++, (int *) x, (int *) q);
        else if (f < 24)
          cam24o_q(c, n, a, f, pdword[i], (int *) x, (int *) q);
        else
          cam24i_q(c, n, a, f, &dtemp, (int *) x, (int *) q);
    }

    break;

  case CNAF_nQ:
    if (index == RPC_CNAF16) {
      if (f < 16) {
        cam16i_rq(c, n, a, f, &pword, count);
        *size = (POINTER_T) pword - (POINTER_T) pdata;
      }
    } else {
      if (f < 16) {
        cam24i_rq(c, n, a, f, &pdword, count);
        *size = (POINTER_T) pdword - (POINTER_T) pdata;
      }
    }

    /* return reduced return size */
    break;

  default: printf("cnaf: Unknown command 0x%X\n", (unsigned int) cmd);
  }

  if (cnaf_debug) {
    if (index == RPC_CNAF16)
      printf("cmd=%d r=%d c=%d n=%d a=%d f=%d d=%X x=%d q=%d\n", (int) cmd, (int) count, (int) c, (int) n, (int) a,
             (int) f, (int) pword[0], (int) *x, (int) *q);
    else if (index == RPC_CNAF24)
      printf("cmd=%d r=%d c=%d n=%d a=%d f=%d d=%X x=%d q=%d\n", (int) cmd, (int) count, (int) c, (int) n, (int) a,
             (int) f, (int) pdword[0], (int) *x, (int) *q);
  }

  return RPC_SUCCESS;
}

void register_cnaf_callback(int debug) {
  cnaf_debug = debug;
  /* register CNAF callback */
  cm_register_function(RPC_CNAF16, cnaf_callback);
  cm_register_function(RPC_CNAF24, cnaf_callback);
}

/* end file */
Attachment 3: cnaf_callback_root.cxx
/********************************************************************\

  Name:         cnaf_callback.c
  Created by:   Stefan Ritt
  Created by:   moved here from mfe.c by Konstantin Olchanski

  Contents:     The system part of the MIDAS frontend. Has to be
                linked with user code to form a complete frontend

  $Id$

\********************************************************************/

#include <stdio.h>
#include <assert.h>
#include "midas.h"
#include "msystem.h"
#include "mcstd.h"

/*------------------------------------------------------------------*/

static int cnaf_debug = 0;

INT cnaf_callback(INT index, void *prpc_param[])
{
   DWORD cmd, b, c, n, a, f, *pdword, *size, *x, *q, dtemp;
   WORD *pword, *pdata, temp;
   INT   i, count;

   /* Decode parameters */
   cmd    = CDWORD(0);
   b      = CDWORD(1);
   c      = CDWORD(2);
   n      = CDWORD(3);
   a      = CDWORD(4);
   f      = CDWORD(5);
   pdword = CPDWORD(6);
   pword  = CPWORD(6);
   pdata  = CPWORD(6);
   size   = CPDWORD(7);
   x      = CPDWORD(8);
   q      = CPDWORD(9);

   /* determine repeat count */
   if (index == RPC_CNAF16)
      count = *size / sizeof(WORD); /* 16 bit */
   else
      count = *size / sizeof(DWORD); /* 24 bit */

   switch (cmd) {
      /*---- special commands ----*/

   case CNAF_INHIBIT_SET: cam_inhibit_set(c); break;
   case CNAF_INHIBIT_CLEAR: cam_inhibit_clear(c); break;
   case CNAF_CRATE_CLEAR: cam_crate_clear(c); break;
   case CNAF_CRATE_ZINIT: cam_crate_zinit(c); break;

   case CNAF_TEST: break;

   case CNAF:
      if (index == RPC_CNAF16) {
         for (i = 0; i < count; i++)
            if (f < 16)
               cam16i_q(c, n, a, f, pword++, (int *)x, (int *)q);
            else if (f < 24)
               cam16o_q(c, n, a, f, pword[i], (int *)x, (int *)q);
            else
               cam16i_q(c, n, a, f, &temp, (int *)x, (int *)q);
      } else {
         for (i = 0; i < count; i++)
            if (f < 16)
               cam24i_q(c, n, a, f, pdword++, (int *)x, (int *)q);
            else if (f < 24)
               cam24o_q(c, n, a, f, pdword[i], (int *)x, (int *)q);
            else
               cam24i_q(c, n, a, f, &dtemp, (int *)x, (int *)q);
      }

      break;

   case CNAF_nQ:
      if (index == RPC_CNAF16) {
         if (f < 16) {
            cam16i_rq(c, n, a, f, &pword, count);
            *size = (POINTER_T)pword - (POINTER_T)pdata;
         }
      } else {
         if (f < 16) {
            cam24i_rq(c, n, a, f, &pdword, count);
            *size = (POINTER_T)pdword - (POINTER_T)pdata;
         }
      }

      /* return reduced return size */
      break;

   default: printf("cnaf: Unknown command 0x%X\n", (unsigned int)cmd);
   }

   if (cnaf_debug) {
      if (index == RPC_CNAF16)
         printf("cmd=%d r=%d c=%d n=%d a=%d f=%d d=%X x=%d q=%d\n", (int)cmd, (int)count, (int)c, (int)n, (int)a,
                (int)f, (int)pword[0], (int)*x, (int)*q);
      else if (index == RPC_CNAF24)
         printf("cmd=%d r=%d c=%d n=%d a=%d f=%d d=%X x=%d q=%d\n", (int)cmd, (int)count, (int)c, (int)n, (int)a,
                (int)f, (int)pdword[0], (int)*x, (int)*q);
   }

   return RPC_SUCCESS;
}

void register_cnaf_callback(int debug)
{
   cnaf_debug = debug;
   /* register CNAF callback */
   cm_register_function(RPC_CNAF16, cnaf_callback);
   cm_register_function(RPC_CNAF24, cnaf_callback);
}

/* end file */
Attachment 4: cnaf_callback_gnu.cxx
/********************************************************************\

  Name:         cnaf_callback.c
  Created by:   Stefan Ritt
  Created by:   moved here from mfe.c by Konstantin Olchanski

  Contents:     The system part of the MIDAS frontend. Has to be
                linked with user code to form a complete frontend

  $Id$

\********************************************************************/

#include <stdio.h>
#include <assert.h>
#include "midas.h"
#include "msystem.h"
#include "mcstd.h"

/*------------------------------------------------------------------*/

static int cnaf_debug = 0;

INT cnaf_callback (INT index, void *prpc_param[])
{
  DWORD cmd, b, c, n, a, f, *pdword, *size, *x, *q, dtemp;
  WORD *pword, *pdata, temp;
  INT i, count;

  /* Decode parameters */
  cmd = CDWORD(0);
  b = CDWORD(1);
  c = CDWORD(2);
  n = CDWORD(3);
  a = CDWORD(4);
  f = CDWORD(5);
  pdword = CPDWORD(6);
  pword = CPWORD(6);
  pdata = CPWORD(6);
  size = CPDWORD(7);
  x = CPDWORD(8);
  q = CPDWORD(9);

  /* determine repeat count */
  if (index == RPC_CNAF16)
    count = *size / sizeof (WORD); /* 16 bit */
  else
    count = *size / sizeof (DWORD); /* 24 bit */

  switch (cmd)
    {
      /*---- special commands ----*/

  case CNAF_INHIBIT_SET: cam_inhibit_set (c);
      break;
  case CNAF_INHIBIT_CLEAR: cam_inhibit_clear (c);
      break;
  case CNAF_CRATE_CLEAR: cam_crate_clear (c);
      break;
  case CNAF_CRATE_ZINIT: cam_crate_zinit (c);
      break;

  case CNAF_TEST: break;

  case CNAF:
    if (index == RPC_CNAF16)
      {
        for (i = 0; i < count; i++)
          if (f < 16)
            cam16i_q (c, n, a, f, pword++, (int *) x, (int *) q);
          else if (f < 24)
            cam16o_q (c, n, a, f, pword[i], (int *) x, (int *) q);
          else
            cam16i_q (c, n, a, f, &temp, (int *) x, (int *) q);
      }
    else
      {
        for (i = 0; i < count; i++)
          if (f < 16)
            cam24i_q (c, n, a, f, pdword++, (int *) x, (int *) q);
          else if (f < 24)
            cam24o_q (c, n, a, f, pdword[i], (int *) x, (int *) q);
          else
            cam24i_q (c, n, a, f, &dtemp, (int *) x, (int *) q);
      }

      break;

  case CNAF_nQ:
    if (index == RPC_CNAF16)
      {
        if (f < 16)
          {
            cam16i_rq (c, n, a, f, &pword, count);
            *size = (POINTER_T) pword - (POINTER_T) pdata;
          }
      }
    else
      {
        if (f < 16)
          {
            cam24i_rq (c, n, a, f, &pdword, count);
            *size = (POINTER_T) pdword - (POINTER_T) pdata;
          }
      }

      /* return reduced return size */
      break;

  default: printf ("cnaf: Unknown command 0x%X\n", (unsigned int) cmd);
    }

  if (cnaf_debug)
    {
      if (index == RPC_CNAF16)
        printf ("cmd=%d r=%d c=%d n=%d a=%d f=%d d=%X x=%d q=%d\n", (int) cmd, (int) count, (int) c, (int) n, (int) a,
                (int) f, (int) pword[0], (int) *x, (int) *q);
      else if (index == RPC_CNAF24)
        printf ("cmd=%d r=%d c=%d n=%d a=%d f=%d d=%X x=%d q=%d\n", (int) cmd, (int) count, (int) c, (int) n, (int) a,
                (int) f, (int) pdword[0], (int) *x, (int) *q);
    }

  return RPC_SUCCESS;
}

void register_cnaf_callback (int debug)
{
  cnaf_debug = debug;
  /* register CNAF callback */
  cm_register_function (RPC_CNAF16, cnaf_callback);
  cm_register_function (RPC_CNAF24, cnaf_callback);
}

/* end file */
Attachment 5: cnaf_callback_google.cxx
/********************************************************************\

  Name:         cnaf_callback.c
  Created by:   Stefan Ritt
  Created by:   moved here from mfe.c by Konstantin Olchanski

  Contents:     The system part of the MIDAS frontend. Has to be
                linked with user code to form a complete frontend

  $Id$

\********************************************************************/

#include <stdio.h>
#include <assert.h>
#include "midas.h"
#include "msystem.h"
#include "mcstd.h"

/*------------------------------------------------------------------*/

static int cnaf_debug = 0;

INT cnaf_callback(INT index, void *prpc_param[]) {
  DWORD cmd, b, c, n, a, f, *pdword, *size, *x, *q, dtemp;
  WORD *pword, *pdata, temp;
  INT i, count;

  /* Decode parameters */
  cmd = CDWORD(0);
  b = CDWORD(1);
  c = CDWORD(2);
  n = CDWORD(3);
  a = CDWORD(4);
  f = CDWORD(5);
  pdword = CPDWORD(6);
  pword = CPWORD(6);
  pdata = CPWORD(6);
  size = CPDWORD(7);
  x = CPDWORD(8);
  q = CPDWORD(9);

  /* determine repeat count */
  if (index == RPC_CNAF16)
    count = *size / sizeof(WORD); /* 16 bit */
  else
    count = *size / sizeof(DWORD); /* 24 bit */

  switch (cmd) {
    /*---- special commands ----*/

    case CNAF_INHIBIT_SET: cam_inhibit_set(c);
      break;
    case CNAF_INHIBIT_CLEAR: cam_inhibit_clear(c);
      break;
    case CNAF_CRATE_CLEAR: cam_crate_clear(c);
      break;
    case CNAF_CRATE_ZINIT: cam_crate_zinit(c);
      break;

    case CNAF_TEST: break;

    case CNAF:
      if (index == RPC_CNAF16) {
        for (i = 0; i < count; i++)
          if (f < 16)
            cam16i_q(c, n, a, f, pword++, (int *) x, (int *) q);
          else if (f < 24)
            cam16o_q(c, n, a, f, pword[i], (int *) x, (int *) q);
          else
            cam16i_q(c, n, a, f, &temp, (int *) x, (int *) q);
      } else {
        for (i = 0; i < count; i++)
          if (f < 16)
            cam24i_q(c, n, a, f, pdword++, (int *) x, (int *) q);
          else if (f < 24)
            cam24o_q(c, n, a, f, pdword[i], (int *) x, (int *) q);
          else
            cam24i_q(c, n, a, f, &dtemp, (int *) x, (int *) q);
      }

      break;

    case CNAF_nQ:
      if (index == RPC_CNAF16) {
        if (f < 16) {
          cam16i_rq(c, n, a, f, &pword, count);
          *size = (POINTER_T) pword - (POINTER_T) pdata;
        }
      } else {
        if (f < 16) {
          cam24i_rq(c, n, a, f, &pdword, count);
          *size = (POINTER_T) pdword - (POINTER_T) pdata;
        }
      }

      /* return reduced return size */
      break;

    default: printf("cnaf: Unknown command 0x%X\n", (unsigned int) cmd);
  }

  if (cnaf_debug) {
    if (index == RPC_CNAF16)
      printf("cmd=%d r=%d c=%d n=%d a=%d f=%d d=%X x=%d q=%d\n", (int) cmd, (int) count, (int) c, (int) n, (int) a,
             (int) f, (int) pword[0], (int) *x, (int) *q);
    else if (index == RPC_CNAF24)
      printf("cmd=%d r=%d c=%d n=%d a=%d f=%d d=%X x=%d q=%d\n", (int) cmd, (int) count, (int) c, (int) n, (int) a,
             (int) f, (int) pdword[0], (int) *x, (int) *q);
  }

  return RPC_SUCCESS;
}

void register_cnaf_callback(int debug) {
  cnaf_debug = debug;
  /* register CNAF callback */
  cm_register_function(RPC_CNAF16, cnaf_callback);
  cm_register_function(RPC_CNAF24, cnaf_callback);
}

/* end file */
  2063   04 Jan 2021 Stefan RittSuggestionCode formatting
After pondering over the holidays, I decided to use the widely used LLVM code formatting, 
just adapted slightly for 3 spaces and "case" indentation in a "switch" statement. This 
formatting is now very close to our original one. Nevertheless, I did not reformat all 
existing code, since that would screw up the git repository, and you cannot see then anymore 
who wrote which line of code. But having the .clang-format file now in the midas root, all 
NEW files fill follow that standard. 

The CLion editor automatically picks up the .clang-format file if your enable ClangFomrat 
via Preferences -> Code Style -> General -> Enable ClangFormat.

EMACS can also use this file by adding following lines to your .emacs:

(load "<path-to-clang>/tools/clang-format/clang-format.el")
(global-set-key [C-M-tab] 'clang-format-region)

One problem left is if you check out midas on a new machine, you might not have there your 
personal .emacs file. If there is a way to ship a .emacs with midas, which gets 
automatically loaded, I would be happy to put this into the distribution.

Stefan
Attachment 1: .clang-format
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -3
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignOperands: false
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: MultiLine
BreakBeforeBraces: Custom
BraceWrapping:
  AfterCaseLabel: false
  AfterClass: false
  AfterControlStatement: Never
  AfterEnum: false
  AfterFunction: false
  AfterNamespace: false
  AfterUnion: false
  BeforeCatch: false
  BeforeElse: false
  IndentBraces: false
  SplitEmptyFunction: false
  SplitEmptyRecord: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 3
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 3
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 3
UseTab: Never
  2145   12 Apr 2021 Isaac Labrie BoulayForumClient gets immediately removed when using a script button.
Hi all,

I'm running into a curious problem when I try to run a program using my custom 
script button. I have been using a script button to start my DAQ, this button 
has always worked. It starts by exporting an absolute path to scripts and then 
runs scripts, my frontend, my analyzer, and mlogger relative to this path.

I recently added a line of code to run a new script "logic_controller". If I run 
the script_daq from my terminal (./start_daq), mhttpd accepts the client and the 
program works as intended. But, if I use the script button, the logic_controller 
program is immediately deleted by MIDAS. It can be seen appearing in the status 
page clients list and then immediately gets deleted. This is a client that runs 
on the local experiment host.

What might be the issue? What is the difference between running the script 
through the terminal as opposed to running it through the mhttpd button?

I have added a picture of my simple script and the logic_controller code.

Any help would be greatly appreciated.

Cheers.

Isaac
Attachment 1: logicCtrl.cpp
//
// Isaac Labrie-Boulay
//
// Program that enables the modification of gate and delay values 
// in the logic unit
//
// Last Edit: 2021-030-29
//

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <iostream>

using namespace std;

#include "CAEN_PLULib.h"
#include "midas.h"
#include "assert.h"
#include "mfe.h"
#include "mvmestd.h"
#include "odbxx.h"
//#include "CAEN_PLULib_TEST.h"

#ifdef WIN32 // Windows
#include <windows.h>
#include <conio.h>
#else // Linux
#define _popen popen
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>

char _getch() {
        char buf = 0;
        struct termios old = { 0 };
        fflush(stdout);
        if (tcgetattr(0, &old)<0)
                perror("tcsetattr()");
        old.c_lflag &= ~ICANON;
        old.c_lflag &= ~ECHO;
        old.c_cc[VMIN] = 1;
        old.c_cc[VTIME] = 0;
        if (tcsetattr(0, TCSANOW, &old)<0)
                perror("tcsetattr ICANON");
        if (read(0, &buf, 1)<0)
                perror("read()");
        old.c_lflag |= ICANON;
        old.c_lflag |= ECHO;
        if (tcsetattr(0, TCSADRAIN, &old)<0)
                perror("tcsetattr ~ICANON");
        printf("%c\n", buf);
        return buf;
}
#endif

char *base_address = "32100000";


void err_check(CAEN_PLU_ERROR_CODE err);

int main()
{

	cm_connect_experiment("", "", "logic_controller", NULL);
   	midas::odb::set_debug(true);

	//Establish a connection with the unit through the V1718
	int handle;
	CAEN_PLU_ERROR_CODE err_code;

	err_code = CAEN_PLU_OpenDevice(CAEN_PLU_CONNECT_VME_V1718, base_address, 0, 0, &handle);
	err_check(err_code);

	//Create an ODB key to hold the V2495 handle
	midas::odb hKey = {{"V2495 Handle", handle}};
	hKey.connect("/Modules/Logic");

	uint32_t firmware;
	err_code = CAEN_PLU_ReadReg(handle, 0x1000, &firmware);
	err_check(err_code);
	printf("Firmware version: %d\n", firmware);
	
	//Initialize Gate and Delay Generators
	err_code = CAEN_PLU_InitGateAndDelayGenerators(handle);
	err_check(err_code);

	//Take the Default gate values from the ODB
	midas::odb def("/Modules/Logic/Default");

	uint32_t commonGate = (uint32_t)def["width"];
        uint32_t commonDelay = (uint32_t)def["delay"];
        uint32_t commonScale = (uint32_t)def["scale"];

	//Set all gates to the same default settings
	err_code = CAEN_PLU_SetGateAndDelayGenerators(handle, commonGate, commonDelay, commonScale);
        err_check(err_code);

	//Watch the ODB subtree
	midas::odb to_watch("/Modules/Logic");
	
	//Lambda function
	//
	// if any of these keys are changed through the web server, 
	// write the new value to the logic unit
	//
	to_watch.watch([](midas::odb &logic){
      		
		//std::cout << "Value of key \"" + logic.get_full_path() + "\" changed to " << logic << std::endl;
		
		CAEN_PLU_ERROR_CODE err_code;

		//Retrieve the V2495 handle
		midas::odb temp("/Modules/Logic");
		int h = temp["V2495 Handle"];

		//Get the QDC parameters
		midas::odb qdc("/Modules/Logic/QDCGateA");
		uint32_t qdcGate = qdc["width"];
		uint32_t qdcDelay = qdc["delay"];
		uint32_t qdcScale = qdc["scale"];

		//Set the new values
		err_code = CAEN_PLU_SetGateAndDelayGenerator(h, 0, 1,  qdcGate, qdcDelay, qdcScale);
                err_check(err_code);
		
		//Get the TDC parameters
		midas::odb tdc("/Modules/Logic/TDCGate");
                uint32_t tdcGate = tdc["width"];
                uint32_t tdcDelay = tdc["delay"];
                uint32_t tdcScale = tdc["scale"];

		//Set the new values
		err_code = CAEN_PLU_SetGateAndDelayGenerator(h, 1, 1, tdcGate, tdcDelay, tdcScale);
                err_check(err_code);

   	});
	
	do {
      		int status = cm_yield(100);
      		if (status == SS_ABORT || status == RPC_SHUTDOWN)
         		break;
   	} while (!ss_kbhit());

	cm_disconnect_experiment();

	return 0;
}

void err_check(CAEN_PLU_ERROR_CODE err)
{
	if (err != CAEN_PLU_OK)
        {
                printf("Error %d\n", err);
                exit(0);
        }
}















Attachment 2: start_daq.PNG
start_daq.PNG
  2146   12 Apr 2021 Ben SmithForumClient gets immediately removed when using a script button.
> if I use the script button, the logic_controller program is immediately deleted by MIDAS.

This is indeed very curious, and I can't reproduce it on my test experiment. Can you redirect stdout and stderr from the logic_controller program into a file, to see how far the program gets? If it gets to the while loop at the end, then it would be useful to add some debug statements to see what condition causes it to exit the loop.

Are there any relevant messages in the midas message log about the program being killed? What's the value of "/Programs/logic_controller/Watchdog timeout"? 
  2147   12 Apr 2021 Isaac Labrie BoulayForumClient gets immediately removed when using a script button.
> > if I use the script button, the logic_controller program is immediately deleted by MIDAS.
> 
> This is indeed very curious, and I can't reproduce it on my test experiment. Can you redirect stdout and stderr from the logic_controller program into a file, to see how far the program gets? If it gets to the while loop at the end, then it would be useful to add some debug statements to see what condition causes it to exit the loop.

I have redirected stdout and stderr into a text file and I have attached it to this entry. From what the stdout says, it seems that the lambda
function gets called 4 times before the program disconnects from the experiment. Somehow the status must become SS_ABORT or RPC_SHUTDOWN.

> Are there any relevant messages in the midas message log about the program being killed? What's the value of "/Programs/logic_controller/Watchdog timeout"? 

There are no interesting messages in the midas.log and "/Programs/logic_controller/Watchdog timeout" is 10000 when I run the command from the terminal window.
What happens when you run it on your test experiment?

I'll try some more debugging.

Thanks for helping me out! Cheers.

Isaac
Attachment 1: debug_logic_controller.txt
Get definition for ODB key "/Modules/Logic"
Get definition for ODB key "/Modules/Logic/QDCGateA"
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate"
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/Default"
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/V2495 Handle"
Get ODB key "/Modules/Logic/V2495 Handle": 0
Get definition for ODB key "/Modules/Logic/QDCGateA"
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate"
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/Default"
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/V2495 Handle"
Get ODB key "/Modules/Logic/V2495 Handle": 0
Firmware version: 0
Get definition for ODB key "/Modules/Logic/Default"
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get ODB key "/Modules/Logic/Default/width": 200
Get ODB key "/Modules/Logic/Default/delay": 10
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic"
Get definition for ODB key "/Modules/Logic/QDCGateA"
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate"
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/Default"
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/V2495 Handle"
Get ODB key "/Modules/Logic/V2495 Handle": 0
Get definition for ODB key "/Modules/Logic/QDCGateA"
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate"
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/Default"
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/V2495 Handle"
Get ODB key "/Modules/Logic/V2495 Handle": 0
  2148   12 Apr 2021 Ben SmithForumClient gets immediately removed when using a script button.
I think it would be useful to find the minimal example that exhibits this behaviour.

What happens if your logic controller code is simply the 17 lines below? What happens if you create another script button that only starts the logic controller, not any of the other programs? etc. Gradually re-add features until you hit the problem (or scream in horror if it breaks with 17 lines of C++ and a 1 line shell script).



#include "midas.h"
#include "stdio.h"

int main() {
   cm_connect_experiment("", "", "logic_controller", NULL);

   do {
     int status = cm_yield(100);
     printf("cm_yield returned %d\n", status);
     if (status == SS_ABORT || status == RPC_SHUTDOWN)
       break;
   } while (!ss_kbhit());

   cm_disconnect_experiment();

   return 0;
}
  2149   13 Apr 2021 Isaac Labrie BoulayForumClient gets immediately removed when using a script button.
> I think it would be useful to find the minimal example that exhibits this behaviour.
> 
> What happens if your logic controller code is simply the 17 lines below? What happens if you create another script button that only starts the logic controller, not any of the other programs? etc. Gradually re-add features until you hit the problem (or scream in horror if it breaks with 17 lines of C++ and a 1 line shell script).
> 

Hi Ben,

I have followed your suggestions and the program still stops immediately. My status as returned from "cm_yield(100)" is always 412 (SS_TIMEOUT) which is fine. 
The issue is that, when run with the script button, the do-wile loop stops immediately because the !ss_kbhit() always evaluates to FALSE.

My temporary solution has been to let the loop run forever :)

Let me know what think. Thanks again!

Isaac

> 
> 
> #include "midas.h"
> #include "stdio.h"
> 
> int main() {
>    cm_connect_experiment("", "", "logic_controller", NULL);
> 
>    do {
>      int status = cm_yield(100);
>      printf("cm_yield returned %d\n", status);
>      if (status == SS_ABORT || status == RPC_SHUTDOWN)
>        break;
>    } while (!ss_kbhit());
> 
>    cm_disconnect_experiment();
> 
>    return 0;
> }
  2151   13 Apr 2021 Stefan RittForumClient gets immediately removed when using a script button.
> I have followed your suggestions and the program still stops immediately. My status as returned from "cm_yield(100)" is always 412 (SS_TIMEOUT) which is fine. 
> The issue is that, when run with the script button, the do-wile loop stops immediately because the !ss_kbhit() always evaluates to FALSE.
> 
> My temporary solution has been to let the loop run forever :)

Ahh, could be that ss_kbhit() misbehaves if there is no keyboard, meaning that it is started in the background as a script. 
We never had the issue before, since all "standard" midas programs like mlogger, mhttpd etc. also use ss_kbhit() and they 
can be started in the background via the "-D" flag, but maybe the stdin is then handled differentlhy. 

So just remove the ss_kbhit(), but keep the break, so that you can stop your program via the web page, like

#include "midas.h"
#include "stdio.h"

int main() {
  cm_connect_experiment("", "", "logic_controller", NULL);

  do {
    int status = cm_yield(100);
    printf("cm_yield returned %d\n", status);
    if (status == SS_ABORT || status == RPC_SHUTDOWN)
      break;
  } while (TRUE);

  cm_disconnect_experiment();

  return 0;
}
  1052   13 May 2015 Andreas SuterForumCheck if Client is running from Javascript
Is there currently an easy way to check from javascript if a midas client is
running? I mean an equivalent to cm_exist.

Sometimes this would be very useful in custom pages.
  1053   13 May 2015 Stefan RittForumCheck if Client is running from Javascript

Andreas Suter wrote:
Is there currently an easy way to check from javascript if a midas client is
running? I mean an equivalent to cm_exist.

Sometimes this would be very useful in custom pages.


Sounds like a good idea. We will add it this summer.
  1054   13 May 2015 Thomas LindnerForumCheck if Client is running from Javascript

Andreas Suter wrote:
Is there currently an easy way to check from javascript if a midas client is
running? I mean an equivalent to cm_exist.

Sometimes this would be very useful in custom pages.


It is not as clean as what you asked, but I have in the past written javascript like this to check if a program is running

var req = new Array();
req[0]= "Programs/towerfe3_00/First failed";
var result = ODBMGet(req);
if(result[0] == 0){
// then program is running
}
  1055   13 May 2015 Konstantin OlchanskiForumCheck if Client is running from Javascript
> Is there currently an easy way to check from javascript if a midas client is running? I mean an equivalent 
to cm_exist.

Yes, I can add an ajax method for cm_exist. While at it, maybe ajax methods for starting and stopping 
clients - to permit fully ajaxed implementation of the "programs" page?

K.O.

(But only under the condition that you post elog messages in "plain" format - fancy formatted messages 
with highlighted word "very" show up as complete dog breakfast in my text based email. If you want to 
highlight something, just say "***!!!***very***!!!***", add more bangs to taste).
  1056   14 May 2015 Andreas SuterForumCheck if Client is running from Javascript
Thanks a lot! This helps for now.

Thomas Lindner wrote:

Andreas Suter wrote:
Is there currently an easy way to check from javascript if a midas client is
running? I mean an equivalent to cm_exist.

Sometimes this would be very useful in custom pages.


It is not as clean as what you asked, but I have in the past written javascript like this to check if a program is running

var req = new Array();
req[0]= "Programs/towerfe3_00/First failed";
var result = ODBMGet(req);
if(result[0] == 0){
// then program is running
}
  2277   19 Sep 2021 Stefan RittBug FixChat working again
Not sure how many people are using it, but the Chat facility in midas was broken 
for some time now and got fixed today again.

Just for your information: Chat can be used like WhatsApp & Co, and connects all 
people who access a midas experiment through their browser. It's good to 
communicate between shift crew members located at different places. One advantage 
is that the chat messages can get 'spoken' by the text-to-speech engine of your 
browser, so it can be used to "wake up" shifters. Can be configured through the 
"Config" page.

Stefan
Attachment 1: Screenshot_2021-09-19_at_21.27.19_.png
Screenshot_2021-09-19_at_21.27.19_.png
  397   26 Jul 2007 Stefan RittInfoChange of pointer type in mvmestd.h
I had to change the pointer type of mvme_read and mvme_write to (void *) instead
to (mvme_locaddr_t *) to avoid warnings under 64-bit linux. Please adjust your
VME drivers if necessary.

- Stefan
  398   12 Aug 2007 Konstantin OlchanskiInfoChange of pointer type in mvmestd.h
> I had to change the pointer type of mvme_read and mvme_write to (void *) instead
> to (mvme_locaddr_t *) to avoid warnings under 64-bit linux. Please adjust your
> VME drivers if necessary.

Updated: vmicvme.c (VMIVME-7750/7805) and gefvme.c (GEFANUC V7865)

K.O.
ELOG V3.1.4-2e1708b5