thermferm/statetbl.h

Thu, 02 May 2024 15:49:16 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 02 May 2024 15:49:16 +0200
changeset 716
5c30c8ef83a8
parent 655
780cc08df263
permissions
-rw-r--r--

Version 0.9.19b3. The simulator thread can be paused to be able to add and delete simulators. Added simulated door and PSU status. Devices can now fully use multiple simulators. Better rounding of simulated temperature values. The server SIMULATOR DEL and ADD commands pause the simulator when the linked list is manipulated. Fixed SIGSEGV when a simulator is added. Added socket SO_REUSEADDR again to the server socket.

/**
 * @brief State table macro's
 */

#ifndef STATETBL_H
#define STATETBL_H

#define SM_DECL(proc,name) \
int proc(void)\
{\
    int sm_success=0;\
    char *sm_name=name;

#define SM_STATES \
    enum {

#define SM_NAMES \
    } sm_state; \
    char * sm_sname[] = {

#define SM_EDECL \
    };

#define SM_START(x) \
    sm_state=x;\
    if (debug)\
	syslog(LOG_NOTICE, "SM (%s): Start => %s", sm_name, sm_sname[sm_state]); \
    while (!sm_success) switch (sm_state)\
    {\
    default: syslog(LOG_WARNING, "Statemachine %s error: state=%d",sm_name,sm_state);\
    sm_success=-1;

#define SM_STATE(x) \
    break;\
    case x:

#define SM_END \
    }\

#define SM_RETURN \
    return (sm_success != 1);\
}

#define SM_PROCEED(x) \
    if (x != sm_state && debug) {\
	syslog(LOG_NOTICE, "SM (%s): %s => %s", sm_name, sm_sname[sm_state], sm_sname[x]);\
    }\
    sm_state=x; break;

#define SM_SUCCESS \
    if (debug)\
	syslog(LOG_NOTICE, "SM (%s): %s => Success", sm_name, sm_sname[sm_state]);\
    sm_success=1; break;

#define SM_ERROR \
    syslog(LOG_WARNING, "SM (%s): %s => Error", sm_name, sm_sname[sm_state]);\
    sm_success=-1; break;

#endif

mercurial