#pragma once #ifndef TRUE #define FALSE (0) #define TRUE (1) #endif #ifndef EXIT_FAILURE #define EXIT_FAILURE 1 #endif #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif #define QUOTE1(name) #name #define QUOTE(name) QUOTE1(name) /* need to expand name */ #ifndef RT //#error "must define RT" #endif #ifndef MODEL //#error "must define MODEL" #endif #ifndef NUMST //#error "must define number of sample times, NUMST" #endif #ifndef NCSTATES //#error "must define NCSTATES" #endif #ifndef SAVEFILE #define MATFILE2(file) #file ".mat" #define MATFILE1(file) MATFILE2(file) #define MATFILE MATFILE1(MODEL) #else #define MATFILE QUOTE(SAVEFILE) #endif #define RUN_FOREVER -1.0 #define EXPAND_CONCAT(name1,name2) name1 ## name2 #define CONCAT(name1,name2) EXPAND_CONCAT(name1,name2) #define RT_MODEL CONCAT(MODEL,_rtModel) #define EXPAND_CONCAT3(name1,name2,name3) name1 ## _ ## name2 ## . ## name3 #define CONCAT3(name1,name2,name3) EXPAND_CONCAT3(name1,name2,name3) #define SIG_MODEL(suffix,name) CONCAT3(MODEL,suffix,name) #define NINT(a) ((a) >= 0.0 ? (int)((a)+0.5) : (int)((a)-0.5)) #define MIN(a,b) ((a)>(b)?(b):(a)) #include #include #include #include #include //#include "rtwtypes.h" //#include "rtmodel.h" //#include "rt_sim.h" //#include "rt_logging.h" #ifdef UseMMIDataLogging #include "rt_logging_mmi.h" #endif //#include "rt_nonfinite.h" //#include "ext_work.h" #include "Header.h" void __declspec(dllexport) __cdecl DISCON(float *avrSwap, int *aviFail, char *accInfile, char *avcOutname, char *avcMsg) { int iStatus; char errorMsg[257], inFile[257], outName[1025], psBuffer[128]; float rTime, rSample, rGeneratorSpeed, rRatedSpeed, rBelowRatedPitch, rForeAftTower, rSideTower, rMeasuredPitch, rMeasuredTorque, rModeGain; static float rTorqueDemand, rPitchDemand; FILE *pPipe; /* Take local copies of strings */ memcpy(inFile, accInfile, NINT(avrSwap[49])); inFile[NINT(avrSwap[49])+1] = '\0'; memcpy(outName, avcOutname, NINT(avrSwap[50])); outName[NINT(avrSwap[50])+1] = '\0'; /* Set message to blank */ memset(errorMsg, ' ', 257); /* Set constants */ //SetParams(avrSwap); /* Load variables from FAST */ iStatus = NINT(avrSwap[0]); rTime = avrSwap[1]; rSample = avrSwap[2]; rMeasuredPitch = avrSwap[3]; rBelowRatedPitch = avrSwap[4]; rModeGain = avrSwap[15]; rRatedSpeed = avrSwap[18]; rGeneratorSpeed = avrSwap[19]; rMeasuredTorque = avrSwap[22]; rForeAftTower = avrSwap[52]; rSideTower = avrSwap[53]; /* Trying to creat a pipe to send the above loaded data * to the server. Don't forget to convert the above array to int 8 (Beacuse of Matlab\Simulink) */ //StartProgram("C:\\ link to my Server_Im"); if ((pPipe = _popen("server_Im *.c /on /p", "wr")) == NULL) exit(1); /* Read pipe until end of file, or an error occurs. */ while (fgets(psBuffer, 128, pPipe)) { printf(psBuffer); } /* Close pipe and print return value of pPipe. */ if (feof(pPipe)) { printf("\nProcess returned %d\n", _pclose(pPipe)); } else { printf("Error: Failed to read the pipe to the end.\n"); } /* Maybe a delay is needed to be sure that all the * variables are loaded to the pipe. */ /* Store variables to FAST */ avrSwap[27] = 0; /* Pitch control */ avrSwap[34] = 1; /* Generator contactor status */ avrSwap[35] = 0; /* Shaft brake status: 0=off */ avrSwap[40] = 0; /* Demanded yaw actuator torque */ avrSwap[44] = rPitchDemand; /* Pitch angle demand */ avrSwap[45] = 0; /* Demanded pitch rate (Collective pitch) */ avrSwap[46] = rTorqueDemand; /* Torque angle demand */ avrSwap[47] = 0; /* Demanded nacelle yaw rate */ avrSwap[54] = 0; /* Pitch override */ avrSwap[55] = 0; /* Torque override */ avrSwap[64] = 0; /* Number of variables returned for logging */ avrSwap[71] = 0; /* Generator start-up resistance */ avrSwap[78] = 0; /* Request for loads: 0=none */ avrSwap[79] = 0; /* Variable slip current status */ avrSwap[80] = 0; /* Variable slip current demand */ /* Maybe a delay is also needed here * to be sure all the variable have been loaded correctly. */ /* Return message */ memcpy(avcMsg, errorMsg, MIN(256, NINT(avrSwap[48]))); return; } /* end DISCON */