From 497723c50fc7e726bf1cc8e693f7a49ff1163670 Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 2 Jun 2025 13:26:40 +0300 Subject: [PATCH] Init --- Inc/AudioRecorderSimComSim7600E.h | 22 ++++ Src/AudioRecorderSimComSim7600E.c | 199 ++++++++++++++++++++++++++++++ modular.json | 12 ++ 3 files changed, 233 insertions(+) create mode 100644 Inc/AudioRecorderSimComSim7600E.h create mode 100644 Src/AudioRecorderSimComSim7600E.c create mode 100644 modular.json diff --git a/Inc/AudioRecorderSimComSim7600E.h b/Inc/AudioRecorderSimComSim7600E.h new file mode 100644 index 0000000..33796fb --- /dev/null +++ b/Inc/AudioRecorderSimComSim7600E.h @@ -0,0 +1,22 @@ +// +// Created by zemon on 05.04.23. +// + +#ifndef UVEOS_ON_NATION_AUDIORECORDERSIMCOMSIM7600E_H +#define UVEOS_ON_NATION_AUDIORECORDERSIMCOMSIM7600E_H + +#include "stdlib.h" +#include "stdbool.h" +#include "AudioRecorderInterface.h" +#include "AtGsmSimcomSim7600.h" + +typedef struct { + tAtCmd *atCmd; + bool recorderIsBusy; +} tAudioRecorder; + +void AudioRecordSimComSim7600E_Init(tAudioRecorder *player, tAtCmd *env); +tAudioRecorderInterface AudioRecordSimComSim7600E_GetInterface(tAudioRecorder *env); +static bool AudioPlayerSimComSim7600E_WaitStop(tAudioRecorder *env, uint32_t timeout); +static bool AudioRecordSimComSim7600E_Stop(tAudioRecorder *env); +#endif //UVEOS_ON_NATION_AUDIORECORDERSIMCOMSIM7600E_H diff --git a/Src/AudioRecorderSimComSim7600E.c b/Src/AudioRecorderSimComSim7600E.c new file mode 100644 index 0000000..cf60c8c --- /dev/null +++ b/Src/AudioRecorderSimComSim7600E.c @@ -0,0 +1,199 @@ +// +// Created by zemon on 29.11.22. +// + +#include +#include "AudioRecorderSimComSim7600E.h" +#include "SystemDelayInterface.h" + +void AudioRecordSimComSim7600E_Init(tAudioRecorder *env, tAtCmd *atCmd){ + env->atCmd = atCmd; + env->recorderIsBusy = false; +} + +static bool AudioRecorderSimComSim7600E_Start(tAudioRecorder *env, char *name, uint16_t nameLen, uint32_t timeout) { ; + if (env->recorderIsBusy == false) { + env->recorderIsBusy = true; + } + if (osMutexAcquire(env->atCmd->access, 1000) == osOK) { + AtCommandResult result = AT_ERROR; + if(AtGsmSimComSim7600E_RecAudioFileTo(env->atCmd, name, nameLen) == AT_OK){ + result = AtCmdWaitOk(env->atCmd, 10, 10); + if (env->recorderIsBusy == true) { + env->recorderIsBusy = false; + } + osMutexRelease(env->atCmd->access); + return result; + } else { + if (env->recorderIsBusy == true) { + env->recorderIsBusy = false; + } + osMutexRelease(env->atCmd->access); + return AT_ERROR; + } + } + if (env->recorderIsBusy == true) { + env->recorderIsBusy = false; + } + return AT_ERROR; +} + +static AtCommandResult AudioRecorderSimComSim7600E_WaitStopToEndRecord(tAudioRecorder *env, uint32_t timeout) { + AtCommandResult result = AT_ERROR; + env->recorderIsBusy = true; + result = AtGsmSimComSim7600E_RecorderAudioFileStopNotSubmit(env->atCmd); + if (result== AT_OK) { + result = AtGsmSimComSim7600E_RecorderAudioFileWaitToStop(env->atCmd); + if (result == AT_OK) { + if (env->recorderIsBusy == true) { + env->recorderIsBusy = false; + } + return AT_OK; + } + } + return AT_ERROR; +} + +static bool AudioRecordSimComSim7600E_StartToEnd(tAudioRecorder *env, char *name, uint16_t nameLen) { + AtCommandResult res; + res = AudioRecorderSimComSim7600E_Start(env, name, nameLen, 0); + return res; +} + +static bool AudioRecordSimComSim7600E_Start(tAudioRecorder *env, char *name, uint16_t nameLen) { + char fileName[nameLen + 4]; + memcpy(fileName, name, nameLen); + stpncpy(fileName + nameLen, ".wav", 4); + + AtCommandResult result = AT_ERROR; + uint32_t end = SystemGetMs() + 5000; + while (end > SystemGetMs()){ + if (osMutexAcquire(env->atCmd->access, 500) == osOK) { + result = AtGsmSimComSim7600E_RecorderAudioFileStart(env->atCmd, fileName, nameLen + 4); + if(result == AT_OK) { + osMutexRelease(env->atCmd->access); + return true; + } + osMutexRelease(env->atCmd->access); + SystemDelayMs(100); + } + } + return result; +} + +static bool AtGsmSimComSim7600E_RecordrerAudioFileDel(tAudioRecorder *env, char *name, uint16_t nameLen) { + env->recorderIsBusy = true; + char fileName[nameLen + 4]; + memcpy(fileName, name, nameLen); + stpncpy(fileName + nameLen, ".wav", 4); + + AtCommandResult result = AT_ERROR; + uint32_t end = SystemGetMs() + 500; + while (end > SystemGetMs()){ + if (osMutexAcquire(env->atCmd->access, 1000) == osOK) { + result = AtGsmSimComSim7600E_DeleteAudioFile(env->atCmd, fileName, nameLen + 4); + if(result == AT_OK){ + osMutexRelease(env->atCmd->access); + env->recorderIsBusy = false; + return result; + } + osMutexRelease(env->atCmd->access); + env->recorderIsBusy = false; + } + SystemDelayMs(100); + } + env->recorderIsBusy = false; + return result; +} + +static bool AudioRecordSimComSim7600E_StopToEnd(tAudioRecorder *env, uint32_t timeout) { + AtCommandResult result = AT_ERROR; + uint32_t tm = SystemGetMs() + timeout; + while (tm > SystemGetMs()) { + SystemDelayMs(1); + } + + env->recorderIsBusy = true; + if (osMutexAcquire(env->atCmd->access, 1000) == osOK) { + result = AudioRecorderSimComSim7600E_WaitStopToEndRecord(env, timeout); + osMutexRelease(env->atCmd->access); + env->recorderIsBusy = false; + return result; + } + env->recorderIsBusy = false; + return result; +} + +static bool AudioRecordSimComSim7600E_Stop(tAudioRecorder *env) { + AtCommandResult result = AT_ERROR; + result = AtGsmSimComSim7600E_RecorderAudioFileStop(env->atCmd); + return result; +} + +static bool AudioPlayerSimComSim7600E_StopRecord(tAudioRecorder *env, uint64_t timeout) { + AtCommandResult result = AT_ERROR; + if (osMutexAcquire(env->atCmd->access, 1000) == osOK) { + result = AtGsmSimComSim7600E_RecorderAudioFileWaitStop(env->atCmd, timeout) == AT_OK; + osMutexRelease(env->atCmd->access); + } + if(result == AT_OK){ + if(env->recorderIsBusy == true){ + env->recorderIsBusy = false; + } + return result; + } else { + AudioRecordSimComSim7600E_Stop(env); + if(env->recorderIsBusy == true){ + env->recorderIsBusy = false; + } + return result; + } +} + + + +bool AudioRecordSimComSim7600E_IsBusy(tAudioRecorder *env, uint32_t timeout) { + if(env->recorderIsBusy){ + return true; + } else { + return false; + } +} + + +static bool AudioPlayerSimComSim7600E_WaitStop(tAudioRecorder *env, uint32_t timeout) { + AtCommandResult result = AT_ERROR; + if (osMutexAcquire(env->atCmd->access, 1000) == osOK) { + result = AtGsmSimComSim7600E_RecorderAudioFileWaitStop(env->atCmd, timeout) == AT_OK; + if(result == AT_OK){ + osMutexRelease(env->atCmd->access); + if(env->recorderIsBusy == true){ + env->recorderIsBusy = false; + } + return result; + } else { + AudioPlayerSimComSim7600E_StopRecord(env, timeout); + osMutexRelease(env->atCmd->access); + if(env->recorderIsBusy == true){ + env->recorderIsBusy = false; + } + return result; + } + } + return result; +} + +tAudioRecorderInterface AudioRecordSimComSim7600E_GetInterface(tAudioRecorder *env) { + tAudioRecorderInterface result = { + .env = env, + .start = (audioRecordStart) AudioRecordSimComSim7600E_Start, + .recordToEnd = (audioRecordStartToEnd) AudioRecordSimComSim7600E_StartToEnd, + .stop = (audioRecordStop) AudioRecordSimComSim7600E_Stop, + .stopToEnd = (audioRecordStopToEnd) AudioRecordSimComSim7600E_StopToEnd, + .del = (audioRecordDel) AtGsmSimComSim7600E_RecordrerAudioFileDel, + .waitStop = (audioRecordWaitStop) AudioPlayerSimComSim7600E_WaitStop, + .IsBusy = (audioRecordIsBusy) AudioRecordSimComSim7600E_IsBusy, + }; + + return result; +} diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..d4d574e --- /dev/null +++ b/modular.json @@ -0,0 +1,12 @@ +{ + "dep": [ + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file