### Construct and start RMAP Engine and Initiator Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Shows how to construct and start an RMAP engine and then create an RMAP initiator with a logical address. The example uses the RMAPEngine and RMAPInitiator classes. ```cpp /* Construct and start RMAP Engine */ RMAPEngine* rmapEngine = new RMAPEngine(spwif); rmapEngine->start(); /* Construct an RMAP Initiator instance */ RMAPInitiator* rmapInitiator = new RMAPInitiator(rmapEngine); rmapInitiator->setInitiatorLogicalAddress(0xFE); ``` -------------------------------- ### Install SpaceWireRMAPLibrary using Homebrew Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/README.md Installs SpaceWireRMAPLibrary and its dependencies via Homebrew. The library and related libraries are installed to /usr/local/include. When compiling, include the header search path with -I/usr/local/include and link xerces-c with -lxerces-c. ```sh brew tap yuasatakayuki/hxisgd brew install xerces-c spacewirermaplibrary ``` -------------------------------- ### Install from Git repository and set environment variables Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/README.md Clones the SpaceWireRMAPLibrary, CxxUtilities, and XMLUtilities repositories, installs xerces-c via Homebrew, and sets environment variables for the library paths. Save the export commands in .zshrc or .bashrc. ```sh #Move to your favorite install directory! mkdir $HOME/work/install cd $HOME/work/install #Cloning libraries from github repositories git clone https://github.com/yuasatakayuki/SpaceWireRMAPLibrary git clone https://github.com/yuasatakayuki/CxxUtilities git clone https://github.com/sakuraisoki/XMLUtilities #Install xerces-c++ # See http://mxcl.github.com/homebrew/ for details of HomeBrew brew install xerces-c #Set environment variables (save in .zshrc/.bashrc) export SPACEWIRERMAPLIBRARY_PATH=$HOME/work/install/SpaceWireRMAPLibrary export CXXUTILITIES_PATH=$HOME/work/install/CxxUtilities export XMLUTILITIES_PATH=$HOME/work/install/XMLUtilities export XERCESDIR=/usr/local ``` -------------------------------- ### Build and install Ruby SpaceWire/RMAP module Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/README.md Build and install the Ruby SpaceWire/RMAP module from the SWIG wrapper. By default, the compiled library is installed to $HOME/lib; use cmake -DCMAKE_INSTALL_PREFIX=install/directory/ to change the destination. ```sh cd SpaceWireRMAPLibrary/swig/ cmake . make make install # By default, compiled library (Ruby module) is installed to $HOME/lib. #If you want to change this, do: # cmake -DCMAKE_INSTALL_PREFIX=install/directory/ . ``` -------------------------------- ### Set SPACEWIRERMAPLIBRARY_PATH environment variable Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Add this line to your shell initialization file (.zshrc for zsh, .bashrc for bash) to point to the installed SpaceWire RMAP Library folder. Adjust the path to match your installation location. ```shell export SPACEWIRERMAPLIBRARY_PATH=/Users/yuasa/workspace/SpaceWireRMAPLibrary ``` -------------------------------- ### Set XERCESDIR environment variable Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Add this line to your shell initialization file to point to the xerces-c++ installation. The example Makefile uses this variable to locate the xerces-c++ library. ```shell export XERCESDIR=/Users/yuasa/work/install/xerces-c-3.1.1 ``` -------------------------------- ### Construct RMAPEngine and RMAPInitiator (Listing 14) Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Shows how to construct an RMAPEngine and an RMAPInitiator. The RMAPEngine is a subclass of CxxUtilities::Thread and its start() method forks a new thread to wait for incoming packets. The RMAPInitiator is constructed with a pointer to the RMAPEngine, and its initiator logical address can be set (default 0xFE, but any 0x20-0xFD is allowed). ```cpp // Listing 14: Sample code for constructing RMAPEngine/RMAPInitiator. // (Code not provided in the source text; the listing is referenced but not shown.) ``` -------------------------------- ### Example Makefile for compiling user applications Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf A Makefile that compiles a user application (UserApplication.cc) with SpaceWire RMAP Library and related libraries. It uses environment variables SPACEWIRERMAPLIBRARY_PATH, XERCESDIR, and optionally CXXUTILITIES_PATH and XMLUTILITIES_PATH. The Makefile includes rules for building the target and cleaning up. ```makefile # ############################################################## # An example Makefile for SpaceWire RMAP Library. # ############################################################## # Note 1: # To compile a user application with SpaceWire RMAP Library, # set SPACEWIRERMAPLIBRARY_PATH and XERCESDIR in the shell # initialization file first. # Execute below to check if these variables are correctly # set in your shell. # # > ls $SPACEWIRERMAPLIBRARY_PATH # > ls $XERCESDIR # # If no error is observed, the paths seem valid. # Note 2: # This Makefile assumes a user-application source code named # UserApplication.cc. If other source files are necessary, # add them to CXXFLAGS and LDFLAGS. # ############################################################## # Set target (binary names) TARGETS = UserApplication # See also the rule part below. # Check CxxUtilities ifndef $(CXXUTILITIES_PATH) CXXUTILITIES_PATH = $(SPACEWIRERMAPLIBRARY_PATH)/externalLibraries/CxxUtilities endif # Check XMLUtilities ifndef $(XMLUTILITIES_PATH) XMLUTILITIES_PATH = $(SPACEWIRERMAPLIBRARY_PATH)/externalLibraries/XMLUtilities endif # Set compiler / linker flags CXXFLAGS = -I$(SPACEWIRERMAPLIBRARY_PATH)/includes -I$(CXXUTILITIES_PATH)/includes -I$(XMLUTILITIES_PATH) -I/$(XERCESDIR)/include LDFLAGS = -L/$(XERCESDIR)/lib -lxerces-c TARGETS_OBJECTS = $(addsuffix .o, $(basename $(TARGETS))) TARGETS_SOURCES = $(addsuffix .cc, $(basename $(TARGETS))) # ############################################################## .PHONY : all all : $(TARGETS) UserApplication : UserApplication.o $(CXX) -g $(CXXFLAGS) -o $@ $@.cc $(LDFLAGS) clean : rm -rf $(TARGETS) $(addsuffix .o, $(TARGETS)) ``` -------------------------------- ### RMAPInitiator Configuration Methods Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Methods to set and get the initiator logical address, configure RMAP options (reply mode, increment mode, verify mode), manage transaction ID, and access raw packet pointers and target node database. ```APIDOC ## RMAPInitiator Configuration Methods ### Description These methods allow configuration of the RMAP initiator's logical address, RMAP options, transaction ID, and access to raw packet pointers and the target node database. ### Methods #### setInitiatorLogicalAddress ```cpp void setInitiatorLogicalAddress(uint8_t initiatorLogicalAddress); ``` Sets the logical address of this RMAP initiator. #### getInitiatorLogicalAddress ```cpp uint8_t getInitiatorLogicalAddress(); ``` Gets the logical address of this RMAP initiator. #### setReplyMode ```cpp void setReplyMode(bool replyMode); ``` Sets the reply mode option. #### unsetReplyMode ```cpp void unsetReplyMode(); ``` Unsets the reply mode option. #### isReplyModeSet ```cpp bool isReplyModeSet(); ``` Checks if reply mode is set. #### setIncrementMode ```cpp void setIncrementMode(bool incrementMode); ``` Sets the increment mode option. #### unsetIncrementMode ```cpp void unsetIncrementMode(); ``` Unsets the increment mode option. #### isIncrementModeSet ```cpp bool isIncrementModeSet(); ``` Checks if increment mode is set. #### setVerifyMode ```cpp void setVerifyMode(bool verifyMode); ``` Sets the verify mode option. #### unsetVerifyMode ```cpp void unsetVerifyMode(); ``` Unsets the verify mode option. #### isVerifyModeSet ```cpp bool isVerifyModeSet(); ``` Checks if verify mode is set. #### setTransactionID ```cpp void setTransactionID(uint16_t transactionID); ``` Sets the transaction ID. #### unsetTransactionID ```cpp void unsetTransactionID(); ``` Unsets the transaction ID. #### getTransactionID ```cpp uint16_t getTransactionID(); ``` Gets the transaction ID. #### isTransactionIDSet ```cpp bool isTransactionIDSet(); ``` Checks if transaction ID is set. #### getCommandPacketPointer ```cpp RMAPPacket* getCommandPacketPointer(); ``` Gets the raw command packet pointer. #### getReplyPacketPointer ```cpp RMAPPacket* getReplyPacketPointer(); ``` Gets the raw reply packet pointer. #### setRMAPTargetNodeDB ```cpp void setRMAPTargetNodeDB(RMAPTargetNodeDB* targetNodeDB); ``` Sets the RMAP target node database. #### getRMAPTargetNodeDB ```cpp RMAPTargetNodeDB* getRMAPTargetNodeDB(); ``` Gets the RMAP target node database. ``` -------------------------------- ### RMAPInitiator option setters and getters Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Excerpt from RMAPInitiator class showing methods to set and get logical address, reply mode, increment mode, verify mode, and transaction ID. Also includes accessors for command and reply packet pointers and methods to set/get RMAPTargetNodeDB. ```cpp /* set / get logical address of this RMAPInitiator */ void setInitiatorLogicalAddress(uint8_t initiatorLogicalAddress); uint8_t getInitiatorLogicalAddress(); /* accessor for other RMAP options */ void setReplyMode(bool replyMode); void unsetReplyMode(); bool isReplyModeSet(); void setIncrementMode(bool incrementMode); void unsetIncrementMode(); bool isIncrementModeSet(); void setVerifyMode(bool verifyMode); void unsetVerifyMode(); bool isVerifyModeSet(); void setTransactionID(uint16_t transactionID); void unsetTransactionID(); uint16_t getTransactionID(); bool isTransactionIDSet(); /* accessor for raw packet pointer */ RMAPPacket* getCommandPacketPointer(); RMAPPacket* getReplyPacketPointer(); /* interface for RMAPTargetNodeDB */ void setRMAPTargetNodeDB(RMAPTargetNodeDB* targetNodeDB); RMAPTargetNodeDB* getRMAPTargetNodeDB(); }; ``` -------------------------------- ### Perform RMAP read/write with manually constructed RMAPTargetNode (Listing 15) Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Executes RMAP read/write using a manually constructed RMAPTargetNode instance. Read buffers can be C-array or std::vector, write data are passed as C-array. Time-out duration can be passed to avoid infinite wait. RMAP options are set via RMAPInitiator methods (see List 12). The example includes error handling for RMAPInitiatorException, RMAPReplyException, RMAPEngineException, and unknown errors. ```cpp // /////////////////////////////////////////////////////////////////////////////////// // Example 1 // Manually sets RMAPTargetNode information cout << "Example 1" << endl; RMAPTargetNode rmapTargetNode1; rmapTargetNode1.setTargetLogicalAddress(0xfe); rmapTargetNode1.setDefaultKey(0x20); std::vector targetSpaceWireAddress; targetSpaceWireAddress.push_back(0x01); targetSpaceWireAddress.push_back(0x0a); targetSpaceWireAddress.push_back(0x05); rmapTargetNode1.setTargetSpaceWireAddress(targetSpaceWireAddress); std::vector replyAddress; replyAddress.push_back(0x08); replyAddress.push_back(0x03); replyAddress.push_back(0x0f); rmapTargetNode1.setReplyAddress(replyAddress); cout << rmapTargetNode1.toString() << endl; /* RMAP Read / Write with address / length */ try { // case 1-1 : using C-array as a read buffer uint32_t readLength = 1024; uint8_t* readData = new uint8_t[(size_t) readLength]; uint32_t readAddress = 0xFF801100; rmapInitiator-> read(rmapTargetNode1, readAddress, readLength, readData, readTimeoutDuration); // case 1-2 : using std :: vector < uint8_t > as a read buffer std::vector readDataVector; rmapInitiator-> read(rmapTargetNode1, readAddress, readLength, (uint8_t*)readDataVector.begin(), readTimeoutDuration); // case 1-3 : write using C-array write data uint32_t writeAddress = 0xFF803800; uint32_t writeLength = 4; uint8_t* writeData = new uint8_t[writeLength]; writeData[0] = 0xAB; writeData[1] = 0xCD; writeData[2] = 0x12; writeData[3] = 0x34; rmapInitiator-> write(rmapTargetNode1, writeAddress, writeData, writeLength, writeTimeoutDuration); delete readData; delete writeData; delete rmapTargetNode1; cout << "RMAP Read/Write Example1 done" << endl; } catch (RMAPInitiatorException e) { cerr << "RMAPInitiatorException " << e.toString() << endl; cerr << "Continue to next example" << endl; } catch (RMAPReplyException e) { cerr << "RMAPReplyException " << e.toString() << endl; cerr << "Continue to next example" << endl; } catch (RMAPEngineException e) { cerr << "RMAPEngineException " << e.toString() << endl; cerr << "Continue to next example" << endl; } catch (...) { cerr << "Unkown error" << endl; exit(-1); } // /////////////////////////////////////////////////////////////////////////////////// ``` -------------------------------- ### RMAPPacket Class Methods Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf This snippet documents the RMAPPacket class methods for creating and interpreting RMAP packets, as shown in the user guide examples. ```APIDOC ## RMAPPacket::setTargetSpaceWireAddress ### Description Sets the target SpaceWire address for the RMAP packet. This is used to specify the destination path in the SpaceWire network. ### Method `void setTargetSpaceWireAddress(const std::vector& address)` ### Parameters - **address** (vector) - Required - The target SpaceWire address as a vector of bytes. ### Example ```cpp vector targetSpaceWireAddress; targetSpaceWireAddress.push_back(3); targetSpaceWireAddress.push_back(10); targetSpaceWireAddress.push_back(21); rmapPacket1.setTargetSpaceWireAddress(targetSpaceWireAddress); ``` ``` ```APIDOC ## RMAPPacket::setReplyAddress ### Description Sets the reply address for the RMAP packet. This is used to specify the return path for replies. ### Method `void setReplyAddress(const std::vector& address)` ### Parameters - **address** (vector) - Required - The reply address as a vector of bytes. ### Example ```cpp vector replyAddress; replyAddress.push_back(5); replyAddress.push_back(3); rmapPacket1.setReplyAddress(replyAddress); ``` ``` ```APIDOC ## RMAPPacket::setWrite ### Description Sets the RMAP packet as a write command. This indicates that the operation is a write to the target. ### Method `void setWrite()` ### Parameters None. ### Example ```cpp rmapPacket1.setWrite(); ``` ``` ```APIDOC ## RMAPPacket::setCommand ### Description Sets the RMAP packet as a command packet. This distinguishes it from a reply packet. ### Method `void setCommand()` ### Parameters None. ### Example ```cpp rmapPacket1.setCommand(); ``` ``` ```APIDOC ## RMAPPacket::setIncrementMode ### Description Sets the RMAP packet to use increment mode for addressing. This means the address is incremented for each data byte. ### Method `void setIncrementMode()` ### Parameters None. ### Example ```cpp rmapPacket1.setIncrementMode(); ``` ``` ```APIDOC ## RMAPPacket::setNoVerifyMode ### Description Sets the RMAP packet to no verify mode. This disables verification of the write operation. ### Method `void setNoVerifyMode()` ### Parameters None. ### Example ```cpp rmapPacket1.setNoVerifyMode(); ``` ``` ```APIDOC ## RMAPPacket::setExtendedAddress ### Description Sets the extended address for the RMAP packet. This is used for addressing beyond the standard 32-bit address space. ### Method `void setExtendedAddress(uint8_t extendedAddress)` ### Parameters - **extendedAddress** (uint8_t) - Required - The extended address byte. ### Example ```cpp rmapPacket1.setExtendedAddress(0x00); ``` ``` ```APIDOC ## RMAPPacket::setAddress ### Description Sets the 32-bit address for the RMAP packet. This is the target memory address for the operation. ### Method `void setAddress(uint32_t address)` ### Parameters - **address** (uint32_t) - Required - The target address. ### Example ```cpp rmapPacket1.setAddress(0xff803800); ``` ``` ```APIDOC ## RMAPPacket::setDataLength ### Description Sets the data length (in bytes) for the RMAP packet. This specifies the number of data bytes to be transferred. ### Method `void setDataLength(uint32_t dataLength)` ### Parameters - **dataLength** (uint32_t) - Required - The length of the data in bytes. ### Example ```cpp uint32_t dataLength = 0x31; rmapPacket1.setDataLength(dataLength); ``` ``` ```APIDOC ## RMAPPacket::addData ### Description Adds a single data byte to the RMAP packet. This is used to build the data payload. ### Method `void addData(uint8_t data)` ### Parameters - **data** (uint8_t) - Required - The data byte to add. ### Example ```cpp for (size_t i = 0; i < dataLength; i++) { rmapPacket1.addData((uint8_t) i); } ``` ``` ```APIDOC ## RMAPPacket::constructPacket ### Description Constructs the complete RMAP packet from the set properties. This generates the packet buffer. ### Method `void constructPacket()` ### Parameters None. ### Example ```cpp rmapPacket1.constructPacket(); ``` ``` ```APIDOC ## RMAPPacket::getPacketBufferPointer ### Description Returns a pointer to the constructed packet buffer. This is used to access the raw packet bytes. ### Method `uint8_t* getPacketBufferPointer()` ### Parameters None. ### Returns - **uint8_t*** - Pointer to the packet buffer. ### Example ```cpp SpaceWireUtilities::dumpPacket(rmapPacket1.getPacketBufferPointer()); ``` ``` ```APIDOC ## RMAPPacket::setHeaderCRCMode ### Description Sets the header CRC mode. The mode can be set to `RMAPPacket::AutoCRC` to automatically compute the CRC. ### Method `void setHeaderCRCMode(RMAPPacket::CRCMode mode)` ### Parameters - **mode** (RMAPPacket::CRCMode) - Required - The CRC mode, e.g., `RMAPPacket::AutoCRC`. ### Example ```cpp rmapPacket1.setHeaderCRCMode(RMAPPacket::AutoCRC); ``` ``` ```APIDOC ## RMAPPacket::constructHeader ### Description Constructs the header part of the RMAP packet. This is used to regenerate the header with the current settings. ### Method `void constructHeader()` ### Parameters None. ### Example ```cpp rmapPacket1.constructHeader(); ``` ``` ```APIDOC ## RMAPPacket::toString ### Description Returns a human-readable string representation of the RMAP packet. ### Method `std::string toString()` ### Parameters None. ### Returns - **std::string** - The string representation. ### Example ```cpp cout << rmapPacket1.toString() << endl; ``` ``` ```APIDOC ## RMAPPacket::toXMLString ### Description Returns an XML string representation of the RMAP packet. ### Method `std::string toXMLString()` ### Parameters None. ### Returns - **std::string** - The XML string representation. ### Example ```cpp cout << rmapPacket1.toXMLString() << endl; ``` ``` ```APIDOC ## RMAPPacket::interpretAsAnRMAPPacket ### Description Interprets a byte sequence as an RMAP packet. If the interpretation is successful, the packet properties are accessible from the instance. If the CRC checks fail, an exception is thrown. ### Method `void interpretAsAnRMAPPacket(uint8_t* packet, size_t length)` ### Parameters - **packet** (uint8_t*) - Required - Pointer to the byte sequence. - **length** (size_t) - Required - Length of the byte sequence. ### Exceptions - **RMAPPacketException** - Thrown if the packet is invalid, e.g., invalid header or data CRC. ### Example ```cpp try { rmapPacket2.interpretAsAnRMAPPacket(bytes, sizeof(bytes)); } catch (RMAPPacketException e) { cerr << "RMAPPacketException " << e.toString() << endl; exit(-1); } ``` ``` ```APIDOC ## RMAPPacket::setHeaderCRCIsChecked ### Description Sets whether the header CRC is checked during interpretation. By default, it is checked. ### Method `void setHeaderCRCIsChecked(bool checked)` ### Parameters - **checked** (bool) - Required - Set to `false` to disable header CRC checking. ### Example ```cpp rmapPacket.setHeaderCRCIsChecked(false); ``` ``` ```APIDOC ## RMAPPacket::setDataCRCIsChecked ### Description Sets whether the data CRC is checked during interpretation. By default, it is checked. ### Method `void setDataCRCIsChecked(bool checked)` ### Parameters - **checked** (bool) - Required - Set to `false` to disable data CRC checking. ### Example ```cpp rmapPacket.setDataCRCIsChecked(false); ``` ``` -------------------------------- ### RMAPInitiator read and write methods Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Excerpt from RMAPInitiator class showing read and write method overloads. Includes fast methods using RMAPTargetNode pointers and convenient but slower methods that search the RMAPTargetNodeDB and RMAPMemoryObjectDB. All methods throw RMAPEngineException, RMAPInitiatorException, and RMAPReplyException. ```cpp /* convenient, but somewhat slow due to RMAPTargetNode DB and RMAPMemoryObject DB search */ void read(std::string targetNodeID, std::string memoryObjectID, uint8_t* buffer, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException); /* convenient, but somewhat slow due to RMAPTargetNode DB search */ void read(std::string targetNodeID, uint32_t memoryAddress, uint32_t length, uint8_t* buffer, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException); /* convenient, but somewhat slow due to RMAPMemoryObject DB search */ void read(RMAPTargetNode* rmapTargetNode, std::string memoryObjectID, uint8_t *buffer, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException); /* RMAP Write methods */ /* fast */ void write(RMAPTargetNode *rmapTargetNode, uint32_t memoryAddress, uint8_t *data, uint32_t length, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException); /* convenient, but somewhat slow due to RMAPTargetNode DB and RMAPMemoryObject DB search */ void write(std::string targetNodeID, std::string memoryObjectID, uint8_t* data, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException); /* convenient, but somewhat slow due to RMAPTargetNode DB search */ void write(std::string targetNodeID, uint32_t memoryAddress, uint8_t *data, uint32_t length, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException); /* convenient, but somewhat slow due to RMAPMemoryObject DB search */ void write(RMAPTargetNode *rmapTargetNode, std::string memoryObjectID, uint8_t* data, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException); ``` -------------------------------- ### RMAPInitiator class methods (excerpt) Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Shows the public interface of the RMAPInitiator class, including the constructor and two read methods. The first read method is fast but requires a pre-allocated buffer, while the second is easier to use but slower due to data copy, returning a newly constructed vector. ```cpp class RMAPInitiator { public: /* constructor */ RMAPInitiator(RMAPEngine *rmapEngine); /* RMAP Read methods */ /* fast */ void read(RMAPTargetNode* rmapTargetNode, uint32_t memoryAddress, uint32_t length, uint8_t *buffer, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException); /* easy to use, but somewhat slow due to data copy. */ /* this methods throw */ std::vector* readConstructingNewVecotrBuffer(std::string targetNodeID, uint32_t memoryAddress, uint32_t length, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException); }; ``` -------------------------------- ### RMAPEngineStoppedActionByRMAPViewController subclass Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Example subclass of RMAPEngineStoppedAction used in SpaceWire RMAP GUI. It stores a view controller and calls rmapEngineWasStopped on it when the engine stops. ```Objective-C class RMAPEngineStoppedActionByRMAPViewController : public RMAPEngineStoppedAction{ private: id rmapViewController; public: RMAPEngineStoppedActionByRMAPViewController(id rmapViewController){ this->rmapViewController=rmapViewController; } virtual void doAction(void * rmapEngine){ [rmapViewController rmapEngineWasStopped]; } }; ``` -------------------------------- ### RMAPEngine class methods (excerpt) Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Shows the public interface of the RMAPEngine class, including constructor, start/stop methods, transaction initiation and cancellation, raw packet sending, target management, and accessors. It also includes methods for adding/removing actions when the engine stops. ```cpp class RMAPEngine: public CxxUtilities::Thread { public: /* constructor */ RMAPEngine(SpaceWireIF* spwif); /* start / stop */ virtual void start(); void stop(); bool isStopped(); bool isStarted(); /* methods used by RMAPInitiator */ void initiateTransaction(RMAPTransaction* transaction) throw (RMAPEngineException); void cancelTransaction(RMAPTransaction* transaction) throw (RMAPEngineException); /* raw packet send method which even can be used while RMAPEngine is running */ void sendPacket(std::vector* bytes); /* methods used when a user application implements an RMAPTarget */ void addRMAPTarget(RMAPTarget* rmapTarget); void removeRMAPTarget(RMAPTarget* rmapTarget); /* accessor for a SpaceWireIF instance */ void setSpaceWireIF(SpaceWireIF* spwif); SpaceWireIF* getSpaceWireIF(); /* actions invoked when RMAPEngine is stopped ( automatically or manually) */ void addRMAPEngineStoppedAction(RMAPEngineStoppedAction* rmapEngineStoppedAction); void removeRMAPEngineStoppedAction(RMAPEngineStoppedAction* rmapEngineStoppedAction); CxxUtilities::Actions* getRMAPEngineStoppedActions(); }; ``` -------------------------------- ### Subclass of SpaceWireIFActionCloseAction (SpaceWireViewController) Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Example of a subclass of SpaceWireIFActionCloseAction defined in SpaceWire RMAP GUI. The doAction method stops continuous packet receive and periodic timecode emission when the interface is closed. ```cpp class SpaceWireViewContollerCloseActionStopContinuousReceive : public SpaceWireIFActionCloseAction { private: id spacewireViewController; public: SpaceWireViewContollerCloseActionStopContinuousReceive(id spacewireViewController){ this->spacewireViewController=spacewireViewController; } public: void doAction(SpaceWireIF* spacewireIF){ [spacewireViewController stopContinuousPacketReceive]; [spacewireViewController stopPeriodicTimecodeEmission]; } }; ``` -------------------------------- ### SpaceWireIF Interface Methods Summary Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Summarizes frequently used user-side interface methods of the SpaceWireIF class, including open/close, send/receive, timeout, timecode, link close actions, and EOP/EEP handling. See SpaceWireIF.hh for full details. ```cpp class SpaceWireIF { public: /* open / close */ virtual void open() throw (SpaceWireIFException); virtual void close() throw (SpaceWireIFException); /* send methods */ virtual void send(uint8_t* data, size_t length, SpaceWireEOPMarker::EPPType eopType = SpaceWireEOPMarker::EOP) throw ( SpaceWireIFException); virtual void send(std::vector& data, SpaceWireEOPMarker::EPPType eopType = SpaceWireEOPMarker::EOP) throw ( SpaceWireIFException); virtual void send(std::vector* data, SpaceWireEOPMarker::EPPType eopType = SpaceWireEOPMarker::EOP) throw ( SpaceWireIFException); /* receive methods */ // fast virtual std::vector* receive() throw (SpaceWireIFException); // fast virtual void receive(std::vector* buffer) throw (SpaceWireIFException); // slow; not recommended virtual void receive(uint8_t* buffer, SpaceWireEOPMarker::EPPType& eopType, size_t maxLength, size_t& length) throw ( SpaceWireIFException); /* set receive timeout */ virtual void setTimeoutDuration(double microsecond) throw (SpaceWireIFException); /* emit timecode */ virtual void emitTimecode(uint8_t timeIn, uint8_t controlFlagIn = 0x00) throw (SpaceWireIFException); /* Action related to timecode */ void addTimecodeAction(SpaceWireIFActionTimecodeScynchronizedAction* action); void registerTimecodeAction(SpaceWireIFActionTimecodeScynchronizedAction* action); void deleteTimecodeAction(SpaceWireIFActionTimecodeScynchronizedAction* action); void clearTimecodeSynchronizedActions(); /* Action related to link close event */ void addSpaceWireIFCloseAction(SpaceWireIFActionCloseAction* spacewireIFCloseAction); void deleteSpaceWireIFCloseAction(SpaceWireIFActionCloseAction* spacewireIFCloseAction); void invokeSpaceWireIFCloseActions(); /* EOP / EEP related */ bool isTerminatedWithEEP(); bool isTerminatedWithEOP(); void setReceivedPacketEOPMarkerType(int eopType); int getReceivedPacketEOPMarkerType(); void eepShouldBeReportedAsAnException(); void eepShouldNotBeReportedAsAnException(); }; ``` -------------------------------- ### Extract size from byte array (SSDTP2) Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Restores the packet size from the byte array buffer, which contains the bytes shown in the table. The size is stored in 10 bytes starting at index 2. ```C /* Code to restore the size from the byte array. */ /* buffer[] should contain the bytes shown above. */ unsigned int size=0; for (int i=2;i<12;i++){ size=size*0x100+buffer[i]; } ``` -------------------------------- ### Set RUBYLIB for Ruby SpaceWire/RMAP module Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/README.md Set the RUBYLIB environment variable so Ruby can find the SpaceWire/RMAP module. If you changed the install destination with cmake's -DCMAKE_INSTALL_PREFIX option, set an appropriate path instead of $HOME/lib/ruby. ```sh export RUBYLIB=$HOME/lib/ruby #when you changed an install destination using the cmake's -DCMAKE_INSTALL_PREFIX option, #set an appropriate path instead of $HOME/lib/ruby. ``` -------------------------------- ### RMAP read/write using RMAPTargetNodeDB with XML configuration Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Constructs RMAPTargetNodeDB from an XML-like configuration file, checks for file existence and non-empty database, sets it to RMAPInitiator, and performs read/write operations using node and memory object IDs. Handles RMAPInitiatorException, RMAPReplyException, and RMAPEngineException. Note: methods using IDs are slower than direct pointer/address methods but offer higher reconfigurability. ```cpp // /////////////////////////////////////////////////////////////////////////////////// /* Example 2 */ /* Use RMAPTargetNodes constructed from an XML-like configuration file. */ cout << "Example 2" << endl; if (argc < 2) { cerr << "Example2 requires an XML-like configuration file." << endl; exit(-1); } // check file existence if (!CxxUtilities::File::exists(argv[1])) { cerr << "File " << argv[1] << " does not exist." << endl; exit(-1); } // construct RMAPTargetNodes from the XML file std::string filename(argv[1]); cout << "Constructing RMAPTargetNodes from " << filename << endl; RMAPTargetNodeDB* rmapTargetNodeDB; try { rmapTargetNodeDB = new RMAPTargetNodeDB(filename); } catch (RMAPTargetNodeDBException e) { cerr << "An exception thrown while loading the XML file " << filename << endl; cerr << e.toString() << endl; exit(-1); } // check the number of entries if (rmapTargetNodeDB->getSize() == 0) { cerr << "No RMAPTargetNode instance was constructed..." << endl; exit(-1); } // set the db to RMAPInitiator rmapInitiator->setRMAPTargetNodeDB(rmapTargetNodeDB); /* RMAP Read / Write with address / length */ try { // case 1-1 : read using C-array as a read buffer uint32_t readLength = 2; uint8_t* readData = new uint8_t[(size_t) readLength]; rmapInitiator-> read("SpaceWireDigitalIOBoard", "LEDRegister", readData, readTimeoutDuration); // case 1-2 : read using std :: vector < uint8_t > as a read buffer std::vector readDataVector(readLength); rmapInitiator-> read("SpaceWireDigitalIOBoard", "LEDRegister", &(readDataVector.at(0)), readTimeoutDuration); // case 1-3 : write using C-array write data uint32_t writeLength = 2; uint8_t* writeData = new uint8_t[writeLength]; writeData[0] = 0xFF; writeData[1] = 0xFF; rmapInitiator-> write("SpaceWireDigitalIOBoard", "LEDRegister", writeData, writeTimeoutDuration); delete readData; delete writeData; cout << "RMAP Read/Write Example2 done" << endl; } catch (RMAPInitiatorException e) { cerr << "RMAPInitiatorException " << e.toString() << endl; cerr << "Continue to next example" << endl; } catch (RMAPReplyException e) { cerr << "RMAPReplyException " << e.toString() << endl; cerr << "Continue to next example" << endl; } catch (RMAPEngineException e) { cerr << "RMAPEngineException " << e.toString() << endl; cerr << "Continue to next example" << endl; } catch (...) { cerr << "Unkown error" << endl; exit(-1); } // /////////////////////////////////////////////////////////////////////////////////// ``` -------------------------------- ### Subclassing CxxUtilities::Thread Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Shows how to create a subclass of CxxUtilities::Thread, requiring the full path 'CxxUtilities::Thread' and 'public CxxUtilities::Thread' in the class declaration. The run() method contains the thread content. ```cpp class SubclassOfThread : public CxxUtilities::Thread { public: void run(){ ... thread content ... } }; ``` -------------------------------- ### Manually create an RMAP packet (Example1) Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Constructs an RMAP write command packet by setting target address, reply address, data, and various modes. Uses AutoCRC for header CRC and outputs the packet dump, string, and XML representations. ```C++ // Example1: Manually create an RMAP packet vector targetSpaceWireAddress; targetSpaceWireAddress.push_back(3); targetSpaceWireAddress.push_back(10); targetSpaceWireAddress.push_back(21); vector replyAddress; replyAddress.push_back(5); replyAddress.push_back(3); uint32_t dataLength = 0x31; RMAPPacket rmapPacket1; rmapPacket1.setTargetSpaceWireAddress(targetSpaceWireAddress); rmapPacket1.setReplyAddress(replyAddress); rmapPacket1.setWrite(); rmapPacket1.setCommand(); rmapPacket1.setIncrementMode(); rmapPacket1.setNoVerifyMode(); rmapPacket1.setExtendedAddress(0x00); rmapPacket1.setAddress(0xff803800); rmapPacket1.setDataLength(dataLength); for (size_t i = 0; i < dataLength; i++) { rmapPacket1.addData((uint8_t) i); } rmapPacket1.constructPacket(); cout << "RMAPPacket1" << endl; SpaceWireUtilities::dumpPacket(rmapPacket1.getPacketBufferPointer()); cout << "----------------------------" << endl; rmapPacket1.setHeaderCRCMode(RMAPPacket::AutoCRC); rmapPacket1.constructHeader(); cout << rmapPacket1.toString() << endl; cout << rmapPacket1.toXMLString() << endl; cout << endl; ``` -------------------------------- ### Open and close SpaceWire-to-GigabitEther interface Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf Constructs a SpaceWireIFOverIPClient with IP address 192.168.1.100 and port 10030, then opens it inside a try-catch block to handle connection timeouts. After the user process, the interface is closed with spwif->close(). The default port is 10030, but some devices like Shimafuji's may accept 10031. ```cpp /* Open the SpaceWire interface */ cout << "Opening SpaceWireIF..."; SpaceWireIF* spwif = **new** SpaceWireIFOverIPClient("192.168.1.100", 10030); **try** { spwif->open(); } **catch** (...) { cerr << "Connection timed out." << endl; exit(-1); } cout << "done" << endl; ... user process **using** spwif ... /* Close */ spwif->close(); ``` -------------------------------- ### RMAPInitiator Source: https://github.com/yuasatakayuki/spacewirermaplibrary/blob/master/doc/SpaceWireRMAPLibraryUserGuide_20120110.pdf The RMAPInitiator class provides methods for performing RMAP read operations. It includes a fast method that writes directly to a user-provided buffer and a slower method that constructs a new vector buffer. ```APIDOC ## RMAPInitiator ### Description The RMAPInitiator class provides methods for initiating RMAP read transactions. It offers two read methods: a fast method that writes directly to a user-provided buffer, and a slower method that constructs a new vector buffer. ### Constructor - **RMAPInitiator(RMAPEngine *rmapEngine)** - Creates an RMAPInitiator instance with the given RMAPEngine. ### Methods #### read(RMAPTargetNode* rmapTargetNode, uint32_t memoryAddress, uint32_t length, uint8_t *buffer, double timeoutDuration = DefaultTimeoutDuration) - **Signature**: `void read(RMAPTargetNode* rmapTargetNode, uint32_t memoryAddress, uint32_t length, uint8_t *buffer, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException)` - **Description**: Performs an RMAP read operation. This is the fast method that writes the read data directly into the provided buffer. The timeout duration is optional and defaults to DefaultTimeoutDuration. #### readConstructingNewVecotrBuffer(std::string targetNodeID, std::string memoryObjectID, uint32_t memoryAddress, uint32_t length, double timeoutDuration = DefaultTimeoutDuration) - **Signature**: `std::vector* readConstructingNewVecotrBuffer(std::string targetNodeID, std::string memoryObjectID, uint32_t memoryAddress, uint32_t length, double timeoutDuration = DefaultTimeoutDuration) throw (RMAPEngineException, RMAPInitiatorException, RMAPReplyException)` - **Description**: Performs an RMAP read operation and returns a pointer to a newly constructed std::vector containing the read data. This method is easy to use but somewhat slow due to data copy. The timeout duration is optional and defaults to DefaultTimeoutDuration. ```