Changeset 909 for trunk


Ignore:
Timestamp:
08/15/01 12:39:04 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/.cosyrc

    r808 r909  
    22# -85.0 , +310.0
    33#
    4 MinAz[Deg]:   -30.0
    5 MaxAz[Deg]:  +375.0
     4Az_MaxTime2ReachHome[s]: 100
     5Az_Min[Deg]:   -30.0
     6Az_Max[Deg]:  +375.0
    67
    78#
    89#
    910#
    10 MinZd[Deg]:   -70.0
    11 MaxZd[Deg]:   +70.0
     11Zd_MaxTime2ReachHome[s]: 100
     12Zd_Min[Deg]:   -70.0
     13Zd_Max[Deg]:   +70.0
  • trunk/MagicSoft/Cosy/MCosy.cc

    r808 r909  
    1414
    1515#include "macs.h"
    16 #include "timer.h"
     16#include "base/timer.h"
    1717#include "shaftencoder.h"
    1818
    19 #include <sys/resource.h>  // PRIO_PROCESS
     19#include "MGSkyPosition.h" // FIXME!!!!!!!!!!!!!!!!!
     20
     21//#include <sys/resource.h>  // PRIO_PROCESS
    2022
    2123typedef struct tm tm_t;
     
    121123        min = dist;
    122124    }
    123     cout << "Shortest Zd: " << ret.Zd() << "  Az:" << ret.Az() << endl;
    124125    return ret*(16384.0/360.0);
    125126}
     
    347348        {
    348349            lout << "Error 6004 happened" << endl;
    349             SkipPendingSdos();
    350350            break;
    351351        }
     
    393393        {
    394394            lout << "Error 3006 happened" << endl;
    395             SkipPendingSdos();
    396395            break;
    397396        }
     
    525524}
    526525
     526void *MTGui::Thread()
     527{
     528    fCosy->GuiThread(this);
     529    return NULL;
     530}
     531
     532void *MTTalk::Thread()
     533{
     534    fCosy->TalkThread();
     535    return NULL;
     536}
     537
    527538void MCosy::TalkThread()
    528539{
     
    530541    // Start the Network
    531542    //
    532     Network::Start();
     543    cout << "Reading configuration file..." << flush;
     544    TEnv env(".cosyrc");
     545    cout << "done." << endl;
    533546
    534547    const int res = fMac3->GetVelRes();
     
    538551    fMac3->SetDeceleration(res);
    539552
    540     fMac3->SetSyncMode();
    541 
    542     fMac1->SetHome(250000);
    543     fMac2->SetHome(250000);
     553    fMac3->StartPosSync();
     554
     555    cout << "Going Home..." << endl;
     556    fMac1->SetHome(250000, env.GetValue("Az_MaxTime2ReachHome[s]", 100));
     557    fMac2->SetHome(250000, env.GetValue("Zd_MaxTime2ReachHome[s]", 100));
    544558    PostMsg(WM_PRESET, 0, 0);
    545559    PostMsg(WM_WAIT,   0, 0);
     
    551565    cout << "APOS: " << repos.Zd() << "re, " << repos.Az() << "re" << endl;
    552566
    553     TEnv env(".cosyrc");
    554 
    555     cout << Deg2AzRE(env.GetValue("MinAz[Deg]", -1.0)) << " < Az < "
    556         << Deg2AzRE(env.GetValue("MaxAz[Deg]", +1.0)) << "RE" << endl;
    557     cout << env.GetValue("MinAz[Deg]", -1.0) << " < Az < "
    558         << env.GetValue("MaxAz[Deg]", +1.0) << kDEG << endl;
    559     cout << Deg2ZdRE(env.GetValue("MinZd[Deg]", -1.0)) << "RE < Zd < "
    560         << Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)) << "RE" << endl;
    561 
    562     fMac1->SetNegEndswitch(Deg2AzRE(env.GetValue("MinAz[Deg]", -1.0)));
    563     fMac1->SetPosEndswitch(Deg2AzRE(env.GetValue("MaxAz[Deg]", +1.0)));
     567    /*
     568     cout << Deg2AzRE(env.GetValue("MinAz[Deg]", -1.0)) << " < Az < "
     569     << Deg2AzRE(env.GetValue("MaxAz[Deg]", +1.0)) << "RE" << endl;
     570     cout << env.GetValue("MinAz[Deg]", -1.0) << " < Az < "
     571     << env.GetValue("MaxAz[Deg]", +1.0) << kDEG << endl;
     572     cout << Deg2ZdRE(env.GetValue("MinZd[Deg]", -1.0)) << "RE < Zd < "
     573     << Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)) << "RE" << endl;
     574     */
     575
     576    cout << "Setting up software endswitch..." << flush;
     577    fMac1->SetNegEndswitch(Deg2AzRE(env.GetValue("Az_Min[Deg]", -1.0)));
     578    fMac1->SetPosEndswitch(Deg2AzRE(env.GetValue("Az_Max[Deg]", +1.0)));
     579
     580    fMac2->SetNegEndswitch(Deg2ZdRE(env.GetValue("Zd_Min[Deg]", -1.0)));
     581    fMac2->SetPosEndswitch(Deg2ZdRE(env.GetValue("Zd_Max[Deg]", +1.0)));
     582    cout << "done." << endl;
    564583
    565584/*
     
    567586    fMac2->SetPosEndswitch(Deg2ZdRE(env.GetValue("MaxZd[Deg]", +1.0)));
    568587*/
    569     fMac3->SetSyncMode();
     588//    fMac3->StartVelSync();
    570589/*
    571590    cout << "PostMsg(WM_PRESET)" << endl;
     
    588607    // dest = AltAz(-46.0, 210);
    589608    // SetPosition(dest);
    590     setpriority(PRIO_PROCESS, 0, 10);
    591609
    592610    Slalib sla;
     
    675693}
    676694
    677 void *MCosy::MapTalkThread(void *arg)
    678 {
    679     pthread_detach(pthread_self());
    680 
    681     MCosy *cosy = (MCosy*)arg;
    682 
    683     cosy->TalkThread();
    684 
    685     cosy->lout << "- Sending Thread done." << endl;
    686 
    687     return NULL;
    688 }
    689 
    690 int MCosy::StopWaitingForSDO()
    691 {
    692     return Break() || fMac1->HasError() || fMac2->HasError();
     695void MCosy::GuiThread(MTGui *t)
     696{
     697    MGSkyPosition *disp = fWin->GetSkyDisplay();
     698    while (!t->HasStopFlag())
     699    {
     700        usleep(100000); // 0.1s
     701
     702        fAlt1->DisplayVal();
     703        fAlt2->DisplayVal();
     704        fAz->DisplayVal();
     705
     706        // gSystem->ProcessEvents();
     707
     708        ZdAz ist = GetSePos()*(360.0/16384.0); // [se]
     709        disp->DrawPosition(ist);
     710    }
     711    cout << "Not running anymore." << endl;
     712}
     713
     714int MCosy::StopWaitingForSDO() const
     715{
     716    return Break() || HasError(); //fMac1->HasError() || fMac2->HasError();
    693717}
    694718
    695719void MCosy::Start()
    696720{
    697     if (fTxThrd)
    698     {
    699         cout << "Error: tx thread already started." << endl;
    700         return;
    701     }
    702 
    703     lout << "- Starting sending Thread." << endl;
    704 
    705     fTxThrd = new pthread_t;
    706     pthread_create(fTxThrd, NULL, MapTalkThread, this);
     721    // Don't call this function twice!
     722    Network::Start();
     723
     724    lout << "- Starting TX Thread." << endl;
     725    fTTalk = new MTTalk(this);
     726
     727    lout << "- Starting GUI Thread." << endl;
     728    fTGui = new MTGui(this);
    707729}
    708730
    709731void MCosy::Stop()
    710732{
    711     if (!fTxThrd)
    712         return;
    713 
    714     pthread_cancel(*fTxThrd);
    715 
    716     delete fTxThrd;
    717     fTxThrd = NULL;
    718 
    719     lout << "- Sending Thread stopped." << endl;
    720 
    721     SkipPendingSdos();
     733    delete fTGui;
     734    lout << "- GUI Thread stopped." << endl;
     735
     736    delete fTTalk;
     737    lout << "- TX Thread stopped." << endl;
    722738
    723739    Network::Stop();
     
    725741
    726742MCosy::MCosy(const char *dev, const int baud, ostream &out)
    727 : Network(dev, baud, out), fTxThrd(NULL), fTracking(kFALSE)
     743: Network(dev, baud, out), fTracking(kFALSE)
    728744{
    729745    //
     
    747763    SetNode(fAz);
    748764
    749     MGCosy *fWin=new MGCosy(this, gClient->GetRoot(), 1, 1);
     765    fWin=new MGCosy(this, gClient->GetRoot(), 1, 1);
    750766
    751767    fAz->SetDisplay(fWin->GetLabel1());
     
    756772void MCosy::TerminateApp()
    757773{
    758    gSystem->ExitLoop();
     774    cout << "MCosy::TerminateApp()" << endl;
     775    gApplication->Terminate(0);
    759776}
    760777
    761778MCosy::~MCosy()
    762779{
     780    cout << "Deleting Nodes." << endl;
     781
    763782    delete fAz;
    764783    delete fAlt2;
     
    768787    delete fMac3;
    769788
     789    cout << "Deleting MGCosy." << endl;
     790
    770791    delete fWin;
    771 }
     792
     793    cout << "MGCosy deleted." << endl;
     794}
  • trunk/MagicSoft/Cosy/MCosy.h

    r808 r909  
    55#include "msgqueue.h"
    66#include "network.h"
     7#include "MThread.h"
    78
    89#define kDEG ((char)0xb0)  // Linux 'ø'
    910
     11#define WM_WAIT      WM_NULL
    1012#define WM_PRESET    0x1000
    1113#define WM_POSITION  0x1001
     
    1315#define WM_STOP      0x1003
    1416#define WM_POLARIS   0x1004
    15 #define WM_WAIT      0x1005
    1617
    1718class ShaftEncoder;
    1819class Macs;
    1920class MGCosy;
     21class MCosy;
     22
     23class MTGui : public MThread
     24{
     25private:
     26    MCosy *fCosy;
     27
     28    void *Thread();
     29
     30public:
     31    MTGui(MCosy *cosy) : MThread(false), fCosy(cosy)
     32    {
     33        SetPriority(20);
     34        Start();
     35    }
     36};
     37
     38class MTTalk : public MThread
     39{
     40private:
     41    MCosy *fCosy;
     42
     43    void *Thread();
     44
     45public:
     46    MTTalk(MCosy *cosy) : MThread(false), fCosy(cosy)
     47    {
     48        SetPriority(10);
     49        Detach();
     50        Start();
     51    }
     52};
    2053
    2154class MCosy : public Network, public MsgQueue
    2255{
     56    friend class MTGui;
     57    friend class MTTalk;
     58
    2359private:
    2460    ShaftEncoder *fAlt1;
     
    3268    MGCosy *fWin;
    3369
    34     pthread_t *fTxThrd;
     70    MTGui  *fTGui;
     71    MTTalk *fTTalk;
    3572
    3673    ZdAz  fOffset;    // Tracking Offset between SE and calc-pos [re]
     
    3875    int   fTracking;  // Flag for present tracking action
    3976
    40     static void *MapTalkThread(void *arg);
    41 
     77    ZdAz GetRePos();
    4278    ZdAz GetSePos();     // [se]
    43     ZdAz GetRePos();
    4479
    4580    void TalkThread();
     81    void GuiThread(MTGui *t);
     82
    4683    int  SetPosition(const ZdAz &dst);
    4784
     
    5087    void TrackPosition(const RaDec &dst); // ra, dec [rad]
    5188
    52     int StopWaitingForSDO();
     89    int StopWaitingForSDO() const;
    5390
    5491public:
     
    63100    static ZdAz CorrectTarget(const ZdAz &src, const ZdAz &dst);
    64101//    static ZdAz RaDec2ZdAz(const double mjd, const RaDec &pos, const RaDec &pm=RaDec(0,0));
     102
    65103};
    66104
  • trunk/MagicSoft/Cosy/Makefile

    r808 r909  
    1111
    1212#
    13 #  ----->>>   settings for compiler
     13#  please change all system depend values in the
     14#  config.mk.${OSTYPE} file
     15#
     16#
     17include Makefile.conf.$(OSTYPE)
     18include Makefile.conf.general
     19
    1420#
    1521
    16 CC     = gcc
    17 CXX    = g++
    18 AR     = ar -rc
    19 AS     = as
    20 LD     = ld
    21 RANLIB = ranlib
    22 
    23 #
    24 #  ----->>>   settings for compilation
    25 #
    26 
    27 PROGRAMS  = cosy starg
    28 
    29 ROOTFLAGS = `root-config --cflags`
    30 ROOTGLIBS = `root-config --glibs`
     22PROGRAMS = cosy starg
     23SOLIB    =
     24CINT     = M
     25INCLUDES = -I. -Iincl -Ibase -Igui -Idevdrv -Icandrv -Ivideodev -Icatalog
     26LIBS     = -lpng -lz -L/usr/X11R6/lib
    3127
    3228#
     
    3430#
    3531#    WARNING: the result (whether the linkage works or not) depends on the
    36 #             order of the libraries
     32#             order of the libraries. It seems, that the most base library
     33#             must be the last one
    3734#
    38 #
    39 #LIBS      = -L. -L/usr/lib -lstdc++ -lpthread
    40 INCLUDES  = -I. -I/usr/X11R6/include -Icandrv -Idevdrv -Ibase -Igui -Iincl -Islalib -Ivideodev -Icatalog
    41 LIBS      = -L. -L/usr/X11R6/lib -lpthread -lpng -lz
    42 #INCLUDES  = -I. -Ibase -Igui -Islalib
    43 
    44 WARNING   = -Wall -fno-rtti -fno-exceptions
    45 OPTIM     = -O2
    46 DEBUG     = -g
    47 DEFINES   = -DCPU=486 -DBUS_LITTLE_ENDIAN -DDEBUG=0 -DLINUX -DSHOW
    48 
    49 CFLAGS    = $(OPTIM) $(DEBUG) $(WARNING) $(INCLUDES) $(ROOTFLAGS) $(DEFINES)
    50 CXXFLAGS  = $(CFLAGS)
    51 
    52 CINT     = M
    5335
    5436#
    5537#  ----->>>   mars libraries
    5638#
     39SUBDIRS = \
     40        candrv      \
     41        catalog     \
     42        devdrv      \
     43        gui         \
     44        videodev    \
     45        base        \
     46        slalib
     47
     48LIBRARIES = $(SUBDIRS:=.a)
    5749
    5850#------------------------------------------------------------------------------
    59 .SILENT:
    6051
    6152.SUFFIXES: .c .cc .h .o
    6253
    63 SLASRC  = slalib/cldj.c   slalib/dranrm.c  slalib/mappa.c  slalib/aoppa.c \
    64           slalib/mapqk.c  slalib/aopqk.c   slalib/epj.c    slalib/evp.c   \
    65           slalib/dvn.c    slalib/prenut.c  slalib/geoc.c   slalib/refco.c \
    66           slalib/eqeqx.c  slalib/dcs2c.c   slalib/dvdv.c   slalib/dmxv.c  \
    67           slalib/dcc2s.c  slalib/refz.c    slalib/refro.c  slalib/prec.c  \
    68           slalib/nut.c    slalib/dmxm.c    slalib/nutc.c   slalib/range.c \
    69           slalib/aoppat.c slalib/deuler.c  slalib/drange.c slalib/daf2r.c \
    70           slalib/dh2e.c   slalib/gmst.c    slalib/de2h.c   slalib/altaz.c \
    71           slalib/gmsta.c  slalib/dat.c     slalib/dtt.c    slalib/oapqk.c \
    72           slalib/ampqk.c  slalib/dimxv.c   slalib/mapqkz.c slalib/dr2af.c \
    73           slalib/dd2tf.c
    74 
    75 SLAOBJ  = $(SLASRC:.c=.o)
    76 
    77 SRCFILES = candrv/vmodican.cc \
    78            candrv/canopen.cc \
    79            candrv/network.cc \
    80            candrv/nodedrv.cc \
    81            candrv/sdolist.cc \
    82            devdrv/shaftencoder.cc \
    83            devdrv/macs.cc \
    84            gui/MGCosy.cc \
    85            gui/MGImage.cc \
    86            gui/MGCoordinate.cc \
    87            gui/MGCoordinates.cc \
    88            base/timer.cc \
    89            base/msgqueue.cc \
    90            base/File.cc \
    91            base/MStopwatch.cc \
    92            catalog/SaoFile.cc \
    93            catalog/StarCatalog.cc \
    94            catalog/Slalib.cc \
    95            videodev/Camera.cc \
    96            videodev/Filter.cc \
    97            videodev/Writer.cc \
    98            MStarguider.cc \
    99            MCosy.cc \
    100            Starguider.cc
     54SRCFILES = MCosy.cc Starguider.cc
    10155
    10256SRCS    = $(SRCFILES)
     
    10660############################################################
    10761
    108 all: $(PROGRAMS)
     62all: rmlib $(PROGRAMS) $(SOLIB)
    10963
    110 $(SLAOBJ):
    111         echo 'Compiling $*.c'
    112         $(CC) -c $(CFLAGS) -pedantic $*.c -o $*.o
     64# Use $(CXX) -v ... for a more verbose output
     65#
     66# We could link mars.so instead of all libraries. This would need
     67# some MBs less space on the HD. But this means, that the Shared
     68# Library Path in your system must be set properly to be able to start
     69# 'mars'
     70#
     71$(PROGRAMS): $(LIBRARIES) $(OBJS) $(HEADERS) $(PROGRAMS:=.o)
     72        @echo " Linking $@ ..."
     73        $(CXX) $(CXXFLAGS) $(LIBS) $@.o $(OBJS) $(MARS_LIB) $(ROOTGLIBS) -o $@
    11374
    114 #$(PROGRAMS): $(PROGRAMS:=.o) $(OBJS) $(SLAOBJ)
    115 #       @echo " Linking $@ ..."
    116 #       $(CXX) $(CXXFLAGS) $@.o $(LIBS) $(ROOTGLIBS) -o $@
    117 $(PROGRAMS): $(SLAOBJ) $(OBJS) $(PROGRAMS:=.o)
    118         @echo " Linking $@ ..."
    119         $(CXX) $(CXXFLAGS) $(LIBS) $(SLAOBJ) $(OBJS) $(ROOTGLIBS) -o $@ $@.o
     75$(SOLIB): $(LIBRARIES) $(OBJS) $(HEADERS) MCint.o
     76        @echo " Linking $(SOLIB) ..."
     77        $(CXX) -shared $(CXXFLAGS) $(SUBDIRS:=/*.o) $(ROOTGLIBS) -o $@
     78        mv cosy.so lib
    12079
    121 #dox:
    122 #       @echo " Creating html documentation:"
    123 #       root -b -q dohtml.C
     80$(LIBRARIES):
     81        @echo " " 
     82        @echo " Creating lib$@:"
     83        (cd $*; make -f Makefile; cd ..; mv $*/$@ lib/lib$@)
    12484
     85dox:
     86        @echo " Creating html documentation:"
     87        root -b -q dohtml.C
    12588
    12689include Makefile.rules
    12790
    128 clean:  rmcint rmobjs rmcore rmbin rmbak
     91clean:  rmlib rmcint rmobjs rmcore rmbin
    12992
    130 tar:    clean
     93mrproper:       clean rmbak
     94        @rm -f macros/*~
     95        @rm -rf htmldoc
     96        @echo "cd base"
     97        @cd base; make mrproper; cd ..
     98        @echo "cd .."
     99        @echo "cd candrv"
     100        @cd candrv; make mrproper; cd ..
     101        @echo "cd .."
     102        @echo "cd devdrv"
     103        @cd devdrv; make mrproper; cd ..
     104        @echo "cd .."
     105        @echo "cd gui"
     106        @cd gui; make mrproper; cd ..
     107        @echo "cd .."
     108        @echo "cd videodev"
     109        @cd videodev; make mrproper; cd ..
     110        @echo "cd .."
     111        @echo "cd catalog"
     112        @cd videodev; make mrproper; cd ..
     113        @echo "cd .."
     114
     115tar:    mrproper
    131116        @echo "Making tar-file"
    132117        @tar -cvf ../cosy.tar *
  • trunk/MagicSoft/Cosy/Makefile.conf.linux-gnu

    r738 r909  
    88# @maintitle
    99
     10# @code
     11
    1012# compilers
    1113
    12 CC  = gcc
    13 CXX = g++
    14 F77 = f77
    15 AR  = ar -rc
     14CC            = gcc
     15CXX           = g++
     16F77           = f77
     17AR            = ar -rc
    1618#
    1719#  ----->>>   settings for compilation
    1820#
    1921
    20 OPTIM = -O2 -Wall -fno-rtti -fno-exceptions -fPIC
    21 DEBUG = -g
     22OPTIM    = -O2 -Wall -fno-rtti -fno-exceptions -fPIC -Wtraditional -Wpointer-arith -Wcast-align -Wwrite-strings -Wconversion -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Woverloaded-virtual
     23DEBUG    = -g
     24
     25MARS_LIB  = -Llib $(SUBDIRS:%=-l%)
     26INCLUDES  = -I. $(SUBDIRS:%=-I%)
    2227
    2328# uncomment this for quiet compilation
    2429
    25 #.SILENT:
     30.SILENT:
    2631
    2732# @endcode
  • trunk/MagicSoft/Cosy/Makefile.rules

    r738 r909  
    44        -f Makefile.depend 2> kk.kk ; cat kk.kk
    55
    6 $(LIB): $(OBJS) $(CINT)Cint.o
    7         @echo " - Building Library $(LIB) ... "
     6$(LIB): $(OBJS) $(HEADERS)
     7        @echo " - Building Library lib$(LIB) ... "
    88        $(AR) $(LIB) *.o
    99
     
    1313
    1414        $(ROOTSYS)/bin/rootcint -f $(CINT)Cint.cc \
    15         -c $(INCLUDES) $(HEADERS) $(CINT)Incl.h $(CINT)LinkDef.h
     15        -c $(INCLUDES) $(DEFINES) $(HEADERS) $(CINT)Incl.h $(CINT)LinkDef.h
    1616
    1717.cxx.o:
     
    3232rmcint:
    3333        @echo "Removing cint-stuff..."
    34         @rm -rf *Cint.*
     34        @rm -f *Cint.*
     35
     36rmlib: 
     37        @echo "Removing libraries..."
     38        @rm -f lib/lib*.a  lib*.a
    3539
    3640rmobjs:
    3741        @echo "Removing object files..."
    3842        @rm -f *.o
    39         @rm -f base/*.o
    40         @rm -f gui/*.o
    41         @rm -f candrv/*.o
    42         @rm -f devdrv/*.o
    43         @rm -f slalib/*.o
    4443
    4544rmcore:
    4645        @echo "Removing core files..."
    47         @rm -rf core*
     46        @rm -f core*
    4847
    4948rmbin: 
    5049        @echo "Removing binary files..."
    51         @rm -rf $(PROGRAMS) so_locations
     50        @rm -f $(PROGRAMS) so_locations
    5251
    5352rmbak:
    5453        @echo "Removing backup files..."
    55         @rm -f *~        kk.kk        *.bak
    56         @rm -f base/*~   base/kk.kk   base/*.bak
    57         @rm -f gui/*~    gui/kk.kk    gui/*.bak
    58         @rm -f candrv/*~ candrv/kk.kk candrv/*.bak
    59         @rm -f devdrv/*~ devdrv/kk.kk devdrv/*.bak
    60         @rm -f slalib/*~ slalib/kk.kk slalib/*.bak
     54        @rm -f *~ kk.kk *.bak
    6155
    6256cflags:
  • trunk/MagicSoft/Cosy/Starguider.cc

    r808 r909  
    1212#include "Filter.h"
    1313#include "Writer.h"
    14 #include "timer.h"
     14#include "base/timer.h"
    1515
    1616enum {
     
    293293}
    294294
    295 void Starguider::Execute(const unsigned long n, byte *img, struct timeval *tm)
     295void Starguider::ProcessFrame(const unsigned long n, byte *img, struct timeval *tm)
    296296{
    297297
  • trunk/MagicSoft/Cosy/Starguider.h

    r808 r909  
    6060    // Execution of one frame - this function may be overloaded!
    6161    //
    62     void Execute(const unsigned long n, byte *img, struct timeval *tm);
     62    void ProcessFrame(const unsigned long n, byte *img, struct timeval *tm);
    6363};
    6464
  • trunk/MagicSoft/Cosy/base/MGList.h

    r732 r909  
    11#ifndef MGLIST_H
    22#define MGLIST_H
     3
     4#include <iostream.h>
    35
    46#ifndef ROOT_TOrdCollection
     
    1113    ~MGList()
    1214    {
     15        cout << "Deleting:" << flush;
     16
    1317        TIter Next(this);
    1418
    1519        TObject *obj;
    1620        while ((obj=Next()))
     21        {
     22            cout << " <" << ((TGObject*)obj)->GetName() << ">" << flush;
    1723            delete (TGObject*)obj;
     24        }
     25        cout << endl;
    1826    }
    1927    void Add(TGObject *obj)
  • trunk/MagicSoft/Cosy/base/msgqueue.cc

    r732 r909  
    7373    //
    7474    // Set break state and wait until Proc() returned (break state deleted)
     75    // This means, that a new command is invoked and (if forseen) the
     76    // running command should stop execution.
     77    //
     78    // This is some kind of controlled user break without using signals
    7579    //
    7680    fBreak = 1;
  • trunk/MagicSoft/Cosy/base/msgqueue.h

    r732 r909  
    3232    virtual ~MsgQueue();
    3333
    34     int Break() { return fBreak; }
     34    int Break() const { return fBreak; }
    3535
    3636    virtual void *Proc(int msg, void *mp1);
  • trunk/MagicSoft/Cosy/candrv/canopen.cc

    r732 r909  
    223223}
    224224
    225 WORD_t CanOpen::CobId(BYTE_t node, BYTE_t fcode)
     225WORD_t CanOpen::CobId(BYTE_t node, BYTE_t fcode) const
    226226{
    227227    return (fcode<<7) | node&0x1f;
  • trunk/MagicSoft/Cosy/candrv/network.cc

    r808 r909  
    66void Network::Start()
    77{
    8     StartReceiver();
     8    lout << "- Starting network." << endl;
     9
     10    VmodIcan::Start();
    911    InitNodes();
     12
     13    lout << "- Network started." << endl;
    1014}
    1115
    1216void Network::Stop()
    1317{
     18    lout << "- Stopping network." << endl;
     19
    1420    StopNodes();
    15     StopReceiver();
     21    VmodIcan::Stop();
    1622
    1723    lout << "- Network stopped." << endl;
     
    166172}
    167173
    168 bool Network::HasError()
     174bool Network::HasError() const
    169175{
    170176    for (int i=0; i<32; i++)
  • trunk/MagicSoft/Cosy/candrv/network.h

    r808 r909  
    3131    virtual void Stop();
    3232
    33     bool HasError();
     33    bool HasError() const;
    3434};
    3535
  • trunk/MagicSoft/Cosy/candrv/nodedrv.cc

    r808 r909  
    116116}
    117117
    118 void NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx)
     118void NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORD_t timeout)
    119119{
    120     while (fNetwork->WaitingForSdo(fId, idx, subidx))
    121         usleep(1);
     120    fNetwork->WaitForSdo(fId, idx, subidx, timeout);
    122121}
    123122
     123/*
    124124void NodeDrv::WaitForSdos()
    125125{
     
    127127        usleep(1);
    128128}
     129*/
    129130
    130131void NodeDrv::WaitForNextPdo1()
  • trunk/MagicSoft/Cosy/candrv/nodedrv.h

    r808 r909  
    2929    virtual void StopDevice() = 0;
    3030
    31     bool HasError()        { return fError; }
     31    bool HasError()       { return fError; }
    3232
    3333    virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, struct timeval *tv);
     
    6464    void WaitForNextPdo4();
    6565
    66     void WaitForSdos();
    67     void WaitForSdo(WORD_t idx, BYTE_t subidx=0);
     66    // void WaitForSdos();
     67    void WaitForSdo(WORD_t idx, BYTE_t subidx=0, WORD_t timeout=500);
    6868
    6969    void EnableCanMsg(BYTE_t fcode);
  • trunk/MagicSoft/Cosy/candrv/sdolist.cc

    r732 r909  
    8686}
    8787
    88 int PendingSDOList::IsPending()
     88int PendingSDOList::IsPending() const
    8989{
    9090    return (int)fFirst->Next;
  • trunk/MagicSoft/Cosy/candrv/sdolist.h

    r732 r909  
    3434    void DelAll();
    3535
    36     int IsPending();
     36    int IsPending() const;
    3737    int IsPending(BYTE_t node);
    3838    int IsPending(BYTE_t node, WORD_t idx, BYTE_t subidx);
  • trunk/MagicSoft/Cosy/candrv/vmodican.cc

    r732 r909  
    5252}
    5353
    54 void *VmodIcan::ReceiveThread(void *data)
    55 {
    56     VmodIcan *cal = (VmodIcan*)data;
    57 
    58     cal->lout << "- Starting Receiver Loop." << endl;
    59 
    60     //
    61     // set higher priority to make sure that no messages are lost.
    62     //
    63     setpriority(PRIO_PROCESS, 0, -10);
     54void *VmodIcan::Thread()
     55{
     56    lout << "- Starting Receiver Loop." << endl;
    6457
    6558    while (1)
     
    7063        //cout << "waiting..." << endl;
    7164
    72         const int n = read(cal->fd, &c, 1); // sleep until message arrive
     65        const int n = read(fd, &c, 1); // sleep until message arrive
    7366
    7467        gettimeofday(&tv, NULL);
     
    8982            FastMessage fmsg;
    9083
    91             if (cal->ReceiveFast(&fmsg) < 0)
     84            if (ReceiveFast(&fmsg) < 0)
    9285                return (void *)1;
    9386
     
    10598            Message msg;
    10699
    107             if (cal->Receive(&msg) < 0)
     100            if (Receive(&msg) < 0)
    108101                return (void *)1;
    109102
    110103            //cal->PrintMsg(&msg);
    111             cal->HandleMessage(&msg, &tv);
     104            HandleMessage(&msg, &tv);
    112105
    113106            break;
    114107        }
    115 
    116108    }
     109    return NULL;
    117110}
    118111
     
    765758}
    766759
    767 VmodIcan::VmodIcan(const char *dev, const int baud, ostream &out) : Log(out), fRxThrd(NULL)//: CanDriver(dev, baud)
    768 {
     760VmodIcan::VmodIcan(const char *dev, const int baud, ostream &out) : Log(out), MThread(false)//: CanDriver(dev, baud)
     761{
     762    //
     763    // Set priority of receiving thread and detach the receiving thread
     764    //
     765    SetPriority(-10);
     766    Detach();
     767
    769768    Open(dev);                         // open module
    770769    Reset();
     
    782781VmodIcan::~VmodIcan()
    783782{
    784     StopReceiver();
     783    Stop();
    785784    DisableCanBusConnection();
    786785    Close();
     
    794793    SendCanFrame(cobid, msg);
    795794}
    796 
     795/*
    797796void VmodIcan::StopReceiver()
    798797{
     
    804803    delete fRxThrd;
    805804    fRxThrd = NULL;
    806 
    807805    lout << "- Receiver Thread stopped." << endl;
    808806}
     807*/
     808
     809/*
    809810void VmodIcan::StartReceiver()
    810811{
    811     //**************************************
    812     //* create thread waiting for messages *
    813     //**************************************
     812    **************************************
     813    * create thread waiting for messages *
     814    **************************************
    814815    if (fRxThrd)
    815816    {
     
    823824    pthread_create(fRxThrd, NULL, ReceiveThread, this);
    824825}
    825 
     826*/
     827
  • trunk/MagicSoft/Cosy/candrv/vmodican.h

    r732 r909  
    99#include "gendef.h"
    1010
    11 class VmodIcan : public Log
     11#include "MThread.h"
     12/*
     13class VmodIcanRX : public MThread
    1214{
    1315private:
     16    VmodIcan *fModule;
     17
     18    void *Thread();
     19
     20public:
     21    MTGui(VmodIcan *mod) : MThread(false), fModule(mod)
     22    {
     23        SetPriority(-10);
     24        Detach();
     25    }
     26};
     27*/
     28class VmodIcan : public Log, protected MThread
     29{
     30    friend class VmodIcanRX;
     31
     32private:
    1433    int fd; // file descriptor for can module
    15     pthread_t *fRxThrd;
     34    //    pthread_t *fRxThrd;
    1635
    1736    int Ioctl(int msg, void *arg);
    1837
    19     static void *ReceiveThread(void *data);
     38    void *Thread();
    2039
    2140    void HandleMessage(Message *msg, struct timeval *tv);
     
    5271    virtual void TerminateApp() { exit(-1); }
    5372
    54 protected:
    55     void StartReceiver();
    56     void StopReceiver();
     73//protected:
     74//    void StartReceiver();
     75//    void StopReceiver();
    5776
    5877public:
  • trunk/MagicSoft/Cosy/cosy.cc

    r738 r909  
    88#include <TSystem.h>
    99#include <TApplication.h>
    10 
    11 #include "MGCosy.h"
    12 
    13 #include "macs.h"
    14 #include "timer.h"
    15 #include "slalib.h"
    16 #include "slamac.h"
    17 #include "shaftencoder.h"
    18 
    19 #include <sys/resource.h>  // PRIO_PROCESS
    2010
    2111int main(int argc, char **argv)
     
    3222    lout << "- Initialising Root environment." << endl;
    3323    TROOT root("Cosy", "Magic Control System");
    34     TApplication app ("App", &argc, argv);
     24    TApplication app("App", &argc, argv);
    3525
    3626    //
     
    4030    cosy->Start();
    4131
    42     lout << "- Starting mailoop." << endl;
    43     app.Run();
     32    lout << "- Starting mainloop." << endl;
     33    app.Run(kTRUE);
    4434
     35    lout << "- Stopping cosy." << endl;
    4536    cosy->Stop();
     37    lout << "- cosy stopped." << endl;
    4638
    4739    delete cosy;
Note: See TracChangeset for help on using the changeset viewer.