📄 mc_signal.c
字号:
}
/* beginning of telegram -- only relevant when receiving formatted data telegrams */
if(currentFPchannelSCI0 == -1) {
/* no header has previously been received -> try to fetch it*/
/* read telegram header (if fully received) */
if(Buffercounter(FreePortComBufPtrSCI0) >= 4) {
// debug
//PORTB |= 0x08;
/* read first 4 bytes (size, channel, data_type_len, '0') */
for (i=0; i<4; i++) {
OutBuffer(FreePortComBufPtrSCI0, myBuf[i], char_T);
}
currentFPchannelSCI0 = myBuf[1];
admin = freecomTelBuf[currentFPchannelSCI0];
size = (uint16_T)admin->buf_size;
buf = admin->buf;
} /* header available */
} /* currentFPchannelSCI0 == -1 */
/* remainder of telegram */
if(currentFPchannelSCI0 != -1) {
/* a header has previously been received -> try to fetch remainder*/
/* read remainder of the telegram (if available) */
if(Buffercounter(FreePortComBufPtrSCI0) >= size) {
/* at this stage, the entire remainder of the telegram is in the ring buffer */
/* read remaining bytes from the ring buffer */
#ifdef ERASE
OutBuffer(FreePortComBufPtrSCI0, *buf, char_T);
if(*buf == 5) PORTB |= 0x01;
OutBuffer(FreePortComBufPtrSCI0, *(++buf), char_T);
if(*buf == 4) PORTB |= 0x02;
OutBuffer(FreePortComBufPtrSCI0, *(++buf), char_T);
if(*buf == 3) PORTB |= 0x04;
OutBuffer(FreePortComBufPtrSCI0, *(++buf), char_T);
if(*buf == 2) PORTB |= 0x08;
OutBuffer(FreePortComBufPtrSCI0, *(++buf), char_T);
if(*buf == 1) PORTB |= 0x10;
#endif
for (i=0; i<size; i++) {
OutBuffer(FreePortComBufPtrSCI0, *buf++, char_T);
}
/* indicate receipt of a telegram */
admin->buffer_full = 1;
/* reset global variable 'currentFPchannel' */
currentFPchannelSCI0 = -1;
// debug
//PORTB &= ~(0x08|0x04);
} /* remainder in buffer */
} /* currentFPchannelSCI0 != -1 */
} /* End of process_fpdata_SCI0 */
/* Function: process_fpdata_SCI1 ====================================================
* Abstract:
* Attempts to read a telegram from the FreePortComBuf ring buffer. If one is
* found, it is copied to the appropriate buffer.
* This function simply returns if there are less than 4 bytes in the reception
* buffer, otherwise it BLOCKS until the entire telegram has been received.
*/
void process_fpdata_SCI1(uint16_T raw_data) {
char_T myBuf[4];
uint_T i;
static myUsrBuf *admin; /* static, coz they may get used in subsequent calls to this function */
static uint16_T size; /* static, coz they may get used in subsequent calls to this function */
static uint8_T *buf; /* static, coz they may get used in subsequent calls to this function */
/* check if we're dealing with formatted data or not (raw_data == 1) */
if(raw_data) {
currentFPchannelSCI1 = 0; /* using channel '0' for raw data transmissions */
admin = freecomTelBuf[currentFPchannelSCI1];
size = (uint16_T)admin->buf_size;
buf = admin->buf;
}
/* beginning of telegram -- only relevant when receiving formatted data telegrams */
if(currentFPchannelSCI1 == -1) {
/* no header has previously been received -> try to fetch it*/
/* read telegram header (if fully received) */
if(Buffercounter(FreePortComBufPtrSCI1) >= 4) {
// debug
//PORTB |= 0x08;
/* read first 4 bytes (size, channel, data_type_len, '0') */
for (i=0; i<4; i++) {
OutBuffer(FreePortComBufPtrSCI1, myBuf[i], char_T);
}
currentFPchannelSCI1 = myBuf[1];
admin = freecomTelBuf[currentFPchannelSCI1];
size = (uint16_T)admin->buf_size;
buf = admin->buf;
} /* header available */
} /* currentFPchannelSCI1 == -1 */
/* remainder of telegram */
if(currentFPchannelSCI1 != -1) {
/* a header has previously been received -> try to fetch remainder*/
/* read remainder of the telegram (if available) */
if(Buffercounter(FreePortComBufPtrSCI1) >= size) {
/* at this stage, the entire remainder of the telegram is in the ring buffer */
/* read remaining bytes from the ring buffer */
#ifdef ERASE
OutBuffer(FreePortComBufPtrSCI1, *buf, char_T);
if(*buf == 5) PORTB |= 0x01;
OutBuffer(FreePortComBufPtrSCI1, *(++buf), char_T);
if(*buf == 4) PORTB |= 0x02;
OutBuffer(FreePortComBufPtrSCI1, *(++buf), char_T);
if(*buf == 3) PORTB |= 0x04;
OutBuffer(FreePortComBufPtrSCI1, *(++buf), char_T);
if(*buf == 2) PORTB |= 0x08;
OutBuffer(FreePortComBufPtrSCI1, *(++buf), char_T);
if(*buf == 1) PORTB |= 0x10;
#endif
for (i=0; i<size; i++) {
OutBuffer(FreePortComBufPtrSCI1, *buf++, char_T);
}
/* indicate receipt of a telegram */
admin->buffer_full = 1;
/* reset global variable 'currentFPchannelSCI1' */
currentFPchannelSCI1 = -1;
// debug
//PORTB &= ~(0x08|0x04);
} /* remainder in buffer */
} /* currentFPchannelSCI1 != -1 */
} /* End of process_fpdata_SCI1 */
/* Function: put_fpdata_SCI0 ====================================================
* Abstract:
* Sends nbyte via free port SCI0
*/
void put_fpdata_SCI0(uint8_T channel, uint8_T size, uint8_T dtype, uint8_T *src, uint8_T raw_data) {
uint_T i;
uint8_T myBuf[4];
/* check if we need to send a header at all... (formatted telegrams) */
if(!raw_data) {
/* yes -> assemble header (size, channel, data_type_len, '0') */
myBuf[0] = (uint8_T)(size + 4);
myBuf[1] = channel;
myBuf[2] = dtype;
myBuf[3] = 0;
/* send header */
for (i = 0; i < 4; i++) {
while((SCI0SR1 & TDRE_mask) == 0){}; // wait until the end of a possibly ongoing transmission
SCI0DRL = myBuf[i]; // send character
//SCI0DRL = '0'+myBuf[i]; // send character
}
} /* raw_data == 0 */
/* send remainder of the telegram (data) */
for (i = 0; i < size; i++) {
while((SCI0SR1 & TDRE_mask) == 0){}; // wait until the end of a possibly ongoing transmission
SCI0DRL = src[i]; // send character
//SCI0DRL = '0'+src[i]; // send character
}
} /* end of put_fpdata_SCI0 */
/* Function: put_fpdata_SCI1 ====================================================
* Abstract:
* Sends nbyte via free serial port SCI1
*/
void put_fpdata_SCI1(uint8_T channel, uint8_T size, uint8_T dtype, uint8_T *src, uint8_T raw_data) {
uint_T i;
uint8_T myBuf[4];
/* check if we need to send a header at all... (formatted telegrams) */
if(!raw_data) {
/* yes -> assemble header (size, channel, data_type_len, '0') */
myBuf[0] = (uint8_T)(size + 4);
myBuf[1] = channel;
myBuf[2] = dtype;
myBuf[3] = 0;
/* send header */
for (i = 0; i < 4; i++) {
while((SCI1SR1 & TDRE_mask) == 0){}; // wait until the end of a possibly ongoing transmission
SCI1DRL = myBuf[i]; // send character
//SCI1DRL = '0'+myBuf[i]; // send character
}
} /* raw_data == 0 */
/* send remainder of the telegram (data) */
for (i = 0; i < size; i++) {
while((SCI1SR1 & TDRE_mask) == 0){}; // wait until the end of a possibly ongoing transmission
SCI1DRL = src[i]; // send character
//SCI1DRL = '0'+src[i]; // send character
}
} /* end of put_fpdata_SCI1 */
/* only include this function if the model includes RFcomm 'client' blocks */
/* HAS_RFCOMMS: '0' : no RF communications, '1' : server, '2' : client, '3' : 'both' */
#if ((HAS_RFCOMMS == 2) | (HAS_RFCOMMS == 3))
/* Function: process_RadioCommData_client ====================================================
* Abstract:
* Attempts to read a telegram from the ring buffer of the radio module. If one is
* found, it is copied to the appropriate buffer.
* This function simply returns if there are less than 4 bytes in the reception
* buffer, otherwise it BLOCKS until the entire telegram has been received.
*/
void process_RadioCommData_client(uint16_T raw_data, uint8_T client) {
char_T myBuf[4];
uint_T i;
static myUsrBuf *admin; /* static, coz they may get used in subsequent calls to this function */
static uint16_T size; /* static, coz they may get used in subsequent calls to this function */
static uint8_T *buf; /* static, coz they may get used in subsequent calls to this function */
/* check if we're dealing with formatted data or not (raw_data == 1) */
if(raw_data) {
currentRFchannel = 0; /* using channel '0' for raw data transmissions */
admin = radiocomTelBuf[5*client + currentRFchannel];
size = (uint16_T)admin->buf_size;
buf = admin->buf;
}
/* beginning of telegram -- only relevant when receiving formatted data telegrams */
if(currentRFchannel == -1) {
/* no header has previously been received -> try to fetch it */
if(RadioClient_HasElements() >= 4) {
/* read first 4 bytes from the RF input buffer */
for (i=0; i<4; i++) {
/* fetch value from RF input buffer */
myBuf[i] = RadioClient_InChar();
}
currentRFchannel = myBuf[1];
admin = radiocomTelBuf[5*client + currentRFchannel];
size = (uint16_T)admin->buf_size;
buf = admin->buf;
} /* header available */
} /* currentRFchannel == -1 */
/* remainder of telegram */
if(currentRFchannel != -1) {
/* a header has previously been received -> try to fetch remainder*/
/* read remainder of the telegram (if available) */
if(RadioClient_HasElements() >= size) {
/* at this stage, the entire remainder of the telegram is in the ring buffer */
/* read remaining bytes from the ring buffer */
for (i=0; i<size; i++) {
/* fetch value from RF input buffer */
buf[i] = RadioClient_InChar();
}
/* indicate receipt of a telegram */
admin->buffer_full = 1;
/* reset global variable 'currentFPchannel' */
currentRFchannel = -1;
} /* remainder in buffer */
} /* currentRFchannel != -1 */
} /* End of process_RadioCommData_client */
/* Function: put_RFdata_client =======================================================
* Abstract:
* Sends nbyte through the RF module
*/
void put_RFdata_client(uint8_T channel, uint8_T size, uint8_T dtype, uint8_T *src, uint8_T raw_data) {
uint_T i;
uint8_T myBuf[4];
/* check if we need to send a header at all... (formatted telegrams) */
if(!raw_data) {
/* yes -> assemble header (size, channel, data_type_len, '0') */
myBuf[0] = (uint8_T)(size + 4);
myBuf[1] = channel;
myBuf[2] = dtype;
myBuf[3] = 0;
/* send header */
for (i = 0; i < 4; i++) {
/* ensure that RF transmission buffer is not full */
while(RadioClient_IsOutFull()) blinky(1000);
/* write output data to output buffer */
RadioClient_OutChar(myBuf[i]);
}
} /* raw_data == 0 */
/* send remainder of the telegram (data) */
for (i = 0; i < size; i++) {
/* ensure that RF transmission buffer is not full */
while(RadioClient_IsOutFull()) blinky(1000);
/* write output data to output buffer */
RadioClient_OutChar(src[i]);
}
} /* end of put_RFdata_client */
#endif /* HAS_RFCOMMS == 2 (client) */
/* only include this function if the model includes RFcomm 'server' blocks */
/* HAS_RFCOMMS: '0' : no RF communications, '1' : server, '2' : client, '3' : 'both' */
#if ((HAS_RFCOMMS == 1) | (HAS_RFCOMMS == 3))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -