next up previous
Next: About this document ... Up: RTDX_Service Previous: RTDX_Service API


RTDX_Service Listing

/*
 * RTDX_Service_3.h
 */

#ifndef _RTDX_SERVICE_3_H_
#define _RTDX_SERVICE_3_H_

#import "rtdxint.dll"
using namespace RTDXINTLib;
#import "cc_setup.exe"
using namespace CodeComposerSetup;

class RTDX_Service_3
{
public:
    RTDX_Service_3();

    long Init(wchar_t* board,wchar_t* cpu);
    
    long OpenCommandChannel();
    long CloseCommandChannel();
    long OpenResponseChannel();
    long CloseResponseChannel();
    long OpenWriteChannel();
    long CloseWriteChannel();
    long OpenReadChannel();
    long CloseReadChannel();
    long OpenAllChannels(long* status);
    long CloseAllChannels();
    
    long CommandToClient(long data);
    long ResponseFromClient(long* data);

    long DataToClient(long* data);
    
    long DataFromClient(long* data);

private:
    IRtdxExpPtr c_pRtdx;
    IRtdxExpPtr r_pRtdx;
    IRtdxExpPtr dw_pRtdx;
    IRtdxExpPtr dr_pRtdx;
};

#endif	// RTDX_SERVICE_3_H_

/**
 * RTDX_Service_3.cpp
 */
#include "RTDX_Service_3.h"
#include <string.h>

RTDX_Service_3::RTDX_Service_3() {
}

/**
 * Initialization of the RTDX communication
 * @param[in] boardName		name of DSP-board in wide-character format
 * @param[in] processorName	CPU-name on board in wide-character format
 * @return     0    success
 *            -1    instantiation error 'cchan'-channel
 *            -2    instantiation error 'rchan'-channel
 *            -3    instantiation error 'ichan'-channel
 *            -4    instantiation error 'ochan'-channel
 *           -11    board/cpu-name error 'cchan'-channel
 *           -12    board/cpu-name error 'rchan'-channel
 *           -13    board/cpu-name error 'ichan'-channel
 *           -14    board/cpu-name error 'ochan'-channel
 *           -21    RTDX-disable error
 *           -22    RTDX-configuration error
 *           -23    RTDX-enable error
 */
long RTDX_Service_3::Init(wchar_t* boardName,wchar_t* processorName) {
    HRESULT hr = S_OK;

    ::CoInitialize(NULL);                    // initialize COM

    // instanciate RTDX for command channel 'cchan'
    hr = c_pRtdx.CreateInstance(__uuidof(RTDXINTLib::RtdxExp));
    if (!SUCCEEDED(hr)) {
        return -1; // signal instantiation error
    }

    // instanciate RTDX for response channel 'rchan'
    hr = r_pRtdx.CreateInstance(__uuidof(RTDXINTLib::RtdxExp));
    if (!SUCCEEDED(hr)) {
        return -2; // signal instantiation error
    }

    // instanciate RTDX for data write channel 'ichan'
    hr = dw_pRtdx.CreateInstance(__uuidof(RTDXINTLib::RtdxExp));
    if (!SUCCEEDED(hr)) {
        return -3; // signal instantiation error
    }

    // instanciate RTDX for data read channel 'ochan'
    hr = dr_pRtdx.CreateInstance(__uuidof(RTDXINTLib::RtdxExp));
    if (!SUCCEEDED(hr)) {
        return -4; // signal instantiation error
    }
    long status;

    // Set board and processor in RTDX for command channel
    status = c_pRtdx->SetProcessor(boardName,processorName);
    if (status != Success)
    return -11; // board and cpu name error

    // Set board and processor in RTDX for response channel
    status = r_pRtdx->SetProcessor(boardName,processorName);
    if (status != Success)
        return -12; // board and cpu name error

    // Set board and processor in RTDX for data write channel
    status = dw_pRtdx->SetProcessor(boardName,processorName);
    if (status != Success)
        return -13; // board and cpu name error

    // Set board and processor in RTDX for data read channel
    status = dr_pRtdx->SetProcessor(boardName,processorName);
    if (status != Success)
        return -14; // board and cpu name error

    // only necessary for one instantiation because of global.
    // set configuration for 'continuous, buffer size 1024, 4 buffers
    // RTDX can only be configured if RTDX is disabled
    hr = c_pRtdx->DisableRtdx();
    if (!SUCCEEDED(hr)) {
        return -21; // signal rtdx-disable error
    }
    // now configure RTDX
    hr = c_pRtdx->ConfigureRtdx(1,1024,8);
    if (!SUCCEEDED(hr)) {
        return -22; // signal configuration error
    }
    hr = c_pRtdx->EnableRtdx();
    if (!SUCCEEDED(hr)) {
        return -23; // signal rtdx-enable error
    }
    return 0;
}

