📄 ext_svr.c
字号:
PRINT_DEBUG_MSG_LVL2_UDec(error);
PRINT_DEBUG_MSG_NL2;
return(error);
} /* end ProcessSelectSignalsPkt */
/* Function: ProcessSelectTriggerPkt ===========================================
* Receive and process the EXT_SELECT_TRIGGER packet.
*/
PRIVATE boolean_T ProcessSelectTriggerPkt(RTWExtModeInfo *ei, const int pktSize) {
const char *pkt;
int32_T upInfoIdx;
boolean_T error=EXT_NO_ERROR;
// local function name... debugging only
#if DEBUG_MSG_LVL > 0
const char *funct_name="ProcessSelectTriggerPkt";
#endif
PRINT_DEBUG_MSG_LVL2("IN\n\r");
pkt=GetPkt(pktSize);
if(pkt==NULL) {
SendResponseStatus(EXT_SELECT_TRIGGER_RESPONSE, NOT_ENOUGH_MEMORY, -1);
abort_LED(68);
error=EXT_ERROR;
goto EXIT_POINT;
}
/* Extract upInfoIdx */
(void)memcpy(&upInfoIdx, pkt, sizeof(int32_T));
PRINT_DEBUG_MSG_LVL3("Got EXT_SELECT_TRIGGER packet for upInfoIdx ");
PRINT_DEBUG_MSG_LVL3_UDec((uint16_T)upInfoIdx);
PRINT_DEBUG_MSG_NL3;
error=UploadInitTrigger(ei, pkt+sizeof(int32_T), upInfoIdx);
if(error!=EXT_NO_ERROR) {
SendResponseStatus(EXT_SELECT_TRIGGER_RESPONSE, NOT_ENOUGH_MEMORY, upInfoIdx);
abort_LED(69);
//printf(
// "\nError in UploadInitTrigger(). Most likely a memory\n"
// "allocation error or an attempt to re-initialize the\n"
// "trigger selection during the data logging process\n"
// "(i.e., multiple EXT_SELECT_TRIGGER packets were received\n"
// "before the logging session terminated or an\n"
// "EXT_CANCEL_LOGGING packet was received)\n");
goto EXIT_POINT;
}
error=SendResponseStatus(EXT_SELECT_TRIGGER_RESPONSE, STATUS_OK, upInfoIdx);
if(error!=EXT_NO_ERROR) {
abort_LED(70);
goto EXIT_POINT;
}
EXIT_POINT:PRINT_DEBUG_MSG_LVL2("OUT, error status: ");
PRINT_DEBUG_MSG_LVL2_UDec(error);
PRINT_DEBUG_MSG_NL2;
return error;
} /* end ProcessSelectTriggerPkt */
/* Function: ProcessCancelLoggingPkt ===========================================
* Receive and process the EXT_CANCEL_LOGGING packet.
*/
PRIVATE boolean_T ProcessCancelLoggingPkt(const int pktSize) {
const char *pkt;
int32_T upInfoIdx;
boolean_T error=EXT_NO_ERROR;
// local function name... debugging only
#if DEBUG_MSG_LVL > 0
const char *funct_name="ProcessCancelLoggingPkt";
#endif
PRINT_DEBUG_MSG_LVL2("IN\n\r");
pkt=GetPkt(pktSize);
if(pkt==NULL) {
SendResponseStatus(EXT_CANCEL_LOGGING_RESPONSE, NOT_ENOUGH_MEMORY, -1);
abort_LED(71);
error=EXT_ERROR;
goto EXIT_POINT;
}
/* Extract upInfoIdx */
(void)memcpy(&upInfoIdx, pkt, sizeof(int32_T));
PRINT_DEBUG_MSG_LVL3("Got EXT_CANCEL_LOGGING packet for upInfoIdx ");
PRINT_DEBUG_MSG_LVL3_UDec((uint16_T)upInfoIdx);
PRINT_DEBUG_MSG_NL3;
UploadCancelLogging(upInfoIdx);
error=SendResponseStatus(EXT_CANCEL_LOGGING_RESPONSE, STATUS_OK, upInfoIdx);
if(error!=EXT_NO_ERROR) {
abort_LED(72);
goto EXIT_POINT;
}
EXIT_POINT:PRINT_DEBUG_MSG_LVL2("OUT, error status: ");
PRINT_DEBUG_MSG_LVL2_UDec(error);
PRINT_DEBUG_MSG_NL2;
return error;
} /* end ProcessCancelLoggingPkt */
/* Function: ExtInitUD =============================================
* Abstract:
* The external mode UserData is created here
*/
PRIVATE void ExtInitUD(void) {
/*
* Create and initialize the user data -- fw-04-05
*/
extUD=ExtUserDataCreate();
if(extUD==NULL)
abort_LED(73);
} /* end ExtInitUD */
/*********************
* Visible Functions *
*********************/
/* Function: ExtSetWaitForStartPkt ============================================
* Abstract:
* Define the target behaviour w/h regard to 'wait for start pkt' - fw-06-07
*/
PUBLIC void ExtSetWaitForStartPkt(uint_T w4start) {
// local function name... debugging only
#if DEBUG_MSG_LVL > 0
const char *funct_name="ExtSetWaitForStartPkt";
#endif
if(w4start==TRUE) {
/* configure for 'wait for start Pkt from host' */
ExtSetWaitForStartPktFromHost(extUD, TRUE); // effectively: extUD->waitForStartPkt = TRUE;
startModel=FALSE;
//PRINT_DEBUG_MSG_LVL1("startModel = FALSE\n\r");
}
else {
/* configure for 'don't wait for start Pkt from host' */
ExtSetWaitForStartPktFromHost(extUD, FALSE); // effectively: extUD->waitForStartPkt = FALSE;
startModel=TRUE;
//PRINT_DEBUG_MSG_LVL1("startModel = TRUE\n\r");
}
} /* end ExtSetWaitForStartPkt */
#ifdef ERASE
/* Function: ExtParseArgsAndInitUD =============================================
* Abstract:
* Pass remaining arguments (main program should have NULL'ed out any args
* that it processed) to external mode.
*
* The actual, transport-specific parsing routine (implemented in
* ext_svr_transport.c) MUST NULL out all entries of argv that it processes.
* The main program depends on this in order to determine if any unhandled
* command line options were specified (i.e., if the main program detects
* any non-null fields after the parse, it throws an error).
*
* Returns an error string on failure, NULL on success.
*
* NOTES:
* The external mode UserData is created here so that the specified command-
* line options can be stored.
*/
PUBLIC const char_T * ExtParseArgsAndInitUD(const int_T argc, const char_T *argv[]) {
const char_T *error=NULL;
/*
* Create the user data.
*/
extUD=ExtUserDataCreate();
if(extUD==NULL) {
error="Could not create external mode user data. Out of memory.\n";
goto EXIT_POINT;
}
/*
* Parse the transport-specific args.
*/
error=ExtProcessArgs(extUD, argc, argv);
if(error!=NULL)
goto EXIT_POINT;
EXIT_POINT:
if(error!=NULL) {
ExtUserDataDestroy(extUD);
extUD=NULL;
}
return(error);
} /* end ExtParseArgsAndInitUD */
#endif
/* Function: ExtWaitForStartPkt ================================================
* Abstract:
* Return true if waiting for host to tell us when to start.
*/
PUBLIC boolean_T ExtWaitForStartPkt(void) {
return(ExtWaitForStartPktFromHost(extUD));
} /* end ExtWaitForStartPkt */
/* Function: UploadServerWork =================================================
* Abstract:
* Upload model signals to host for a single upInfo.
*/
void UploadServerWork(int32_T upInfoIdx, int_T numSampTimes) {
int_T i;
ExtBufMemList upList;
boolean_T error=EXT_NO_ERROR;
// local function name... debugging only
#if DEBUG_MSG_LVL > 0
const char *funct_name="UploadServerWork";
#endif
PRINT_DEBUG_MSG_LVL3("IN\n\r");
#ifdef VXWORKS
/*
* Don't spin the CPU unless we've got data to upload.
* The upload.c/UploadBufAddTimePoint function gives the sem
* each time that data is added.
*/
semTake(uploadSem, WAIT_FOREVER);
#endif
if(!connected)
goto EXIT_POINT;
UploadBufGetData(&upList, upInfoIdx, numSampTimes);
#ifdef TXactiveControl
while(upList.nActiveBufs>0 && TXactive) {
#else
while(upList.nActiveBufs>0) {
#endif
for(i=0; i<upList.nActiveBufs; i++) {
const BufMem *bufMem= &upList.bufs[i];
/*
* We call SendPktDataToHost() instead of SendPktToHost() because
* the packet header is combined with packet payload. We do this
* to avoid the overhead of making two calls for each upload
* packet - one for the head and one for the payload.
*/
error=SendPktDataToHost(bufMem->section1, bufMem->nBytes1);
if(error!=EXT_NO_ERROR) {
abort_LED(74);
//fprintf(stderr,"SendPktDataToHost() failed on data upload.\n");
goto EXIT_POINT;
}
if(bufMem->section2!=NULL) {
error=SendPktDataToHost(bufMem->section2, bufMem->nBytes2);
if(error!=EXT_NO_ERROR) {
abort_LED(75);
//fprintf(stderr,"SendPktDataToHost() failed on data upload.\n");
goto EXIT_POINT;
}
}
/* comfirm that the data was sent */
UploadBufDataSent(upList.tids[i], upInfoIdx);
}
UploadBufGetData(&upList, upInfoIdx, numSampTimes);
#ifdef TXactiveControl
/* deactivate TXactive flag (re-activated on demand, by the host) -- fw-07-07 */
TXactive = FALSE;
#endif
}
EXIT_POINT:
if(error!=EXT_NO_ERROR) {
/* currently never reached -- errors thrown: 24 and 25 (see above) -- fw-07-07 */
abort_LED(76); // just in case... (debug test)
/* An error in this function is caused by a physical failure in the
* external mode connection. We assume this failure caused the host
* to disconnect. The target must be disconnected and returned to a
* state where it is running and can be re-connected to by the host.
*/
ForceDisconnectFromHost(numSampTimes);
}
PRINT_DEBUG_MSG_LVL3("OUT, error status: ");
PRINT_DEBUG_MSG_LVL3_UDec(error);
PRINT_DEBUG_MSG_NL3;
}
/* end UploadServerWork */
/* Function: rt_UploadServerWork ===============================================
* Abstract:
* Wrapper function that calls UploadServerWork once for each upInfo
*/
PUBLIC void rt_UploadServerWork(int_T numSampTimes) {
int i;
for(i=0; i<NUM_UPINFOS; i++) {
UploadServerWork(i, numSampTimes);
}
} /* end rt_UploadServerWork */
/* Function: rt_ExtModeInit ====================================================
* Abstract:
* Called once at program startup to do any initialization related to external
* mode.
*/
PUBLIC boolean_T rt_ExtModeInit(int_T numSampTimes) {
int i;
boolean_T error=EXT_NO_ERROR;
// local function name... debugging only
#if DEBUG_MSG_LVL > 0
const char *funct_name="rt_ExtModeInit";
#endif
PRINT_DEBUG_MSG_LVL3("IN\n\r");
/* create and initialize extUD */
ExtInitUD();
error=ExtInit(extUD);
if(error!=EXT_NO_ERROR) {
abort_LED(77);
goto EXIT_POINT;
}
for(i=0; i<NUM_UPINFOS; i++) {
UploadLogInfoReset(i, numSampTimes);
}
rtExtModeTestingInit();
EXIT_POINT:PRINT_DEBUG_MSG_LVL3("OUT, error status: ");
PRINT_DEBUG_MSG_LVL3_UDec(error);
PRINT_DEBUG_MSG_NL3;
return error;
} /* end rt_ExtModeInit */
/* Function: rt_ExtModeSleep ===================================================
* Abstract:
* Called by grt_main, ert_main, and grt_malloc_main to "pause". It attempts
* to do this in a way that does not hog the processor.
*/
#ifndef VXWORKS
PUBLIC void rt_ExtModeSleep(long sec, /* number of seconds to wait */
long usec) /* number of micro seconds to wait */ {
ExtModeSleep(extUD, sec, usec);
} /* end rt_ExtModeSleep */
#endif
/* Function: rt_PktServerWork ==================================================
* Abstract:
* If not connected, establish communication of the packet line and the
* data upload line. If connected, send/receive packets and parameters
* on the packet line.
*/
PUBLIC void rt_PktServerWork(RTWExtModeInfo *ei, int_T numSampTimes, boolean_T *stopReq) {
PktHeader pktHdr;
boolean_T hdrAvail;
boolean_T error=EXT_NO_ERROR;
boolean_T disconnectOnError=FALSE;
// local function name... debugging only
#if DEBUG_MSG_LVL > 0
const char *funct_name="rt_PktServerWork";
#endif
PRINT_DEBUG_MSG_LVL3("IN\n\r");
/*
* If not connected, attempt to make connection to host.
*/
if(!connected) {
PRINT_DEBUG_MSG_LVL3("not connected\n\r");
rtExtModeTestingKillIfOrphaned(FALSE);
error=ExtOpenConnection(extUD, &connected);
if(error!=EXT_NO_ERROR) {
abort_LED(78);
goto EXIT_POINT;
}
PRINT_DEBUG_MSG_LVL3("now connected\n\r");
}
/*
* If ExtOpenConnection is not blocking and there are no pending
* requests to open a connection, we'll still be unconnected.
*/
if(!connected)
goto EXIT_POINT; /* nothing do do */
//PRINT_DEBUG_MSG_LVL3("rt_PktServerWork: connected\n\r");
/*
* Process packets.
*/
/* Wait for a packet. */
error=GetPktHdr(&pktHdr, &hdrAvail);
if(error!=EXT_NO_ERROR) {
PRINT_DEBUG_MSG_LVL3("Error occured getting packet header, disconnecting...\n\r");
abort_LED(79);
disconnectOnError=TRUE;
goto EXIT_POINT;
}
rtExtModeTestingKillIfOrphaned(hdrAvail);
if(!hdrAvail)
goto EXIT_POINT; /* nothing to do */
PRINT_DEBUG_MSG_LVL3("Received packet header\n\r");
/*
* This is the first packet. Should contain the string:
* 'ext-mode'. Its contents are not important to us.
* It is used as a flag to start the handshaking process.
*/
if(!commInitialized) {
#ifdef LCDUSE4ERRORS
writeLine("-> connecting ", 1);
#endif
#ifdef TXactiveControl
/* any message header other than EXT_DATA_UPLD_NOACK_REQUEST causes the communication to be reinitialised -- fw-07-07 */
if(pktHdr.type != EXT_DATA_UPLD_NOACK_REQUEST) {
PRINT_DEBUG_MSG_LVL3("Received first packet header (EXT_CONNECT)\n\r");
pktHdr.type=EXT_CONNECT;
}
#else
PRINT_DEBUG_MSG_LVL3("Received first packet header (EXT_CONNECT)\n\r");
pktHdr.type=EXT_CONNECT;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -