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

📄 ictab4b8.c

📁 ICCP Toolkit 是在 Tru64下开发Tase.2通信协议的开发包
💻 C
📖 第 1 页 / 共 5 页
字号:
    ICA_Log_Flow0 ("icSendTypedMessage OK!");    printf ("icSendTypedMessage OK!");    }  }/************************************************************************//* sendPlForecast: send Power Plant Forecase message			*//************************************************************************/static void sendPlForecast (int msgType, icLinkId linkId)  {icMsgTypeForecast	*ptkMsg;icTypeIccpHeader	*pstIccpHdr;icTypeForecast		*pstMsgPtr;icInt			msgSize, status, anInt;icUChar			*message, *tmpMsg;int			numPeriods, i;icInt			*pMatrix, *pInt;icFloat			*pFloat, aFloat;  /* figure out message size						*/  printf ("\nEnter Number of Periods to send:  ");  intget (&numPeriods);  msgSize = sizeof (icMsgTypeForecast) +   	    2 * sizeof (icInt)	+	    numPeriods * sizeof (icFloat) +	    numPeriods * sizeof (icInt);  /* allocate memory and fill it up			*/  message = chk_malloc (msgSize);  ptkMsg = (icMsgTypeForecast *) message;  pstMsgPtr = &ptkMsg->MsgTypeHeader;  pstIccpHdr = &ptkMsg->MsgHeader;  /* fill up the message struct */  pstMsgPtr->ForecastRefId = msgType;  printf ("\nEnter Plant ID (an integer): ");  intget (&pstMsgPtr->PlantId);  printf ("\nEnter Unit ID (an integer):  ");  intget (&pstMsgPtr->UnitId);  pstMsgPtr->StartTime = time (NULL) + 52800;  printf ("\nEnter Period Resolution (an integer):  ");  intget (&anInt);  pstMsgPtr->PeriodResolution = (icTimeIntervalSType) anInt;  pstMsgPtr->NumberOfPeriods = numPeriods;  if (ask ("\n Forecast Type: Generation (N)? ",SD_FALSE))    pstMsgPtr->ForecastType = 0x80;  if (ask ("\n Forecast Type: Reserve (N)? ",SD_FALSE))    pstMsgPtr->ForecastType |= 0x40;    /* take care of the iccp header	*/  getHdrData ();  pstIccpHdr->RemoteId = _hdrRemoteId;  pstIccpHdr->RequestId = _hdrRequestId;  pstIccpHdr->DestinationId = _hdrDestId;  pstIccpHdr->ReferenceNumber = _hdrRefNum;  pstIccpHdr->MessageType = msgType;  pstIccpHdr->Conditions = _hdrConditions;  tmpMsg = message + sizeof (icMsgTypeForecast);  pMatrix = (icInt *) tmpMsg;  printf ("\nEnter Matrix 1 ID (an integer):  ");  intget (&anInt);  *pMatrix++ = anInt;  printf ("\nEnter Matrix 2 ID (an integer):  ");  intget (&anInt);  *pMatrix++ = anInt;  aFloat = (icFloat) 1.234;  tmpMsg += (2 * sizeof (icInt));  for (i=0; i < numPeriods; i++)    {    pFloat = (icFloat *) tmpMsg;    *pFloat = aFloat * i;			/* put MwValues here		*/    tmpMsg += sizeof (icFloat);    pInt = (icInt *) tmpMsg;    *pInt = i;				/* put LFC_Code values here	*/    tmpMsg += sizeof (icInt);    }    /* send the message	*/  status = icSendTypedMessage (linkId, msgType, NULL, (char) TAC_ALL,  			       message, msgSize);  if (status)    {    ICA_Log_Err2 ("ERROR:  icSendTypedMessage status = %d %s",                  status, icPerror(status));    printf ("\n\nSend Message Failed %d %s", status, icPerror (status));    }  else    {    ICA_Log_Flow0 ("icSendTypedMessage OK!");    printf ("icSendTypedMessage OK!");    }  }/************************************************************************//* sendPlCurve: send Power Plant Curve message				*//************************************************************************/static void sendPlCurve (int msgType, icLinkId linkId)  {icMsgTypeCurve		*ptkMsg;icTypeCurve   		*pstCurve;icTypeIccpHeader	*pstHeader;icTypeCurveSegDescription *pstSegDescr;icInt	      	msgSize, status, segDescrLen, floatLen;icUChar	      	*message, *tmpMsgPtr;int		numSegs = 5;	/* 5 segments per curve object		*/int		numFloats = 4;  /* 4 float values per curve descr	*/int 		i;icFloat		lowRange, hiRange, currFloat, *floatPtr;  /* determine message size 	*/  /* allocating memory for the message is the hard part here so     we will try to elaborate the details as much as possible	*/  segDescrLen = sizeof (icTypeCurveSegDescription);  IC_ALIGN_DATA (segDescrLen);  floatLen = numFloats * sizeof(icFloatValue);  IC_ALIGN_DATA (floatLen);  msgSize = sizeof (icMsgTypeCurve);		/* msg header space */  msgSize+= numSegs * segDescrLen;		/* curve descr space*/  msgSize+= numSegs * floatLen;			/* the float arrays */  message = chk_malloc (msgSize);  ptkMsg = (icMsgTypeCurve *) message;  pstCurve = &ptkMsg->MsgTypeHeader;  pstHeader = &ptkMsg->MsgHeader;  /* take care of the header	*/  getHdrData ();  pstHeader->RemoteId = _hdrRemoteId;  pstHeader->RequestId = _hdrRequestId;  pstHeader->DestinationId = _hdrDestId;  pstHeader->ReferenceNumber = _hdrRefNum;  pstHeader->MessageType = msgType;  pstHeader->Conditions = _hdrConditions;  /* fill up the message struct */  printf ("\nEnter Plant ID (an integer): ");  intget (&pstCurve->PlantReferenceId);  printf ("\nEnter Unit ID (an integer):  ");  intget (&pstCurve->UnitId);  printf ("\nEnter Curve Type (0-9):  ");  intget (&pstCurve->CurveType);  pstCurve->NumberOfSegments = numSegs;  tmpMsgPtr = message + sizeof (icMsgTypeCurve);  lowRange = (icFloat) 1.1;  currFloat = (icFloat) 1.01;/*  currFloat = (icFloat) 1.27; */  hiRange = lowRange * currFloat;  for (i=0; i < numSegs; i++)    {    pstSegDescr = (icTypeCurveSegDescription *) tmpMsgPtr;    pstSegDescr->Order = numFloats;    pstSegDescr->LowRange = lowRange;    pstSegDescr->HighRange = hiRange;    lowRange = hiRange;    hiRange += lowRange * currFloat;    pstSegDescr->NumberOfSegments = numFloats;    tmpMsgPtr += segDescrLen;    floatPtr = (icFloat *) tmpMsgPtr;    *floatPtr = currFloat;    floatPtr++;    *floatPtr = currFloat * (icFloat) 2.0;    floatPtr++;    *floatPtr = currFloat * (icFloat) 3.0;    floatPtr++;    *floatPtr = currFloat * (icFloat) 4.0;/*    currFloat = *floatPtr; */    tmpMsgPtr += floatLen;    }  /* send the message	*/  status = icSendTypedMessage (linkId, msgType, NULL, (char) TAC_ALL,  			       message, msgSize);  if (status)    {    ICA_Log_Err2 ("ERROR:  icSendTypedMessage status = %d %s",                  status, icPerror(status));    printf ("\n\nSend Message Failed %d %s", status, icPerror (status));    }  else    {    ICA_Log_Flow0 ("icSendTypedMessage OK!");    printf ("icSendTypedMessage OK!");    }  chk_free (message);  }/************************************************************************//* sendPlGenDataRpt:  send General Data Report				*//************************************************************************/static void sendPlGenDataRpt (int msgType, icLinkId linkId)  {icMsgTypeGeneralDataReport	*ptkMsg;icTypeGeneralDataReportHeader	*pstRpt;icTypeGDRDataHeader		*pstOffset;icTypeIccpHeader		*pstHeader;icUChar				*message, *tmpMsg;icInt msgSize, status;int headerLength, locRefLength, numLocalRef=0;int text1MatrixLength, text1Length, numText1=0, numText1Rows=0;int text2MatrixLength, text2Length, numText2=0, numText2Rows=0;int integer1MatrixLength, integer1Length, numInteger1=0, numInteger1Rows=0;    int integer2MatrixLength, integer2Length, numInteger2=0, numInteger2Rows=0;int float1MatrixLength, float1Length, numFloat1=0, numFloat1Rows=0;int float2MatrixLength, float2Length, numFloat2=0, numFloat2Rows=0;icReferenceNumType *pLocalRef;icMatrixId         *pMatrixId;icText32Value      *pText32;icInt		   *pIntVal;icFloatValue	   *pFloatVal;int i, j;  printf ("\nEnter Number of Local References:  ");  intget (&numLocalRef);  printf ("\nEnter Number of Text1 items:  ");  intget (&numText1);  printf ("\nEnter Number of Text1 Rows:  ");  intget (&numText1Rows);  printf ("\nEnter Number of Text2 items:  ");  intget (&numText2);  printf ("\nEnter Number of Text2 Rows:  ");  intget (&numText2Rows);  printf ("\nEnter Number of Integer1 items:  ");  intget (&numInteger1);  printf ("\nEnter Number of Integer1 Rows:  ");  intget (&numInteger1Rows);  printf ("\nEnter Number of Integer2 items:  ");  intget (&numInteger2);  printf ("\nEnter Number of Integer2 Rows:  ");  intget (&numInteger2Rows);  printf ("\nEnter Number of Float1 items:  ");  intget (&numFloat1);  printf ("\nEnter Number of Float1 Rows:  ");  intget (&numFloat1Rows);  printf ("\nEnter Number of Float2 items:  ");  intget (&numFloat2);  printf ("\nEnter Number of Float2 Rows:  ");  intget (&numFloat2Rows);  /* allocate memory!!!!					*/  headerLength = sizeof (icMsgTypeGeneralDataReport);  locRefLength = numLocalRef * sizeof(icReferenceNumType);  IC_ALIGN_DATA(locRefLength);  text1MatrixLength = numText1 * sizeof(icMatrixId);  IC_ALIGN_DATA(text1MatrixLength);  text1Length = numText1 * numText1Rows * sizeof(icText32Value);  IC_ALIGN_DATA(text1Length);  text2MatrixLength = numText2 * sizeof(icMatrixId);  IC_ALIGN_DATA(text2MatrixLength);  text2Length = numText2 * numText2Rows * sizeof(icText32Value);  IC_ALIGN_DATA(text2Length);  integer1MatrixLength = numInteger1 * sizeof(icMatrixId);  IC_ALIGN_DATA(integer1MatrixLength);  integer1Length = numInteger1 * numInteger1Rows * sizeof(icInt);  IC_ALIGN_DATA(integer1Length);  integer2MatrixLength = numInteger2 * sizeof(icMatrixId);  IC_ALIGN_DATA(integer2MatrixLength);  integer2Length = numInteger2 * numInteger2Rows * sizeof(icInt);  IC_ALIGN_DATA(integer2Length);  float1MatrixLength = numFloat1 * sizeof(icMatrixId);  IC_ALIGN_DATA(float1MatrixLength);  float1Length = numFloat1 * numFloat1Rows * sizeof(icFloatValue);  IC_ALIGN_DATA(float1Length);  float2MatrixLength = numFloat2 * sizeof(icMatrixId);  IC_ALIGN_DATA(float2MatrixLength);  float2Length = numFloat2 * numFloat2Rows * sizeof(icFloatValue);  IC_ALIGN_DATA(float2Length);  msgSize = locRefLength + headerLength +    	text1MatrixLength + text2MatrixLength + 	text1Length + text2Length +    	integer1MatrixLength + integer2MatrixLength + 	integer1Length + integer2Length +    	float1MatrixLength + float2MatrixLength + 	float1Length + float2Length;  message = chk_malloc (msgSize);  ptkMsg = (icMsgTypeGeneralDataReport *) message;  pstRpt = &ptkMsg->MsgTypeHeader;  pstHeader = &ptkMsg->MsgHeader;  pstOffset = &ptkMsg->MsgDataHeader;  /* this offset data is important	*/  pstOffset->LocalRefOffset = 0;  pstOffset->Text1Offset = locRefLength;  pstOffset->Text2Offset = pstOffset->Text1Offset +   			   text1MatrixLength + text1Length;  pstOffset->Integer1Offset = pstOffset->Text2Offset +  			      text2MatrixLength + text2Length;  pstOffset->Integer2Offset = pstOffset->Integer1Offset +  			      integer1MatrixLength + integer1Length;  pstOffset->Float1Offset = pstOffset->Integer2Offset +  			    integer2MatrixLength + integer2Length;  pstOffset->Float2Offset = pstOffset->Float1Offset +  			    float1MatrixLength + float1Length;  /* take care of the header	*/  getHdrData ();  pstHeader->RemoteId = _hdrRemoteId;  pstHeader->RequestId = _hdrRequestId;  pstHeader->DestinationId = _hdrDestId;  pstHeader->ReferenceNumber = _hdrRefNum;  pstHeader->MessageType = msgType;  pstHeader->Conditions = _hdrConditions;  /* fill up the general data report header struct */  pstRpt->GeneralDataReportRef = msgType;  printf ("\nEnter Report Name (a string):  ");  strget (pstRpt->ReportName);  pstRpt->ReportDateAndTime = time (NULL);  pstRpt->NumberLocalRef = numLocalRef;  pstRpt->NumberText1 = numText1;  pstRpt->NumberText2 = numText2;  pstRpt->NumberInteger1 = numInteger1;  pstRpt->NumberInteger2 = numInteger2;  pstRpt->NumberFloat1 = numFloat1;  pstRpt->NumberFloat2 = numFloat2;  pstRpt->NumberText1Rows = numText1Rows;  pstRpt->NumberText2Rows = numText2Rows;  pstRpt->NumberInteger1Rows = numInteger1Rows;  pstRpt->NumberInteger2Rows = numInteger2Rows;  pstRpt->NumberFloat1Rows = numFloat1Rows;  pstRpt->NumberFloat2Rows = numFloat2Rows;  /* take care of local references	*/  tmpMsg = message + sizeof (icMsgTypeGeneralDataReport);  pLocalRef = (icReferenceNumType *) tmpMsg;  for (i=0; i<numLocalRef; i++, pLocalRef++)    *pLocalRef = LOCAL_REF_START * i;  /* take care of text1 matrix ids next	*/  tmpMsg += locRefLength;  pMatrixId = (icMatrixId *) tmpMsg;  for (i=1; i<=numText1; i++, pMatrixId++)    *pMatrixId = i;  /* take care of text1 data next	*/  tmpMsg += text1MatrixLength;  pText32 = (icText32Value *) tmpMsg;  for (i=0; i<numText1; i++)    {    for (j=0; j<numText1Rows; j++, pText32++)      sprintf (*pText32, "Text1 item%d row%d", i, j);    }  /* take care of text2 matrix ids next	*/  tmpMsg += text1Length;  pMatrixId = (icMatrixId *) tmpMsg;  for (i=1; i<=numText2; i++, pMatrixId++)    *pMatrixId = i;  /* take care of text2 data next	*/  tmpMsg += text2MatrixLength;  pText32 = (icText32Value *) tmpMsg;  for (i=0; i<numText2; i++)    {    for (j=0; j<numText2Rows; j++, pText32++)      sprintf (*pText32, "Text2 item%d row%d", i, j);    }  /* take care of integer 1 matrix ids	*/  tmpMsg += text2Length;  pMatrixId = (icMatrixId *) tmpMsg;  for (i=1; i<=numInteger1; i++, pMatrixId++)    *pMatrixId = i;  /* take care of integer 1 data	*/  tmpMsg += integer1MatrixLength;  pIntVal = (icInt *) tmpMsg;  for (i=1; i<=numInteger1; i++)    {    for (j=1; j<=numInteger1Rows; j++, pIntVal++)      *pIntVal = INTEGER_START * i * j;    }  /* take care of integer 2 matrix ids	*/  tmpMsg += integer1Length;  pMatrixId = (icMatrixId *) tmpMsg;  for (i=1; i<=numInteger2; i++, pMatrixId++)    *pMatrixId = i;  /* take care of integer 2 data	*/  tmpMsg += integer2MatrixLength;  pIntVal = (icInt *) tmpMsg;  for (i=1; i<=numInteger2; i++)    {    for (j=1; j<=numInteger2Rows; j++, pIntVal++)      *pIntVal = INTEGER_START * i * j;    }  /* take care of float 1 matrix ids	*/  tmpMsg += integer2Length;  pMatrixId = (icMatrixId *) tmpMsg;  for (i=1; i<=numFloa

⌨️ 快捷键说明

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