Skip to content

Commit

Permalink
Implemented AT commends for HTTP actions support
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Cherednichenko committed Mar 22, 2013
1 parent 1906a0a commit 18577d2
Show file tree
Hide file tree
Showing 5 changed files with 721 additions and 8 deletions.
104 changes: 103 additions & 1 deletion src/HTTPConfig.cpp
Expand Up @@ -9,6 +9,17 @@

using namespace std;

const char HTTPConfig::bearerProfileParamName[] = "CID";
const char HTTPConfig::urlParamName[] = "URL";
const char HTTPConfig::userAgentParamName[] = "UA";
const char HTTPConfig::proxyIPParamName[] = "PROIP";
const char HTTPConfig::proxyPortParamName[] = "PROPORT";
const char HTTPConfig::redirectionParamName[] = "REDIR";
const char HTTPConfig::breakStartPosParamName[] = "BREAK";
const char HTTPConfig::breakEndPosParamName[] = "BREAKEND";
const char HTTPConfig::timeoutParamName[] = "TIMEOUT";
const char HTTPConfig::contentTypeParamName[] = "CONTENT";

HTTPConfig::HTTPConfig(const unsigned int bearerProfileID, const char url[URL_MAX_LENGHT]) {
this->bearerProfileID = bearerProfileID;
strcpy(this->url, url);
Expand All @@ -24,6 +35,10 @@ HTTPConfig::HTTPConfig(const unsigned int bearerProfileID, const char url[URL_MA
HTTPConfig::~HTTPConfig() {
}

void HTTPConfig::setUrl(const char url[URL_MAX_LENGHT]) {
strcpy(this->url, url);
}

void HTTPConfig::setUserAgent(const char userAgent[USER_AGENT_MAX_LENGHT]) {
strcpy(this->userAgent, userAgent);
}
Expand Down Expand Up @@ -90,7 +105,47 @@ const char * const HTTPConfig::getContentType() const {
return this->contentType;
}

const bool HTTPConfig::isEnabledREdirection() const {
const char * const HTTPConfig::getBearerProfileParamName() const {
return HTTPConfig::bearerProfileParamName;
}

const char * const HTTPConfig::getUrlParamName() const {
return HTTPConfig::urlParamName;
}

const char * const HTTPConfig::getUserAgentParamName() const {
return HTTPConfig::userAgentParamName;
}

const char * const HTTPConfig::getProxyIPParamName() const {
return HTTPConfig::proxyIPParamName;
}

const char * const HTTPConfig::getProxyPortParamName() const {
return HTTPConfig::proxyPortParamName;
}

const char * const HTTPConfig::getRedirectParamName() const {
return HTTPConfig::redirectionParamName;
}

const char * const HTTPConfig::getBreakStartPosParamName() const {
return HTTPConfig::breakStartPosParamName;
}

const char * const HTTPConfig::getBreakEndPosParamName() const {
return HTTPConfig::breakEndPosParamName;
}

const char * const HTTPConfig::getTimeoutParamName() const {
return HTTPConfig::timeoutParamName;
}

const char * const HTTPConfig::getContentTypeParamName() const {
return HTTPConfig::contentTypeParamName;
}

const bool HTTPConfig::isEnabledRedirection() const {
return this->enableRedirection;
}

Expand All @@ -108,3 +163,50 @@ const bool HTTPConfig::isEnabledBreakState() const {
return true;
}

int HTTPConfig::compareWith(const HTTPConfig &config, HTTPCONFIG_CHANGES &changes) const {
int nChanges = 0;

while(true) {
if((changes.bearerProfileChanged = (getBearerProfileID() == config.getBearerProfileID())) == true) {
nChanges++;;
}

if((changes.urlChanged = (strcmp(getUrl(), config.getUrl()) == 0)) == true) {
nChanges++;
}

if((changes.userAgentChanged = (strcmp(getUserAgent(), config.getUserAgent()) == 0)) == true) {
nChanges++;
}

if((changes.proxyIPChanged = (strcmp(getProxyIP(), config.getProxyIP()) == 0)) == true) {
nChanges++;
}

if((changes.proxyPortChanged = (getProxyPort() == config.getProxyPort())) == true) {
nChanges++;
}

if((changes.redirectionChanged = (isEnabledRedirection() == config.isEnabledRedirection())) == true) {
nChanges++;
}

if((changes.breakStartPosChanged = (getBreakStartPos() == config.getBreakStartPos())) == true) {
nChanges++;
}

if((changes.breakEndPosChanged = (getBreakEndPos() == config.getBreakEndPos())) == true) {
nChanges++;
}

if((changes.timeoutChanged = (getTimeout() == config.getTimeout())) == true) {
nChanges++;
}

if((changes.contentTypeChanged = (strcmp(getContentType(), config.getContentType()) == 0)) == true) {
nChanges++;
}
}

return nChanges;
}
56 changes: 54 additions & 2 deletions src/HTTPConfig.h
Expand Up @@ -17,8 +17,46 @@
#define USER_AGENT_MAX_LENGHT 100
#define CONTENT_TYPE_MAX_LENGHT 100

struct HTTPCONFIG_CHANGES {
bool bearerProfileChanged;
bool urlChanged;
bool userAgentChanged;
bool proxyIPChanged;
bool proxyPortChanged;
bool redirectionChanged;
bool breakStartPosChanged;
bool breakEndPosChanged;
bool timeoutChanged;
bool contentTypeChanged;

public:
HTTPCONFIG_CHANGES() {
bearerProfileChanged = true;
urlChanged = true;
userAgentChanged = true;
proxyIPChanged = true;
proxyPortChanged = true;
redirectionChanged = true;
breakStartPosChanged = true;
breakEndPosChanged = true;
timeoutChanged = true;
contentTypeChanged = true;
}
};

class HTTPConfig {
private:
static const char bearerProfileParamName[4];
static const char urlParamName[4];
static const char userAgentParamName[3];
static const char proxyIPParamName[6];
static const char proxyPortParamName[8];
static const char redirectionParamName[6];
static const char breakStartPosParamName[6];
static const char breakEndPosParamName[9];
static const char timeoutParamName[8];
static const char contentTypeParamName[8];

unsigned int bearerProfileID;
char url[URL_MAX_LENGHT];
char userAgent[USER_AGENT_MAX_LENGHT];
Expand All @@ -30,9 +68,10 @@ class HTTPConfig {
unsigned int timeout;
char contentType[CONTENT_TYPE_MAX_LENGHT];
public:
HTTPConfig(const unsigned int bearerProfileID, const char url[URL_MAX_LENGHT]);
HTTPConfig(const unsigned int bearerProfileID = 0, const char url[URL_MAX_LENGHT] = "");
virtual ~HTTPConfig();

void setUrl(const char url[URL_MAX_LENGHT]);
void setUserAgent(const char userAgent[USER_AGENT_MAX_LENGHT]);
void setProxy(const char proxyIP[16], unsigned int proxyPort);
void setRedirection(const bool enableRedirection);
Expand All @@ -50,9 +89,22 @@ class HTTPConfig {
const unsigned int & getTimeout() const;
const char * const getContentType() const;

const bool isEnabledREdirection() const;
const char * const getBearerProfileParamName() const;
const char * const getUrlParamName() const;
const char * const getUserAgentParamName() const;
const char * const getProxyIPParamName() const;
const char * const getProxyPortParamName() const;
const char * const getRedirectParamName() const;
const char * const getBreakStartPosParamName() const;
const char * const getBreakEndPosParamName() const;
const char * const getTimeoutParamName() const;
const char * const getContentTypeParamName() const;

const bool isEnabledRedirection() const;
const bool isEnabledProxy() const;
const bool isEnabledBreakState() const;

int compareWith(const HTTPConfig &config, HTTPCONFIG_CHANGES &changes) const;
};

#endif /* HTTPCONFIG_H_ */
88 changes: 86 additions & 2 deletions src/Sim900.cpp
Expand Up @@ -23,13 +23,96 @@ int main() {
PortIO * portIO = new PortIO();
Sim900AT * atProcessor = new Sim900AT(portIO);

COMMON_AT_RESULT r = atProcessor->testAT();
/**
* Initialise modem
*/
COMMON_AT_RESULT r;
r= atProcessor->testAT();
SIMCARD_STATE s = atProcessor->checkSimCardLockState();
if(s == SIM_PIN_REQUIRED) {
r = atProcessor->unlockSimCard("0000");
}
CALL_STATE cs = atProcessor->startCall("0501906337", true);

/**
* Create GPRS connection for HTTP AT commands
*/
BEARER_PARAMETER_DETAILS bearerDetails;
int bearerId = 1;

//setup connection
while(true) {
//connection type
bearerDetails.bearerProfileID = bearerId;
bearerDetails.paramName = BEARER_PARAM_CONTYPE;
//bearerDetails.paramValue = BEARER_PARAM_CONTYPE_GPRS;

r = atProcessor->setIPBearerParameters(bearerDetails);
if(r != DCE_OK) {
return -1;
}

//AP name
bearerDetails.bearerProfileID = bearerId;
bearerDetails.paramName = BEARER_PARAM_APN;
//bearerDetails.paramValue = "internet";

r = atProcessor->setIPBearerParameters(bearerDetails);
if(r != DCE_OK) {
return -1;
}

break;
}

//open connection
r = atProcessor->openIPBearer(bearerId);

//check connection state
BEARER_STATUS bearerStatus;
int counter = 0;
while(bearerStatus.mode != BEARER_CONNECTED && counter < 100) {
r = atProcessor->getIPBearerState(bearerId, bearerStatus);

cout << "Stating GPRS connection ..." << " bearerProfileID=" << bearerStatus.bearerProfileID
<< " mode=" << bearerStatus.mode << " IP=" << bearerStatus.ipAddress << endl;

if(r != DCE_OK) {
return -1;
}

counter++;
}

/**
* Start HTTP session
*/
r = atProcessor->initialiseHTTP();
if(r != DCE_OK) {
return -1;
}

HTTPConfig httpConfig = HTTPConfig(1, "www.ya.ru");
atProcessor->initialiseHTTPContext(httpConfig);
if(r != DCE_OK) {
return -1;
}

HTTP_ACTION_STATUS httpActionStatus;
r = atProcessor->setCurrentAction(HTTP_ACTION_METHOD_GET, httpActionStatus);
if(r != DCE_OK) {
return -1;
}

cout << "HTTP action status ..." << " action=" << httpActionStatus.method << " HTTPCODE=" << httpActionStatus.httpResponcecCode
<< " size=" << httpActionStatus.size << endl;

r = atProcessor->terminateHTTP();
if(r != DCE_OK) {
return -1;
}

/*
CALL_STATE cs = atProcessor->startCall("0501906337", true);
while(cs == CALL_CONNECT_VOICE) {
CALL_DETAILS * const details = new CALL_DETAILS[2];
int nCalls = atProcessor->getListCurrentCalls(details, 2);
Expand All @@ -39,6 +122,7 @@ int main() {
}
delete details;
}
*/

delete portIO;

Expand Down

0 comments on commit 18577d2

Please sign in to comment.