Skip to content

Commit

Permalink
Merge branch 'master' into emprojectDSP310missssingDot
Browse files Browse the repository at this point in the history
  • Loading branch information
ojousima authored Mar 18, 2023
2 parents f4f9c12 + 31df1af commit 6d84908
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 13 deletions.
141 changes: 141 additions & 0 deletions reviewpad.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# This file is used to configure Reviewpad.
# The configuration is a proposal to help you get started.
# You can use it as a starting point and customize it to your needs.
# For more details see https://docs.reviewpad.com/guides/syntax.

# Define the list of labels to be used by Reviewpad.
# For more details see https://docs.reviewpad.com/guides/syntax#label.
labels:
small:
description: Pull request is small
color: "#76dbbe"
medium:
description: Pull request is medium
color: "#2986cc"
large:
description: Pull request is large
color: "#c90076"

# Define the list of workflows to be run by Reviewpad.
# A workflow is a list of actions that will be executed based on the defined rules.
# For more details see https://docs.reviewpad.com/guides/syntax#workflow.
workflows:
# This workflow praises contributors on their pull request contributions.
# This helps contributors feel appreciated.
- name: praise-contributors-on-milestones
description: Praise contributors based on their contributions
always-run: true
if:
# Praise contributors on their first pull request.
- rule: $pullRequestCountBy($author()) == 1
extra-actions:
- $commentOnce($sprintf("Thank you @%s for this first contribution!", [$author()]))
# Praise contributors on their 100th pull request.
- rule: $pullRequestCountBy($author()) == 100
extra-actions:
- $commentOnce($sprintf("Way to go 🎉 This is your 100th pull request!", [$author()]))

# This workflow validates that pull requests follow the conventional commits specification.
# This helps developers automatically generate changelogs.
# For more details, see https://www.conventionalcommits.org/en/v1.0.0/.
- name: check-conventional-commits
description: Validate that pull requests follow the conventional commits
always-run: true
if:
- rule: $isDraft() == false
then:
# Check commits messages against the conventional commits specification
- $commitLint()
# Check pull request title against the conventional commits specification.
- $titleLint()

# This workflow validates best practices for pull request management.
# This helps developers follow best practices.
- name: best-practices
description: Validate best practices for pull request management
always-run: true
if:
# Warn pull requests that do not have an associated GitHub issue.
- rule: $hasLinkedIssues() == false
extra-actions:
- $warn("Please link an issue to the pull request")
# Warn pull requests if their description is empty.
- rule: $description() == ""
extra-actions:
- $warn("Please provide a description for the pull request")
# Warn pull request do not have a clean linear history.
- rule: $hasLinearHistory() == false
extra-actions:
- $warn("Please rebase your pull request on the latest changes")

# This workflow labels pull requests based on the total number of lines changed.
# This helps pick pull requests based on their size and to incentivize small pull requests.
- name: size-labeling
description: Label pull request based on the number of lines changed
always-run: true
if:
- rule: $size() < 100
extra-actions:
- $removeLabels(["medium", "large"])
- $addLabel("small")
- rule: $size() >= 100 && $size() < 300
extra-actions:
- $removeLabels(["small", "large"])
- $addLabel("medium")
- rule: $size() >= 300
extra-actions:
- $removeLabels(["small", "medium"])
- $addLabel("large")

# This workflow assigns a random reviewer to pull requests.
# This helps guarantee that most pull requests are reviewed by at least one person.
- name: reviewer-assignment
description: Assign a reviewer to pull requests
always-run: true
if:
# Automatically assign a random reviewer when the pull request is ready for review;
- rule: $isDraft() == false
extra-actions:
- $assignRandomReviewer()

# This workflow signals pull requests waiting for reviews.
# This helps guarantee that pull requests are reviewed and approved by at least one person.
- name: check-approvals
description: Check that pull requests have the required number of approvals
always-run: true
if:
# Label pull requests with `waiting-for-review` if there are no approvals;
- rule: $isDraft() == false && $approvalsCount() < 1
extra-actions:
- $addLabel("waiting-for-review")

