89 lines
2.4 KiB
C
89 lines
2.4 KiB
C
//
|
|
// Created by cfif on 05.07.23.
|
|
//
|
|
#include <SystemDelayInterface.h>
|
|
#include "GsmWithGnss.h"
|
|
#include "AtGsmSimComA7600.h"
|
|
|
|
|
|
#define LOG_SIGN "GSM SOCK"
|
|
#define LOGGER &env->slog->logger
|
|
|
|
static uint16_t
|
|
Gsm_SrvSerialPortTransmit_Dir(
|
|
tGsmWithGnss *env,
|
|
tGsmSocketSlot *slot,
|
|
uint8_t *data,
|
|
uint16_t size,
|
|
uint32_t timeout
|
|
) {
|
|
|
|
if (slot->type == eSocketType_TCP) {
|
|
if (AtGsmSimComA7600_SocketSendData(env->gsmAt, slot->contextId, data, size, timeout) == AT_OK) {
|
|
return size;
|
|
}
|
|
} else if (slot->type == eSocketType_UDP) {
|
|
if (AtGsmSimComA7600_SocketSendDataUdp(
|
|
env->gsmAt,
|
|
slot->contextId,
|
|
data,
|
|
size,
|
|
slot->addr.data,
|
|
slot->addr.length,
|
|
slot->port,
|
|
timeout
|
|
) == AT_OK) {
|
|
return size;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
static uint16_t Gsm_transmit(tGsm *env, uint8_t contextId, uint8_t *data, uint16_t size, uint32_t timeout) {
|
|
if (!size) {
|
|
return 0;
|
|
}
|
|
|
|
uint32_t end = SystemGetMs() + timeout;
|
|
if (osMutexAcquire(env->deviceAccess, timeout) == osOK) {
|
|
uint32_t sendTimeout = timeout == SystemWaitForever ? 10 * 1000 : end - SystemGetMs();
|
|
|
|
uint16_t res = Gsm_SrvSerialPortTransmit_Dir(env, env->slots + contextId, data, size, sendTimeout);
|
|
|
|
osMutexRelease(env->deviceAccess);
|
|
return res;
|
|
} else {
|
|
LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка доступа (Gsm_transmit)")
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
*/
|
|
|
|
static uint16_t Gsm_transmit(tGsmWithGnss *env, uint8_t contextId, uint8_t *data, uint16_t size, uint32_t timeout) {
|
|
if (!size) {
|
|
return 0;
|
|
}
|
|
|
|
// uint32_t end = SystemGetMs() + timeout;
|
|
if (osMutexAcquire(env->gsmAt->access, timeout) == osOK) {
|
|
// uint32_t sendTimeout = timeout == SystemWaitForever ? 2000 : end - SystemGetMs();
|
|
|
|
uint16_t res = Gsm_SrvSerialPortTransmit_Dir(env, env->slots + contextId, data, size, timeout);
|
|
|
|
osMutexRelease(env->gsmAt->access);
|
|
return res;
|
|
} else {
|
|
LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка доступа (Gsm_transmit)")
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
size_t Gsm_Socket_send(tGsmWithGnss *env, uint8_t contextId, uint8_t *data, size_t size, uint32_t timeout) {
|
|
return Gsm_transmit(env, contextId, data, size, timeout);
|
|
}
|