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

samples: cellular: udp: cleanup and add way to shutdown modem #13066

Merged
merged 3 commits into from
Dec 20, 2023
Merged

samples: cellular: udp: cleanup and add way to shutdown modem #13066

merged 3 commits into from
Dec 20, 2023

Conversation

MirkoCovizzi
Copy link
Contributor

@MirkoCovizzi MirkoCovizzi commented Nov 13, 2023

This commit adds a new Kconfig option for configuring
the number of data transmissions to the server.
Shutdown the modem library when there are no more
transmissions to execute.
Moved sample to CI-iot-samples-test plan.

@MirkoCovizzi MirkoCovizzi self-assigned this Nov 13, 2023
@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Nov 13, 2023
@MirkoCovizzi MirkoCovizzi removed the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Nov 13, 2023
@NordicBuilder
Copy link
Contributor

NordicBuilder commented Nov 13, 2023

Test specification

CI/Jenkins/NRF

  • Integration Platforms

CI/Jenkins/integration

Test Module File based changes Manually selected West overwrite
test-fw-nrfconnect-nrf-iot_samples X

Detailed information of selected test modules

Note: This message is automatically posted and updated by the CI

@github-actions github-actions bot added the doc-required PR must not be merged without tech writer approval. label Nov 13, 2023
@MirkoCovizzi MirkoCovizzi changed the title samples: cellular: udp: move function samples: cellular: udp: cleanup and add way to shutdown modem Nov 13, 2023
Comment on lines 131 to 142
static bool is_nrf9160(void)
{
char resp[32];

if (nrf_modem_at_cmd(resp, sizeof(resp), "AT+CGMM") == 0) {
if (strstr(resp, "nRF9160") != NULL) {
return true;
}
}

return false;
}
Copy link
Contributor

@lemrey lemrey Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sample only works on nRF 9 series boards. It may have had support for qemu_cortex_m3 earlier, but that is no longer the case. I do not see why this function is necessary anymore, can we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update the sample accordingly then. I was under the assumption that qemu target was still required.

Comment on lines 17 to 23
config UDP_DATA_UPLOAD_FOREVER
bool "Enable that data is transmitted to the server forever"
default y

config UDP_DATA_UPLOAD_ITERATIONS
int "NUmber of data transmissions to the server before shutdown" if !UDP_DATA_UPLOAD_FOREVER
default 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need two entries for this; one config for the number of iterations should be sufficient.
If set to -1 let the loop run forever.

Copy link
Contributor Author

@MirkoCovizzi MirkoCovizzi Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about the -1 idea before, but I don't like the fact that a different value has a completely different behavior. While these two options make sense just by reading their name, in the -1 case the user will have to find such behavior in the documentation instead. I'll think more about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about UDP_DATA_UPLOAD_ITERATIONS_BEFORE_EXIT, then -1 means that the application will not exit after n iterations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MechanicV1 made me aware that the download_client uses -1 already in a similar way

so I updated this sample to align to that.

@@ -239,5 +269,14 @@ int main(void)

k_work_schedule(&socket_transmission_work, K_NO_WAIT);

#if defined(CONFIG_NRF_MODEM_LIB) && !defined(CONFIG_UDP_DATA_UPLOAD_FOREVER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove all the occurrences where we check for NRF_MODEM_LIB. This sample runs only on nRF9 series boards, so this is always defined. Keep it a separate commit if you can.

Comment on lines 194 to 205
static int modem_shutdown(void)
{
int err;

err = nrf_modem_lib_shutdown();
if (err) {
printk("Failed to shutdown modem library, error: %d\n", err);
return err;
}

return 0;
}
Copy link
Contributor

@lemrey lemrey Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point to define this function to call nrf_modem_lib_shutdown(); just call nrf_modem_lib_shutdown() directly.

@NordicBuilder
Copy link
Contributor

You can find the documentation preview for this PR at this link. It will be updated about 10 minutes after the documentation build succeeds.

Note: This comment is automatically posted by the Documentation Publishing GitHub Action.

samples/cellular/udp/Kconfig Outdated Show resolved Hide resolved
Comment on lines 17 to 23
config UDP_DATA_UPLOAD_FOREVER
bool "Enable that data is transmitted to the server forever"
default y

config UDP_DATA_UPLOAD_ITERATIONS
int "NUmber of data transmissions to the server before shutdown" if !UDP_DATA_UPLOAD_FOREVER
default 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about UDP_DATA_UPLOAD_ITERATIONS_BEFORE_EXIT, then -1 means that the application will not exit after n iterations.