# This workflow labels pull requests based on the pull request change type.
# This helps pick pull requests based on their change type.
- name: change-type-labelling
description: Label pull requests based on the type of changes
always-run: true
if:
# Label pull requests with `docs` if they only modify Markdown or txt files.
- rule: $hasFileExtensions([".md", ".txt"])
extra-actions:
- $addLabel("docs")
# Label pull requests with `infra` if they modify Terraform files.
- rule: $hasFileExtensions([".tf"])
extra-actions:
- $addLabel("infra")
# Label pull requests with `dependencies` if they only modify `package.json` and `package.lock` files.
- rule: $hasFileExtensions(["package.json", "package-lock.json"])
extra-actions:
- $addLabel("dependencies")


# This workflow validates that pull requests do not contain changes to the license.
# This helps avoid unwanted license modifications.
- name: license-validation
description: Validate that licenses are not modified
always-run: true
if:
# Fail Reviewpad check on pull requests that modify any LICENSE;
- rule: $hasFilePattern("**/LICENSE*")
extra-actions:
- $fail("License files cannot be modified")
2 changes: 1 addition & 1 deletion src/app_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ ri_gpio_slope_t get_activation (const ri_gpio_evt_t * const evt)

if (ii < RB_BUTTONS_NUMBER)
{
activation = (states[ii] == RI_GPIO_HIGH) ? RI_GPIO_SLOPE_LOTOHI :
activation = (states[ii] == RI_GPIO_HIGH) ? RI_GPIO_SLOPE_LOTOHI : //-V547
RI_GPIO_SLOPE_HITOLO;
}
else
Expand Down
23 changes: 22 additions & 1 deletion src/app_comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ TESTABLE_STATIC void handle_comms (const ri_comm_xfer_fp_t reply_fp, void * p_da
{
// Stop heartbeat processing.
err_code |= app_heartbeat_stop();
#if APP_GATT_ENABLED
// Switch GATT to faster params.
err_code |= ri_gatt_params_request (RI_GATT_TURBO, CONN_PARAM_UPDATE_DELAY_MS);
#endif
// Parse message type.
re_type_t type = raw_message[RE_STANDARD_DESTINATION_INDEX];

Expand Down Expand Up @@ -314,7 +316,9 @@ TESTABLE_STATIC void handle_comms (const ri_comm_xfer_fp_t reply_fp, void * p_da
}

// Switch GATT to slower params.
#if APP_GATT_ENABLED
err_code |= ri_gatt_params_request (RI_GATT_LOW_POWER, 0);
#endif
// Resume heartbeat processing.
err_code |= app_heartbeat_start();
}
Expand Down Expand Up @@ -471,6 +475,18 @@ TESTABLE_STATIC void on_nfc_tx_done_isr (void * p_data, size_t data_len)
{
m_tx_done = true;
}

TESTABLE_STATIC void handle_nfc_data (void * p_data, uint16_t data_len)
{
handle_comms (&rt_nfc_send, p_data, data_len);
}

TESTABLE_STATIC void on_nfc_data_isr (void * p_data, size_t data_len)
{
rd_status_t err_code = RD_SUCCESS;
err_code |= ri_scheduler_event_put (p_data, (uint16_t) data_len, &handle_nfc_data);
RD_ERROR_CHECK (err_code, RD_SUCCESS);
}
#endif

rd_status_t app_comms_configure_next_enable (void)
Expand All @@ -493,14 +509,16 @@ rd_status_t app_comms_configure_next_disable (void)
TESTABLE_STATIC void handle_config_disable (void * p_data, uint16_t data_len)
{
rd_status_t err_code = RD_SUCCESS;

// Do not kick out current connection, disconnect handler
// will disable config.
#if APP_GATT_ENABLED

if (!rt_gatt_nus_is_connected())
{
err_code |= enable_config_on_next_conn (false);
}

#endif
RD_ERROR_CHECK (err_code, RD_SUCCESS);
}

Expand Down Expand Up @@ -553,6 +571,7 @@ static rd_status_t nfc_init (ri_comm_dis_init_t * const p_dis)
rt_nfc_set_on_connected_isr (&on_nfc_connected_isr);
rt_nfc_set_on_disconn_isr (&on_nfc_disconnected_isr);
rt_nfc_set_on_sent_isr (&on_nfc_tx_done_isr);
rt_nfc_set_on_received_isr (&on_nfc_data_isr);
#endif
return err_code;
}
Expand Down Expand Up @@ -681,7 +700,9 @@ rd_status_t app_comms_ble_uninit (void)
{
rd_status_t err_code = RD_SUCCESS;
err_code |= rt_adv_uninit();
#if APP_GATT_ENABLED
err_code |= rt_gatt_uninit();
#endif
return err_code;
}

