int Handshake( void ) { char test_char; int i; int master = 0; for( i = 0; i < 100; i++ ) /* Flush the buffer */ Serial_Read( &test_char ); delay( 1000 ); if( Serial_Read( &test_char ) == -1 ) { /* printf("We are the master \n"); */ master = 1; while( Serial_Read( &test_char ) == -1 ) { if( Jon_Kbhit() ) /* If user hits escape return error */ { if( Jon_Getkey() == INDEX_ESC ) return -1; } Serial_Write( '1' ); delay( 500 ); } for( i = 0; i < 100; i++ ) /* Flush the buffer */ { delay(1); Serial_Read( &test_char ); } delay( 500 ); } else { /* printf("We are the slave \n"); */ Serial_Write( '2' ); for( i = 0; i < 100; i++ ) /* Flush the buffer */ { delay(1); Serial_Read( &test_char ); } } return master; } /* End of Handshake() */
// Set the index LED, property with the value int SerialOsc_BlobPropertySet( int property, uchar* blob, int length ) { switch ( property ) { case 0: Serial_Write( blob, length, 100 ); break; } return CONTROLLER_OK; }
// TODO restrict ptr, stream static size_t fwrite_serial(const void *ptr, size_t size, size_t nitems, FILE *stream) { // tx buffer is 256 bytes, don't get stuck waiting if (size > 256 || serial_ensureopen()) { IOERR(stream, EIO); return 0; } // Transmit size_t remain = nitems; while (remain > 0) { if (Serial_PollTX() > size) { Serial_Write(ptr, size); remain--; } else { // Wait for space in tx buffer // TODO sleep for an interrupt or something } } return nitems - remain; }