Commit a6491bc9 authored by Peter Zumbruch's avatar Peter Zumbruch
Browse files

apfelApi.c: read called twice, range check on port letters

apfel.c: condensing the code
all apfel: refactoring of Ampl to Amplification, cosmetics
parent 8d873a61
......@@ -441,15 +441,19 @@ int16_t apfelReadDac_Inline(apfelAddress *address, uint8_t dacNr, uint8_t quiet)
apfelWriteClockSequence_Inline(address, APFEL_COMMAND_ReadDac_CommandClockCycles_Trailer);
if (0 == quiet)
{
clearString(resultString, BUFFER_SIZE);
snprintf_P(resultString, BUFFER_SIZE - 1, string_address_format, APFEL_ADDRESS_ORDER(address->port, address->pinSetIndex, address->sideSelection, address->chipId) );
snprintf_P(resultString, BUFFER_SIZE - 1, string_dac_x_, resultString, dacNr);
}
// check validity for correct header (10) and trailing bits (111)
/* Error */
if ( APFEL_READ_CHECK_VALUE != (value & APFEL_READ_CHECK_MASK))
{
/* Error */
if (0 == quiet)
{
clearString(resultString, BUFFER_SIZE);
snprintf_P(resultString, BUFFER_SIZE - 1, string_address_format, APFEL_ADDRESS_ORDER(address->port, address->pinSetIndex, address->sideSelection, address->chipId) );
snprintf_P(resultString, BUFFER_SIZE - 1, string_dac_x_, resultString, dacNr);
CommunicationError(ERRA, -1, 0,
PSTR("%S %S %s- read validity check failed, raw value:0x%x"),
(const char*) ( pgm_read_word( &(commandKeywords[commandKeyNumber_APFEL])) ),
......@@ -466,9 +470,7 @@ int16_t apfelReadDac_Inline(apfelAddress *address, uint8_t dacNr, uint8_t quiet)
createExtendedSubCommandReceiveResponseHeader(ptr_uartStruct, commandKeyNumber_APFEL,
apfelApiCommandKeyNumber_DAC, apfelApiCommandKeywords);
snprintf_P(resultString, BUFFER_SIZE -1, string_address_format, APFEL_ADDRESS_ORDER(address->port, address->pinSetIndex, address->sideSelection, address->chipId) );
strncat(uart_message_string, resultString, BUFFER_SIZE - 1);
snprintf_P(uart_message_string, BUFFER_SIZE - 1, string_dac_x_, uart_message_string, dacNr);
apiShowValue(uart_message_string, &value, apiVarType_UINT16);
apiSubCommandsFooter(apiCommandResult_SUCCESS_WITH_OUTPUT);
}
......@@ -553,13 +555,13 @@ void apfelTestPulse_Inline(apfelAddress *address, uint16_t pulseHeight, uint8_t
}
/*#setAmplitude channelId[1 ... 2] chipId[0 ... FF]*/
void apfelSetAmplitude_Inline(apfelAddress *address, uint8_t channel)
void apfelSetAmplification_Inline(apfelAddress *address, uint8_t channel)
{
apfelSendCommandValueChipIdClockSequence_p(APFEL_COMMAND_SetAmplitude + ((channel==1)?1:0), 0, APFEL_COMMAND_SetAmplification_CommandClockCycles, address);
}
/*#resetAmplitude channelId[1 ... 2] chipId[0 ... FF]*/
void apfelResetAmplitude_Inline(apfelAddress *address, uint8_t channel)
void apfelResetAmplification_Inline(apfelAddress *address, uint8_t channel)
{
apfelSendCommandValueChipIdClockSequence_p(APFEL_COMMAND_ResetAmplitude + ((channel==2)?2:0), 0, APFEL_COMMAND_ResetAmplification_CommandClockCycles, address);
}
......
......@@ -46,9 +46,9 @@ void apfelListIds_Inline(apfelAddress *address, bool all, uint8_t nElements, u
uint16_t apfelReadBitSequence_Inline(apfelAddress *address, uint8_t nBits);
int16_t apfelReadDac_Inline(apfelAddress *address, uint8_t dacNr, uint8_t quiet);
int8_t apfelReadPort(apfelAddress *address);
void apfelResetAmplitude_Inline(apfelAddress *address, uint8_t channel);
void apfelResetAmplification_Inline(apfelAddress *address, uint8_t channel);
void apfelSendCommandValueChipIdClockSequence(uint8_t command, uint16_t value, uint16_t clockCycles, apfelAddress *address);
void apfelSetAmplitude_Inline(apfelAddress *address, uint8_t channel);
void apfelSetAmplification_Inline(apfelAddress *address, uint8_t channel);
void apfelSetDac_Inline(apfelAddress *address, uint16_t value, uint8_t dacNr, uint8_t quiet);
void apfelStartStreamHeader_Inline(apfelAddress *address);
void apfelTestPulse_Inline(apfelAddress *address, uint16_t pulseHeight, uint8_t channel);
......
......@@ -290,7 +290,6 @@ void apfelApiVersion0(void)
CommunicationError_p(ERRA, -1, 1, string_wrong_number_of_arguments_PS, string_bracket_6_bracket);
return;
}
apfelReadDac_Inline(&address, dacNr, quiet);
}
break;
case apfelApiCommandKeyNumber_AutoCalibration:
......@@ -337,7 +336,7 @@ void apfelApiVersion0(void)
{
if (5 == nSubCommandsArguments )
{
apfelSetAmplitude_Inline(&address, arg[1]);
apfelSetAmplification_Inline(&address, arg[1]);
}
else
{
......@@ -350,7 +349,7 @@ void apfelApiVersion0(void)
{
if (5 == nSubCommandsArguments )
{
apfelResetAmplitude_Inline(&address, arg[1]);
apfelResetAmplification_Inline(&address, arg[1]);
}
else
{
......@@ -444,6 +443,21 @@ apiCommandResult apfelApiParseAddress(apfelAddress *address, uint8_t portArgumen
else
{
address->port = setParameter[portArgumentIndex + 1][0];
switch(address->port)
{
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
break;
default:
CommunicationError_p(ERRA, SERIAL_ERROR_arguments_exceed_boundaries, true, PSTR("[A-G] %c"), address->port);
address->port = 0;
return apiCommandResult_FAILURE_QUIET;
}
}
if ( apiCommandResult_SUCCESS_QUIET != apiAssignParameterToValue( pinSetIndexArgumentIndex + 1, &(address-> pinSetIndex),apiVarType_UINT8,1,2))
......@@ -498,7 +512,7 @@ void apfelApi(struct uartStruct *ptr_uartStruct)
}
else
{
#warning move to api and generalize it to be used via fcn pointer also by sub commands
#warning TODO: move to api and generalize it to be used via fcn pointer also by sub commands
apiCallCommands(1, ptr_uartStruct, apfelApiCommandKeywords, apfelApiCommandKeyNumber_MAXIMUM_NUMBER,
apfelApiSubCommands, apfelApiCommandKeyNumber_STATUS);
}
......@@ -806,9 +820,6 @@ apiCommandResult apfelApiSubCommandEnablePortAddressSet(void)
printDebug_p(debugLevelVerboseDebug, debugSystemAPFEL, __LINE__, filename, PSTR("EnablePortAddressSet "));
return apiCommandResult_SUCCESS_QUIET;
}
#if 0
#endif
#if 0
//just a paste and copy of spi to be adopted
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment