
/* ********************************************************************** */
/*                                                                        */
/*                                SAMPLING()                              */
/*                               ==========                              */
/*                                                                        */
/*            get the sampled data of system input and output             */
/*                                                                        */
/* ********************************************************************** */
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include "apss.h"
#include "global.h"
#include "MatrixCal.hpp"   // For the random number generation 

void sampling(double *yt, double *ut)
{
    
 

	if (msgrcv(queueid1, (struct msgbuf *) &msgin,
        	sizeof(msgin.datain), msgin.mtype, 0 ) == -1) {
		printf("Error: in 'APSS_%d: sampling()'\n", msgin.mtype) ;
               	printf("\tqueueid1 = %d\n", queueid1 );
               	printf("\terrno = %d\n", errno );
               	exit( 1 );
	}

       	//ut = msgin.datain.Upss ;
	
	*ut = msgout.dataout.Upss ;
	/*
	switch( sampledSignal ) {
	  case 1 :
	    yt = msgin.datain.Omega ; break ;
	  case 2 :
	    yt = msgin.datain.dPe ; break ;
	  default :
	    yt = msgin.datain.dPe ; break ;
	  }
	*/
	*yt =  msgin.datain.Omega  ;//  *( 1+ 0.00005*random_1(&idnum))  ;/* generator speed  */
	//*yt =   msgin.datain.dOmega ;//*( 1 + 0.00005*random_1(&idnum)) ;/* derivative of speed(dOmega/dt)/
	//*yt = msgin.datain.Pe ;//*( 1+ 0.00005*random_1(&idnum)); /* generator electric power     */
	//*yt = msgin.datain.dPe ;//*( 1+ 0.00005*random_1(&idnum))  ;/*	accelerating power (Pm - Pe)*/
	sample_no++ ;

}












