Changeset 219 in xtideuniversalbios for trunk/Serial_Server/library


Ignore:
Timestamp:
Jan 25, 2012, 7:04:43 AM (13 years ago)
Author:
gregli@…
google:author:
gregli@hotmail.com
Message:

Serial Server, more minor improvements, added support for larger than 2 GB disks under Win32

Location:
trunk/Serial_Server/library
Files:
1 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Serial_Server/library/FlatImage.h

    r217 r219  
    66//
    77
    8 #include <stdio.h>
    98#include "library.h"
    109
     
    1211{
    1312private:
    14     FILE *fp;
     13    class FileAccess fp;
    1514
    1615public:
    17     FlatImage( char *name, int p_readOnly, int p_drive, int create, unsigned long cyl, unsigned long head, unsigned long sect, int useCHS );
    18     ~FlatImage();
     16    FlatImage( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_cyl, unsigned long p_head, unsigned long p_sect, int p_useCHS )   :   Image( name, p_readOnly, p_drive, p_create, p_cyl, p_head, p_sect, p_useCHS )
     17    {
     18        long filesize;
    1919
    20     int seekSector( unsigned long cyl, unsigned long sect, unsigned long head );
    21     int seekSector( unsigned long lba );
    22     int writeSector( void *buff );
    23     int readSector( void *buff );
     20        if( p_create )
     21        {
     22            char buff[512];
     23            unsigned long size;
     24            double sizef;
     25            FileAccess cf;
     26
     27            size = (unsigned long) p_cyl * (unsigned long) p_sect * (unsigned long) p_head;
     28            if( size > cf.MaxSectors )
     29                log( -1, "'%s', can't create flat file with size greater than %lu 512-byte sectors", name, cf.MaxSectors );
     30            sizef = size / 2048.0;   // 512 byte sectors -> MB
     31
     32            cf.Create( name );
     33
     34            memset( &buff[0], 0, 512 );
     35            while( size-- )
     36                cf.Write( &buff[0], 512 );
     37       
     38            if( p_cyl > 1024 )
     39                log( 0, "Created file '%s', size %.1lf MB", name, sizef );
     40            else
     41                log( 0, "Created file '%s', geometry %u:%u:%u, size %.1lf MB", name, p_cyl, p_sect, p_head, sizef );
     42
     43            cf.Close();
     44        }
     45
     46        fp.Open( name );
     47
     48        totallba = fp.SizeSectors();
     49
     50        init( name, p_readOnly, p_drive, p_cyl, p_head, p_sect, p_useCHS );
     51    }
     52
     53    FlatImage::~FlatImage()
     54    {
     55        fp.Close();
     56    }
     57
     58    void seekSector( unsigned long lba )
     59    {
     60        fp.SeekSectors( lba );
     61    }
     62
     63    void writeSector( void *buff )
     64    {
     65        fp.Write( buff, 512 );
     66    }
     67
     68    void readSector( void *buff )
     69    {
     70        fp.Read( buff, 512 );
     71    }
    2472};
    2573
  • trunk/Serial_Server/library/Image.cpp

    r217 r219  
    1010#include <stdlib.h>
    1111#include <string.h>
     12#include <stdio.h>
    1213
    1314Image::Image( char *name, int p_readOnly, int p_drive )
     
    8283    sizef = totallba/2048.0;
    8384    if( useCHS )
    84         log( 0, "Opening '%s', CHS geometry %u:%u:%u, total size %.1lf MB", name, cyl, sect, head, sizef );
    85     else
    86         log( 0, "Opening '%s', total lba %lu, total size %.1lf MB", name, totallba, sizef );
     85        log( 0, "Opening '%s', CHS geometry %u:%u:%u, total LBA %lu, total size %.1lf MB", name, cyl, sect, head, totallba, sizef );
     86    else
     87        log( 0, "Opening '%s', total LBA %lu, total size %.1lf MB", name, totallba, sizef );
    8788}
    8889
  • trunk/Serial_Server/library/Library.h

    r217 r219  
    99#define LIBRARY_H_INCLUDED
    1010
    11 #include "stdio.h"
     11void log( int level, char *message, ... );
    1212
    13 void log( int level, char *message, ... );
    1413unsigned long GetTime(void);
    1514unsigned long GetTime_Timeout(void);
     
    2019{
    2120public:
    22     virtual int seekSector( unsigned long cyl, unsigned long sect, unsigned long head ) = 0;
    23     virtual int seekSector( unsigned long lba ) = 0;
     21    virtual void seekSector( unsigned long lba ) = 0;
    2422
    25     virtual int writeSector( void *buff ) = 0;
     23    virtual void writeSector( void *buff ) = 0;
    2624   
    27     virtual int readSector( void *buff ) = 0;
     25    virtual void readSector( void *buff ) = 0;
    2826
    2927    Image( char *name, int p_readOnly, int p_drive );
     
    5755struct baudRate *baudRateMatchDivisor( unsigned char divisor );
    5856
    59 class Serial
    60 {
    61 public:
    62     virtual unsigned long readCharacters( void *buff, unsigned long len ) = 0;
     57#ifdef WIN32
     58#include "../win32/win32serial.h"
     59#else
     60// there is no standard way to read/write and configure the serial port, OS specifc only
     61#endif
    6362
    64     virtual unsigned long writeCharacters( void *buff, unsigned long len ) = 0;
     63#ifdef WIN32
     64#include "../win32/win32file.h"
     65#else
     66#include "file.h"
     67#endif
    6568
    66     Serial( char *name, struct baudRate *p_baudRate )
    67     {
    68         speedEmulation = 0;
    69         resetConnection = 0;
    70         baudRate = p_baudRate;
    71     };
    72 
    73     virtual ~Serial() {};
    74 
    75     int speedEmulation;
    76     int resetConnection;
    77 
    78     struct baudRate *baudRate;
    79 };
    80 
    81 void processRequests( Serial *serial, Image *image0, Image *image1, int timeoutEnabled, int verboseLevel );
    82 
    83 #define ATA_COMMAND_LBA 0x40
    84 #define ATA_COMMAND_HEADMASK 0xf
    85 
    86 #define ATA_DriveAndHead_Drive 0x10
     69void processRequests( SerialAccess *serial, Image *image0, Image *image1, int timeoutEnabled, int verboseLevel );
    8770
    8871#endif
  • trunk/Serial_Server/library/Process.cpp

    r217 r219  
    99#include <memory.h>
    1010#include <string.h>
     11#include <stdio.h>
    1112
    1213union _buff {
     
    5455#define SERIAL_INQUIRE_PORTANDBAUD_PORTTRANSLATE( a ) ( ((a) & SERIAL_INQUIRE_PORTANDBAUD_PORT) << 1 | SERIAL_INQUIRE_PORTANDBAUD_STARTINGPORT )
    5556
     57#define ATA_COMMAND_LBA 0x40
     58#define ATA_COMMAND_HEADMASK 0xf
     59
     60#define ATA_DriveAndHead_Drive 0x10
     61
    5662void logBuff( char *message, unsigned long buffoffset, unsigned long readto, int verboseLevel )
    5763{
     
    7581}
    7682
    77 void processRequests( Serial *serial, Image *image0, Image *image1, int timeoutEnabled, int verboseLevel )
     83void processRequests( SerialAccess *serial, Image *image0, Image *image1, int timeoutEnabled, int verboseLevel )
    7884{
    7985    unsigned char workCommand;
     
    204210            // Echo back the CRC
    205211            //
    206             if( serial->writeCharacters( &buff.w[256], 2 ) != 2 )
    207                 log( 0, "Serial Port Write Error" );
     212            if( !serial->writeCharacters( &buff.w[256], 2 ) )
     213                break;
    208214
    209215            workOffset++;
     
    340346                buff.w[256] = checksum( &buff.w[0], 256 );
    341347
    342                 if( serial->writeCharacters( &buff.w[0], 514 ) != 514 )
    343                     log( 0, "Serial Port Write Error" );
     348                if( !serial->writeCharacters( &buff.w[0], 514 ) )
     349                    break;
    344350
    345351                if( verboseLevel >= 3 )
Note: See TracChangeset for help on using the changeset viewer.