Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix many entities #179

Open
wants to merge 13 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion controller/app/cmdline/src/cmd_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ cmd_line::cmd_line()

cmd_line::cmd_line(void (*notification_callback) (void *, int32_t, uint64_t, uint16_t, uint16_t, uint16_t, uint32_t, void *),
void (*log_callback) (void *, int32_t, const char *, int32_t),
bool test_mode, char *interface, int32_t log_level)
bool test_mode, char *interface, int32_t log_level, int32_t pacing)
: test_mode(test_mode)
, output_redirected(false)
{
Expand All @@ -108,6 +108,7 @@ cmd_line::cmd_line(void (*notification_callback) (void *, int32_t, uint64_t, uin

atomic_cout << "AVDECC Controller version: " << controller_obj->get_version() << std::endl;
print_interfaces_and_select(interface);
sys->discovery_pacing(pacing);
sys->process_start();
}

Expand Down
2 changes: 1 addition & 1 deletion controller/app/cmdline/src/cmd_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class cmd_line
*/
cmd_line(void (*notification_callback) (void *, int32_t, uint64_t, uint16_t, uint16_t, uint16_t, uint32_t, void *),
void (*log_callback) (void *, int32_t, const char *, int32_t),
bool test_mode, char *interface, int32_t log_level);
bool test_mode, char *interface, int32_t log_level, int32_t pacing);

~cmd_line();

Expand Down
9 changes: 7 additions & 2 deletions controller/app/cmdline/src/cmd_line_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ static void usage(char *argv[])
std::cerr << " -t : Sets test mode which disables checks" << std::endl;
std::cerr << " -i interface : Sets the name of the interface to use" << std::endl;
std::cerr << " -l log_level : Sets the log level to use." << std::endl;
std::cerr << " -p pacing : Sets packets per second for startup endstation enumeration." << std::endl;
std::cerr << log_level_help << std::endl;
exit(1);
}
Expand All @@ -225,8 +226,9 @@ int main(int argc, char *argv[])
char *interface = NULL;
int c = 0;
int32_t log_level = avdecc_lib::LOGGING_LEVEL_ERROR;
int32_t pacing = -1;

