Changeset 219 in xtideuniversalbios for trunk/Serial_Server/library
- Timestamp:
- Jan 25, 2012, 7:04:43 AM (13 years ago)
- google:author:
- gregli@hotmail.com
- Location:
- trunk/Serial_Server/library
- Files:
-
- 1 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Serial_Server/library/FlatImage.h
r217 r219 6 6 // 7 7 8 #include <stdio.h>9 8 #include "library.h" 10 9 … … 12 11 { 13 12 private: 14 FILE *fp;13 class FileAccess fp; 15 14 16 15 public: 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; 19 19 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 } 24 72 }; 25 73 -
trunk/Serial_Server/library/Image.cpp
r217 r219 10 10 #include <stdlib.h> 11 11 #include <string.h> 12 #include <stdio.h> 12 13 13 14 Image::Image( char *name, int p_readOnly, int p_drive ) … … 82 83 sizef = totallba/2048.0; 83 84 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 ); 87 88 } 88 89 -
trunk/Serial_Server/library/Library.h
r217 r219 9 9 #define LIBRARY_H_INCLUDED 10 10 11 #include "stdio.h" 11 void log( int level, char *message, ... ); 12 12 13 void log( int level, char *message, ... );14 13 unsigned long GetTime(void); 15 14 unsigned long GetTime_Timeout(void); … … 20 19 { 21 20 public: 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; 24 22 25 virtual intwriteSector( void *buff ) = 0;23 virtual void writeSector( void *buff ) = 0; 26 24 27 virtual intreadSector( void *buff ) = 0;25 virtual void readSector( void *buff ) = 0; 28 26 29 27 Image( char *name, int p_readOnly, int p_drive ); … … 57 55 struct baudRate *baudRateMatchDivisor( unsigned char divisor ); 58 56 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 63 62 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 65 68 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 69 void processRequests( SerialAccess *serial, Image *image0, Image *image1, int timeoutEnabled, int verboseLevel ); 87 70 88 71 #endif -
trunk/Serial_Server/library/Process.cpp
r217 r219 9 9 #include <memory.h> 10 10 #include <string.h> 11 #include <stdio.h> 11 12 12 13 union _buff { … … 54 55 #define SERIAL_INQUIRE_PORTANDBAUD_PORTTRANSLATE( a ) ( ((a) & SERIAL_INQUIRE_PORTANDBAUD_PORT) << 1 | SERIAL_INQUIRE_PORTANDBAUD_STARTINGPORT ) 55 56 57 #define ATA_COMMAND_LBA 0x40 58 #define ATA_COMMAND_HEADMASK 0xf 59 60 #define ATA_DriveAndHead_Drive 0x10 61 56 62 void logBuff( char *message, unsigned long buffoffset, unsigned long readto, int verboseLevel ) 57 63 { … … 75 81 } 76 82 77 void processRequests( Serial *serial, Image *image0, Image *image1, int timeoutEnabled, int verboseLevel )83 void processRequests( SerialAccess *serial, Image *image0, Image *image1, int timeoutEnabled, int verboseLevel ) 78 84 { 79 85 unsigned char workCommand; … … 204 210 // Echo back the CRC 205 211 // 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; 208 214 209 215 workOffset++; … … 340 346 buff.w[256] = checksum( &buff.w[0], 256 ); 341 347 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; 344 350 345 351 if( verboseLevel >= 3 )
Note:
See TracChangeset
for help on using the changeset viewer.