// Read a packet from the serial port static void read_request_packet() { u16 temp16; u32 readbytes; while( 1 ) { // First read the length if( ( readbytes = ser_read( ser, rfs_buffer, RFS_START_OFFSET ) ) != RFS_START_OFFSET ) { log_msg( "read_request_packet: ERROR reading packet length. Requested %d bytes, got %d bytes\n", RFS_START_OFFSET, readbytes ); flush_serial(); continue; } if( remotefs_get_packet_size( rfs_buffer, &temp16 ) == REMOTEFS_ERR ) { log_msg( "read_request_packet: ERROR getting packet size.\n" ); flush_serial(); continue; } // Then the rest of the data if( ( readbytes = ser_read( ser, rfs_buffer + RFS_START_OFFSET, temp16 - RFS_START_OFFSET ) ) != temp16 - RFS_START_OFFSET ) { log_msg( "read_request_packet: ERROR reading full packet, got %u bytes, expected %u bytes\n", ( unsigned )readbytes, ( unsigned )temp16 - RFS_START_OFFSET ); flush_serial(); continue; } else break; } }
// Read a single byte and return it (or -1 for error) int ser_read_byte( int id ) { u8 data; int res = ser_read( id, &data, 1 ); return res == 1 ? data : -1; }
// Read & Write to Transport void transport_read_buffer (Transport *tpt, u8 *buffer, int length) { u32 n; struct exception e; TRANSPORT_VERIFY_OPEN; while( length > 0 ) { TRANSPORT_VERIFY_OPEN; n = ser_read( tpt->fd, buffer, length ); // error handling if( n == 0 ) { e.errnum = ERR_NODATA; e.type = nonfatal; Throw( e ); } if( n < 0 ) { e.errnum = transport_errno; e.type = fatal; Throw( e ); } buffer += n; length -= n; } }
//call from main loop for processing data received from other if short st_loop(void) { unsigned char type=0; if(st_path) //both external_ST and run_as_ST modes { st_len=ser_read(st_buf); //get exactly 36 bytes of data from serial if(!st_len) return 0; //no data receiced from serial if(st_path>0) //external_ST mode { type=st_buf[0]&TYPE_MASK; //check data type switch(type) { //ST cannot output any data to TR!!! case TYPE_UI:{ui_send_to_ui(st_buf, st_len);break;} //data will be passed to UI case TYPE_CR:{cr_send_to_cr(st_buf, st_len);} //data will be passed to CR } st_len=0; //clear len return 1; //return job } } //for normal mode and _run_as_storage mode if(st_len) //check we have data from other if { type=st_buf[0]&TYPE_MASK; //check destination switch(type) { //UI cannot transpass any data to other if!!! case TYPE_ST:{st_process(st_buf, st_len);break;} //data for Cryptor from UI and ST } st_len=0; //clear data length (data was processed0 type=1; //set job flag } return (short)type; //return job flag }
// Read a single byte and return it (or -1 for error) int ser_read_byte( ser_handler id, u32 timeout ) { u8 data; int res = ser_read( id, &data, 1, timeout ); return res == 1 ? data : -1; }
// Read a single byte and return it (or -1 for error) int ser_read_byte( ser_handler id ) { uint8_t data; int res = ser_read( id, &data, 1 ); return res == 1 ? data : -1; }
// Read a single byte and return it (or -1 for error) int ser_read_byte( ser_handler id ) { u8 data; int res = ser_read( id, &data, 1 ); //printf( "READ %02X, res is %d\n", data, res ); return res == 1 ? data : -1; }
int timeout_get_char(int port) { long end_time; /* Calc timeout - 1/2 sec */ Errcode err; char c; if (ser_read(port, &c, 1) == 1) /* Fast return for ready char */ return(c); end_time = pj_clock_1000() + 500; /* else set up 1/2 second time-out */ for (;;) { if (ser_read(port, &c, 1) == 1) return(c); else { if ((err = ser_status(port)) < 0) return(err); /* Line dropped or something */ if (pj_clock_1000() > end_time) return(Err_timeout); } } }
static void flush_read(SHORT port) /* Read any pending characters and throw 'em out. */ { int err; char c; for (;;) { err = ser_status(port); if (err <= Success && err != Err_overflow) break; if (ser_read(port, &c, 1) != 1) break; } }
static int parport_read(void) { int data = 0; //printf("parport_read\n"); ser_send(0xFF); data=ser_read(); if ((data ^ cable->INPUT_INVERT) & cable->TDO_MASK) return 1; else return 0; }
// Read a single byte and return it (or -1 for error) int ser_read_byte( ser_handler id, u32 timeout ) { u8 data; return ser_read( id, &data, 1, timeout ) == 1 ? data : -1; }
static u32 transport_ser_recv( u8 *p, u32 size ) { TRANSPORT_SER *pser = ( TRANSPORT_SER* )transport_data; return ser_read( pser->fd, p, size, SER_INF_TIMEOUT ); }