Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Deprecated/old_18mar_diff/nto/TrainDef.cpp

Go to the documentation of this file.
00001 #ifndef __TrainDef_CPP__
00002 #define __TrainDef_CPP__
00003 
00004 #include "TrainDef.hpp"
00005 
00006 void KickStart()
00007 {
00008  USHORT CV  = 65;
00009  UCHAR  val =  1;
00010  
00011  // Send
00012 }
00013 
00014 void ForwardTrim() 
00015 {
00016  USHORT CV  =  66;
00017  UCHAR  val = 128;
00018  
00019  // Send
00020 }
00021 
00022 void ReverseTrim() 
00023 {
00024  USHORT CV  =  80;
00025  UCHAR  val = 128;
00026  
00027  // Send
00028 }
00029 
00030 
00031 static char SpeedTable[ 28 ] = {
00032   10,
00033   14,
00034   18,
00035   22,
00036   24,
00037   28, 
00038   32, 
00039   36,
00040   40,
00041   44,
00042   50,
00043   54,
00044   60,
00045   64,
00046   70,
00047   76,
00048   82,
00049   90,
00050   96,
00051  106,
00052  114,
00053  126,
00054  136,
00055  148,
00056  162,
00057  178,
00058  198,
00059  212
00060 };
00061 
00062 
00063 // Taken from page 134.
00064 void SetSpeed( UCHAR step )
00065 {
00066  assert ( step >= 1 && step <= 28 );
00067 
00068  register UCHAR s = step;
00069 
00070  USHORT CV  = 66 + step;
00071  UCHAR  val = SpeedTable[ step ];
00072  
00073  // Send
00074 }
00075 
00076 // Given the Pulse Rate in Seconds
00077 // provide the CV value as a UCHAR
00078 // given in the table, page 107.
00079 
00080 UCHAR PulseRate_to_CV_value( double rate ) 
00081 {
00082   register UCHAR  val = 0;
00083   register double r = rate;
00084 
00085   if ( r <= PULSE_CONSTANT ) { r = PULSE_CONSTANT; }
00086   if ( r >= PULSE_MAX      ) { r = PULSE_MAX;      }
00087   
00088   r = ceil( r * 10 );
00089 
00090   val = (UCHAR)r;
00091 
00092   return val;
00093 }
00094 
00095 
00096 // Given the Flash Rate in Seconds
00097 // provide the CV value as a UCHAR
00098 // given in the table, page 108.
00099 
00100 UCHAR FlashRate_to_CV_value( double flash )
00101 {
00102   register UCHAR  val = 0;
00103   register double f = flash;
00104 
00105   if ( f <= FLASH_MIN  ) 
00106   { 
00107     f = FLASH_MIN;  
00108   }
00109 
00110 
00111   if ( f >  FLASH_MAX1 ) 
00112   { 
00113     f   = FLASH_MAX2; 
00114     val = FLASH_OFFSET;
00115     return val; 
00116   }
00117   
00118   f = ceil( f * 10 );
00119 
00120   val = (UCHAR)f + FLASH_OFFSET;
00121  
00122   return val;
00123 }
00124 
00125 typedef struct _abcd_output_addr 
00126 {
00127   USHORT decoder;
00128   UCHAR  lsb;  // LSB CV 513
00129   UCHAR  msb;  // MSB CV 521
00130 
00131   USHORT a;
00132   USHORT b;
00133   USHORT c;
00134   USHORT d;
00135 
00136 } abcd_output_addr_t;
00137 
00138 
00139 // Given the decoder number, this function will provide
00140 // the ABCD addresses and the MSB/LSB for CV 521 and CV 513
00141 // respectively, taken from tables pp. 109-113.
00142 
00143 
00144 // decoderNo = 511 is special, since it will broadcast value
00145 // to the selected output (A/D) that will change ALL cards connected.
00146 
00147 // 256, 128 64 32 16, 8 4 2 1
00148 
00149 abcd_output_addr_t DecoderCard_to_ABCD_addresses( USHORT decoderNo )
00150 {
00151   abcd_output_addr_t addr;
00152   memset( &addr, 0, sizeof( abcd_output_addr_t ) );
00153 
00154   register USHORT d = decoderNo;
00155 
00156   assert( d > 0   );
00157   assert( d < 512 );
00158 
00159   addr.decoder = d;
00160 
00161   addr.lsb = d & 0x3F;
00162   addr.msb = (d >> 6) & 0x07;
00163 
00164   d--;
00165   d = ( d * 4 ) + 1;
00166   addr.a   = d; d++;
00167   addr.b   = d; d++;
00168   addr.c   = d; d++;
00169   addr.d   = d;
00170 
00171   return addr;
00172 }
00173 
00174 void DisplayMemory( UCHAR line, USHORT memory )
00175 {
00176   // assert( line >= 0 );
00177   assert( line < 16 );
00178 
00179   char buf[ 10 ];
00180   memset( buf, 0, 10 );
00181 
00182   sprintf( buf, "F %01X %04X", line, memory );
00183   printf( "[%s]\n", buf );  
00184 
00185 
00186   // Send....
00187 }
00188 
00189 void testDisplayMemory()
00190 {
00191   for( int i = 0; i < 16; i++ )
00192     for( int j = 0x01; j < 0xffff; )
00193     {
00194    DisplayMemory( i, j );
00195    j = (j << 1) | 1;
00196     }
00197 }
00198 
00199 void KillMainTrack()
00200 {
00201   char buf[2] = { 'K', '0' };
00202 
00203   // Send...
00204 }
00205 
00206 void EnableMainTrack()
00207 {
00208   char buf[2] = { 'E', '0' };
00209 
00210   // Send...
00211 }
00212 
00213 void DisplayVersionNumber()
00214 {
00215   char buf[2] = { 'V', '0' };
00216 
00217   // Send...
00218 }
00219 
00220 void QueuePakcet()
00221 {
00222    char buf[160];
00223    memset( buf, 0, 160 );
00224 
00225    sprintf( buf, "Q %02X %02X %02X ... ", ... );
00226    
00227 }
00228 
00229 
00230 
00231 #endif

Generated on Sun Oct 14 18:46:26 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001