|
|
@@ -4,6 +4,7 @@
|
|
|
#define SCPI_ARGS_N_Q 0
|
|
|
#include "app/scpi/scpi_handler.h"
|
|
|
#include "app/control_table/control_table.h"
|
|
|
+#include "drivers/switchboard_control/switchboard_control.h"
|
|
|
|
|
|
// -----
|
|
|
// @argTypesCommand
|
|
|
@@ -16,14 +17,17 @@ DECLARE_SCPI_ARGS_C( eScpiArg_Numeric, eScpiArg_Numeric );
|
|
|
// Supported arguments: 0
|
|
|
DECLARE_SCPI_ARGS_Q();
|
|
|
|
|
|
-DECLARE_ARGUMENT_NUMERIC_VALUES_I32(AllowedValues_PortNumber, 0, 16);
|
|
|
+DECLARE_ARGUMENT_NUMERIC_VALUES_I32(AllowedValues_SW_Number, 1, 10);
|
|
|
+DECLARE_ARGUMENT_NUMERIC_VALUES_I32(AllowedValues_SW_State, 0, 3);
|
|
|
|
|
|
-const uint8_t fsqvbl_CommandHandlerPortSet = 1; // CTRL:PORT
|
|
|
+const uint8_t fsqvbl_CommandHandlerSwCtrl = 1; // CTRL:SW
|
|
|
const uint8_t fsqvbl_CommandHandlerMeasStart = 2; // MEAS:START
|
|
|
const uint8_t fsqvbl_CommandHandlerMeasStop = 3; // MEAS:STOP
|
|
|
const uint8_t fsqvbl_CommandHandlerMeasCont = 4; // MEAS:CONTinue
|
|
|
const uint8_t fsqvbl_CommandHandlerMeasMode = 5; // MEAS:MODE
|
|
|
|
|
|
+static uint16_t sw_cmd_reg = 0x0000;
|
|
|
+
|
|
|
#include "app/scpi/commandHandlers/power_switch.h"
|
|
|
#include "app/nfm/nfm_base.h"
|
|
|
|
|
|
@@ -63,6 +67,41 @@ static void fsql_CommandHandlerCtrl_Switch_Group( const struct fFSeqEntry_t * th
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+// Set bit into possition func
|
|
|
+uint16_t set_bit(uint16_t cmd_register, uint16_t SW_Number, uint16_t SW_State) {
|
|
|
+
|
|
|
+ unsigned char bit_position=0;
|
|
|
+
|
|
|
+ switch (SW_Number)
|
|
|
+ {
|
|
|
+ case 1: {bit_position = 1;} break;
|
|
|
+ case 2: {bit_position = 9;} break;
|
|
|
+ case 3: {bit_position = 2;} break;
|
|
|
+ case 4: {bit_position = 10;} break;
|
|
|
+ case 5: {bit_position = 3;} break;
|
|
|
+ case 6: {bit_position = 4;} break;
|
|
|
+ case 7: {bit_position = 12;} break;
|
|
|
+ case 8: {bit_position = 13;} break;
|
|
|
+ case 9: {bit_position = 14;} break;
|
|
|
+ case 10: {bit_position = 15;} break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (SW_Number == 4)
|
|
|
+ { // clear control bits positions
|
|
|
+ cmd_register &= ~(3 << bit_position);
|
|
|
+ // set control bits positions
|
|
|
+ cmd_register |= (SW_State << bit_position);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ { // reset bit in possition
|
|
|
+ cmd_register &= ~(1 << bit_position);
|
|
|
+ cmd_register |= ((SW_State & 1) << bit_position);
|
|
|
+ }
|
|
|
+
|
|
|
+ return cmd_register;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
static const struct fFSeqEntry_t * fsqf_CommandHandlerCtrl_Switch_Group( const struct fFSeqEntry_t * this,
|
|
|
tFSeqCtx_t ctx,
|
|
|
const struct fFSeqEntry_t * * pDeferredNext )
|
|
|
@@ -83,39 +122,26 @@ static const struct fFSeqEntry_t * fsqf_CommandHandlerCtrl_Switch_Group( const s
|
|
|
else if( ! common_ctx->isQuery )
|
|
|
{
|
|
|
common_ctx->status = eProgramDataIllegalArgument; // forward set, illegal parameter value, caller should generate error message
|
|
|
- if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerPortSet )
|
|
|
+ if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerSwCtrl )
|
|
|
{
|
|
|
// Parse first argument
|
|
|
- const sNumericEntry_t * ne = SCPI_PROCESS_ARGUMENT_NUMERIC(common_ctx, &AllowedValues_PortNumber, 0);
|
|
|
+ const sNumericEntry_t * ne = SCPI_PROCESS_ARGUMENT_NUMERIC(common_ctx, &AllowedValues_SW_Number, 0);
|
|
|
if( ScpiNumericSuccess != ne->error ) break;
|
|
|
- uint16_t port1 = ne->Value.demicalInteger;
|
|
|
+ uint16_t swNumber = ne->Value.demicalInteger;
|
|
|
|
|
|
// Parse second argument
|
|
|
- ne = SCPI_PROCESS_ARGUMENT_NUMERIC(common_ctx, &AllowedValues_PortNumber, 1);
|
|
|
+ ne = SCPI_PROCESS_ARGUMENT_NUMERIC(common_ctx, &AllowedValues_SW_State, 1);
|
|
|
if( ScpiNumericSuccess != ne->error ) break;
|
|
|
- uint16_t port2 = ne->Value.demicalInteger;
|
|
|
+ uint16_t swState = ne->Value.demicalInteger;
|
|
|
|
|
|
- if((port1 || port2) && (port1 == port2)) break;
|
|
|
+ sw_cmd_reg = set_bit(sw_cmd_reg, swNumber, swState);
|
|
|
+
|
|
|
+ HAL_GPIO_WritePin( GPIOA, GPIO_PIN_8, GPIO_PIN_SET); // Turn OFF active Reset signal on external shift REG that was set during powerup
|
|
|
|
|
|
- if( port1 > NFMClass->properties.allowedOutputPorts || port2 > NFMClass->properties.allowedOutputPorts)
|
|
|
- {
|
|
|
- common_ctx->status = eProgramDataRuntimeError;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if( !NFMClass->methods.portMethods.setPortState(eNFMPort_1, port1) || !NFMClass->methods.portMethods.setPortState(eNFMPort_2, port2) )
|
|
|
- {
|
|
|
- common_ctx->status = eProgramDataRuntimeError;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- sTableTablePoint_t portCommutation =
|
|
|
- {
|
|
|
- .port1 = NFMClass->methods.portMethods.getPortState(eNFMPort_1),
|
|
|
- .port2 = NFMClass->methods.portMethods.getPortState(eNFMPort_2)
|
|
|
- };
|
|
|
-
|
|
|
- ControlHandle.PortSet(portCommutation);
|
|
|
+ SBHandle.ClrNSS();
|
|
|
+ SBHandle.Transmit(((uint8_t*)&(sw_cmd_reg)), sizeof(uint8_t));
|
|
|
+ SBHandle.SetNSS();
|
|
|
+
|
|
|
|
|
|
common_ctx->status = eProgramDataDone;
|
|
|
}
|
|
|
@@ -134,12 +160,9 @@ static const struct fFSeqEntry_t * fsqf_CommandHandlerCtrl_Switch_Group( const s
|
|
|
if( common_ctx->MeasAndSwitch.idx == 0 ) // first reading
|
|
|
{
|
|
|
size_t length = 0;
|
|
|
- if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerPortSet )
|
|
|
+ if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerSwCtrl )
|
|
|
{
|
|
|
- sTableTablePoint_t portState = ControlHandle.PortRead();
|
|
|
- NFMClass->methods.portMethods.setPortState(eNFMPort_1, portState.port1);
|
|
|
- NFMClass->methods.portMethods.setPortState(eNFMPort_2, portState.port2);
|
|
|
- length = _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%d, %d", portState.port1, portState.port2);
|
|
|
+ length = _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%d", sw_cmd_reg);
|
|
|
}
|
|
|
else if( common_ctx->handler_ctx == &fsqvbl_CommandHandlerMeasStart )
|
|
|
{
|
|
|
@@ -164,6 +187,8 @@ static const struct fFSeqEntry_t * fsqf_CommandHandlerCtrl_Switch_Group( const s
|
|
|
length = _snprintf( common_ctx->tempBuffer, sizeof(common_ctx->tempBuffer), "%s", res ? "TABLE\n" : "MANUAL\n");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
if( length > 0 )
|
|
|
{
|