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

drivers: modem: gsm: allow using custom modem setup commands #39727

Conversation

bbilas
Copy link
Collaborator

@bbilas bbilas commented Oct 26, 2021

Sometimes there is a need to use a custom setup sequence for the GSM modem so add the possibility to use your own
setup_cmd structure with commands that are required.

Signed-off-by: Bartosz Bilas b.bilas@grinn-global.com

Make modem cmd macros and structures public so that
applications can use them. That is also necessary
for the upcoming support of custom modem setup commands.

Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
Sometimes there is a need to use a custom setup sequence
for the GSM modem so add possibility to use your own
setup_cmd structure with commands that are required.

Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
@bbilas
Copy link
Collaborator Author

bbilas commented Oct 26, 2021

Due to the lack of "request of review" permissions, I have to do that here.
@jukkar
@ycsin

SETUP_CMD(send_cmd_, NULL, NULL, 0U, NULL)

/* series of modem setup commands to run */
struct setup_cmd {
Copy link
Member

Choose a reason for hiding this comment

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

Would be better to prefix that structure name with modem_. The same goes for SETUP_CMD_NOHANDLE and SETUP_CMD.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought that it will be better to make a change in the next MR because in that one I wanted to make those macros public only.

Copy link
Member

Choose a reason for hiding this comment

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

In order to make those macros public, we need to make sure they are in a proper namespace. So I would prefer renaming before making it public.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make sense. Should I do a change to the namespace in the same commit which makes this header public or split it into 2 commits?

Copy link
Member

Choose a reason for hiding this comment

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

As you wish, but I think having that in 2 commits might be easier to review.

Comment on lines +64 to +75
/**
* @brief Set custom modem setup commands.
*
* @param dev: gsm modem device.
* @param data: custom modem setup commands array.
* @param len: length of custom modem setup commands array.
*
* @retval None.
*/
void gsm_ppp_set_custom_setup_cmds(const struct device *dev,
const struct setup_cmd *data,
size_t len);
Copy link
Member

Choose a reason for hiding this comment

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

Is that going to be used by application or modem device drivers? Could you also elaborate or give an example how do you use that function in your case? I mean what exactly do you use as your "custom AT commands" and for what purpose?

Copy link
Collaborator

@ycsin ycsin Oct 27, 2021

Choose a reason for hiding this comment

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

I also wondered how to use this function yesterday, it isn't immediately clear at least, @bbilas maybe you can modify the gsm_modem sample and demonstrate a simple use case there?

Copy link
Collaborator Author

@bbilas bbilas Oct 27, 2021

Choose a reason for hiding this comment

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

It's going to be used by the application, the following example shows how I'm using it:

static const struct setup_cmd telit_setup_cmds[] = {
	/* Use band B20 only to speed-up registration to network */
	SETUP_CMD_NOHANDLE("AT+QCFG=\"band\",0,80000,80000,1"),
	/* Use both NB-IoT and eMTC */
	SETUP_CMD_NOHANDLE("AT+QCFG=\"iotopmode\",2,1"),
	/* Use NB-IoT -> eMTC scan sequence */
	SETUP_CMD_NOHANDLE("AT+QCFG=\"nwscanseq\",0302,1"),
	/* Disable echo */
	SETUP_CMD_NOHANDLE("ATE0"),
};

static int modem_init(const struct device *dev)
{
	modem = DEVICE_DT_GET(DT_NODELABEL(modem_gsm));
	if (!device_is_ready(modem)) {
		LOG_ERR("Modem device not available!");
		return -ENODEV;
	}

	/* Use custom setup commands for telit GSM modem */
	gsm_ppp_set_custom_setup_cmds(modem_gsm, telit_setup_cmds, ARRAY_SIZE(telit_setup_cmds));
	
	gsm_ppp_start(modem);

	return 0;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ycsin I agree that gsm_modem sample should contain some examples, I haven't thought about that. I will try to add it this week.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, not very relevant to this pr, have you ever thought about exposing the AT channel of the modem so that it is possible to configure the modem in application? i.e. enabling/disabling GPS, poll GPIO/ADC pins, modem FOTA, etc

Copy link
Member

Choose a reason for hiding this comment

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

But then we will break the API by replacing command list with callback. I would prefer callback, but let's say it is not a "must-have" from my side.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can't we just have both options? As I know the setup commands mostly don't need extra special logic so the simple commands replacement would be enough for some cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jukkar what is your opinion here?

Copy link
Member

Choose a reason for hiding this comment

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

I do not have big preference here, using callbacks sounds a bit more flexible so I am inclined to that direction. If both options are possible, then +1 to that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mniestroj what is your opinion about having both options? Currently I would be able to get some time to finish at least the current proposition so it's still better to have this one instead of nothing.

@ycsin ycsin requested a review from jukkar October 27, 2021 10:04
@tautologyclub
Copy link
Contributor

I missed this PR because it's not prefixed with gsm_ppp, just so you know.

@tautologyclub
Copy link
Contributor

There's many ways to accomplish this. I will try to submit a PR today with an alternative.

@github-actions
Copy link

github-actions bot commented Jan 4, 2022

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jan 4, 2022
@github-actions github-actions bot closed this Jan 18, 2022
@bbilas bbilas reopened this Jul 7, 2022
@bbilas bbilas removed the Stale label Jul 7, 2022
@bbilas bbilas marked this pull request as draft July 7, 2022 15:28
@HrMitrev
Copy link
Contributor

Hi!
I'm looking forward to the merge of this PR - it would solve many problems.
Also I was thinking if there's a way to add the custom setup commands after gsm_query_modem_info() function is finished. That way we could support multiple modems and add commands based on gsm->minfo. Now I'm modifying gsm_ppp.c and using gsm->minfo.mdm_model to branch into two different setup paths depenging on the modem used.
Cheers!

@bbilas
Copy link
Collaborator Author

bbilas commented Jul 11, 2022

Hi! I'm looking forward to the merge of this PR - it would solve many problems. Also I was thinking if there's a way to add the custom setup commands after gsm_query_modem_info() function is finished. That way we could support multiple modems and add commands based on gsm->minfo. Now I'm modifying gsm_ppp.c and using gsm->minfo.mdm_model to branch into two different setup paths depenging on the modem used. Cheers!

I've re-opened that MR since I'm coming back to this topic this or next week since it's needed for my project. I'll consider your suggestions and we'll see how to deal with them.

@WilliamGFish
Copy link
Collaborator

Hi! I'm looking forward to the merge of this PR - it would solve many problems. Also I was thinking if there's a way to add the custom setup commands after gsm_query_modem_info() function is finished. That way we could support multiple modems and add commands based on gsm->minfo. Now I'm modifying gsm_ppp.c and using gsm->minfo.mdm_model to branch into two different setup paths depenging on the modem used. Cheers!

I've re-opened that MR since I'm coming back to this topic this or next week since it's needed for my project. I'll consider your suggestions and we'll see how to deal with them.

Stubbled across this PR and am intrigued. I can see you are attempting to use Vendor specific AT commands as part of the modem setup which has been an issue for some time. It may be worth considering a 'library' of additional vendor specific AT commands that would be included based on manufacturer as defined in the Config, ie CONFIG_MODEM_UBLOX_SARA.
OR
Maybe the GSM aspect could be added to the actual modem driver and become a config selection (CONFIG_MODEM_UBLOX_SARA_GSM), eg the SARA would include the generic GSM commands and its vendor specific ones.

With the initialisation routine of various modem being a combination of hardware and software processes and timing creating a wholly generic driver may prove to be unrealistic and/or overly complex.

Just some thoughts.
Billy..

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Sep 11, 2022
@github-actions github-actions bot closed this Sep 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Modem Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants