Hello Gentlemen,
thank you for the replies. The ; to concatenate commands is new for me, very usefull. But in this case it is probably best to check for an error. Otherwise, when my application tries to set band 8, which doesn’t exist, it would end up being in a reset loop.
Best regards, Matthijs
ps. the code how it ended up. By the way, what a mess it creates, this event driven programming! 100 lines of code and 3 callbacks to change the frequency.
/**
* Callback function for handling AT+WMBS= .. response
*
* After setting the band with "AT+WMBS=[band],0" the modem needs to be rebooted to activate the new band
*/
veBool wmbsSetLaterHandler(adl_atResponse_t* rsp)
{
if (strcmp(rsp->StrData, "OK") != 0)
{
ve_qtrace("Response to AT+WMBS=[band],0 was not OK: '%s'. Stop trying to change the band", rsp->StrData);
} else {
ve_qtrace("Response to AT+WMBS=[band],0 was OK. Reboot to activate new setting");
adl_atCmdSend("AT+CFUN=1", NULL, NULL);
}
return veFalse;
}
/**
* Callback function for handling AT+WMBS= .. response
*/
veBool wmbsSetNowHandler(adl_atResponse_t* rsp)
{
if (strcmp(rsp->StrData, "OK") != 0)
{
Str command;
GsmBand band = dev_regs.gsmUserBand;
ve_qtrace("Response to AT+WMBS=[band],1 was ERROR. Set it with ,0 parameter");
if (band == GSM_BAND_DEFAULT)
band = dev_regs.gsmDefaultBand;
// Apparently we couldn't set it right now. Set it the slow way
// and have the reboot-callback called when done.
str_new(&command, 11, 1);
str_addf(&command, "AT+WMBS=%d,0", band);
adl_atCmdSend(command.data, wmbsSetLaterHandler, "*", NULL);
str_free(&command);
} else {
ve_qtrace("Response to AT+WMBS=[band],1 was OK. New frequency band set successfully");
}
return veFalse;
}
/**
* Callback function for handling AT+WMBS? response
*/
veBool wmbsGetHandler(adl_atResponse_t* parms)
{
char* temp = ve_malloc(parms->StrLength);
u8 currentBand;
GsmBand band = dev_regs.gsmUserBand;
// The first parameter is the current band
wm_strGetParameterString(temp, parms->StrData, 1);
currentBand = atoi(temp);
ve_free(temp);
if (band == GSM_BAND_DEFAULT)
band = dev_regs.gsmDefaultBand;
if (band != currentBand)
{
// Set the network band.
Str command;
ve_qtrace("Current band (%d) != requested band (%d). Change band and reboot afterwards", currentBand, band);
str_new(&command, 11, 1);
str_addf(&command, "AT+WMBS=%d,1", band);
adl_atCmdSend(command.data, wmbsSetNowHandler, "*", NULL);
str_free(&command);
} else {
ve_qtrace("Current band == requested band (%d)", currentBand);
}
return veFalse;
}
/*
* Initialise the GSM handler, called at startup
*/
void comm_gsmInit(void)
{
// Request the current network band.
adl_atCmdSend("AT+WMBS?", wmbsGetHandler, "+WMBS:", NULL);