samples/cellular/udp/Kconfig Outdated Show resolved Hide resolved
samples/cellular/udp/Kconfig Outdated Show resolved Hide resolved
Comment on lines 68 to 80
if (data_upload_iterations > 0) {
data_upload_iterations--;
goto transmit;
} else if (data_upload_iterations == 0) {
k_sem_give(&modem_shutdown_sem);
return;
} else if (data_upload_iterations < 0) {
goto transmit;
}
Copy link
Contributor

@eivindj-nordic eivindj-nordic Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last else if is not strictly necessary. We could instead do:

Suggested change
if (data_upload_iterations > 0) {
data_upload_iterations--;
goto transmit;
} else if (data_upload_iterations == 0) {
k_sem_give(&modem_shutdown_sem);
return;
} else if (data_upload_iterations < 0) {
goto transmit;
}
if (data_upload_iterations == 0) {
k_sem_give(&modem_shutdown_sem);
return;
}
if (data_upload_iterations > 0) {
data_upload_iterations--;
}

Not sure what is clearest.

@MirkoCovizzi MirkoCovizzi requested a review from a team as a code owner November 24, 2023 14:14
Comment on lines 77 to 80
/* Transmit indefinitely. */
if (CONFIG_UDP_DATA_UPLOAD_ITERATIONS == -1) {
goto transmit;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary

config UDP_DATA_UPLOAD_ITERATIONS
int "Number of data transmissions to the server before shutdown"
range -1 2147483647
default -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the sample should terminate by default, so that we can run it in CI.

Copy link
Contributor Author

@MirkoCovizzi MirkoCovizzi Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MechanicV1 From CI point of view should this sample terminate by default? Or can CI configure it locally?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI can change the Kconfig value when building it. Though many other samples are terminating by default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test automation will take care of setting the Kconfig ! @MirkoCovizzi

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should implement the same behavior as other sample. It's easy enough to change that for users if needed.
CI might want to override the value anyway to shorten the time it takes to complete the test.

config UDP_DATA_UPLOAD_ITERATIONS
int "Number of data transmissions to the server before shutdown"
range -1 2147483647
default -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test automation will take care of setting the Kconfig ! @MirkoCovizzi

@shanthanordic shanthanordic requested review from jorgenmk and removed request for a team November 30, 2023 20:47
@@ -316,6 +316,10 @@ Cellular samples

* Added the configuration overlay file :file:`overlay-supl.conf` for building the sample with SUPL assistance support.

* :ref:`udp` sample:

* Added the :kconfig:option:`CONFIG_UDP_DATA_UPLOAD_ITERATIONS` Kconfig option for configuring the number of data transmissions to the server.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Added the :kconfig:option:`CONFIG_UDP_DATA_UPLOAD_ITERATIONS` Kconfig option for configuring the number of data transmissions to the server.
* Added the :ref:`CONFIG_UDP_DATA_UPLOAD_ITERATIONS <CONFIG_UDP_DATA_UPLOAD_ITERATIONS>` Kconfig option for configuring the number of data transmissions to the server.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@divipillai Is this the new standard syntax to use from now on?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the way to represent the application-specific Kconfig options. For example, for UDP sample, the ones that are defined here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/cellular/udp/README.html#configuration. The Kconfig options defined in the Kconfig reference (library-specific) are provided with the ":kconfig:option:" syntax.


CONFIG_UDP_DATA_UPLOAD_ITERATIONS - UDP data upload iterations configuration
This configuration option sets the number of times the sample transmits data to the server before shutting down.
Set to -1 to transmit indefinitely.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Set to -1 to transmit indefinitely.
Set to ``-1`` to transmit indefinitely.

This commit adds a new Kconfig option for configuring
the number of data transmissions to the server.
Shutdown the modem library when there are no more
transmissions to execute.

Signed-off-by: Mirko Covizzi <[email protected]>
This commit aligns the semaphore naming convention.

Signed-off-by: Mirko Covizzi <[email protected]>
This commit moves the cellular/udp sample from
`CI-thingy91-test` to `CI-iot-samples-test`.
This is because now the testing automation
for `samples/cellular` is under the `CI-iot-samples-test`
plan.

Signed-off-by: Mirko Covizzi <[email protected]>
@rlubos rlubos merged commit 04a2450 into nrfconnect:main Dec 20, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-required PR must not be merged without tech writer approval.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants