00001 #ifndef __J2K__Train__Train_CPP__
00002 #define __J2K__Train__Train_CPP__
00003
00004 Train::Train()
00005 {
00006 TrainID = 1;
00007 SetTrainID( TrainID );
00008 Velocity = 0;
00009 Direction = CW;
00010 }
00011
00012 void Train::setOutput(int OutP)
00013 {
00014 Output = OutP;
00015 }
00016
00017 void Train::setTrainID(int ID)
00018 {
00019 TrainID = ID;
00020 }
00021
00022 int Train::getTrainID()
00023 {
00024 return TrainID;
00025 }
00026
00027 int Train::getDirection()
00028 {
00029 return Direction;
00030 }
00031
00032 void Train::setPosition(int X)
00033 {
00034 Position = X;
00035 }
00036
00037 int Train::getPosition()
00038 {
00039 return Position;
00040 }
00041
00042 void Train::setVelocity(int V)
00043 {
00044 int Output;
00045 Velocity = V;
00046
00047 int START = 96;
00048 int STOP = 97;
00049 int REVERSE = 15;
00050 int change = 0;
00051
00052 if ( Velocity >= 0 && Direction == CCW ) {
00053 Direction = CW;
00054 change = 1;
00055
00056 } else if ( Velocity < 0 && Direction == CW ) {
00057 Direction = CCW;
00058 change = 1;
00059 }
00060
00061 Output = open( ELAN104_SERIAL, O_RDWR );
00062 write( Output, &START, 1 );
00063 delay(250);
00064
00065 if (change == 1) {
00066 write(Output, &REVERSE,1);
00067 delay(250);
00068 write(Output,&TrainID,1);
00069 delay(250);
00070 }
00071
00072 change = 0;
00073 write(Output,&Velocity,1);
00074 delay(250);
00075 write(Output,&TrainID,1);
00076 delay(250);
00077
00078 close(Output);
00079 }
00080
00081 int Train::getVelocity()
00082 {
00083 return Velocity;
00084 }
00085
00086 void Train::setBufferZone(int B)
00087 {
00088 BufferZone = B;
00089 }
00090
00091 int Train::getBufferZone()
00092 {
00093 return BufferZone;
00094 }
00095
00096 #endif