Skip to content

Initial version for Quectel M26 GSM/GPRS Module. #9261

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

Merged
merged 1 commit into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "QUECTEL_M26_CellularNetwork.h"
#include "QUECTEL_M26_CellularPower.h"
#include "QUECTEL_M26_CellularSIM.h"
#include "QUECTEL_M26_CellularContext.h"
#include "QUECTEL_M26.h"

using namespace events;
using namespace mbed;

#define CONNECT_DELIM "\r\n"
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format
#define CONNECT_TIMEOUT 8000

#define MAX_STARTUP_TRIALS 5
#define MAX_RESET_TRIALS 5

static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::AT_CGAUTH,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
};

QUECTEL_M26::QUECTEL_M26(FileHandle *fh) : AT_CellularDevice(fh)
{
AT_CellularBase::set_unsupported_features(unsupported_features);
}

QUECTEL_M26::~QUECTEL_M26()
{
}

AT_CellularNetwork *QUECTEL_M26::open_network_impl(ATHandler &at)
{
return new QUECTEL_M26_CellularNetwork(at);
}

AT_CellularPower *QUECTEL_M26::open_power_impl(ATHandler &at)
{
return new QUECTEL_M26_CellularPower(at);
}

AT_CellularSIM *QUECTEL_M26::open_sim_impl(ATHandler &at)
{
return new QUECTEL_M26_CellularSIM(at);
}

AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *apn)
{
return new QUECTEL_M26_CellularContext(at, this, apn);
}
41 changes: 41 additions & 0 deletions features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef QUECTEL_M26_H_
#define QUECTEL_M26_H_

#include "AT_CellularDevice.h"

namespace mbed {

class QUECTEL_M26 : public AT_CellularDevice {
public:
QUECTEL_M26(FileHandle *fh);
virtual ~QUECTEL_M26();

protected: // AT_CellularDevice
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
virtual AT_CellularPower *open_power_impl(ATHandler &at);
virtual AT_CellularSIM *open_sim_impl(ATHandler &at);
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);

public: // NetworkInterface
void handle_urc(FileHandle *fh);
};
} // namespace mbed

#endif // QUECTEL_M26_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "QUECTEL_M26_CellularContext.h"
#include "QUECTEL_M26_CellularStack.h"

namespace mbed {

QUECTEL_M26_CellularContext::QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
AT_CellularContext(at, device, apn)
{
}

QUECTEL_M26_CellularContext::~QUECTEL_M26_CellularContext()
{
}

bool QUECTEL_M26_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type)
{
return stack_type == IPV4_STACK ? true : false;
}

#if !NSAPI_PPP_AVAILABLE
NetworkStack *QUECTEL_M26_CellularContext::get_stack()
{
if (!_stack) {
_stack = new QUECTEL_M26_CellularStack(_at, _cid, _ip_stack_type);
}
return _stack;
}
#endif // #if !NSAPI_PPP_AVAILABLE

nsapi_error_t QUECTEL_M26_CellularContext::do_user_authentication()
{

_at.cmd_start("AT+QICSGP=");
_at.write_int(1); /*GPRS MODE = 1, CSD MODE = 0*/
_at.write_string(_apn);
if (_pwd && _uname) {
_at.write_string(_uname);
_at.write_string(_pwd);
}
_at.cmd_stop();
_at.resp_start();
_at.resp_stop();
if (_at.get_last_error() != NSAPI_ERROR_OK) {
return NSAPI_ERROR_AUTH_FAILURE;
}

return NSAPI_ERROR_OK;
}

} /* namespace mbed */
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef QUECTEL_M26_CELLULARCONTEXT_H_
#define QUECTEL_M26_CELLULARCONTEXT_H_

#include "AT_CellularContext.h"

namespace mbed {

class QUECTEL_M26_CellularContext: public AT_CellularContext {
public:
QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
virtual ~QUECTEL_M26_CellularContext();

protected:
virtual bool stack_type_supported(nsapi_ip_stack_t stack_type);
#if !NSAPI_PPP_AVAILABLE
virtual NetworkStack *get_stack();
#endif // #if !NSAPI_PPP_AVAILABLE
virtual nsapi_error_t do_user_authentication();
};

} /* namespace mbed */

#endif // QUECTEL_M26_CELLULARCONTEXT_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "QUECTEL_M26_CellularNetwork.h"

using namespace mbed;

QUECTEL_M26_CellularNetwork::QUECTEL_M26_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler)
{
_op_act = RAT_EGPRS;
}

QUECTEL_M26_CellularNetwork::~QUECTEL_M26_CellularNetwork()
{
}

AT_CellularNetwork::RegistrationMode QUECTEL_M26_CellularNetwork::has_registration(RegistrationType reg_type)
{
return (reg_type == C_GREG) ? RegistrationModeLAC : RegistrationModeDisable;
}

nsapi_error_t QUECTEL_M26_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
{
if (opRat != RAT_EGPRS) {
// only GPRS support in the driver.
_op_act = RAT_EGPRS;
return NSAPI_ERROR_UNSUPPORTED;
}

return NSAPI_ERROR_OK;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef QUECTEL_M26_CELLULAR_NETWORK_H_
#define QUECTEL_M26_CELLULAR_NETWORK_H_

#include "AT_CellularNetwork.h"

namespace mbed {

class QUECTEL_M26_CellularNetwork : public AT_CellularNetwork {
public:
QUECTEL_M26_CellularNetwork(ATHandler &atHandler);
virtual ~QUECTEL_M26_CellularNetwork();

protected:
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
virtual RegistrationMode has_registration(RegistrationType reg_type);
};
} // namespace mbed
#endif // QUECTEL_M26_CELLULAR_NETWORK_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "QUECTEL_M26_CellularPower.h"

using namespace mbed;

QUECTEL_M26_CellularPower::QUECTEL_M26_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
{

}

QUECTEL_M26_CellularPower::~QUECTEL_M26_CellularPower()
{

}

nsapi_error_t QUECTEL_M26_CellularPower::set_at_mode()
{
_at.lock();
_at.cmd_start("AT");
_at.cmd_stop_read_resp();

_at.cmd_start("AT+CMEE="); // verbose responses
_at.write_int(1);
_at.cmd_stop_read_resp();

return _at.unlock_return_error();
}

nsapi_error_t QUECTEL_M26_CellularPower::on()
{

return NSAPI_ERROR_OK;
}

nsapi_error_t QUECTEL_M26_CellularPower::off()
{
_at.lock();
_at.cmd_start("AT+QPOWD=0");
_at.cmd_stop();
_at.resp_start();
_at.resp_stop();

return _at.unlock_return_error();;
}
Loading