diff --git a/example/linux/gw-example/main.c b/example/linux/gw-example/main.c index ee505b3..e98475c 100644 --- a/example/linux/gw-example/main.c +++ b/example/linux/gw-example/main.c @@ -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"; @@ -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) { diff --git a/example/linux/proto-api/main.c b/example/linux/proto-api/main.c index 1002cb9..99d6b39 100644 --- a/example/linux/proto-api/main.c +++ b/example/linux/proto-api/main.c @@ -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 */ @@ -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; diff --git a/lib/api/wpc_proto.h b/lib/api/wpc_proto.h index c0383d7..f59dffb 100644 --- a/lib/api/wpc_proto.h +++ b/lib/api/wpc_proto.h @@ -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; @@ -71,6 +72,10 @@ 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, @@ -78,7 +83,9 @@ 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); /** * \brief close protobuf interface diff --git a/lib/wpc_proto/internal_modules/proto_otap.c b/lib/wpc_proto/internal_modules/proto_otap.c index b16df25..2515c56 100644 --- a/lib/wpc_proto/internal_modules/proto_otap.c +++ b/lib/wpc_proto/internal_modules/proto_otap.c @@ -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; diff --git a/lib/wpc_proto/wpc_proto.c b/lib/wpc_proto/wpc_proto.c index 5f08c1c..fb1aadb 100644 --- a/lib/wpc_proto/wpc_proto.c +++ b/lib/wpc_proto/wpc_proto.c @@ -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; }