while ((c = getopt(argc, argv, "ti:l:")) != -1) {
while ((c = getopt(argc, argv, "ti:l:p:")) != -1) {
switch (c) {
case 't':
test_mode = true;
Expand All @@ -237,6 +239,9 @@ int main(int argc, char *argv[])
case 'l':
log_level = atoi(optarg);
break;
case 'p':
pacing = atoi(optarg);
break;
case ':':
fprintf(stderr, "Option -%c requires an operand\n", optopt);
error++;
Expand Down Expand Up @@ -264,7 +269,7 @@ int main(int argc, char *argv[])
}

cmd_line avdecc_cmd_line_ref(notification_callback, log_callback,
test_mode, interface, log_level);
test_mode, interface, log_level, pacing);

std::vector<std::string> input_argv;
size_t pos = 0;
Expand Down
6 changes: 6 additions & 0 deletions controller/lib/include/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ namespace avdecc_lib
*/
AVDECC_CONTROLLER_LIB32_API virtual int STDCALL get_last_resp_status() = 0;

/**
* Limit background endstation enumeration packet rate.
* \param packets_per_second The number of packets per second. Minimum value is 10.
*/
AVDECC_CONTROLLER_LIB32_API virtual void STDCALL discovery_pacing(int packets_per_second) = 0;

/**
* Start point of the system process, which calls the thread initialization function.
*/
Expand Down
101 changes: 101 additions & 0 deletions controller/lib/src/discovery_pacer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Licensed under the MIT License (MIT)
*
* Copyright (c) 2015 AudioScience Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/**
* discovery pacer.h
*
* This class supports pacing the rate at which background enumeration sends packets.
*
*/

#pragma once

#include "timer.h"

namespace avdecc_lib
{
class discovery_pacer
{
public:
static discovery_pacer& getInstance() {
// The only instance
// Guaranteed to be lazy initialized
// Guaranteed that it will be destroyed correctly
static discovery_pacer instance;
return instance;
}

bool ok_to_send_packet(void) {
if (m_packets_per_second < 0)
return true;
if (m_packets_available > 0)
{
m_packets_available--;
return true;
}
else
{
return false;
}
};

void set_packets_per_second(int pps, int tick_rate_ms)
{
if (m_packets_per_second < 0)
{
m_timestamp = timer::clk_convert_to_ms(timer::clk_monotonic());
}
m_packets_per_second = pps;
m_packets_per_tick = pps * 1000 / tick_rate_ms;
// never go as low as zero packets per tick
if (0 == m_packets_per_tick)
m_packets_per_tick = 1;
};

void tick(void)
{
uint32_t the_time = timer::clk_convert_to_ms(timer::clk_monotonic());
if (the_time != m_timestamp)
{
m_packets_available += (m_packets_per_second * 1000) / (the_time - m_timestamp);
if (m_packets_available > m_packets_per_tick)
m_packets_available = m_packets_per_tick;
}
m_timestamp = the_time;
};

private:
// Private Constructor
discovery_pacer(){ m_packets_per_second = -1; }; // by default pacing is disabled
// Stop the compiler generating methods of copy the object
discovery_pacer(discovery_pacer const& copy); // Not Implemented
discovery_pacer& operator=(discovery_pacer const& copy); // Not Implemented

int m_packets_per_second; // -1 implies no pacing
int m_packets_per_tick; // packets per timer tick
int m_packets_available; // current packets available to send
uint32_t m_timestamp; // last timestamp


};
}
34 changes: 21 additions & 13 deletions controller/lib/src/end_station_imp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "system_tx_queue.h"
#include "jdksavdecc.h"
#include "end_station_imp.h"
#include "discovery_pacer.h"

namespace avdecc_lib
{
Expand Down Expand Up @@ -71,7 +72,8 @@ namespace avdecc_lib
selected_entity_index = 0;
selected_config_index = 0;

read_desc_init(JDKSAVDECC_DESCRIPTOR_ENTITY, 0);
queue_background_read_request(JDKSAVDECC_DESCRIPTOR_ENTITY, 0, 1);
background_read_submit_pending();

return 0;
}
Expand Down Expand Up @@ -407,9 +409,21 @@ namespace avdecc_lib
// check inflight timeout
if (b->m_timer.timeout())
{
log_imp_ref->post_log_msg(LOGGING_LEVEL_ERROR, "Background read timeout reading descriptor %s index %d\n", utility::aem_desc_value_to_name(b->m_type), b->m_index);
ii = m_backbround_read_inflight.erase(ii);
delete b;
/* If read times out, resubmit it. Using 1 second timeouts set in background_read_submit_pending(), so no great load here. */
b->m_resubmit_count++;
if (b->m_resubmit_count < 10)
{
log_imp_ref->post_log_msg(LOGGING_LEVEL_ERROR, "Background read timeout (resubmit %d) reading descriptor %s index %d from 0x%llx\n",
b->m_resubmit_count, utility::aem_desc_value_to_name(b->m_type), b->m_index, this->end_station_entity_id);
m_backbround_read_pending.push_back(b);
}
else
{
log_imp_ref->post_log_msg(LOGGING_LEVEL_ERROR, "Background read timeout (terminate) reading descriptor %s index %d from 0x%llx\n",
utility::aem_desc_value_to_name(b->m_type), b->m_index, this->end_station_entity_id);
delete b;
}
}
else
{
Expand Down Expand Up @@ -450,22 +464,16 @@ namespace avdecc_lib
// empty submit the next set of read operations
if (m_backbround_read_inflight.empty() && !m_backbround_read_pending.empty())
{
background_read_request *b_first = m_backbround_read_pending.front();
m_backbround_read_pending.pop_front();
log_imp_ref->post_log_msg(LOGGING_LEVEL_DEBUG, "Background read of %s index %d", utility::aem_desc_value_to_name(b_first->m_type), b_first->m_index);
read_desc_init(b_first->m_type, b_first->m_index);
b_first->m_timer.start(750); // 750 ms timeout (1722.1 timeout is 250ms)
m_backbround_read_inflight.push_back(b_first);

if (!m_backbround_read_pending.empty())
uint16_t first_type = m_backbround_read_pending.front()->m_type;
if (!m_backbround_read_pending.empty() && discovery_pacer::getInstance().ok_to_send_packet())
{
background_read_request *b_next = m_backbround_read_pending.front();
while (b_next->m_type == b_first->m_type)
while (b_next->m_type == first_type)
{
m_backbround_read_pending.pop_front();
log_imp_ref->post_log_msg(LOGGING_LEVEL_DEBUG, "Background read of %s index %d", utility::aem_desc_value_to_name(b_next->m_type), b_next->m_index);
read_desc_init(b_next->m_type, b_next->m_index);
b_next->m_timer.start(750); // 750 ms timeout (1722.1 timeout is 250ms)
b_next->m_timer.start(1000); // 1000 ms timeout (1722.1 timeout is 250ms)
m_backbround_read_inflight.push_back(b_next);
if (m_backbround_read_pending.empty())
{
Expand Down
9 changes: 5 additions & 4 deletions controller/lib/src/end_station_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ namespace avdecc_lib
class background_read_request
{
public:
background_read_request(uint16_t t, uint16_t I) :
m_type(t), m_index(I) {};
uint16_t m_type;
uint16_t m_index;
background_read_request(uint16_t t, uint16_t I) :
m_type(t), m_index(I) {m_resubmit_count = 0;};
uint16_t m_type;
uint16_t m_index;
uint16_t m_resubmit_count;
timer m_timer;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#include "system_message_queue.h"
#include "system_tx_queue.h"
#include "system_layer2_multithreaded_callback.h"

#include "discovery_pacer.h"

namespace avdecc_lib
{
Expand Down Expand Up @@ -185,6 +185,10 @@ namespace avdecc_lib
return resp_status_for_cmd;
}

void STDCALL system_layer2_multithreaded_callback::discovery_pacing(int packets_per_second)
{
discovery_pacer::getInstance().set_packets_per_second(packets_per_second, TIME_PERIOD_25_MILLISECONDS);
}

int system_layer2_multithreaded_callback::timer_start_interval(int timerfd)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ namespace avdecc_lib
*/
int STDCALL get_last_resp_status();

/**
* Limit background endstation enumeration packet rate.
*/
void STDCALL discovery_pacing(int packets_per_second);

/**
* Start point of the system process, which calls the thread initialization function.
*/
Expand Down
2 changes: 1 addition & 1 deletion controller/lib/src/msvc/net_interface_imp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace avdecc_lib

uint16_t ether_type[1];
ether_type[0] = JDKSAVDECC_AVTP_ETHERTYPE;
set_capture_ether_type(ether_type, 0); // Set the filter
set_capture_ether_type(ether_type, 1); // Set the filter

free(AdapterInfo);
return 0;
Expand Down
Loading