⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sc6netmesot.cpp

📁 socket编程
💻 CPP
字号:
#include "stdafx.h"	// only used in the testing prj made by VC++

#ifdef _WINDOWS

#include  "tosteel.h"
#include  <string.h>
#include  "SC6NETMESOT.h"
#else 

#include  <stdio.h>
#include  <string.h>
#include  <time.h>
#include  <errno.h>
#include  "tosteel.h"
#include  "MSGSREQ.h"

#endif

static         char     *c_mesdat[32];

static int MESOTCNGFMT(char *p_mesfmt,long *p_mesdat);
int COMBINEMSG(char ** p_msg) ;

int SC6NETMESOT(char *p_host,int p_factno , int p_mesno,char *p_mesfmt,long *p_mesdat)
{
	int             w_sts		;
	int             w_messize	;
	char            * w_mesdat	;
	char            w_ctime[32] ;
	struct MSGSREQ	w_msgsreq	;
	int				dely_time = 0	;

/****************************/
/*    Logic start           */
/****************************/
    /* Initialize intarnal variable.                                */
    w_sts   = 0 ;
    /* limit check with a message number */
    if ( p_mesno <= 0 || p_mesno > 10000){
       return(-1);
    }

#ifdef _WINDOWS

	SYSTEMTIME time ;
	GetLocalTime( &time ) ;
    sprintf( w_ctime , "[%04d/%02d/%02d %02dh:%02dm:%02ds] " ,
             time.wYear , time.wMonth , time.wDay , 
			 time.wHour , time.wMinute, time.wSecond ) ;

#else
	struct timespec  w_timespec ;
	char            *w_charpnt ;
	pid_t            w_pid; 

	/* Issue message on console */
    SC6MESOT(p_mesno,p_mesfmt,p_mesdat);

	/* get time */
	w_sts = clock_gettime( CLOCK_REALTIME, &w_timespec ) ;
	if(  w_sts < 0 )
	{
		w_sts = E_MES_GETTIME | errno ;
		return(w_sts);
	}
    w_charpnt = ctime( &w_timespec.tv_sec ) ;

    if( w_charpnt == (char*)NULL )
	{
		w_sts = E_MES_CTIME | errno ;
		return(w_sts);
    }
    w_charpnt[strlen(w_charpnt)-1] = '\0' ;
    strcpy( w_ctime, w_charpnt ) ;
#endif

    /*Output A message format is changed */
    w_sts = MESOTCNGFMT(p_mesfmt,p_mesdat);
    if ( w_sts != 0 ) 
	{
		return(w_sts);
    }

	w_messize = COMBINEMSG(&w_mesdat) ;

	//Max size is 1023
	if ( w_messize > 1023 )
		return -1 ;

    //w_sts = S3MSGEDT (p_mesno, c_mesdat, &w_messize, w_mesdat);
    w_msgsreq.req = 1 ;
	w_msgsreq.facno = p_factno ;
    w_msgsreq.msgno = p_mesno ;
    strcpy( w_msgsreq.host, p_host) ;
    sprintf( w_msgsreq.data, "%s%s", w_ctime, w_mesdat) ;
    w_msgsreq.size =  strlen(w_msgsreq.data) + 1 ;

	w_messize = w_msgsreq.size + (sizeof(struct MSGSREQ)-1024*sizeof(char)) ;

    //w_sts = S1WAKEUP( "MSGS", &w_messize, &w_msgsreq, &dely_time );

    w_sts = S1WAKEUP( "ALARM_CLT", &w_messize, &w_msgsreq, &dely_time );
    
    return( w_sts ) ;
}


