Init
This commit is contained in:
commit
655aa2cc81
|
|
@ -0,0 +1,17 @@
|
||||||
|
//
|
||||||
|
// Created by zemon on 24.07.24.
|
||||||
|
//
|
||||||
|
#include "ComIntCodec.h"
|
||||||
|
#include "XfcProtTable.h"
|
||||||
|
|
||||||
|
|
||||||
|
void XfcProtMethodsAdd_CodecInit(tXfcCodec *env, tAudioCodec *audioCodec){
|
||||||
|
env->audioCodec = audioCodec;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void XfcProtMethodsAdd_Codec(tXfcProtTable *protTab, tXfcCodec *audioCodec) {
|
||||||
|
XfcProtTable_AddStatic(protTab, "GET_CODEC", XfcProtMethod_CodecGet, audioCodec);
|
||||||
|
XfcProtTable_AddStatic(protTab, "SET_CODEC", XfcProtMethod_CodecSet, audioCodec);
|
||||||
|
XfcProtTable_AddStatic(protTab, "SAVE_CODEC", XfcProtMethod_CodecSave, audioCodec);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
//
|
||||||
|
// Created by zemon on 24.07.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SMART_COMPONENTS_COMINTCODEC_H
|
||||||
|
#define SMART_COMPONENTS_COMINTCODEC_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "I2cIO.h"
|
||||||
|
#include "XfcProtProcessorUtilDefines.h"
|
||||||
|
#include "AudioCodec.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ADR,
|
||||||
|
VALUE,
|
||||||
|
VOLUME_LEVEL
|
||||||
|
} tXfcCodecType;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tAudioCodec *audioCodec;
|
||||||
|
|
||||||
|
uint16_t adr;
|
||||||
|
uint16_t data;
|
||||||
|
uint16_t volumeLevel;
|
||||||
|
} tXfcCodec;
|
||||||
|
|
||||||
|
void XfcProtMethodsAdd_Codec(tXfcProtTable *protTab, tXfcCodec *audioCodec);
|
||||||
|
|
||||||
|
void XfcProtMethodsAdd_CodecInit(tXfcCodec *env, tAudioCodec *audioCodec);
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_CodecGet(tXfcArray *request, tXfcArray *response, tXfcCodec *amplifier);
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_CodecSet(tXfcArray *request, tXfcArray *response, tXfcCodec *env);
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_CodecSave(tXfcArray *request, tXfcArray *response, tXfcCodec *env);
|
||||||
|
#endif //SMART_COMPONENTS_COMINTCODEC_H
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
//
|
||||||
|
// Created by zemon on 24.07.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "ComIntCodec.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "nau88u10yg.h"
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_GetCodecVar(tXfcArray *request, tXfcArray *response, tXfcCodec *env, char *paramValueID_text, uint8_t paramValueID_len) {
|
||||||
|
|
||||||
|
// Текстовый вид ID
|
||||||
|
XFC_CMD_TX_ADD_RAW(paramValueID_len);
|
||||||
|
XFC_CMD_TX_ADD_ARR(paramValueID_text, paramValueID_len);
|
||||||
|
|
||||||
|
if (memcmp(paramValueID_text, "ADR", sizeof("ADR") - 1) == 0) {
|
||||||
|
uint8_t len = 2;
|
||||||
|
// Размер данных
|
||||||
|
XFC_CMD_TX_ADD_RAW(len);
|
||||||
|
// Данные
|
||||||
|
uint16_t indexScroll = env->adr; // = ProtMethods_AmplGetLvlVolumeIndex(env->amplifier,env->level);
|
||||||
|
XFC_CMD_TX_ADD_ARR(&indexScroll, len);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp(paramValueID_text, "VALUE", sizeof("VALUE") - 1) == 0) {
|
||||||
|
uint8_t len = 2;
|
||||||
|
// Размер данных
|
||||||
|
XFC_CMD_TX_ADD_RAW(len);
|
||||||
|
// Данные
|
||||||
|
uint16_t indexScroll = env->data; // = ProtMethods_AmplGetLvlVoltIndex(env->amplifier,env->voltage);
|
||||||
|
XFC_CMD_TX_ADD_ARR(&indexScroll, len);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp(paramValueID_text, "VOLUME_LEVEL", sizeof("VOLUME_LEVEL") - 1) == 0) {
|
||||||
|
uint8_t len = 2;
|
||||||
|
// Размер данных
|
||||||
|
XFC_CMD_TX_ADD_RAW(len);
|
||||||
|
// Данные
|
||||||
|
uint16_t indexScroll = ProtMethods_CodecGetLvlVoltIndex(env->audioCodec,env->volumeLevel);
|
||||||
|
XFC_CMD_TX_ADD_ARR(&indexScroll, len);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_CodecGet(tXfcArray *request, tXfcArray *response, tXfcCodec *env) {
|
||||||
|
AudioCodec_GetVolumeLevel(env->audioCodec, &env->volumeLevel);
|
||||||
|
|
||||||
|
// Чтение всех параметров
|
||||||
|
if (XfcArrayGetDataSize(request) == 0) {
|
||||||
|
|
||||||
|
uint16_t paramCount = 3;
|
||||||
|
// Количество параметров
|
||||||
|
XFC_CMD_TX_ADD_RAW(paramCount);
|
||||||
|
|
||||||
|
uint8_t paramValueID_len;
|
||||||
|
char paramValueID_text[20];
|
||||||
|
|
||||||
|
paramValueID_len = sizeof("ADR") - 1;
|
||||||
|
paramValueID_text[0] = '\0';
|
||||||
|
strcat(paramValueID_text, "ADR");
|
||||||
|
if (!XfcProtMethod_GetCodecVar(request, response, env, paramValueID_text, paramValueID_len)) {
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_EXECUTION_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
paramValueID_len = sizeof("VALUE") - 1;
|
||||||
|
paramValueID_text[0] = '\0';
|
||||||
|
strcat(paramValueID_text, "VALUE");
|
||||||
|
if (!XfcProtMethod_GetCodecVar(request, response, env, paramValueID_text, paramValueID_len)) {
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_EXECUTION_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
paramValueID_len = sizeof("VOLUME_LEVEL") - 1;
|
||||||
|
paramValueID_text[0] = '\0';
|
||||||
|
strcat(paramValueID_text, "VOLUME_LEVEL");
|
||||||
|
if (!XfcProtMethod_GetCodecVar(request, response, env, paramValueID_text, paramValueID_len)) {
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_EXECUTION_ERROR;
|
||||||
|
}
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Чтение избранных параметров
|
||||||
|
uint16_t paramCount;
|
||||||
|
XFC_CMD_RX_GET_RAW(paramCount);
|
||||||
|
|
||||||
|
// Количество параметров
|
||||||
|
XFC_CMD_TX_ADD_RAW(paramCount);
|
||||||
|
|
||||||
|
for (uint16_t count = 0; count < paramCount; ++count) {
|
||||||
|
// Получение текстового id параметра
|
||||||
|
uint8_t paramValueID_len;
|
||||||
|
XFC_CMD_RX_GET_RAW(paramValueID_len);
|
||||||
|
char paramValueID_text[paramValueID_len];
|
||||||
|
XFC_CMD_RX_GET_ARR(paramValueID_text, paramValueID_len);
|
||||||
|
|
||||||
|
if(!XfcProtMethod_GetCodecVar(request, response, env, paramValueID_text, paramValueID_len)) {
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_EXECUTION_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_OK;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "XfcArray.h"
|
||||||
|
#include "XfcProtResponseCodes.h"
|
||||||
|
#include "AudioCodec.h"
|
||||||
|
#include "ComIntCodec.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Created by zemon on 30.10.24.
|
||||||
|
//
|
||||||
|
static uint8_t XfcProtMethod_CodecSaveConf(tXfcArray *request, tXfcArray *response, tXfcCodec *env) {
|
||||||
|
AudioCodec_DumpConf(env->audioCodec, env->volumeLevel);
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_CodecSave(tXfcArray *request, tXfcArray *response, tXfcCodec *env) {
|
||||||
|
|
||||||
|
uint8_t result = XfcProtMethod_CodecSaveConf(request, response, env);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
//
|
||||||
|
// Created by zemon on 24.07.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <memory.h>
|
||||||
|
#include "nau88u10yg.h"
|
||||||
|
#include "ComIntCodec.h"
|
||||||
|
|
||||||
|
uint16_t XfcArrayGetBytesFrontToSendCodec(tXfcCodec *env, tXfcCodecType codecType, tXfcArray *array, uint8_t length) {
|
||||||
|
|
||||||
|
uint16_t available = XfcArrayGetDataSize(array);
|
||||||
|
|
||||||
|
uint16_t toGet = available > length ? length : available;
|
||||||
|
|
||||||
|
if (codecType == ADR) {
|
||||||
|
env->adr = *(uint32_t *)(array->data + array->begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codecType == VALUE) {
|
||||||
|
env->data = *(uint32_t *)(array->data + array->begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codecType == VOLUME_LEVEL) {
|
||||||
|
env->volumeLevel = *(uint32_t *)(array->data + array->begin);
|
||||||
|
}
|
||||||
|
array->begin += toGet;
|
||||||
|
|
||||||
|
return toGet;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t XfcProtMethod_CodecSetConf(tXfcArray *request, tXfcArray *response, tXfcCodec *env) {
|
||||||
|
|
||||||
|
// Запись избранных параметров
|
||||||
|
uint16_t paramCount = 0;
|
||||||
|
uint8_t paramValueID_len = 0;
|
||||||
|
uint8_t paramValueID_text[64];
|
||||||
|
|
||||||
|
XFC_CMD_RX_GET_RAW(paramCount);
|
||||||
|
|
||||||
|
if (!paramCount) {
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint16_t count = 0; count < paramCount; ++count) {
|
||||||
|
|
||||||
|
// Получение текстового id параметра
|
||||||
|
XFC_CMD_RX_GET_RAW(paramValueID_len);
|
||||||
|
XFC_CMD_RX_GET_ARR(paramValueID_text, paramValueID_len);
|
||||||
|
|
||||||
|
uint8_t dataLen;
|
||||||
|
XFC_CMD_RX_GET_RAW(dataLen);
|
||||||
|
|
||||||
|
if (memcmp(paramValueID_text, "ADR", sizeof("ADR") - 1) == 0) {
|
||||||
|
uint16_t countLen = XfcArrayGetBytesFrontToSendCodec(env, ADR, request, dataLen);
|
||||||
|
if (countLen != dataLen) {
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_REQUEST_UNEXPECTEDLY_SHORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp(paramValueID_text, "VALUE", sizeof("VALUE") - 1) == 0) {
|
||||||
|
uint16_t countLen = XfcArrayGetBytesFrontToSendCodec(env, VALUE, request, dataLen);
|
||||||
|
if (countLen != dataLen) {
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_REQUEST_UNEXPECTEDLY_SHORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp(paramValueID_text, "VOLUME_LEVEL", sizeof("VOLUME_LEVEL") - 1) == 0) {
|
||||||
|
uint16_t countLen = XfcArrayGetBytesFrontToSendCodec(env, VOLUME_LEVEL, request, dataLen);
|
||||||
|
if (countLen != dataLen) {
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_REQUEST_UNEXPECTEDLY_SHORT;
|
||||||
|
}
|
||||||
|
AudioCodec_SetVolumeLevel(env->audioCodec,env->audioCodec->volume_levels[env->volumeLevel]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// AudioCodec_SetOneRegistr(env->audioCodec,env->adr,env->data);
|
||||||
|
}
|
||||||
|
return XFC_TRANSPORT_PROTOCOL_RESPONSE_RESULT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t XfcProtMethod_CodecSet(tXfcArray *request, tXfcArray *response, tXfcCodec *codec){
|
||||||
|
|
||||||
|
uint8_t result = XfcProtMethod_CodecSetConf(request, response, codec);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"cmake": {
|
||||||
|
"inc_dirs": [
|
||||||
|
"./"
|
||||||
|
],
|
||||||
|
"srcs": [
|
||||||
|
"./**.c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue