Changeset 2251

Show
Ignore:
Timestamp:
11/21/06 19:27:55 (7 years ago)
Author:
balister
Message:

Improve File input component.

Location:
components/FileInput/trunk/FileInput
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • components/FileInput/trunk/FileInput/FileInput.cpp

    r2245 r2251  
    2626#include <fstream> 
    2727 
     28#include <math.h> 
     29 
     30#ifdef HAVE_ERRNO_H 
     31#include <errno.h> 
     32#endif 
     33 
    2834#include <omnithread.h> 
    2935 
     
    3238#include "ossie/Resource_impl.h" 
    3339 
    34 FileInput_i::FileInput_i(const char *uuid, omni_condition *condition) : Resource_impl(uuid), component_running(condition), num_blocks(-1), file_repeat(1), inter_packet_time(0.0) 
     40                                FileInput_i::FileInput_i(const char *uuid, omni_condition *condition) : Resource_impl(uuid), component_running(condition), thread_started(false), num_blocks(-1), file_repeat(1) 
    3541{ 
    3642    dataOut = new standardInterfaces_i::complexShort_u("DataOut"); 
     
    4753    if (!CORBA::is_nil(p)) 
    4854        return p._retn(); 
     55 
     56    if (strcmp(portName, "Resource") == 0) 
     57        return CORBA::Object::_duplicate(myObjectRef); 
    4958 
    5059    /*exception*/ 
     
    5968    processing_thread = new omni_thread(do_run_data_send, (void *) this); 
    6069    processing_thread->start(); 
     70 
     71    thread_started = true; 
    6172} 
    6273 
     
    6475 
    6576    std::cout << "stop called on FileInput" << std::endl; 
     77 
     78    thread_started = false; 
    6679} 
    6780 
     
    98111        // num_blocks, unsigned long  
    99112        else if (strcmp(props[i].id, "DCE:019fd89f-589f-4714-8d33-57f108d7d004") == 0) { 
    100             CORBA::ULong val; 
     113            CORBA::Long val; 
    101114            props[i].value >>= val; 
    102115 
     
    111124            omni_mutex_lock l(accessPrivateData); 
    112125            file_repeat = val; 
     126            std::cout << "File repeat = " << file_repeat << std::endl; 
    113127        } 
    114128        // inter_packet_time, float 
     
    118132 
    119133            omni_mutex_lock l(accessPrivateData); 
    120             inter_packet_time = val; 
     134            packetDelay.tv_sec = (time_t) floor(val); 
     135            packetDelay.tv_nsec = ((long) (val - floor(val))) * 10^9; 
    121136        } 
    122137    } 
     
    127142    std::cout << "FileInput process_data thread started" << std::endl; 
    128143 
    129     // read in file size by parsing entire file 
    130     int i, k, file_size(0), num_loops(1); 
    131  
    132     float I, Q; 
    133  
    134     std::fstream file; 
    135     file.open("inputdata.txt", std::ios::in); 
    136     file.setf(std::ios_base::scientific); 
     144    // read data from file 
     145    unsigned int file_size(0); 
     146 
     147    struct timespec delayTime(packetDelay); 
     148 
     149    std::ifstream fin(fileName.c_str()); 
    137150 
    138151    // TODO: check if file exists! 
     152 
     153    PortTypes::ShortSequence I, Q; 
    139154 
    140155    while ( true ) 
    141156    { 
    142         file >> i; 
    143         file >> k; 
    144  
    145         if ( file.eof() ) 
     157        short d, q; 
     158 
     159        fin >> d >> q; 
     160 
     161        if ( fin.eof() ) 
    146162            break; 
    147163 
    148         std::cout << "input file: " << i << "    " << k << std::endl; 
     164        std::cout << "input file: " << d << "    " << q << std::endl; 
     165        I.length(file_size + 1); 
     166        Q.length(file_size + 1); 
     167        I[file_size] = d; 
     168        Q[file_size] = q; 
    149169        file_size++; 
    150170    } 
    151     file.close(); 
    152     std::cout << "File has " << file_size << " I/Q pairs" << std::endl; 
    153  
     171    fin.close(); 
     172    std::cout << "File contained " << file_size << " I/Q pairs" << std::endl; 
     173 
     174    // prepare output sequences 
    154175    PortTypes::ShortSequence I_out, Q_out; 
    155     I_out.length(file_size); 
    156     Q_out.length(file_size); 
    157  
    158     k=0; 
    159     while( true ) 
     176     
     177    std::cout << "Ouput sequence length = " << file_size * file_repeat << std::endl; 
     178 
     179    I_out.length(file_size * file_repeat); 
     180    Q_out.length(file_size * file_repeat); 
     181 
     182 
     183    for (unsigned int i = 0; i < file_repeat; ++i) { 
     184        for (unsigned int j = 0; j < file_size; ++j) { 
     185            I_out[i * file_size + j] = I[j]; 
     186            Q_out[i * file_size + j] = Q[j]; 
     187        } 
     188    } 
     189 
     190    std::cout << "About to send data." << std::endl; 
     191 
     192    // send output sequences num_block times 
     193    int k(num_blocks); 
     194    while( thread_started ) 
    160195    { 
    161         // std::cout << "Reading data stream from file..." << std::endl; 
    162  
    163         file.open("inputdata.txt", std::ios::in); 
    164     file.setf(std::ios_base::scientific); 
    165         if ( !file ) 
    166         { 
    167             std::cout << "ERROR! could not open file!" << std::endl; 
    168             break; 
    169         } 
    170  
    171         i = 0; 
    172         while( i<file_size ) 
    173         { 
    174             file >> I; 
    175             file >> Q; 
    176             (I_out)[i] = (short) I; 
    177             (Q_out)[i] = (short) Q; 
    178             i++; 
    179         } 
    180          
    181         file.close(); 
    182         //std::cout << "FileInput pushing " << i << " samples" << std::endl; 
    183196        dataOut->pushPacket(I_out, Q_out); 
    184197         
    185         k++; 
    186         if (k == num_loops) 
    187             break; 
    188     } 
    189 } 
    190  
    191      
     198        if (k > 0) 
     199            if (--k == 0) 
     200                break; 
     201 
     202        bool done; 
     203        struct timespec rem; 
     204        while (!done) { 
     205            int ret = nanosleep(&delayTime, &rem); 
     206 
     207            if (ret == EINTR) 
     208                delayTime = rem; 
     209            else 
     210                done = true; 
     211        } 
     212    } 
     213 
     214    processing_thread->exit(); 
     215 
     216} 
     217 
     218     
  • components/FileInput/trunk/FileInput/FileInput.h

    r2246 r2251  
    2525#define FILEINPUT_IMPL_H 
    2626 
     27#ifdef HAVE_STDLIB_H 
    2728#include <stdlib.h> 
     29#endif 
     30#ifdef HAVE_TIME_H 
     31#include <time.h> 
     32#endif 
     33 
    2834#include "ossie/cf.h" 
    2935 
     
    4349        FileInput_i(const char *uuid, omni_condition *sem); 
    4450 
     51        void post_constructor(CF::Resource_ptr ref) { myObjectRef = ref; }; 
    4552        static void do_run_data_send(void *data) { ((FileInput_i *)data)->run_data_send(); }; 
    4653 
     
    6269        void run_data_send(); 
    6370 
     71        CF::Resource_var myObjectRef; 
     72 
    6473        omni_condition *component_running;  //for component shutdown 
    6574        omni_thread *processing_thread;     //for component writer function 
    6675        omni_mutex accessPrivateData;           // for access to private data 
     76 
     77        bool thread_started; 
    6778 
    6879        // Values from properties 
     
    7081        unsigned long num_blocks; 
    7182        unsigned long file_repeat; 
    72         float inter_packet_time; 
     83        struct timespec packetDelay; 
    7384         
    7485        //list components provides and uses ports 
    7586        standardInterfaces_i::complexShort_u *dataOut; 
    76          
     87 
    7788}; 
    7889#endif 
  • components/FileInput/trunk/FileInput/FileInput.prf.xml

    r2241 r2251  
    99        <kind kindtype="configure"/> 
    1010    </simple> 
    11     <simple type="ulong" id="DCE:019fd89f-589f-4714-8d33-57f108d7d004" name="num_blocks" mode="readonly"> 
     11    <simple type="long" id="DCE:019fd89f-589f-4714-8d33-57f108d7d004" name="num_blocks" mode="readonly"> 
    1212        <description>Number of blocks of data to send.  Enter a negative number for infinite looping.</description>  
    1313        <value>-1</value>  
    1414        <kind kindtype="configure"/> 
    1515    </simple> 
    16     <simple type="short" id="DCE:23882924-7988-11db-9fc2-00123f573a7f" name="file_repeat" mode="readonly"> 
     16    <simple type="ulong" id="DCE:23882924-7988-11db-9fc2-00123f573a7f" name="file_repeat" mode="readonly"> 
    1717        <description>Number of times to repeat the file contents per output packet.</description>  
    1818        <value>1</value>  
  • components/FileInput/trunk/FileInput/FileInput.scd.xml

    r2206 r2251  
    1414        <supportsinterface supportsname="TestableObject" repid="IDL:CF/TestableObject:1.0"/> 
    1515        <ports> 
     16            <provides providesname="Resource" repid="IDL:CF/Resource:1.0"> 
     17                <porttype type="data"/> 
     18            </provides> 
    1619            <uses usesname="DataOut" repid="IDL:standardInterfaces/complexShort:1.0"> 
    1720                <porttype type="data"/> 
  • components/FileInput/trunk/FileInput/configure.ac

    r2206 r2251  
    99 
    1010AC_HEADER_SYS_WAIT 
     11AC_CHECK_HEADERS(time.h) 
     12AC_CHECK_HEADERS(errno.h) 
    1113 
    1214AC_FUNC_FORK 
  • components/FileInput/trunk/FileInput/main.cpp

    r2206 r2251  
    2626#include "FileInput.h" 
    2727 
    28 using namespace std; 
    29 using namespace standardInterfaces;  // For standard OSSIE interface classes 
    30  
    31  
    3228int main(int argc, char* argv[]) 
    3329 
     
    3834 
    3935    if (argc != 3) { 
    40         cout << argv[0] << " <id> <usage name> " << endl; 
     36        std::cout << argv[0] << " <id> <usage name> " << std::endl; 
    4137        exit (-1); 
    4238    } 
     
    4541    char *label = argv[2]; 
    4642 
    47     cout << "Identifier - " << uuid << "  Label - " << label << endl; 
     43    std::cout << "Identifier - " << uuid << "  Label - " << label << std::endl; 
    4844 
    4945    FileInput_i* fileinput_servant; 
     
    5450    fileinput_servant = new FileInput_i(uuid, component_running); 
    5551    fileinput_var = fileinput_servant->_this(); 
     52    fileinput_servant->post_constructor(fileinput_var); 
    5653 
    5754    orb->bind_object_to_name((CORBA::Object_ptr) fileinput_var, label);