Expand Down
2 changes: 2 additions & 0 deletions src/app_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ void handle_gatt_connected (void * p_data, uint16_t data_len);
void handle_gatt_disconnected (void * p_data, uint16_t data_len);
void handle_nfc_connected (void * p_data, uint16_t data_len);
void handle_nfc_disconnected (void * p_data, uint16_t data_len);
void handle_nfc_data (void * p_data, uint16_t data_len);
void on_nfc_connected_isr (void * p_data, size_t data_len);
void on_nfc_disconnected_isr (void * p_data, size_t data_len);
void on_nfc_tx_done_isr (void * p_data, size_t data_len);
void on_nfc_data_isr (void * p_data, size_t data_len);
void comm_mode_change_isr (void * const p_context);
void handle_comms (const ri_comm_xfer_fp_t reply_fp, void * p_data, size_t data_len);
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/application_config/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
# define APP_SENSOR_NRF52_DSP_PARAM (1U) //!< Only 1 is valid with LAST
#endif
#ifndef APP_SENSOR_NRF52_MODE
# define APP_SENSOR_NRF52_MODE RD_SENSOR_CFG_CONTINUOUS //!< SHTC runs in single-shot mode internally, update data automatically on fetch.
# define APP_SENSOR_NRF52_MODE RD_SENSOR_CFG_CONTINUOUS //!< NRF runs in single-shot mode internally, update data automatically on fetch.
#endif
#ifndef APP_SENSOR_NRF52_RESOLUTION
# define APP_SENSOR_NRF52_RESOLUTION RD_SENSOR_CFG_DEFAULT //!< Only default resolution supported.
Expand Down Expand Up @@ -314,13 +314,13 @@
# define APP_COMMS_BIDIR_ENABLED ((APP_GATT_ENABLED) + (APP_NFC_ENABLED))
#endif

/** @brief Enable Flash tasks if there is storage space */
/** @brief Enable Flash tasks if there is storage space. GATT also requires flash */
#ifndef RT_FLASH_ENABLED
# define RT_FLASH_ENABLED (RB_FLASH_SPACE_AVAILABLE > RB_FLASH_SPACE_SMALL)
#endif

/** @brief Enable Ruuvi Flash interface. */
#define RI_FLASH_ENABLED RT_FLASH_ENABLED
#define RI_FLASH_ENABLED ((RT_FLASH_ENABLED) + (APP_GATT_ENABLED))

// ***** Flash storage constants *****/

Expand Down
6 changes: 4 additions & 2 deletions src/application_config/application_mode_longlife.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

#define APP_BLE_INTERVAL_MS (1285U * 7U) //8995 ms, longest allowed divisible by 1285

#define APP_NUM_REPEATS 7 // ~63 s
#define APP_NUM_REPEATS (7U) // ~63 s

#define APP_LOG_INTERVAL_S (15U * 60U) // 15 minutes
#define APP_GATT_ENABLED (0U)

#define RT_FLASH_ENABLED (0U)

#endif
36 changes: 30 additions & 6 deletions test/test_app_comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void tearDown (void)



static rd_status_t dummy_comm (ri_comm_message_t * const msg)
static rd_status_t dummy_comm_gatt (ri_comm_message_t * const msg)
{
rd_status_t err_code = RD_SUCCESS;

Expand Down Expand Up @@ -156,6 +156,7 @@ static void nfc_init_Expect (ri_comm_dis_init_t * p_dis)
rt_nfc_set_on_connected_isr_Expect (&on_nfc_connected_isr);
rt_nfc_set_on_disconn_isr_Expect (&on_nfc_disconnected_isr);
rt_nfc_set_on_sent_isr_Expect (&on_nfc_tx_done_isr);
rt_nfc_set_on_received_isr_Expect (&on_nfc_data_isr);
#endif
}

Expand Down Expand Up @@ -332,7 +333,7 @@ void test_handle_gatt_password_ok (void)
app_comms_configure_next_enable_Expect ();
ri_gatt_params_request_ExpectAndReturn (RI_GATT_LOW_POWER, 0, RD_ERROR_INVALID_STATE);
app_heartbeat_start_ExpectAndReturn (RD_SUCCESS);
handle_comms (&dummy_comm, mock_data, sizeof (mock_data));
handle_comms (&dummy_comm_gatt, mock_data, sizeof (mock_data));
TEST_ASSERT (m_config_enabled_on_next_conn);
}

