Init
This commit is contained in:
commit
ebe10429da
|
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// Created by zemon on 05.04.23.
|
||||
//
|
||||
|
||||
#ifndef UVEOS_ON_NATION_AUDIOPLAYERSIMCOMSIM7600E_H
|
||||
#define UVEOS_ON_NATION_AUDIOPLAYERSIMCOMSIM7600E_H
|
||||
|
||||
#include "AtGsmSimcomSim7600.h"
|
||||
#include "AudioPlayerInterface.h"
|
||||
|
||||
typedef enum {
|
||||
MP3,
|
||||
WAV,
|
||||
} tFileType;
|
||||
|
||||
typedef struct {
|
||||
tFileType fileType;
|
||||
char *nameFile;
|
||||
uint16_t nameLen;
|
||||
} tFileInfo;
|
||||
|
||||
typedef struct {
|
||||
tAtCmd *atCmd;
|
||||
tFileInfo fileInfo;
|
||||
bool playerIsBusy;
|
||||
} tAudioPlayer;
|
||||
|
||||
void AudioPlayerSimComSim7600E_Init(tAudioPlayer *player, tAtCmd *env);
|
||||
|
||||
tAudioPlayerInterface AudioPlayerSimComSim7600E_GetInterface(tAudioPlayer *env);
|
||||
#endif //UVEOS_ON_NATION_AUDIOPLAYERSIMCOMSIM7600E_H
|
||||
|
|
@ -0,0 +1,272 @@
|
|||
//
|
||||
// Created by zemon on 05.04.23.
|
||||
//
|
||||
|
||||
#include <memory.h>
|
||||
#include "AudioPlayerSimComSim7600E.h"
|
||||
#include "SystemDelayInterface.h"
|
||||
|
||||
tFileType AudioPlayerSimComSim7600E_GetFileFormat(char *name, uint16_t nameLen) {
|
||||
char fileSourceName[nameLen];
|
||||
memcpy(fileSourceName, name, nameLen);
|
||||
|
||||
char fileTypeSource[3] = "";
|
||||
char typeMp3[3] = "mp3";
|
||||
char typeWav[3] = "wav";
|
||||
|
||||
uint16_t notTypeLen = (nameLen - 3);
|
||||
uint8_t indx = 0;
|
||||
for (uint16_t i = notTypeLen; i< nameLen; i++){
|
||||
fileTypeSource[indx] = fileSourceName[i];
|
||||
indx ++;
|
||||
}
|
||||
|
||||
if (memcmp (typeMp3, fileTypeSource, 3) == 0){
|
||||
return MP3;
|
||||
}
|
||||
if (memcmp (typeWav, fileTypeSource, 3) == 0){
|
||||
return WAV;
|
||||
}
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_StopPlayWav(tAudioPlayer *env, uint16_t timeout) {
|
||||
SystemDelayMs(100);
|
||||
AtCommandResult result = AT_ERROR;
|
||||
if (osMutexAcquire(env->atCmd->access, 1000) == osOK) {
|
||||
result = AtGsmSimComSim7600E_PlayAudioStopWav(env->atCmd, timeout);
|
||||
if(result == AT_OK){
|
||||
osMutexRelease(env->atCmd->access);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return AT_ERROR;
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_StopPlayMp3(tAudioPlayer *env, uint16_t timeout) {
|
||||
SystemDelayMs(100);
|
||||
AtCommandResult result = AT_ERROR;
|
||||
if (osMutexAcquire(env->atCmd->access, 2000) == osOK) {
|
||||
result = AtGsmSimComSim7600E_PlayAudioStopMp3(env->atCmd, timeout);
|
||||
osMutexRelease(env->atCmd->access);
|
||||
return result;
|
||||
}
|
||||
return AT_ERROR;
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_Stop(tAudioPlayer *env, uint32_t timeout) {
|
||||
SystemDelayMs(100);
|
||||
if(env->fileInfo.fileType == MP3){
|
||||
return AudioPlayerSimComSim7600E_StopPlayMp3(env, timeout);
|
||||
}
|
||||
|
||||
if(env->fileInfo.fileType == WAV){
|
||||
return AudioPlayerSimComSim7600E_StopPlayWav(env, timeout);
|
||||
}
|
||||
return AT_ERROR;
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_WaitWav(tAudioPlayer *env, uint32_t timeout) {
|
||||
SystemDelayMs(100);
|
||||
AtCommandResult result = AT_ERROR;
|
||||
if (osMutexAcquire(env->atCmd->access, 1000) == osOK) {
|
||||
result = AtGsmSimComSim7600E_PlayAudioWaitEndWav(env->atCmd, timeout) == AT_OK;
|
||||
if(result == AT_OK){
|
||||
SystemDelayMs(50);
|
||||
osMutexRelease(env->atCmd->access);
|
||||
if(env->playerIsBusy == true){
|
||||
env->playerIsBusy = false;
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
AudioPlayerSimComSim7600E_Stop(env, timeout);
|
||||
if(env->playerIsBusy == true){
|
||||
env->playerIsBusy = false;
|
||||
}
|
||||
osMutexRelease(env->atCmd->access);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_WaitMp3(tAudioPlayer *env, uint32_t timeout) {
|
||||
AtCommandResult result = AT_ERROR;
|
||||
if (osMutexAcquire(env->atCmd->access, 4000) == osOK) {
|
||||
result = AtGsmSimComSim7600E_PlayAudioWaitEndMp3(env->atCmd, timeout) == AT_OK;
|
||||
if(result == AT_OK){
|
||||
if(env->playerIsBusy == true){
|
||||
env->playerIsBusy = false;
|
||||
}
|
||||
osMutexRelease(env->atCmd->access);
|
||||
return result;
|
||||
} else {
|
||||
AudioPlayerSimComSim7600E_Stop(env, timeout);
|
||||
if(env->playerIsBusy == true){
|
||||
env->playerIsBusy = false;
|
||||
}
|
||||
osMutexRelease(env->atCmd->access);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_StartToWaw(tAudioPlayer *env, char *name, uint16_t nameLen, uint32_t timeout) {
|
||||
SystemDelayMs(100);
|
||||
if (osMutexAcquire(env->atCmd->access, 1000) == osOK) {
|
||||
AtCommandResult result = AT_ERROR;
|
||||
if(AtGsmSimComSim7600E_PlayWavAudioFileTo(env->atCmd, SIM7600E_AUDIO_FILE_PLAY_TO_SPEAKER, name, nameLen) == AT_OK){
|
||||
result = AtCmdWaitOk(env->atCmd, 10, 10);
|
||||
if(env->playerIsBusy == true){
|
||||
env->playerIsBusy = false;
|
||||
}
|
||||
osMutexRelease(env->atCmd->access);
|
||||
SystemDelayMs(100);
|
||||
return result;
|
||||
} else {
|
||||
if(env->playerIsBusy == true){
|
||||
env->playerIsBusy = false;
|
||||
}
|
||||
osMutexRelease(env->atCmd->access);
|
||||
SystemDelayMs(100);
|
||||
return AT_ERROR;
|
||||
}
|
||||
}
|
||||
SystemDelayMs(100);
|
||||
return AT_ERROR;
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_StartTone(tAudioPlayer *env, uint16_t count) {
|
||||
if (osMutexAcquire(env->atCmd->access, 3000) == osOK) {
|
||||
bool result = AT_ERROR;
|
||||
for(uint16_t cnt = 0; cnt < count; cnt++) {
|
||||
if (AtGsmSimComSim7600E_PlayTone(env->atCmd) == AT_OK) {
|
||||
if(AtCmdWaitOk(env->atCmd, 10, 10) == AT_OK){
|
||||
result = true;
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
SystemDelayMs(300);
|
||||
}
|
||||
osMutexRelease(env->atCmd->access);
|
||||
env->playerIsBusy = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
env->playerIsBusy = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_StartToMp3(tAudioPlayer *env, char *name, uint16_t nameLen, uint32_t timeout) {
|
||||
if (osMutexAcquire(env->atCmd->access, 3000) == osOK) {
|
||||
AtCommandResult result = AT_ERROR;
|
||||
if(AtGsmSimComSim7600E_PlayMp3AudioFileTo(env->atCmd, SIM7600E_AUDIO_FILE_PLAY_TO_SPEAKER, name, nameLen) == AT_OK){
|
||||
result = AtCmdWaitOk(env->atCmd, 10, 10);
|
||||
osMutexRelease(env->atCmd->access);
|
||||
env->playerIsBusy = false;
|
||||
|
||||
return result;
|
||||
} else {
|
||||
osMutexRelease(env->atCmd->access);
|
||||
env->playerIsBusy = false;
|
||||
|
||||
return AT_ERROR;
|
||||
}
|
||||
}
|
||||
return AT_ERROR;
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_Tone(tAudioPlayer *env, uint16_t count) {
|
||||
return AudioPlayerSimComSim7600E_StartTone(env, count);
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_Start(tAudioPlayer *env, char *name, uint16_t nameLen, uint32_t timeout) {
|
||||
SystemDelayMs(100);
|
||||
char fileSourceName[nameLen];
|
||||
memcpy(fileSourceName, name, nameLen);
|
||||
env->fileInfo.nameFile = name;
|
||||
env->fileInfo.nameLen = nameLen;
|
||||
|
||||
if(AudioPlayerSimComSim7600E_GetFileFormat(name, nameLen) == MP3){
|
||||
env->fileInfo.fileType = MP3;
|
||||
return AudioPlayerSimComSim7600E_StartToMp3(env, fileSourceName, nameLen, 0);
|
||||
}
|
||||
if(AudioPlayerSimComSim7600E_GetFileFormat(name, nameLen) == WAV){
|
||||
env->fileInfo.fileType = WAV;
|
||||
return AudioPlayerSimComSim7600E_StartToWaw(env, fileSourceName, nameLen, 0);
|
||||
}
|
||||
|
||||
return AT_ERROR;
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_StartToEnd(tAudioPlayer *env, char *name, uint16_t nameLen, uint32_t timeout) {
|
||||
env->playerIsBusy = true;
|
||||
|
||||
SystemDelayMs(50);
|
||||
char fileSourceName[nameLen];
|
||||
memcpy(fileSourceName, name, nameLen);
|
||||
env->fileInfo.nameFile = name;
|
||||
env->fileInfo.nameLen = nameLen;
|
||||
bool res = false;
|
||||
|
||||
if(AudioPlayerSimComSim7600E_GetFileFormat(name, nameLen) == MP3){
|
||||
env->fileInfo.fileType = MP3;
|
||||
res = AudioPlayerSimComSim7600E_StartToMp3(env, fileSourceName, nameLen, 0);
|
||||
if(res){
|
||||
AudioPlayerSimComSim7600E_WaitMp3(env, timeout);
|
||||
} else{
|
||||
return AT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if(AudioPlayerSimComSim7600E_GetFileFormat(name, nameLen) == WAV){
|
||||
env->fileInfo.fileType = WAV;
|
||||
res = AudioPlayerSimComSim7600E_StartToWaw(env, fileSourceName, nameLen, 0);
|
||||
if(res){
|
||||
AudioPlayerSimComSim7600E_WaitWav( env, timeout);
|
||||
} else{
|
||||
return AT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return AT_ERROR;
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_IsBusy(tAudioPlayer *env, uint32_t timeout) {
|
||||
if(env->playerIsBusy){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool AudioPlayerSimComSim7600E_Wait(tAudioPlayer *env, uint32_t timeout) {
|
||||
if(env->fileInfo.fileType == WAV){
|
||||
return AudioPlayerSimComSim7600E_WaitWav(env, timeout);
|
||||
}
|
||||
if(env->fileInfo.fileType == MP3){
|
||||
return AudioPlayerSimComSim7600E_WaitMp3(env, timeout);
|
||||
}
|
||||
return AT_ERROR;
|
||||
}
|
||||
|
||||
void AudioPlayerSimComSim7600E_Init(tAudioPlayer *env, tAtCmd *atCmd){
|
||||
env->atCmd = atCmd;
|
||||
env->playerIsBusy = false;
|
||||
}
|
||||
|
||||
tAudioPlayerInterface AudioPlayerSimComSim7600E_GetInterface(tAudioPlayer *env) {
|
||||
tAudioPlayerInterface result = {
|
||||
.env = env,
|
||||
.start = (audioPlayerCallStart) AudioPlayerSimComSim7600E_Start,
|
||||
.startToEnd =(audioPlayerCallStart) AudioPlayerSimComSim7600E_StartToEnd,
|
||||
.stop = (audioPlayerCall) AudioPlayerSimComSim7600E_Stop,
|
||||
.wait = (audioPlayerCall) AudioPlayerSimComSim7600E_Wait,
|
||||
.isBusy = (audioPlayerCall) AudioPlayerSimComSim7600E_IsBusy,
|
||||
.startTone = (audioPlayerTone) AudioPlayerSimComSim7600E_Tone,
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"dep": [
|
||||
],
|
||||
"cmake": {
|
||||
"inc_dirs": [
|
||||
"Inc"
|
||||
],
|
||||
"srcs": [
|
||||
"Src/**.c"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue