This commit is contained in:
cfif 2025-06-02 13:26:42 +03:00
commit 7a5a334db4
18 changed files with 441 additions and 0 deletions

17
Inc/AtGsmSms.h Normal file
View File

@ -0,0 +1,17 @@
//
// Created by xemon on 28.11.22.
//
#ifndef UVEOS_ON_NATION_ATGSMSMS_H
#define UVEOS_ON_NATION_ATGSMSMS_H
#include "AtGsmSms_DeleteAll.h"
#include "AtGsmSms_DeleteById.h"
#include "AtGsmSms_SendById.h"
#include "AtGsmSms_SendText.h"
#include "AtGsmSms_SetMode.h"
#include "AtGsmSms_SetServiceCenter.h"
#include "AtGsmSms_WriteNewPduSms.h"
#include "AtGsmSms_ReedOneNewPdu.h"
#endif //UVEOS_ON_NATION_ATGSMSMS_H

12
Inc/AtGsmSms_DeleteAll.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by xemon on 28.11.22.
//
#ifndef UVEOS_ON_NATION_ATGSMSMS_DELETEALL_H
#define UVEOS_ON_NATION_ATGSMSMS_DELETEALL_H
#include <AtCmdBase.h>
AtCommandResult AtGsmSms_DeleteAll(tAtCmd *env);
#endif //UVEOS_ON_NATION_ATGSMSMS_DELETEALL_H

12
Inc/AtGsmSms_DeleteById.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by xemon on 25.11.22.
//
#ifndef UVEOS_ON_NATION_ATGSMSMS_DELETE_BY_ID_H
#define UVEOS_ON_NATION_ATGSMSMS_DELETE_BY_ID_H
#include <AtCmdBase.h>
AtCommandResult AtGsmSms_DeleteById(tAtCmd *env, uint8_t id);
#endif //UVEOS_ON_NATION_ATGSMSMS_DELETE_BY_ID_H

View File

@ -0,0 +1,17 @@
//
// Created by zemon on 27.12.22.
//
#ifndef UVEOS_ON_NATION_ATGSMSMS_REEDONENEWPDU_H
#define UVEOS_ON_NATION_ATGSMSMS_REEDONENEWPDU_H
#include <AtCmdBase.h>
AtCommandResult AtGsmSms_ReedOneNewPdu(
tAtCmd *env,
char *pduHex,
uint8_t *pduHexSize,
uint16_t pduHexLimit
);
#endif //UVEOS_ON_NATION_ATGSMSMS_REEDONENEWPDU_H

12
Inc/AtGsmSms_SendById.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by xemon on 28.11.22.
//
#ifndef UVEOS_ON_NATION_ATGSMSMS_SENDBYID_H
#define UVEOS_ON_NATION_ATGSMSMS_SENDBYID_H
#include <AtCmdBase.h>
AtCommandResult AtGsmSms_SendById(tAtCmd *env, uint8_t id);
#endif //UVEOS_ON_NATION_ATGSMSMS_SENDBYID_H

12
Inc/AtGsmSms_SendText.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by xemon on 28.11.22.
//
#ifndef UVEOS_ON_NATION_ATGSMSMS_SENDTEXT_H
#define UVEOS_ON_NATION_ATGSMSMS_SENDTEXT_H
#include <AtCmdBase.h>
AtCommandResult AtGsmSms_SendText(tAtCmd *env, char *number, uint8_t numberLen, char *text, uint8_t textLen);
#endif //UVEOS_ON_NATION_ATGSMSMS_SENDTEXT_H

17
Inc/AtGsmSms_SetMode.h Normal file
View File

@ -0,0 +1,17 @@
//
// Created by xemon on 25.11.22.
//
#ifndef UVEOS_ON_NATION_ATGSMSMS_SETMODE_H
#define UVEOS_ON_NATION_ATGSMSMS_SETMODE_H
#include <AtCmdBase.h>
typedef enum {
AT_GSM_SMS_MODE_TEXT = 1,
AT_GSM_SMS_MODE_PDU = 0,
} tAtGsmSmsMode;
AtCommandResult AtGsmSms_SetMode(tAtCmd *env, tAtGsmSmsMode mode);
#endif //UVEOS_ON_NATION_ATGSMSMS_SETMODE_H

View File

@ -0,0 +1,14 @@
//
// Created by xemon on 25.11.22.
//
#ifndef UVEOS_ON_NATION_ATGSMSMS_SETSERVICECENTER_H
#define UVEOS_ON_NATION_ATGSMSMS_SETSERVICECENTER_H
#include <AtCmdBase.h>
AtCommandResult AtGsmSms_SetServiceCenter(tAtCmd *env, char *smsCenterNumber, uint8_t smsCenterNumberLen);
#define AtGsmSms_SetServiceCenterStatic(ENV, NUMBER) AtGsmSms_SetServiceCenter(ENV,NUMBER,sizeof(NUMBER)-1)
#endif //UVEOS_ON_NATION_ATGSMSMS_SETSERVICECENTER_H

View File

@ -0,0 +1,12 @@
//
// Created by xemon on 28.11.22.
//
#ifndef UVEOS_ON_NATION_ATGSMSMS_WRITENEWPDUSMS_H
#define UVEOS_ON_NATION_ATGSMSMS_WRITENEWPDUSMS_H
#include <AtCmdBase.h>
AtCommandResult AtGsmSms_WriteNewPduSms(tAtCmd *env, char *pduBody, uint8_t fullLen, uint8_t pduDataLen);
#endif //UVEOS_ON_NATION_ATGSMSMS_WRITENEWPDUSMS_H

13
Src/AtGsmSms_DeleteAll.c Normal file
View File

@ -0,0 +1,13 @@
//
// Created by xemon on 28.11.22.
//
#include "AtGsmSms_DeleteAll.h"
#include "AtCmdCommonProtected.h"
// удалить все смс
AtCommandResult AtGsmSms_DeleteAll(tAtCmd *env) {
AtCmdPrepare(env);
AtCmdSendStatic(env, "AT+CMGD=1,4\r\n");
return AtCmdOkErrAnswer(env, 10 * env->stdRxTimeout);
}

20
Src/AtGsmSms_DeleteById.c Normal file
View File

@ -0,0 +1,20 @@
//
// Created by xemon on 25.11.22.
//
#include "AtGsmSms_DeleteById.h"
#include "AtCmdCommonProtected.h"
AtCommandResult AtGsmSms_DeleteById(tAtCmd *env, uint8_t id) {
AtCmdPrepare(env);
AtCmdTxClear(env);
AtCmdTxAddStatic(env, "AT+CMGD=");
AtCmdTxAddDecimalIntWithLimit(env, id, 3);
AtCmdTxSendLn(env);
return AtCmdOkErrAnswer(env, env->stdRxTimeout);
}

View File

@ -0,0 +1,151 @@
//
// Created by zemon on 27.12.22.
//
#include <AtGsmSms_DeleteAll.h>
#include "AtCmdCommonProtected.h"
#include "SystemDelayInterface.h"
AtCommandResult AtGsmSms_GetPdu(
tAtCmd *env,
char *pduHex,
uint8_t *pduHexSize,
uint8_t pduHexLimit
) {
*pduHexSize = 0;
uint32_t endMs = SystemGetMs() + 2000;
while (endMs > SystemGetMs()) {
if (AtCmdReceiveNextLine(env, 1000) == AT_OK) {
uint16_t pos = 0;
if (AtCmdRxBeginWithStatic(env, "+CMGL:")) {
if (AtCmdReceiveNextLine(env, 500) == AT_OK) {
while ((pos < pduHexLimit) && (env->rxBuffer.data[pos] != '\r')) {
pduHex[pos] = env->rxBuffer.data[pos];
++pos;
}
}
*pduHexSize = pos;
return AT_OK;
}
if (AtCmdRxBeginWithStatic(env, "+CMS ERROR: ")) {
return AT_ERROR;
}
if (AtCmdRxBeginWithStatic(env, "OK")) {
return AT_TIMEOUT;
}
AtCmdProcessUnresolvedLine(env);
}
}
return AT_TIMEOUT;
}
AtCommandResult AtGsmSms_ReedOneNewPdu(
tAtCmd *env,
char *pduHex,
uint8_t *pduHexSize,
uint16_t pduHexLimit
) {
if(env->test == 1){
/// запрос на переотправку МНД
char hexData[] = "04814523F1040A8180515634120004329072513435402B0100000B001E000A00013117000A00400404331400500A000000000000000000000013010000000002712B";
uint16_t pos = 0;
while ((pos < pduHexLimit) && (hexData[pos] != 0)) {
pduHex[pos] = hexData[pos];
++pos;
}
*pduHexSize = pos;
env->test=0;
return AT_OK;
} else if (env->test == 2){
/// запрос повторного вызова
char hexData[] = "04814523F1040A818051563412000432215221141500270100000B001A00040001D913000400400404331000500400000000000000000000001201000DF1";
uint16_t pos = 0;
while ((pos < pduHexLimit) && (hexData[pos] != 0)) {
pduHex[pos] = hexData[pos];
++pos;
}
*pduHexSize = pos;
env->test=0;
return AT_OK;
} else if (env->test == 3){
/// Установка номера для отправки информации по SMS (555)
char hexData[] = "04804523F1040A8080515634120004324041318175402A0100000B001D000A00017516000A00400404331300500A0000000000000000000002230235353535852C";
uint16_t pos = 0;
while ((pos < pduHexLimit) && (hexData[pos] != 0)) {
pduHex[pos] = hexData[pos];
++pos;
}
*pduHexSize = pos;
env->test=0;
return AT_OK;
} else if (env->test == 4){
/// запрос на обновление
char hexData[] = "04814523F1040A8180515634120000429042512592404EB0180C0683C18430582C0883C16030182C6684C56630180C0683D160301A8C369BC56030580D0683C16030180C0683C16030180C0683C16030184C06A3C16433580C37CC01";
// char hexData[] = "04814523F111000A81805156341200F40B4E303130303030304230303141303030303030303146303133303030303030343030343034333331303030353030303030303030303030303030303030303030303030303230343032333031384339";
uint16_t pos = 0;
while ((pos < pduHexLimit) && (hexData[pos] != 0)) {
pduHex[pos] = hexData[pos];
++pos;
}
*pduHexSize = pos;
env->test=0;
return AT_OK;
}
// /// запрос на переотправку МНД
// char hexData[] = "04814523F1040A8180515634120004329072513435402B0100000B001E000A00013117000A00400404331400500A000000000000000000000013010000000002712B";
// char hexData[] = "04814523F1040A8180515634120004329052815002402B0100000B001E000600014A1700060040040433140050060000000000000000000000130100000000028155";
// char hexData[] = "04814523F1040A8180515634120004326090419405402B0100000B001E00010001A91700010040040433140050010000000000000000000000130100000000027290";
// char hexData[] = "0100010B003300010001EA2800010094E07404110A0A282500010222140601430145554B3C25C00000810037F08B8835FC1179A7A7B0FE0F1C1FE000001AA3D2";
/// установка номера
/*
* Установка номера для отправки информации по SMS (555)
*/
// char hexData[] = "04804523F1040A8080515634120004324041318175402A0100000B001D000A00017516000A00400404331300500A0000000000000000000002230235353535852C";
/*
* Установка номера для тестового вызова 79418100025
*/
// char hexData[] = "07919714180010F3040B919714111190F7000432302231033221350100000B0028000A00013D1D000A00010A0000000404331A00500A000000A9010000000100420D0237393431383130303032357D82";
// char hexData[] = "07919714180010F3040B919714111190F70004323022310332213501A001C00012F13001C00400404331000501C0000000000000000000000120100A87010101010";
/// запрос повторного вызова
// char hexData[] = "04814523F1040A818051563412000432215221141500270100000B001A00040001D913000400400404331000500400000000000000000000001201000DF1";
// uint16_t pos = 0;
// while ((pos < pduHexLimit) && (hexData[pos] != 0)) {
// pduHex[pos] = hexData[pos];
// ++pos;
// }
// *pduHexSize = pos;
// return AT_OK;
//
///==============================================================================================================
AtCmdPrepare(env);
AtCmdSendStatic(env, "AT+CMGL=0\r\n");
if(AtGsmSms_GetPdu(env, pduHex, pduHexSize, pduHexLimit) == AT_OK){
return AT_OK;
} else {
AtCmdPrepare(env);
AtCmdSendStatic(env, "AT+CMGL=1\r\n");
if(AtGsmSms_GetPdu(env, pduHex, pduHexSize, pduHexLimit) == AT_OK){
return AT_OK;
}
}
return AT_ERROR;
}

18
Src/AtGsmSms_SendById.c Normal file
View File

@ -0,0 +1,18 @@
//
// Created by xemon on 28.11.22.
//
#include "AtGsmSms_SendById.h"
#include "AtCmdCommonProtected.h"
AtCommandResult AtGsmSms_SendById(tAtCmd *env, uint8_t id) {
AtCmdPrepare(env);
AtCmdTxClear(env);
AtCmdTxAddStatic(env, "AT+CMSS=");
AtCmdTxAddDecimalIntWithLimit(env, id, 3);
AtCmdTxSendLn(env);
return AtCmdOkErrAnswer(env, env->stdRxTimeout * 6);
}

28
Src/AtGsmSms_SendText.c Normal file
View File

@ -0,0 +1,28 @@
//
// Created by xemon on 28.11.22.
//
#include "AtGsmSms_SendText.h"
#include "AtCmdCommonProtected.h"
AtCommandResult AtGsmSms_SendText(tAtCmd *env, char *number, uint8_t numberLen, char *text, uint8_t textLen) {
AtCmdPrepare(env);
AtCmdTxClear(env);
AtCmdTxAddStatic(env, "AT+CMGS=\"");
AtCmdTxAdd(env, number, numberLen);
AtCmdTxAddStatic(env, "\"");
AtCmdTxSendLn(env);
AtCommandResult ready = AtCmdWaitPrefix(env, 10000, ">", 1);
if (ready != AT_OK) {
AtCmdSendStatic(env, AT_ESC_STR);
return ready;
}
AtCmdSend(env, (uint8_t *) text, textLen);
AtCmdSendStatic(env, AT_ESC_STR);
return AtCmdOkErrAnswer(env, env->stdRxTimeout * 5);
}

17
Src/AtGsmSms_SetMode.c Normal file
View File

@ -0,0 +1,17 @@
//
// Created by xemon on 25.11.22.
//
#include "AtGsmSms_SetMode.h"
#include "AtCmdCommonProtected.h"
AtCommandResult AtGsmSms_SetMode(tAtCmd *env, tAtGsmSmsMode mode) {
AtCmdPrepare(env);
AtCmdTxClear(env);
AtCmdTxAddStatic(env, "AT+CMGF=");
AtCmdTxAddDecimalInt(env, mode, 1);
AtCmdTxSendLn(env);
return AtCmdOkErrAnswer(env, env->stdRxTimeout);
}

View File

@ -0,0 +1,19 @@
//
// Created by xemon on 25.11.22.
//
#include "AtGsmSms_SetServiceCenter.h"
#include "AtCmdCommonProtected.h"
AtCommandResult AtGsmSms_SetServiceCenter(tAtCmd *env, char *smsCenterNumber, uint8_t smsCenterNumberLen) {
AtCmdPrepare(env);
AtCmdTxClear(env);
AtCmdTxAddStatic(env, "AT+CSCA=");
AtCmdTxAddStatic(env, "\"");
AtCmdTxAdd(env, smsCenterNumber, smsCenterNumberLen);
AtCmdTxAddStatic(env, "\"");
AtCmdTxSendLn(env);
return AtCmdOkErrAnswer(env, env->stdRxTimeout);
}

View File

@ -0,0 +1,28 @@
//
// Created by xemon on 28.11.22.
//
#include "AtGsmSms_WriteNewPduSms.h"
#include "AtCmdCommonProtected.h"
AtCommandResult AtGsmSms_WriteNewPduSms(tAtCmd *env, char *pduBody, uint8_t fullLen, uint8_t pduDataLen) {
AtCmdPrepare(env);
AtCmdTxClear(env);
AtCmdTxAddStatic(env, "AT+CMGW=");
AtCmdTxAddDecimalIntWithLimit(env, pduDataLen, 3);
AtCmdTxSendLn(env);
AtCommandResult ready = AtCmdWaitChar(env, 10000, '>');
if (ready != AT_OK) {
AtCmdSendStatic(env, AT_ESC_STR);
return ready;
}
AtCmdSend(env, (uint8_t *) pduBody, fullLen);
AtCmdSendStatic(env, AT_ESC_STR);
return AtCmdOkErrAnswer(env, env->stdRxTimeout * 5);
}

22
modular.json Normal file
View File

@ -0,0 +1,22 @@
{
"dep": [
{
"type": "git",
"provider": "Smart_Components_Aurus",
"repo": "AtGsmCommon"
},
{
"type": "git",
"provider": "Smart_Components_Aurus",
"repo": "SmsEncoderDecoder"
}
],
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}