#ifndef _SHM_H
#define _SHM_H


#define TYPE_MX  	1
#define TYPE_ST  	2
#define TYPE_SE  	3
#define TYPE_SG  	4
#define TYPE_SGCB  	5
#define TYPE_CO  	6
#define TYPE_SP  	7
#define TYPE_SV     8

#define CMD_WR_MX   1
#define CMD_WR_ST   2
#define CMD_WR_SE   3
#define CMD_WR_SG   4
#define CMD_WR_SGCB 5
#define CMD_WR_CO   6
#define CMD_WR_SP   7
#define CMD_WR_SV   8

typedef union
{
float f;
int   i;
char  stVal;
void *ptr;
}GEN_VAL;

typedef struct{
unsigned int secs;
unsigned int ms;
}TimeStamp;


typedef struct utc_time_tag
{
  unsigned int secs;      	// Number of seconds since January 1, 1970
  unsigned int fraction;  	// Fraction of a second
  unsigned int qflags;	    // Quality flags, 8 least-significant bits only
} UTC_TIME;


typedef struct{
GEN_VAL     v;
int 		q;
TimeStamp 	t;
//#ifdef SUB_ENABLE
int         subEna;	
GEN_VAL     subVal;
int         subQ;
//#endif		
}SCL_MV; //该结构在共享内存区 


typedef struct{
GEN_VAL     v;
int 		q;
TimeStamp 	t;		
}USR_MV; //该结构在共享内存区 


typedef struct{
GEN_VAL ctlVal;
char ctlNum;
TimeStamp t;
char Test;
char Check;
int  valType;
}SCL_CO;

typedef struct
{
unsigned char NumOfSG; //1-n
unsigned char ActSG;   //1-n
unsigned char EditSG;  //0-n,0
unsigned char CnfEdit;
UTC_TIME LActTm;// TimeStamp
}SGCB_CTRL;


typedef union
{
USR_MV      ana_mv;
SCL_MV 		scl_mv;
SCL_CO 		scl_co;
SGCB_CTRL	sgcb_ctrl;	
}SCL_VAL;//通用DO 


typedef struct{
int type; 			//该USER_MAP的类型编码种类,既表示该编码是MX类型的还是ST类型的,还是CO类型的 
int grp;  			//组号,用于指示在哪个共享内存区 
int num;  			//偏移,用于指示在共享内存区的第off_num个SCL_MX结构 
int ofs;      		//v,q,t分别用0,1,2表示
GEN_VAL v;
}SCL_DATA_SPEC;

typedef struct{
int cmd;
union
{
 SCL_DATA_SPEC data_spec;	
}u;	
}SCL_MSG_TYPE;


int start_scl_mem();
int stop_scl_mem();
void lock_scl_mem();
void unlock_scl_mem();


char *put_scl_data(int grp,int index,void *ptr,int num_bytes);
char *get_scl_data(int grp,int index,void *ptr,int num_bytes);

SCL_VAL* put_mv_data(int grp,int index,USR_MV *usr_mv,int num_do);
SCL_VAL* get_mv_data(int grp,int index,USR_MV *usr_data,int num_do);
SCL_VAL *put_do_data(int grp,int index,SCL_VAL *scl_do,int num_of_do);
SCL_VAL *get_do_data(int grp,int index,SCL_VAL *scl_do,int num_of_do);

SGCB_CTRL* get_sgcb_data(int index,SGCB_CTRL *sgcb);
SGCB_CTRL* put_sgcb_data(int index,SGCB_CTRL *sgcb);
char *get_sg_data(int grp,int index,char *ptr,int num_bytes);
char *put_sg_data(int grp,int index,char *ptr,int num_bytes);
char *get_se_data(int grp,int index,char *ptr,int num_bytes);
char *put_se_data(int grp,int index,char *ptr,int num_bytes);

int get_usr_data(int offs,void *ptr,int num_bytes);
int put_usr_data(int offs,void *ptr,int num_bytes);

int write_scl_msg(int cmd,SCL_DATA_SPEC *data_spec);


#endif

