メインページ | ネームスペース一覧 | クラス階層 | 構成 | Directories | ファイル一覧 | ネームスペースメンバ | 構成メンバ | ファイルメンバ | 関連ページ

DRIHCSh4.h

00001 #ifndef SPR_DRIHCSh4_H
00002 #define SPR_DRIHCSh4_H
00003 
00004 #ifdef _WIN32
00005  #error This program runs on SH4
00006 #endif
00007 
00008 
00009 #include <Base/Env.h>
00010 #include "DRRealDevice.h"
00011 #include "DVDaBase.h"
00012 #include "DVAdBase.h"
00013 #include "DVPioBase.h"
00014 #include "DVCounterBase.h"
00015 
00016 namespace Spr {
00017 
00018 /// DRIHCSh4.cpp: SH4上で動く,デバイスアクセスクラス
00019 class SPR_DLL DRIHCSh4 : public DRRealDevice{
00020 public:
00021     /// 仮想デバイス(DA)
00022     class VirtualDeviceDa:public DVDaBase{
00023     protected:
00024         DRIHCSh4* realDevice;
00025         int ch;
00026         char name[100];
00027     public:
00028         VirtualDeviceDa(DRIHCSh4* r, int c);
00029         virtual DRRealDevice* RealDevice() { return realDevice; }
00030         virtual void Voltage(float v){ realDevice->DaVoltage(ch, v); }
00031         virtual void Digit(int v){ realDevice->DaDigit(ch, v); }
00032         virtual const char* Name() const{ return name; }
00033     };
00034     /// 仮想デバイス(Counter)
00035     class VirtualDeviceCounter:public DVCounterBase{
00036     protected:
00037         DRIHCSh4* realDevice;
00038         int ch;
00039         char name[100];
00040     public:
00041         VirtualDeviceCounter(DRIHCSh4* r, int c);
00042         virtual DRRealDevice* RealDevice() { return realDevice; }
00043         /// カウンタ値の設定
00044         virtual void Count(long c){ realDevice->Count(ch, c); }
00045         /// カウンタ値の読み出し
00046         virtual long Count(){ return realDevice->Count(ch); }
00047         /// 名前
00048         virtual const char* Name() const{ return name; }
00049     };
00050     /// 仮想デバイス(Pio)
00051     class VirtualDevicePio:public DVPioBase{
00052     protected:
00053         DRIHCSh4* realDevice;
00054         int ch;
00055         char name[100];
00056     public:
00057         VirtualDevicePio(DRIHCSh4* r, int c);
00058         virtual DRRealDevice* RealDevice() { return realDevice; }
00059         virtual void Set(int l){ realDevice->Pio(ch, l!=0); }
00060         virtual int Get(){ return realDevice->Pio(ch) ? 1 : 0; }
00061         virtual const char* Name() const{ return name; }
00062     };
00063     /// 仮想デバイス(AD)
00064     class VirtualDeviceAd:public DVAdBase{
00065     protected:
00066         DRIHCSh4* realDevice;
00067         int ch;
00068         char name[100];
00069     public:
00070         VirtualDeviceAd(DRIHCSh4* r, int c);
00071         virtual DRRealDevice* RealDevice() { return realDevice; }
00072         virtual float Voltage(){ return realDevice->AdVoltage(ch); }
00073         virtual int Digit(){ return realDevice->AdDigit(ch); }
00074         virtual const char* Name() const{ return name; }
00075     };
00076 
00077 protected:
00078     char name[100];
00079     float adVoltPerDigit;
00080 
00081     long count[8];
00082     long countOffset[8];
00083     int daOut[8];
00084     int adIn[8];
00085     int pioLevel[16];
00086 
00087 public:
00088     DRIHCSh4();
00089     virtual ~DRIHCSh4();
00090     virtual const char* Name() const { return "IHCSh4"; }
00091     virtual bool Init();
00092     /// virtual device の登録
00093     virtual void Register(DVVirtualDevicePool& vpool);
00094 
00095     /// 電圧出力
00096     void DaVoltage(int ch, float v){
00097         assert(0 <= ch && ch < 8);
00098         const float DigitPerVolt[]={    //  DA指令値/出力電圧 アンプごとに異なるので計測値をアンプに書いておき,読み出す必要がある.
00099             415.0f,
00100             415.0f,
00101             415.0f,
00102             415.0f,
00103             415.0f,
00104             415.0f,
00105             415.0f,
00106             415.0f,
00107         };
00108         daOut[ch] = (int)(v * DigitPerVolt[ch]);
00109     }
00110     /// 電圧出力(数値指定)
00111     void DaDigit(int ch, int v){
00112         daOut[ch] = v;
00113     }
00114     /// カウンタ値の設定
00115     void Count(int ch, long c){
00116         countOffset[ch] = - (count[ch] - c); 
00117     }
00118     /// カウンタ値の読み出し
00119     long Count(int ch){
00120         return count[ch] + countOffset[ch];
00121     }
00122     /// PIOポートの設定
00123     void Pio(int ch, bool level){
00124         pioLevel[ch] = level ? 1 : 0;
00125     }
00126     /// PIOポートの読み出し
00127     bool Pio(int ch){
00128         return pioLevel[ch] == 1;
00129     }
00130     /// スイッチ(ポートの上位5-8ビット)の読み出し
00131     int RotarySwitch(){
00132         int sw=0;
00133         for(int i=0; i<4; ++i){
00134             sw |= pioLevel[i+4] << i;
00135         }
00136         return sw;
00137     }
00138     /// ADの電圧
00139     float AdVoltage(int ch){ return adIn[ch] * adVoltPerDigit; }
00140     /// ADの数値
00141     int AdDigit(int ch){ return adIn[ch]; }
00142 
00143     /// 状態の更新
00144     virtual void Update();
00145     void Read();
00146     void Write();
00147 };
00148 
00149 } //namespace Spr
00150 
00151 #endif // SPR_DRIHCSh4_H

Springheadに対してSun Apr 16 01:57:50 2006に生成されました。  doxygen 1.4.1