85 lines
2.7 KiB
C
85 lines
2.7 KiB
C
//
|
|
// 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;
|
|
} |