Changeset 2251
- Timestamp:
- 11/21/06 19:27:55 (7 years ago)
- Location:
- components/FileInput/trunk/FileInput
- Files:
-
- 6 modified
-
FileInput.cpp (modified) (9 diffs)
-
FileInput.h (modified) (4 diffs)
-
FileInput.prf.xml (modified) (1 diff)
-
FileInput.scd.xml (modified) (1 diff)
-
configure.ac (modified) (1 diff)
-
main.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
components/FileInput/trunk/FileInput/FileInput.cpp
r2245 r2251 26 26 #include <fstream> 27 27 28 #include <math.h> 29 30 #ifdef HAVE_ERRNO_H 31 #include <errno.h> 32 #endif 33 28 34 #include <omnithread.h> 29 35 … … 32 38 #include "ossie/Resource_impl.h" 33 39 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) 35 41 { 36 42 dataOut = new standardInterfaces_i::complexShort_u("DataOut"); … … 47 53 if (!CORBA::is_nil(p)) 48 54 return p._retn(); 55 56 if (strcmp(portName, "Resource") == 0) 57 return CORBA::Object::_duplicate(myObjectRef); 49 58 50 59 /*exception*/ … … 59 68 processing_thread = new omni_thread(do_run_data_send, (void *) this); 60 69 processing_thread->start(); 70 71 thread_started = true; 61 72 } 62 73 … … 64 75 { 65 76 std::cout << "stop called on FileInput" << std::endl; 77 78 thread_started = false; 66 79 } 67 80 … … 98 111 // num_blocks, unsigned long 99 112 else if (strcmp(props[i].id, "DCE:019fd89f-589f-4714-8d33-57f108d7d004") == 0) { 100 CORBA:: ULong val;113 CORBA::Long val; 101 114 props[i].value >>= val; 102 115 … … 111 124 omni_mutex_lock l(accessPrivateData); 112 125 file_repeat = val; 126 std::cout << "File repeat = " << file_repeat << std::endl; 113 127 } 114 128 // inter_packet_time, float … … 118 132 119 133 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; 121 136 } 122 137 } … … 127 142 std::cout << "FileInput process_data thread started" << std::endl; 128 143 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()); 137 150 138 151 // TODO: check if file exists! 152 153 PortTypes::ShortSequence I, Q; 139 154 140 155 while ( true ) 141 156 { 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() ) 146 162 break; 147 163 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; 149 169 file_size++; 150 170 } 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 154 175 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 ) 160 195 { 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;183 196 dataOut->pushPacket(I_out, Q_out); 184 197 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 25 25 #define FILEINPUT_IMPL_H 26 26 27 #ifdef HAVE_STDLIB_H 27 28 #include <stdlib.h> 29 #endif 30 #ifdef HAVE_TIME_H 31 #include <time.h> 32 #endif 33 28 34 #include "ossie/cf.h" 29 35 … … 43 49 FileInput_i(const char *uuid, omni_condition *sem); 44 50 51 void post_constructor(CF::Resource_ptr ref) { myObjectRef = ref; }; 45 52 static void do_run_data_send(void *data) { ((FileInput_i *)data)->run_data_send(); }; 46 53 … … 62 69 void run_data_send(); 63 70 71 CF::Resource_var myObjectRef; 72 64 73 omni_condition *component_running; //for component shutdown 65 74 omni_thread *processing_thread; //for component writer function 66 75 omni_mutex accessPrivateData; // for access to private data 76 77 bool thread_started; 67 78 68 79 // Values from properties … … 70 81 unsigned long num_blocks; 71 82 unsigned long file_repeat; 72 float inter_packet_time;83 struct timespec packetDelay; 73 84 74 85 //list components provides and uses ports 75 86 standardInterfaces_i::complexShort_u *dataOut; 76 87 77 88 }; 78 89 #endif -
components/FileInput/trunk/FileInput/FileInput.prf.xml
r2241 r2251 9 9 <kind kindtype="configure"/> 10 10 </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"> 12 12 <description>Number of blocks of data to send. Enter a negative number for infinite looping.</description> 13 13 <value>-1</value> 14 14 <kind kindtype="configure"/> 15 15 </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"> 17 17 <description>Number of times to repeat the file contents per output packet.</description> 18 18 <value>1</value> -
components/FileInput/trunk/FileInput/FileInput.scd.xml
r2206 r2251 14 14 <supportsinterface supportsname="TestableObject" repid="IDL:CF/TestableObject:1.0"/> 15 15 <ports> 16 <provides providesname="Resource" repid="IDL:CF/Resource:1.0"> 17 <porttype type="data"/> 18 </provides> 16 19 <uses usesname="DataOut" repid="IDL:standardInterfaces/complexShort:1.0"> 17 20 <porttype type="data"/> -
components/FileInput/trunk/FileInput/configure.ac
r2206 r2251 9 9 10 10 AC_HEADER_SYS_WAIT 11 AC_CHECK_HEADERS(time.h) 12 AC_CHECK_HEADERS(errno.h) 11 13 12 14 AC_FUNC_FORK -
components/FileInput/trunk/FileInput/main.cpp
r2206 r2251 26 26 #include "FileInput.h" 27 27 28 using namespace std;29 using namespace standardInterfaces; // For standard OSSIE interface classes30 31 32 28 int main(int argc, char* argv[]) 33 29 … … 38 34 39 35 if (argc != 3) { 40 cout << argv[0] << " <id> <usage name> " <<endl;36 std::cout << argv[0] << " <id> <usage name> " << std::endl; 41 37 exit (-1); 42 38 } … … 45 41 char *label = argv[2]; 46 42 47 cout << "Identifier - " << uuid << " Label - " << label <<endl;43 std::cout << "Identifier - " << uuid << " Label - " << label << std::endl; 48 44 49 45 FileInput_i* fileinput_servant; … … 54 50 fileinput_servant = new FileInput_i(uuid, component_running); 55 51 fileinput_var = fileinput_servant->_this(); 52 fileinput_servant->post_constructor(fileinput_var); 56 53 57 54 orb->bind_object_to_name((CORBA::Object_ptr) fileinput_var, label);