tool/CommandRescan.cpp
author Martin Troxler <ch1010277@ch10pc446>
Tue, 14 Dec 2010 14:00:19 +0100
changeset 2017 4b16e2dce5fb
parent 1968 4f682084c643
child 2421 bc2d4bf9cbe5
permissions -rw-r--r--
Increment injection_seq on slave state changes
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  vim: expandtab
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 ****************************************************************************/
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
#include <sstream>
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <iomanip>
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
using namespace std;
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include "CommandRescan.h"
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "MasterDevice.h"
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
CommandRescan::CommandRescan():
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
    Command("rescan", "Rescan the bus.")
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
{
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
}
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/*****************************************************************************/
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
    48
string CommandRescan::helpString(const string &binaryBaseName) const
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
{
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    stringstream str;
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
1968
4f682084c643 Implemented drive_no for command-line tool; binary base name is now a
Florian Pose <fp@igh-essen.com>
parents: 1961
diff changeset
    52
    str << binaryBaseName << " " << getName() << endl
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
        << endl
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        << getBriefDescription() << endl
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        << endl
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
        << "Command a bus rescan. Gathered slave information will be" << endl
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        << "forgotten and slaves will be read in again." << endl
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
        << endl;
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    return str.str();
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
}
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
/****************************************************************************/
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
void CommandRescan::execute(const StringVector &args)
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
{
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
	MasterIndexList masterIndices;
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    if (args.size() != 0) {
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
        stringstream err;
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
        err << "'" << getName() << "' takes no arguments!";
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
        throwInvalidUsageException(err);
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
    }
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
	masterIndices = getMasterIndices();
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    MasterIndexList::const_iterator mi;
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    for (mi = masterIndices.begin();
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
            mi != masterIndices.end(); mi++) {
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        MasterDevice m(*mi);
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
        m.open(MasterDevice::ReadWrite);
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
        m.rescan();
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    }
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
}
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
/*****************************************************************************/