Init
This commit is contained in:
commit
497723c50f
|
|
@ -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
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
//
|
||||
// Created by zemon on 29.11.22.
|
||||
//
|
||||
|
||||
#include <memory.h>
|
||||
#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;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"dep": [
|
||||
],
|
||||
"cmake": {
|
||||
"inc_dirs": [
|
||||
"Inc"
|
||||
],
|
||||
"srcs": [
|
||||
"Src/**.c"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue