Changeset 258 in xtideuniversalbios for trunk/Serial_Server/win32/Win32Serial.h


Ignore:
Timestamp:
Feb 22, 2012, 7:01:53 PM (12 years ago)
Author:
gregli@…
google:author:
gregli@hotmail.com
Message:

Added floppy drive emulation over the serial connection (MODULE_SERIAL_FLOPPY). Along the way, various optimizations were made to stay within the 8K ROM size target. Also, serial code now returns the number of sectors transferred.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Serial_Server/win32/Win32Serial.h

    r233 r258  
    3535        }
    3636
    37         if( !strcmp( name, "PIPE" ) )
     37        if( name[0] == '\\' && name[1] == '\\' )
    3838        {
    39             log( 0, "Opening named pipe %s (simulating %s baud)", PIPENAME, baudRate->display );
     39            log( 0, "Opening named pipe %s (simulating %s baud)", name, baudRate->display );
    4040       
    41             pipe = CreateNamedPipeA( PIPENAME, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE|PIPE_REJECT_REMOTE_CLIENTS, 2, 1024, 1024, 0, NULL );
     41            pipe = CreateNamedPipeA( name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE|PIPE_REJECT_REMOTE_CLIENTS, 2, 1024, 1024, 0, NULL );
    4242            if( pipe == INVALID_HANDLE_VALUE )
    4343                log( -1, "Could not CreateNamedPipe " PIPENAME );
     
    5959                DCB dcb;
    6060
    61                 log( 0, "Opening %s (%lu baud)", name, baudRate->rate );
     61                log( 0, "Opening %s (%s baud)", name, baudRate->display );
    6262           
    6363                pipe = CreateFileA( name, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
     
    7474                dcb.Parity = NOPARITY;
    7575                if( !SetCommState( pipe, &dcb ) )
    76                     log( -1, "Could not SetCommState" );
     76                {
     77                    char *msg = "";
     78                    COMMPROP comProp;
     79
     80                    if( GetCommProperties( pipe, &comProp ) )
     81                    {
     82                        if( comProp.dwMaxBaud != BAUD_USER )
     83                            msg = "\n    On this COM port, baud rate is limited to 115.2K";
     84                    }
     85                    log( -1, "Could not SetCommState: baud rate selected may not be availabele%s", msg );
     86                }
    7787
    7888                if( !SetCommTimeouts( pipe, &timeouts ) )
     
    8292            {
    8393                char logbuff[ 1024 ];
    84                 int found = 0;
    8594
    86                 sprintf( logbuff, "serial port '%s' not found, detected COM ports:", name );
    87 
    88                 for( int t = 1; t <= 40; t++ )
    89                 {
    90                     sprintf( buff1, "COM%d", t );
    91                     if( QueryDosDeviceA( buff1, buff2, sizeof(buff2) ) )
    92                     {
    93                         strcat( logbuff, "\n    " );
    94                         strcat( logbuff, buff1 );
    95                         found = 1;
    96                     }
    97                 }
    98                 if( !found )
    99                     strcat( logbuff, "\n    (none)" );
     95                EnumerateCOMPorts( logbuff, 1024 );
    10096               
    101                 log( -1, logbuff );
     97                log( -1, "Serial port '%s' not found, detected COM ports: %s", name, logbuff );
    10298            }
    10399        }
     100    }
     101
     102    static void EnumerateCOMPorts( char *logbuff, int logbuffLen )
     103    {
     104        int found = 0;
     105        char buff1[20], buff2[1024];
     106
     107        logbuff[0] = 0;
     108
     109        for( int t = 1; t <= 40 && strlen(logbuff) < (logbuffLen - 40); t++ )
     110        {
     111            sprintf( buff1, "COM%d", t );
     112            if( QueryDosDeviceA( buff1, buff2, sizeof(buff2) ) )
     113            {
     114                if( found )
     115                    strcat( logbuff, ", " );
     116                strcat( logbuff, buff1 );
     117                found = 1;
     118            }
     119        }
     120
     121        if( !found )
     122            strcat( logbuff, "(none)" );
    104123    }
    105124
Note: See TracChangeset for help on using the changeset viewer.