70 lines
1.6 KiB
C
Executable File
70 lines
1.6 KiB
C
Executable File
//
|
|
// Created by xemon on 10.07.23.
|
|
//
|
|
|
|
#include <AtGsmSimComA7600_Http.h>
|
|
#include "Gsm_HttpGet.h"
|
|
|
|
|
|
static size_t Gsm_HttpGet_Open_Dir(tAtCmd *env, char *url, size_t urlSize) {
|
|
AtCommandResult res;
|
|
|
|
res = AtGsmSimComA7600_HttpInit(env);
|
|
if (res != AT_OK) {
|
|
return 0;
|
|
}
|
|
|
|
res = AtGsmSimComA7600_HttpSetUrl(env, url, urlSize);
|
|
if (res != AT_OK) {
|
|
return 0;
|
|
}
|
|
|
|
uint16_t responseCode;
|
|
size_t len;
|
|
|
|
res = AtGsmSimComA7600_HttpMethodAction(env, eAtGsmSimComA7600_HttpMethod_GET, &responseCode, &len, 10000);
|
|
|
|
if (res != AT_OK) {
|
|
return 0;
|
|
}
|
|
if (responseCode != 200) {
|
|
return 0;
|
|
}
|
|
|
|
return len;
|
|
}
|
|
|
|
static size_t Gsm_HttpGet_Read_Dir(tAtCmd *env, uint8_t *data, size_t dataLimit) {
|
|
size_t read;
|
|
AtCommandResult res = AtGsmSimComA7600_HttpRead(env, data, 0, dataLimit, &read);
|
|
if (res != AT_OK) { return 0; }
|
|
return read;
|
|
}
|
|
|
|
|
|
size_t Gsm_HttpGet_Open(tAtCmd *env, char *url, size_t urlSize) {
|
|
size_t res = 0;
|
|
if (osMutexAcquire(env->access, 2000) == osOK) {
|
|
res = Gsm_HttpGet_Open_Dir(env, url, urlSize);
|
|
osMutexRelease(env->access);
|
|
}
|
|
return res;
|
|
}
|
|
|
|
size_t Gsm_HttpGet_Read(tAtCmd *env, uint8_t *data, size_t dataLimit) {
|
|
size_t res = 0;
|
|
if (osMutexAcquire(env->access, 2000) == osOK) {
|
|
res = Gsm_HttpGet_Read_Dir(env, data, dataLimit);
|
|
osMutexRelease(env->access);
|
|
}
|
|
return res;
|
|
}
|
|
|
|
bool Gsm_HttpGet_Close(tAtCmd *env) {
|
|
bool res = false;
|
|
if (osMutexAcquire(env->access, 2000) == osOK) {
|
|
res = AtGsmSimComA7600_HttpTerminate(env) == AT_OK;
|
|
osMutexRelease(env->access);
|
|
}
|
|
return res;
|
|
} |