/**
 * Open Command-Channel 'cchan'
 * @returns RTDX success and error code
 */
long RTDX_Service_3::OpenCommandChannel() {
    return c_pRtdx->Open("cchan","w");
}

/**
 * Close Command-Channel 'cchan'
 * @returns RTDX success and error code
 */
long RTDX_Service_3::CloseCommandChannel() {
    return c_pRtdx->Close();
}

/**
 * Open Response-Channel 'rchan'
 * @returns RTDX success and error code
 */
long RTDX_Service_3::OpenResponseChannel() {
    return r_pRtdx->Open("rchan","r");
}

/**
 * Close Response-Channel 'rchan'
 * @returns RTDX success and error code
 */
long RTDX_Service_3::CloseResponseChannel() {
    return r_pRtdx->Close();
}

/**
 * Open Write-Channel 'ichan'
 * @returns RTDX success and error code
 */
long RTDX_Service_3::OpenWriteChannel() {
    return dw_pRtdx->Open("ichan","w");
}

/**
 * Close Write-Channel 'ichan'
 * @returns RTDX success and error code
 */
long RTDX_Service_3::CloseWriteChannel() {
    return dw_pRtdx->Close();
}

/**
 * Open Read-Channel 'ochan'
 * @returns RTDX success and error code
 */
long RTDX_Service_3::OpenReadChannel() {
    return dr_pRtdx->Open("ochan","r");
}

/**
 * Close Read-Channel 'ochan'
 * @returns RTDX success and error code
 */
long RTDX_Service_3::CloseReadChannel() {
    return dr_pRtdx->Close();
}

/**
 * Open all channels
 * @returns    0    success
 *            -1    error when opening channel 'cchan'
 *            -2    error when opening channel 'rchan'
 *            -3    error when opening channel 'ichan'
 *            -4    error when opening channel 'ochan'
 */
long RTDX_Service_3::OpenAllChannels(long* status) {
    if ((*status = OpenCommandChannel()) != Success)
        return -1;
    if ((*status = OpenResponseChannel()) != Success)
        return -2;
    if ((*status = OpenWriteChannel()) != Success)
        return -3;
    if ((*status = OpenReadChannel()) != Success)
        return -4;
    *status = 0;
    return 0;
}

/**
 * Close all channels
 * @returns    0    success
 *            -1    closing error channel 'cchan'
 *            -2    closing error channel 'rchan'
 *            -3    closing error channel 'ichan'
 *            -4    closing error channel 'ochan'
 */
long RTDX_Service_3::CloseAllChannels() {

    long status_c = CloseCommandChannel();
    long status_r = CloseResponseChannel();
    long status_dw = CloseWriteChannel();
    long status_dr = CloseReadChannel();
    
    if (status_c != Success)
        return -1;
    if (status_r != Success)
        return -2;
    if (status_dw != Success)
        return -3;
    if (status_dr != Success)
        return -4;
    return 0;
}

/**
 * Send Command to client
 * @parameter   the command code as 'long'-number
 * @return  RTDX error and success code
 */
long RTDX_Service_3::CommandToClient(long number) {
    long numBytes;
    return c_pRtdx->WriteI4(number,&numBytes);
}

/**
 * Receive response from client
 * @parameter   pointer to a 'long'-type that receives the response
 * @return  RTDX error and success code
 */
long RTDX_Service_3::ResponseFromClient(long* data) {
    return r_pRtdx->ReadI4(data);
}

/**
 * Send Data to client
 * @parameter   a data item as 'long'-type
 * @return  RTDX error and success code
 */
long RTDX_Service_3::DataToClient(long* data) {
    long numBytes;
    return dw_pRtdx->WriteI4(*data,&numBytes);
}

/**
 * Receive data from client
 * @parameter   pointer to a 'long'-type that receives the data
 * @return  RTDX error and success code
 */
long RTDX_Service_3::DataFromClient(long* data) {
    return dr_pRtdx->ReadI4(data);
}



H. Rogalla 2005-12-07