本文整理汇总了C++中serialRead函数的典型用法代码示例。如果您正苦于以下问题:C++ serialRead函数的具体用法?C++ serialRead怎么用?C++ serialRead使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serialRead函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stm32CmdGet
int stm32CmdGet()
{
int ret = STM_ERR;
if ( sendCommand(0x00)==STM_OK ) {
int i;
unsigned char num;
serialRead(board.serial_fd, &num, 1); // number of bytes
serialRead(board.serial_fd, &board.version, 1);
serialRead(board.serial_fd, board.cmd, num);
if ( waitAck()==STM_OK ) {
printf("Bootloader version: %x.%x\nCommand set-[", board.version >> 4, board.version & 0x0F);
for ( i=0; i < num; i++ )
printf(" %02X", board.cmd[i]);
printf("]\n");
ret = STM_OK;
}
示例2: serialCom
void serialCom(void)
{
uint8_t c;
int i;
for (i = 0; i < numTelemetryPorts; i++) {
currentPortState = &ports[i];
// in cli mode, all serial stuff goes to here. enter cli mode by sending #
if (cliMode) {
cliProcess();
return;
}
if (pendReboot)
systemReset(false); // noreturn
while (serialTotalBytesWaiting(currentPortState->port)) {
c = serialRead(currentPortState->port);
if (currentPortState->c_state == IDLE) {
currentPortState->c_state = (c == '$') ? HEADER_START : IDLE;
if (currentPortState->c_state == IDLE && !f.ARMED)
evaluateOtherData(c); // if not armed evaluate all other incoming serial data
} else if (currentPortState->c_state == HEADER_START) {
currentPortState->c_state = (c == 'M') ? HEADER_M : IDLE;
} else if (currentPortState->c_state == HEADER_M) {
currentPortState->c_state = (c == '<') ? HEADER_ARROW : IDLE;
} else if (currentPortState->c_state == HEADER_ARROW) {
if (c > INBUF_SIZE) { // now we are expecting the payload size
currentPortState->c_state = IDLE;
continue;
}
currentPortState->dataSize = c;
currentPortState->offset = 0;
currentPortState->checksum = 0;
currentPortState->indRX = 0;
currentPortState->checksum ^= c;
currentPortState->c_state = HEADER_SIZE; // the command is to follow
} else if (currentPortState->c_state == HEADER_SIZE) {
currentPortState->cmdMSP = c;
currentPortState->checksum ^= c;
currentPortState->c_state = HEADER_CMD;
} else if (currentPortState->c_state == HEADER_CMD && currentPortState->offset < currentPortState->dataSize) {
currentPortState->checksum ^= c;
currentPortState->inBuf[currentPortState->offset++] = c;
} else if (currentPortState->c_state == HEADER_CMD && currentPortState->offset >= currentPortState->dataSize) {
if (currentPortState->checksum == c) { // compare calculated and transferred checksum
evaluateCommand(); // we got a valid packet, evaluate it
}
currentPortState->c_state = IDLE;
}
}
}
}
示例3: serialRead
//Get power of a specific channel
unsigned short Parallax::getPower(unsigned char channel) {
if(channel > PARALLAX_NUM_MOTORS) {
Log::logf(Log::WARN, "Invalid PWM channel!\n");
return 0;
}
unsigned char command[8] = {'!', 'S', 'C', 'R', 'S', 'P', channel, '\r'};
//3 preamble bytes, 3 command bytes, channel byte, command terminator
if(serialWrite(&command, sizeof(command)) != sizeof(command)) {
Log::logf(Log::ERR, "Error writing to Parallax servo controller!\n");
}
serialRead(&command, sizeof(command)); //Remove remote echo from input buffer, ignore any errors
unsigned char data[3] = {0};
if(serialRead(&data, sizeof(data)) == sizeof(data)) {
return (data[1] << 8) | data[2];
} else {
return 0;
}
}
示例4: while
//!Wait the response of the module
void WaspRFID::waitResponse(void)
{
int val = 0xFF;
long cont = 0;
while((val != PREAMBLE) && (cont < timeOut)) {
val = serialRead(_uart);
delay(5);
cont ++;
}
}
示例5: gpsSetPassthrough
int8_t gpsSetPassthrough(void)
{
if (gpsData.state != GPS_RECEIVINGDATA)
return -1;
LED0_OFF;
LED1_OFF;
while(1) {
if (serialTotalBytesWaiting(core.gpsport)) {
LED0_ON;
serialWrite(core.mainport, serialRead(core.gpsport));
LED0_OFF;
}
if (serialTotalBytesWaiting(core.mainport)) {
LED1_ON;
serialWrite(core.gpsport, serialRead(core.mainport));
LED1_OFF;
}
}
}
示例6: initlbuf
void initlbuf(void) {
lbufptr = lbuf;
#if defined(SERIAL_OVERRIDE) && 0
// don't do the prompt in serialIsOverridden mode
if (serialIsOverridden()) return;
#endif
prompt();
// flush any pending serial input
while (serialAvailable()) serialRead();
}
示例7: serialPassthrough
/*
A high-level serial passthrough implementation. Used by cli to start an
arbitrary serial passthrough "proxy". Optional callbacks can be given to allow
for specialized data processing.
*/
void serialPassthrough(serialPort_t *left, serialPort_t *right, serialConsumer
*leftC, serialConsumer *rightC)
{
waitForSerialPortToFinishTransmitting(left);
waitForSerialPortToFinishTransmitting(right);
if (!leftC)
leftC = &nopConsumer;
if (!rightC)
rightC = &nopConsumer;
LED0_OFF;
LED1_OFF;
// Either port might be open in a mode other than MODE_RXTX. We rely on
// serialRxBytesWaiting() to do the right thing for a TX only port. No
// special handling is necessary OR performed.
while(1) {
// TODO: maintain a timestamp of last data received. Use this to
// implement a guard interval and check for `+++` as an escape sequence
// to return to CLI command mode.
// https://en.wikipedia.org/wiki/Escape_sequence#Modem_control
if (serialRxBytesWaiting(left)) {
LED0_ON;
uint8_t c = serialRead(left);
serialWrite(right, c);
leftC(c);
LED0_OFF;
}
if (serialRxBytesWaiting(right)) {
LED0_ON;
uint8_t c = serialRead(right);
serialWrite(left, c);
rightC(c);
LED0_OFF;
}
}
}
示例8: gpsEnablePassthrough
void gpsEnablePassthrough(serialPort_t *gpsPassthroughPort)
{
waitForSerialPortToFinishTransmitting(gpsPort);
waitForSerialPortToFinishTransmitting(gpsPassthroughPort);
if(!(gpsPort->mode & MODE_TX))
serialSetMode(gpsPort, gpsPort->mode | MODE_TX);
LED0_OFF;
LED1_OFF;
#ifdef DISPLAY
if (feature(FEATURE_DISPLAY)) {
displayShowFixedPage(PAGE_GPS);
}
#endif
char c;
while(1) {
if (serialRxBytesWaiting(gpsPort)) {
LED0_ON;
c = serialRead(gpsPort);
gpsNewData(c);
serialWrite(gpsPassthroughPort, c);
LED0_OFF;
}
if (serialRxBytesWaiting(gpsPassthroughPort)) {
LED1_ON;
c = serialRead(gpsPassthroughPort);
serialWrite(gpsPort, c);
LED1_OFF;
}
#ifdef DISPLAY
if (feature(FEATURE_DISPLAY)) {
updateDisplay();
}
#endif
}
}
示例9: serialFlush
/* getCellInfo() - gets the information from the cell where the module is connected
*
* This function gets the information from the cell where the module is connected
*
* It stores in 'RSSI' and 'cellID' variables the information from the cell
*
* It modifies 'flag' if expected answer is not received after sending a command to GPRS module
*
* Returns '1' on success and '0' if error
*/
uint8_t WaspGPRS::getCellInfo()
{
char command[30];
uint8_t byteIN[200];
long previous=millis();
uint8_t counter=0;
uint8_t a,b,c=0;
serialFlush(PORT_USED);
sprintf(command,"AT%s\r\n",AT_GPRS_CELLID);
printString(command,PORT_USED);
while( (!serialAvailable(PORT_USED)) && ((millis()-previous)<3000) );
previous=millis();
a=0;
while( (millis()-previous) < 2000 )
{
while( serialAvailable(PORT_USED) && (millis()-previous) < 2000 && (a<200) )
{
byteIN[a]=serialRead(PORT_USED);
a++;
}
}
a=0;
while( counter < 5 )
{
while( (byteIN[a]!=',') && (a<200) )
{
a++;
}
a++;
counter++;
}
if(a>=200) return 0;
counter=0;
while( (byteIN[a]!=',') && (a<200) )
{
cellID[c]=byteIN[a];
a++;
c++;
}
a++;
while( (byteIN[a]!=',') && (a<200) )
{
RSSI[b]=byteIN[a];
delay(10);
b++;
a++;
}
return 1;
}
示例10: serialWrite
uint16_t Arduino::command(uint8_t nid, uint8_t cmd, uint8_t pin, uint8_t val) {
// Send.
// printf("Sending command\n");
serialWrite(MESSAGE_HEADER);
serialWrite(nid);
serialWrite(cmd);
serialWrite(pin);
serialWrite(val);
usleep(100); // let it time to reply
// Receive.
char rd = serialRead();
if (rd != MESSAGE_HEADER) {
printf("Error: wrong message header received from node %d: '%c'\n", nid, rd);
exit(-1);
}
uint8_t h = serialRead();
uint8_t l = serialRead();
// Return received value.
return (uint16_t) ( (h << 8) | l );
}
示例11: hottCheckSerialData
static void hottCheckSerialData(uint32_t currentMicros)
{
static bool lookingForRequest = true;
uint8_t bytesWaiting = serialTotalBytesWaiting(hottPort);
if (bytesWaiting <= 1) {
return;
}
if (bytesWaiting != 2) {
flushHottRxBuffer();
lookingForRequest = true;
return;
}
if (lookingForRequest) {
lastHoTTRequestCheckAt = currentMicros;
lookingForRequest = false;
return;
} else {
bool enoughTimePassed = currentMicros - lastHoTTRequestCheckAt >= HOTT_RX_SCHEDULE;
if (!enoughTimePassed) {
return;
}
lookingForRequest = true;
}
uint8_t requestId = serialRead(hottPort);
uint8_t address = serialRead(hottPort);
if ((requestId == 0) || (requestId == HOTT_BINARY_MODE_REQUEST_ID) || (address == HOTT_TELEMETRY_NO_SENSOR_ID)) {
processBinaryModeRequest(address);
}
}
示例12: beginLed
/**
* Send a file over the serial port.
* @param file file to send
*/
int Xmodem::send(File* file) {
_file = file;
_packetNumber = 1;
beginLed();
while (true) {
int c = serialRead();
if (c != -1) {
resetTimer();
break;
}
delay(100);
}
int status = 0;
while (true) {
size_t bytesRead = readPacket();
resetTimer();
if (bytesRead > 0) {
status = sendPacket();
if (_packetNumber % 20 == 0) {
toggleLed();
}
if (status < 0) {
break;
}
}
if (bytesRead < PACKET_SIZE) {
break;
}
}
serialWrite(EOT);
while (serialRead() == -1);
endLed();
return status;
}
示例13: sp_process
void sp_process()
{
char c;
while((c = serialRead()) != -1)
{
if((char_counter > 0) && ((c == '\n') || (c == '\r'))) { // Line is complete. Then execute!
line[char_counter] = 0; // treminate string
status_message(gc_execute_line(line));
char_counter = 0; // reset line buffer index
} else if (c <= ' ') { // Throw away whitepace and control characters
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
line[char_counter++] = c-'a'+'A';
} else {
line[char_counter++] = c;
}
}
}
示例14: gpsReceiveData
static bool gpsReceiveData(void)
{
bool hasNewData = false;
if (gpsState.gpsPort) {
while (serialRxBytesWaiting(gpsState.gpsPort)) {
uint8_t newChar = serialRead(gpsState.gpsPort);
if (gpsNewFrameNMEA(newChar)) {
gpsSol.flags.gpsHeartbeat = !gpsSol.flags.gpsHeartbeat;
gpsSol.flags.validVelNE = 0;
gpsSol.flags.validVelD = 0;
hasNewData = true;
}
}
}
return hasNewData;
}
示例15: gpsThread
void gpsThread(void)
{
// read out available GPS bytes
if (gpsPort) {
while (serialRxBytesWaiting(gpsPort))
gpsNewData(serialRead(gpsPort));
}
switch (gpsData.state) {
case GPS_UNKNOWN:
break;
case GPS_INITIALIZING:
case GPS_CHANGE_BAUD:
case GPS_CONFIGURE:
gpsInitHardware();
break;
case GPS_LOST_COMMUNICATION:
gpsData.timeouts++;
if (gpsConfig()->autoBaud) {
// try another rate
gpsData.baudrateIndex++;
gpsData.baudrateIndex %= GPS_INIT_ENTRIES;
}
gpsData.lastMessage = millis();
// TODO - move some / all of these into gpsData
GPS_numSat = 0;
DISABLE_STATE(GPS_FIX);
gpsSetState(GPS_INITIALIZING);
break;
case GPS_RECEIVING_DATA:
// check for no data/gps timeout/cable disconnection etc
if (millis() - gpsData.lastMessage > GPS_TIMEOUT) {
// remove GPS from capability
sensorsClear(SENSOR_GPS);
gpsSetState(GPS_LOST_COMMUNICATION);
}
break;
}
}