Skip to content

Commit

Permalink
Add parameters to configure max fragment time, and max poll time
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneTriomphe committed Oct 9, 2024
1 parent 07f7c31 commit 5fe17e4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 deletions.
13 changes: 11 additions & 2 deletions example/linux/gw-example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
#define TOPIC_RX_DATA_PREFIX "gw-event/received_data"
#define TOPIC_EVENT_PREFIX "gw-event/status"

/* max default delay to keep incomplete fragmented packet inside our buffers */
#define FRAGMENT_MAX_DURATION_S 45
/* max default delay for poll fail duration */
/* 120s should cover most scratchpad exchanges and image processing. Sink is
not answearing during that time */
#define MAX_POLL_FAIL_DURATION_S 120

// Configuration. It has to be static as it is reused
// to reconnect
static char m_gateway_id[32] = "\0";
Expand Down Expand Up @@ -524,12 +531,14 @@ int main(int argc, char * argv[])
m_gateway_id,
"test_gw",
"v0.1",
"sink0") != APP_RES_PROTO_OK)
"sink0",
MAX_POLL_FAIL_DURATION_S,
FRAGMENT_MAX_DURATION_S
) != APP_RES_PROTO_OK)
{
return -1;
}


// Initialize mutex to protect publish
if (pthread_mutex_init(&m_pub_queue_mutex, &attr) != 0)
{
Expand Down
12 changes: 11 additions & 1 deletion example/linux/proto-api/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ static char * port_name = "/dev/ttyACM0";
#define GATEWAY_VERSION "0.1"
#define SINK_ID "sink0"

/* max default delay to keep incomplete fragmented packet inside our buffers */
#define FRAGMENT_MAX_DURATION_S 45
/* max default delay for poll fail duration */
/* 120s should cover most scratchpad exchanges and image processing. Sink is
not answearing during that time */
#define MAX_POLL_FAIL_DURATION_S 120

static uint8_t m_response_buffer[WPC_PROTO_MAX_RESPONSE_SIZE];

/* Dummy DataRequest generated as followed */
Expand Down Expand Up @@ -69,7 +76,10 @@ int main(int argc, char * argv[])
GATEWAY_ID,
GATEWAY_MODEL,
GATEWAY_VERSION,
SINK_ID) != APP_RES_PROTO_OK)
SINK_ID,
MAX_POLL_FAIL_DURATION_S,
FRAGMENT_MAX_DURATION_S
) != APP_RES_PROTO_OK)

return -1;

Expand Down
9 changes: 8 additions & 1 deletion lib/api/wpc_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef enum
APP_RES_PROTO_RESPONSE_BUFFER_TOO_SMALL,
APP_RES_PROTO_NOT_ENOUGH_MEMORY,
APP_RES_PROTO_NOT_IMPLEMENTED,
APP_RES_PROTO_WRONG_PARAMETER,
} app_proto_res_e;


Expand All @@ -71,14 +72,20 @@ typedef enum
* Pointer to gateway version string, "" if not available
* \param[in] sink_id
* Pointer to the sink id string
* \param[in] max_poll_fail_duration_s
* Maximum duration in seconds for poll failure
* \param[in] max_fragment_duration_s
* Maximum duration in seconds for fragment reassembly
* \return Return code of the operation
*/
app_proto_res_e WPC_Proto_initialize(const char * port_name,
unsigned long bitrate,
char * gateway_id,
char * gateway_model,
char * gateway_version,
char * sink_id);
char * sink_id,
unsigned int max_poll_fail_duration_s,
unsigned int max_fragment_duration_s);

/**
* \brief close protobuf interface
Expand Down
2 changes: 1 addition & 1 deletion lib/wpc_proto/internal_modules/proto_otap.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static app_res_e handle_scratchpad_chunk(uint8_t * chunk,
/* Check chunk is from valid scratchpad */
if (seq != m_scratchpad_load_current_seq)
{
LOGE("Invalid scratcpad seq %u vs %u expected\n",
LOGE("Invalid scratchpad seq %u vs %u expected\n",
seq,
m_scratchpad_load_current_seq);
return APP_RES_INVALID_SEQ;
Expand Down
25 changes: 19 additions & 6 deletions lib/wpc_proto/wpc_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,36 @@ app_proto_res_e WPC_Proto_initialize(const char * port_name,
char * gateway_id,
char * gateway_model,
char * gateway_version,
char * sink_id)
char * sink_id,
unsigned int max_poll_fail_duration_s,
unsigned int max_fragment_duration_s)
{
if (open_and_check_connection(bitrate, port_name) != 0)
{
return APP_RES_PROTO_WPC_NOT_INITIALIZED;
}

if (WPC_set_max_poll_fail_duration(max_poll_fail_duration_s) != APP_RES_OK)
{
LOGE("Cannot set max poll fail duration (%d)\n", max_poll_fail_duration_s);
return APP_RES_PROTO_WRONG_PARAMETER;
}
if ( WPC_set_max_fragment_duration(max_fragment_duration_s) != APP_RES_OK)
{
LOGE("Cannot set max fragment duration (%d)\n", max_fragment_duration_s);
return APP_RES_PROTO_WRONG_PARAMETER;
}

Common_init(gateway_id, gateway_model, gateway_version, sink_id);
Proto_data_init();
Proto_config_init();
Proto_otap_init();

LOGI("WPC proto initialized with gw_id = %s, gw_model = %s, gw_version = %s and sink_id = %s\n",
gateway_id,
gateway_model,
gateway_version,
sink_id);
LOGI("WPC proto initialized with gw_id = %s\n", gateway_id);
LOGI("gw_model = %s, gw_version = %s and sink_id = %s\n",
gateway_model,
gateway_version,
sink_id);

return APP_RES_PROTO_OK;
}
Expand Down

0 comments on commit 5fe17e4

Please sign in to comment.