Expand All @@ -350,7 +351,7 @@ void test_handle_gatt_password_denied (void)
app_comms_configure_next_disable_Expect ();
ri_gatt_params_request_ExpectAndReturn (RI_GATT_LOW_POWER, 0, RD_ERROR_INVALID_STATE);
app_heartbeat_start_ExpectAndReturn (RD_SUCCESS);
handle_comms (&dummy_comm, mock_data, sizeof (mock_data));
handle_comms (&dummy_comm_gatt, mock_data, sizeof (mock_data));
TEST_ASSERT (!m_config_enabled_on_next_conn);
}

Expand Down Expand Up @@ -445,6 +446,29 @@ void test_handle_nfc_disconnected (void)
TEST_ASSERT (m_mode_ops.disable_config);
}

void test_on_nfc_received_isr (void)
{
uint8_t data[RI_SCHEDULER_SIZE];
ri_scheduler_event_put_ExpectAndReturn (data, sizeof (data), &handle_nfc_data,
RD_SUCCESS);
RD_ERROR_CHECK_EXPECT (RD_SUCCESS, RD_SUCCESS);
on_nfc_data_isr (data, sizeof (data));
}

void test_handle_nfc_data_acceleration (void)
{
uint8_t mock_data[RE_STANDARD_MESSAGE_LENGTH] = {0};
mock_data[RE_STANDARD_DESTINATION_INDEX] = RE_STANDARD_DESTINATION_ACCELERATION;
mock_data[RE_STANDARD_OPERATION_INDEX] = RE_STANDARD_VALUE_READ;
app_heartbeat_stop_ExpectAndReturn (RD_SUCCESS);
ri_gatt_params_request_ExpectAndReturn (RI_GATT_TURBO, (30 * 1000), RD_SUCCESS);
app_sensor_handle_ExpectAndReturn (&rt_nfc_send, mock_data,
sizeof (mock_data), RD_SUCCESS);
ri_gatt_params_request_ExpectAndReturn (RI_GATT_LOW_POWER, 0, RD_SUCCESS);
app_heartbeat_start_ExpectAndReturn (RD_SUCCESS);
handle_nfc_data (mock_data, sizeof (mock_data));
}

void test_app_comm_configurable_gatt_after_nfc (void)
{
ri_scheduler_event_put_ExpectAndReturn (NULL, 0, &handle_nfc_connected, RD_SUCCESS);
Expand All @@ -467,7 +491,7 @@ void test_app_comms_blocking_send_ok (void)
ri_rtc_millis_ExpectAndReturn (1000);
ri_rtc_millis_ExpectAndReturn (2000);
// reply_fp would actually return ERROR_NULL, but we can mock around it in test.
err_code = app_comms_blocking_send (&dummy_comm,
err_code = app_comms_blocking_send (&dummy_comm_gatt,
NULL);
TEST_ASSERT (RD_SUCCESS == err_code);
TEST_ASSERT (1 == m_expect_sends);
Expand All @@ -482,7 +506,7 @@ void test_app_comms_blocking_send_no_mem_once (void)
ri_yield_ExpectAndReturn (RD_SUCCESS);
ri_rtc_millis_ExpectAndReturn (4000);
// reply_fp would actually return ERROR_NULL, but we can mock around it in test.
err_code = app_comms_blocking_send (&dummy_comm,
err_code = app_comms_blocking_send (&dummy_comm_gatt,
NULL);
TEST_ASSERT (RD_SUCCESS == err_code);
TEST_ASSERT (2 == m_expect_sends);
Expand All @@ -505,7 +529,7 @@ void test_app_comms_blocking_send_timeout (void)
ri_yield_ExpectAndReturn (RD_SUCCESS);
ri_rtc_millis_ExpectAndReturn (5500);
// reply_fp would actually return ERROR_NULL, but we can mock around it in test.
err_code = app_comms_blocking_send (&dummy_comm,
err_code = app_comms_blocking_send (&dummy_comm_gatt,
NULL);
TEST_ASSERT ( (RD_ERROR_TIMEOUT | RD_ERROR_NO_MEM) == err_code);
TEST_ASSERT (5 == m_expect_sends);
Expand Down

0 comments on commit 6d84908

Please sign in to comment.