Esempio n. 1
0
/*
 * User-facing routine
 * Checks for new frames from PC and sends PC any new CAN bus frames
 * Will echo out any frames from PC that do not match the local node ID 
 * Should be called once per main loop iteration during normal operation
 */
void runSerialCAN(word id) {
    CANframe rxFrame;
    // Check for a new frame from the PC
    if (  readSerialCANframe(&rxFrame) == RX_COMPLETE ) {
        if ( rxFrame.id == id ) {
            CANput(rxFrame.payload);
        } else {
            CANsend(&rxFrame);  // Echo frame from serial onto CAN bus if ID doesn't match
        }
    }
    // Check for a recently sent frame
    if ( data_sent() ) {
        sendSerialCANframe(last_txframe());
    }
    // Check for a recently received frame
    if ( data_received() ) {
        sendSerialCANframe(last_rxframe());
    }
}
Esempio n. 2
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{

  try
    {
      // Initialize the ORB
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      // Parse the command-line arguments to get the IOR
      parse_args (argc, argv);

      // parse args should catch this, but just in case...
      if (iorfile == 0)
        return 0;

      // Read the file, and get the IOR
      ACE_HANDLE input_file = ACE_OS::open (iorfile, 0);
      if (input_file == ACE_INVALID_HANDLE)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open input file %s for reading IOR\n",
                           iorfile),
                          -1);
      ACE_Read_Buffer ior_buffer (input_file);
      char *data = ior_buffer.read ();
      if (data == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Unable to read ior\n"),
                          -1);

      ACE_CString ior = data;
      ior_buffer.alloc ()->free (data);
      ACE_OS::close (input_file);

      CORBA::Object_var object = orb->string_to_object (ior.c_str ());

      // Narrow the object reference to a File::System
      File::System_var file_system = File::System::_narrow (object.in ());

      // Creat the file filename i.e "test"
      File::Descriptor_var fd = file_system->open (ACE_TEXT_ALWAYS_CHAR (filename),
                                                   O_CREAT | O_RDWR);

      int message_length = ACE_OS::strlen (message) + 1;
      CORBA::Octet *buffer = File::Descriptor::DataBuffer::allocbuf (message_length);
      ACE_OS::strcpy ((char *) buffer, ACE_TEXT_ALWAYS_CHAR (message));
      File::Descriptor::DataBuffer data_sent (message_length, message_length, buffer, 1);

      // write the message to the file
      fd->write (data_sent);

      // seek to the beginning of the file
      fd->lseek (0, SEEK_SET);

      // Read back the written message
      File::Descriptor::DataBuffer_var data_received = fd->read (message_length);

      char *result = (char *) &data_received[0];

      // print the read message
      ACE_DEBUG((LM_DEBUG, "%C\n",
                 result));

      // close the file
      fd->destroy ();

      file_system->shutdown ();

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught in main");
      return -1;
    }

  return 0;
}
Esempio n. 3
0
    void parcelhandler::register_counter_types()
    {
        HPX_STD_FUNCTION<boost::int64_t()> num_parcel_sends(
            boost::bind(&parcelport::get_parcel_send_count, &pp_));
        HPX_STD_FUNCTION<boost::int64_t()> num_parcel_receives(
            boost::bind(&parcelport::get_parcel_receive_count, &pp_));

        HPX_STD_FUNCTION<boost::int64_t()> num_message_sends(
            boost::bind(&parcelport::get_message_send_count, &pp_));
        HPX_STD_FUNCTION<boost::int64_t()> num_message_receives(
            boost::bind(&parcelport::get_message_receive_count, &pp_));

        HPX_STD_FUNCTION<boost::int64_t()> sending_time(
            boost::bind(&parcelport::get_sending_time, &pp_));
        HPX_STD_FUNCTION<boost::int64_t()> receiving_time(
            boost::bind(&parcelport::get_receiving_time, &pp_));

        HPX_STD_FUNCTION<boost::int64_t()> sending_serialization_time(
            boost::bind(&parcelport::get_sending_serialization_time, &pp_));
        HPX_STD_FUNCTION<boost::int64_t()> receiving_serialization_time(
            boost::bind(&parcelport::get_receiving_serialization_time, &pp_));

        HPX_STD_FUNCTION<boost::int64_t()> data_sent(
            boost::bind(&parcelport::get_data_sent, &pp_));
        HPX_STD_FUNCTION<boost::int64_t()> data_received(
            boost::bind(&parcelport::get_data_received, &pp_));

        HPX_STD_FUNCTION<boost::int64_t()> queue_length(
            boost::bind(&parcelhandler::get_queue_length, this));

        performance_counters::generic_counter_type_data const counter_types[] =
        {
            { "/parcels/count/sent", performance_counters::counter_raw,
              "returns the number of sent parcels for the referenced locality",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, num_parcel_sends, _2),
              &performance_counters::locality_counter_discoverer,
              ""
            },
            { "/parcels/count/received", performance_counters::counter_raw,
              "returns the number of received parcels for the referenced locality",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, num_parcel_receives, _2),
              &performance_counters::locality_counter_discoverer,
              ""
            },
            { "/messages/count/sent", performance_counters::counter_raw,
              "returns the number of sent messages for the referenced locality",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, num_message_sends, _2),
              &performance_counters::locality_counter_discoverer,
              ""
            },
            { "/messages/count/received", performance_counters::counter_raw,
              "returns the number of received messages for the referenced locality",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, num_message_receives, _2),
              &performance_counters::locality_counter_discoverer,
              ""
            },

            { "/time/data/sent", performance_counters::counter_raw,
              "returns the total time between the start of each asynchronous "
              "write and the invocation of the write callback for the referenced "
              "locality",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, sending_time, _2),
              &performance_counters::locality_counter_discoverer,
              "ns"
            },
            { "/time/data/received", performance_counters::counter_raw,
              "returns the total time between the start of each asynchronous "
              "read and the invocation of the read callback for the referenced "
              "locality",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, receiving_time, _2),
              &performance_counters::locality_counter_discoverer,
              "ns"
            },
            { "/time/serialize/sent", performance_counters::counter_raw,
              "returns the total time required to serialize all sent parcels "
              "for the referenced locality",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, sending_serialization_time, _2),
              &performance_counters::locality_counter_discoverer,
              "ns"
            },
            { "/time/serialize/received", performance_counters::counter_raw,
              "returns the total time required to de-serialize all received "
              "parcels for the referenced locality",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, receiving_serialization_time, _2),
              &performance_counters::locality_counter_discoverer,
              "ns"
            },

            { "/data/size/sent", performance_counters::counter_raw,
              "returns the amount of parcel data (including headers) sent "
              "by the referenced locality",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, data_sent, _2),
              &performance_counters::locality_counter_discoverer,
              "bytes"
            },
            { "/data/size/received", performance_counters::counter_raw,
              "returns the amount of parcel data (including headers) received "
              "by the referenced locality",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, data_received, _2),
              &performance_counters::locality_counter_discoverer,
              "bytes"
            },

            { "/parcelqueue/length", performance_counters::counter_raw,
              "returns the number current length of the queue of incoming threads",
              HPX_PERFORMANCE_COUNTER_V1,
              boost::bind(&performance_counters::locality_raw_counter_creator,
                  _1, queue_length, _2),
              &performance_counters::locality_counter_discoverer,
              ""
            }
        };
        performance_counters::install_counter_types(
            counter_types, sizeof(counter_types)/sizeof(counter_types[0]));
    }