| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2010 by your_name_or_organization, all rights reserved. |
|---|
| 4 | |
|---|
| 5 | ****************************************************************************/ |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | #include <string> |
|---|
| 9 | #include <iostream> |
|---|
| 10 | #include "Proj1Tx.h" |
|---|
| 11 | |
|---|
| 12 | Proj1Tx_i::Proj1Tx_i(const char *uuid, omni_condition *condition) : |
|---|
| 13 | Resource_impl(uuid), component_running(condition) |
|---|
| 14 | { |
|---|
| 15 | dataOut_0 = new standardInterfaces_i::realShort_u("Txout_port"); |
|---|
| 16 | BurstRate = 1; |
|---|
| 17 | PacketDelay = 500; |
|---|
| 18 | |
|---|
| 19 | start(); |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | Proj1Tx_i::~Proj1Tx_i(void) |
|---|
| 23 | { |
|---|
| 24 | delete dataOut_0; |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | // Static function for omni thread |
|---|
| 28 | void Proj1Tx_i::Run( void * data ) |
|---|
| 29 | { |
|---|
| 30 | ((Proj1Tx_i*)data)->ProcessData(); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | CORBA::Object_ptr Proj1Tx_i::getPort( const char* portName ) throw ( |
|---|
| 34 | CORBA::SystemException, CF::PortSupplier::UnknownPort) |
|---|
| 35 | { |
|---|
| 36 | DEBUG(3, Proj1Tx, "getPort() invoked with " << portName) |
|---|
| 37 | |
|---|
| 38 | CORBA::Object_var p; |
|---|
| 39 | |
|---|
| 40 | p = dataOut_0->getPort(portName); |
|---|
| 41 | |
|---|
| 42 | if (!CORBA::is_nil(p)) |
|---|
| 43 | return p._retn(); |
|---|
| 44 | |
|---|
| 45 | /*exception*/ |
|---|
| 46 | throw CF::PortSupplier::UnknownPort(); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | void Proj1Tx_i::start() throw (CORBA::SystemException, |
|---|
| 50 | CF::Resource::StartError) |
|---|
| 51 | { |
|---|
| 52 | DEBUG(3, Proj1Tx, "start() invoked") |
|---|
| 53 | omni_mutex_lock l(processing_mutex); |
|---|
| 54 | if( false == thread_started ) |
|---|
| 55 | { |
|---|
| 56 | thread_started = true; |
|---|
| 57 | // Create the thread for the writer's processing function |
|---|
| 58 | processing_thread = new omni_thread(Run, (void *) this); |
|---|
| 59 | |
|---|
| 60 | // Start the thread containing the writer's processing function |
|---|
| 61 | processing_thread->start(); |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | void Proj1Tx_i::stop() throw (CORBA::SystemException, CF::Resource::StopError) |
|---|
| 66 | { |
|---|
| 67 | DEBUG(3, Proj1Tx, "stop() invoked") |
|---|
| 68 | omni_mutex_lock l(processing_mutex); |
|---|
| 69 | thread_started = false; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | void Proj1Tx_i::releaseObject() throw (CORBA::SystemException, |
|---|
| 73 | CF::LifeCycle::ReleaseError) |
|---|
| 74 | { |
|---|
| 75 | DEBUG(3, Proj1Tx, "releaseObject() invoked") |
|---|
| 76 | |
|---|
| 77 | component_running->signal(); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | void Proj1Tx_i::initialize() throw (CF::LifeCycle::InitializeError, |
|---|
| 81 | CORBA::SystemException) |
|---|
| 82 | { |
|---|
| 83 | DEBUG(3, Proj1Tx, "initialize() invoked") |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | void Proj1Tx_i::query( CF::Properties & configProperties ) throw (CORBA::SystemException, CF::UnknownProperties) |
|---|
| 87 | { |
|---|
| 88 | if( configProperties.length() == 0 ) |
|---|
| 89 | { |
|---|
| 90 | configProperties.length( propertySet.length() ); |
|---|
| 91 | for( int i = 0; i < propertySet.length(); i++ ) |
|---|
| 92 | { |
|---|
| 93 | configProperties[i].id = CORBA::string_dup( propertySet[i].id ); |
|---|
| 94 | configProperties[i].value = propertySet[i].value; |
|---|
| 95 | } |
|---|
| 96 | return; |
|---|
| 97 | } else { |
|---|
| 98 | for( int i = 0; i < configProperties.length(); i++ ) { |
|---|
| 99 | for( int j = 0; j < propertySet.length(); j++ ) { |
|---|
| 100 | if( strcmp(configProperties[i].id, propertySet[i].id) == 0 ) { |
|---|
| 101 | configProperties[i].value = propertySet[i].value; |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | } // end if-else |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | void Proj1Tx_i::configure(const CF::Properties& props) |
|---|
| 109 | throw (CORBA::SystemException, |
|---|
| 110 | CF::PropertySet::InvalidConfiguration, |
|---|
| 111 | CF::PropertySet::PartialConfiguration) |
|---|
| 112 | { |
|---|
| 113 | DEBUG(3, Proj1Tx, "configure() invoked") |
|---|
| 114 | |
|---|
| 115 | static int init = 0; |
|---|
| 116 | if( init == 0 ) { |
|---|
| 117 | if( props.length() == 0 ) { |
|---|
| 118 | std::cout << "configure called with invalid props.length - " << props.length() << std::endl; |
|---|
| 119 | return; |
|---|
| 120 | } |
|---|
| 121 | propertySet.length(props.length()); |
|---|
| 122 | for( int j=0; j < props.length(); j++ ) { |
|---|
| 123 | propertySet[j].id = CORBA::string_dup(props[j].id); |
|---|
| 124 | propertySet[j].value = props[j].value; |
|---|
| 125 | } |
|---|
| 126 | init = 1; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | std::cout << "props length : " << props.length() << std::endl; |
|---|
| 130 | |
|---|
| 131 | for ( int i = 0; i <props.length(); i++) |
|---|
| 132 | { |
|---|
| 133 | std::cout << "Property id : " << props[i].id << std::endl; |
|---|
| 134 | |
|---|
| 135 | if (strcmp(props[i].id, "DCE:fddd7342-1c44-11df-baab-000c29388bec") == 0) |
|---|
| 136 | { |
|---|
| 137 | CORBA::Short simple_temp; |
|---|
| 138 | props[i].value >>= simple_temp; |
|---|
| 139 | simple_0_value = simple_temp; |
|---|
| 140 | for( int k = 0; k < propertySet.length(); k++ ) { |
|---|
| 141 | if( strcmp(propertySet[k].id, props[i].id) == 0 ) { |
|---|
| 142 | propertySet[i].value = props[i].value; |
|---|
| 143 | break; |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | if (strcmp(props[i].id, "DCE:c766e66c-1c45-11df-baab-000c29388bec") == 0) |
|---|
| 149 | { |
|---|
| 150 | CORBA::Short simple_temp; |
|---|
| 151 | props[i].value >>= simple_temp; |
|---|
| 152 | simple_1_value = simple_temp; |
|---|
| 153 | for( int k = 0; k < propertySet.length(); k++ ) { |
|---|
| 154 | if( strcmp(propertySet[k].id, props[i].id) == 0 ) { |
|---|
| 155 | propertySet[i].value = props[i].value; |
|---|
| 156 | break; |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | void Proj1Tx_i::ProcessData() |
|---|
| 165 | { |
|---|
| 166 | DEBUG(3, Proj1Tx, "ProcessData() invoked") |
|---|
| 167 | |
|---|
| 168 | PortTypes::ShortSequence I_out_0; |
|---|
| 169 | |
|---|
| 170 | short ln = sizeof(data_bits)/sizeof(char); |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | while(continue_processing()) |
|---|
| 174 | { |
|---|
| 175 | I_out_0.length(ln*BurstRate); //must define length of output |
|---|
| 176 | |
|---|
| 177 | /*insert code here to do work*/ |
|---|
| 178 | for (short n1=0;n1<BurstRate;n1++) { |
|---|
| 179 | for (short n2 =0; n2<ln ;n2++) { |
|---|
| 180 | |
|---|
| 181 | I_out_0[n1*ln + n2] = data_bits[n2]; |
|---|
| 182 | |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | dataOut_0->pushPacket(I_out_0); |
|---|
| 188 | } |
|---|
| 189 | std::cout << "TRANSMITTER transmitting with " << "Burst rate of: " << BurstRate << " and Packet Delay of: " << PacketDelay << std::endl; |
|---|
| 190 | |
|---|
| 191 | usleep(PacketDelay*10000); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | bool Proj1Tx_i::continue_processing() |
|---|
| 195 | { |
|---|
| 196 | omni_mutex_lock l(processing_mutex); |
|---|
| 197 | return thread_started; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | unsigned char data_bits[1024] = { |
|---|
| 201 | 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, |
|---|
| 202 | 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, |
|---|
| 203 | 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, |
|---|
| 204 | 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, |
|---|
| 205 | 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, |
|---|
| 206 | 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, |
|---|
| 207 | 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, |
|---|
| 208 | 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, |
|---|
| 209 | 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, |
|---|
| 210 | 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, |
|---|
| 211 | 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, |
|---|
| 212 | 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, |
|---|
| 213 | 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, |
|---|
| 214 | 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, |
|---|
| 215 |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