/* Copyright (c) 20011 Hovanes Egiyan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ //!============================================================================= //! //! This is the interface to IOC in the form of a global object //! In this file we define the IOC commands //! for initializing IU Base CAN buses. //! //!============================================================================= #ifndef _BaseIUComDeff_CXX_ #define _BaseIUComDeff_CXX_ extern "C" { #include #include #include #include #include } ; #include "epicsExit.h" #include "epicsThread.h" #include "iocsh.h" #include "registryFunction.h" #include "epicsExport.h" #include "epicsTimer.h" #include #include using namespace std; #include "BaseIUDevice.hh" #include "BaseIUMgr.hh" #include "BaseIURecordMaker.hh" extern "C" { #include "BaseIUComDef.h" // function to configure and start a single CAN bus void drvBaseIUConfigBus(const char* ipName, const char* busName, const char* portName, const char* busType) { // Crate a bus ID for the desired bus BaseIUVirtBusID busID(ipName, busName, portName, busType); // Start a new bus with created bus ID BaseIUMgr::StartBusThread(busID); return; } // function to configure the first nBusses on an anagate device void drvBaseIUConfigAnagate(const char* ipName, const char* crateName, const char* busType, int nBusses ) { // Crate a bus ID for the anagate device which means bus should be "E" BaseIUVirtBusID busID(ipName, "E", crateName, busType); // Start bus with created bus ID for nBusses if( nBusses <= 0 ) BaseIUMgr::StartThreads4Buses(busID); else BaseIUMgr::StartThreads4Buses(busID, nBusses); return; } // A C-wrapper function to load records for IU bus with a given portName void dbLoadRecordsIU( const char* prefix, string portName ) { cout << "Prefix is " << prefix << " , portName is " << portName << endl; BaseIURecordMaker::LoadRecords( prefix, portName ); return; } //// A C-wrapper function to load records for IU buses //void dbLoadRecordsIU( const char* prefix, string crateName, string busName ) { //// if( slot < 0 || slot > 4 ) slot = 4; // Configure all buses if the bus is not give correctly //// string busName = BaseIUDevice::DeviceID::Int2String(slot); // cout << "Prefix is " << prefix << " , crateName is " << crateName << " , busName is " << busName << endl; // BaseIURecordMaker::LoadRecords( prefix, crateName, busName ); // return; //} //! Function to start a CANbus connection on AnaGate bus from IOC shell static void runStartAnagateBus(const iocshArgBuf* args) { cout << endl; cout << "Starting CANbus Application for port " << hex << showbase << args[2].sval << " with address " << args[0].sval << " at bus connector " << args[1].sval << " for type " << args[3].sval << endl; drvBaseIUConfigBus(args[0].sval, args[1].sval, args[2].sval, args[3].sval); return; } //! Function to Stop an AnaGate CANbus connection from IOC shell static void runStopAnagateBus(const iocshArgBuf* args) { cout << "CANbus application for port " << args[0].sval << " is being stopped" << endl; BaseIUMgr::StopBus(args[0].sval); return; } //! Function to start a CANbus connection on AnaGate module from IOC shell static void runStartAnagate(const iocshArgBuf* args) { cout << endl; cout << "Starting Anagate Application for ports starting with " << hex << showbase << args[1].sval << " with address " << args[0].sval << " for type " << args[2].sval << " for first " << args[3].ival << " busses "<< endl; drvBaseIUConfigAnagate( args[0].sval, args[1].sval, args[2].sval, args[3].ival); return; } static void dbLoadRecordsFunIU(const iocshArgBuf* args) { // dbLoadRecordsIU( args[0].sval, args[1].sval, args[2].sval ); dbLoadRecordsIU( args[0].sval, args[1].sval ); return; } //! Define Arguments descriptors for "Start" Command for bus static const iocshArg StartBusArgs[4] = { { "IP Address", iocshArgString }, { "Bus Number", iocshArgString }, { "Port Name", iocshArgString }, { "Bus Type", iocshArgString }, }; //! Define the array of the pointers to the Arguments descriptors for "Start" command for bus static const iocshArg* const StartBusArgs_ptr[4] = { &StartBusArgs[0], &StartBusArgs[1], &StartBusArgs[2], &StartBusArgs[3] }; //! Define Arguments descriptors for "Stop" Command for bus static const iocshArg StopBusArgs[1] = { { "Port Name", iocshArgString } }; //! Define the array of the pointers to the Arguments descriptors for "Stop" command for bus static const iocshArg* const StopBusArgs_ptr[1] = { &StopBusArgs[0] }; //! Define Arguments descriptors for "Start" Command for module static const iocshArg StartAnagateArgs[4] = { { "IP Address", iocshArgString }, { "Port Name", iocshArgString }, { "Bus Type", iocshArgString }, { "Number of busses", iocshArgInt } }; //! Define the array of the pointers to the Arguments descriptors for "Start" command for module static const iocshArg* const StartAnagateArgs_ptr[4] = { &StartAnagateArgs[0], &StartAnagateArgs[1], &StartAnagateArgs[2], &StartAnagateArgs[3] }; ////! Define arguments descriptors for DB loading command (non needed, dummy) //static const iocshArg dbLoadRecordsIUArgs[2] = { { "Prefix", iocshArgString }, // {"Crate Name", iocshArgString}, {"Bus Name", iocshArgString} }; //! Define arguments descriptors for DB loading command (non needed, dummy) static const iocshArg dbLoadRecordsIUArgs[2] = { { "Prefix", iocshArgString }, {"Port Name", iocshArgString} }; //! Define the array of the pointers to the Arguments descriptors for "dbLoad" command static const iocshArg* const dbLoadRecordsIUArgs_ptr[3] = { &dbLoadRecordsIUArgs[0], &dbLoadRecordsIUArgs[1], &dbLoadRecordsIUArgs[2] }; //! Define arguments structures for AnaGate Bus Command static const iocshFuncDef StartAnagateBus_commDef = { "StartAnagateBus", 4, StartBusArgs_ptr }; static const iocshFuncDef StopAnaGateBus_commDef = { "StopAnagateBus", 1, StopBusArgs_ptr }; static const iocshFuncDef StartAnagate_commDef = { "StartAnagate", 4, StartAnagateArgs_ptr }; //static const iocshFuncDef dbLoadRecordsIU_commDef = { "dbLoadRecordsIU", 3, // dbLoadRecordsIUArgs_ptr }; static const iocshFuncDef dbLoadRecordsIU_commDef = { "dbLoadRecordsIU", 2, dbLoadRecordsIUArgs_ptr }; } //! Define a class whose constructor registers Start and Stop commands class IocShellComReg { public: IocShellComReg() { iocshRegister(&StartAnagateBus_commDef, runStartAnagateBus); iocshRegister(&StopAnaGateBus_commDef, runStopAnagateBus); iocshRegister(&StartAnagate_commDef, runStartAnagate ); iocshRegister(&dbLoadRecordsIU_commDef, dbLoadRecordsFunIU); } }; //! Define a dummy global variable to register commands //! before the execution starts static IocShellComReg dummyObj; #endif