/***********************************************************************

 <Change history>
   Designed by :  Y.Enjyoji ,  '97-03-27
   Coded by    :  Y.Enjyoji ,  '97-07-27

 <Module name - title>
   MESOTCNGFMT   - chenging message format

 <Outline>

 <Input-and-output data>
  #J   メッセ〖ジフォ〖マットをchar 房に恃垂し叫蜗する

 <Calling sequence>
   sts = MESOTCNGFMT(char *p_mesfmt,int *p_mesdat)

 <Explanation of the parameter>
   int   sts       - output - status (error information status)
       0: normal
       1: abnormal
   char  p_mesfmt  - input  - input  message format
   char  p_mesdat  - input  - input  message data

***********************************************************************/
static int MESOTCNGFMT(char *p_mesfmt,long *p_mesdat)
{
   int			w_iwi			;
   size_t		w_len			;
   int			w_cnt			;
   int			w_idx			;
   char		*	w_token			;
   char		*	w_cadr			;
   float	*	w_fadr			;
   double	*	w_dadr			;
   static char  w_cdat[32][256]	;
   static char  w_fmt[256]		;
   static char  w_mesfmt[256]	;
   int          w_double_flg	;

   if ( p_mesdat[0] <= 0 || p_mesdat[0] > 31 ) {
       return(-1);
   }

   memset(w_cdat[0],0,sizeof(w_cdat))	;
   memset(w_mesfmt,0,sizeof(w_mesfmt))	;
   w_len = strlen(p_mesfmt)				;
   memcpy(w_mesfmt,p_mesfmt,w_len)		;

   w_idx =1;
   c_mesdat[0] = (char *)p_mesdat[0];
   w_cnt = (int )p_mesdat[0];

   for(w_iwi=0;w_iwi<w_cnt;w_iwi++)
   {
      if ( w_iwi != 0 ) 
	  {
         w_token = strtok(NULL,"%");
      } 
	  else 
	  {
         w_token = strtok(w_mesfmt,"%");
      }

      /*  charcter */
      w_len = strlen(w_token);
      if ( w_token[w_len -1] == 's' ) 
	  {
         w_cadr =  (char *)p_mesdat[w_idx];
         if ( (long)w_cadr > 0 ) 
		 {
            strcpy(w_fmt,"%");
            strcat(w_fmt,w_token);
            sprintf(w_cdat[w_iwi],w_fmt,w_cadr);
         }
         w_len = strlen(w_cdat[w_iwi]);
         if ( w_len == 0 ) w_cdat[w_iwi][0]=' ';
      } 
	  else if ( w_token[w_len -1] == 'f') 
	  {
         w_double_flg = 0 ;

         if( w_len >= 2 )
		 {
           if( w_token[w_len -2] == 'l') 
		   {
             w_double_flg = 1 ;
           }
         }

         if( w_double_flg == 0 )
		 {
             w_fadr =  (float *)p_mesdat[w_idx];
             if ( (long)w_fadr > 0 ) 
			 {
                strcpy(w_fmt,"%");
                strcat(w_fmt,w_token);
                sprintf(w_cdat[w_iwi],w_fmt, *w_fadr);
             }
		 }
		 else
		 {
             w_dadr =  (double *)p_mesdat[w_idx];
             if ( (long)w_fadr > 0 ) 
			 {
                strcpy(w_fmt,"%");
                strcat(w_fmt,w_token);
                sprintf(w_cdat[w_iwi],w_fmt, *w_dadr);
             }
          }

      } 
	  else 
	  {
         strcpy(w_fmt,"%");
         strcat(w_fmt,w_token);
         sprintf(w_cdat[w_iwi],w_fmt,p_mesdat[w_idx]);
      }
      c_mesdat[w_idx] = (char *)w_cdat[w_iwi];
      w_idx++;
   }

   return(0);
}

int COMBINEMSG(char ** p_msg)
{
	int w_num ;
	int w_cnt ;
	int w_len ;
	char * ptr  = NULL ;
	*p_msg = NULL ;

	w_num = 0 ; w_cnt = 0 ; w_len = 0 ;

	w_num = (int)c_mesdat[0] ;
	for ( w_cnt = 1 ; w_cnt < w_num ; w_cnt++ )
	{
		w_len += strlen(c_mesdat[w_cnt]) +1 ;
	}

	if ( w_len <= 0 )
		return 0 ;	

	ptr = (char*)malloc(w_len+1) ;
	memset( ptr , '\0' , w_len+1 ) ;

	*p_msg = ptr ;

	for ( w_cnt = 1 ; w_cnt <= w_num ; w_cnt++ )
	{
		strncpy(ptr , c_mesdat[w_cnt] , strlen(c_mesdat[w_cnt]) ) ;
		ptr += strlen(c_mesdat[w_cnt]) ;
		if ( w_cnt < w_num )
		{
			strncpy(ptr ,";" , 1 ) ;
			ptr += 1 ;
		}
	}

	return w_len ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -