Skip to content

Commit

Permalink
Add function "getContinuousChanges".
Browse files Browse the repository at this point in the history
  • Loading branch information
docbacardi committed Mar 29, 2022
1 parent f008598 commit c93efbb
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 7 deletions.
134 changes: 134 additions & 0 deletions iomatrix/src/main_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string.h>

#include "rdy_run.h"
#include "serial_vectors.h"
#include "systime.h"
#include "uprintf.h"
#include "version.h"
Expand Down Expand Up @@ -509,6 +510,123 @@ static int get_continuous_status_match(IOMATRIX_PARAMETER_GET_CONTINUOUS_STATUS_
}



static int get_continuous_changes(IOMATRIX_PARAMETER_GET_CONTINUOUS_CHANGES_T *ptParameter __attribute__ ((unused)))
{
int iResult;
int iPrintReport;
int iIsRunning;
unsigned long ulPinCnt;
unsigned long ulPinMax;
const PINDESCRIPTION_T *ptPinDescription;
unsigned char ucPinValue;
char cPinValue;
unsigned int uiPeek;
unsigned char ucCancelGet;
const unsigned long ulForcedUpdateInterval = 3000;
TIMER_HANDLE_T tTimer;
unsigned char aucLastPinState[MAX_PINS_UNDER_TEST];


/* Be optimistic */
iResult = 0;

/* Initialize the buffer for the pin values. */
memset(aucLastPinState, 0x00, sizeof(aucLastPinState));

/* Always print a report in the first round. */
iPrintReport = 1;

/* There is no cancel request yet. */
iIsRunning = 1;

systime_handle_start_ms(&tTimer, ulForcedUpdateInterval);

ulPinMax = ulPinsUnderTest;
while(iIsRunning)
{
ulPinCnt = 0;
while( ulPinCnt<ulPinMax )
{
/* Get the pointer to the pin description. */
ptPinDescription = atPinsUnderTest + ulPinCnt;

/* Get the pin value. */
iResult = iopins_get(ptPinDescription, &ucPinValue);
if( iResult!=0 )
{
uprintf("Failed to get the pin: ");
print_pin(ulPinCnt, ptPinDescription);
break;
}

/* Check if the pin value changed.
* If it changed, update the buffer and remember to
* print a report.
*/
if( ucPinValue!=aucLastPinState[ulPinCnt] )
{
aucLastPinState[ulPinCnt] = ucPinValue;
iPrintReport = 1;
}

++ulPinCnt;
}

if( iResult!=0 )
{
iIsRunning = 0;
}
else
{
/* Print a report at least every second. */
if( systime_handle_is_elapsed(&tTimer)!=0 )
{
iPrintReport = 1;
}

if( iPrintReport!=0 )
{
ulPinCnt = 0;
while( ulPinCnt<ulPinMax )
{
/* Convert the pin value to ASCII.
* A value of 0x00 is printed as "0", everything else is a "1".
*/
cPinValue = '0';
if( aucLastPinState[ulPinCnt]!=0 )
{
cPinValue = '1';
}
uprintf("%c", cPinValue);
++ulPinCnt;
}
uprintf("\n");

/* The report was printed. */
iPrintReport = 0;
systime_handle_start_ms(&tTimer, ulForcedUpdateInterval);
}

/* Is a cancel request waiting? */
#if 0
uiPeek = SERIAL_PEEK();
if( uiPeek!=0 )
{
ucCancelGet = SERIAL_GET();
if( ucCancelGet==0x2b )
{
iIsRunning = 0;
}
}
#endif
}
}

return iResult;
}


/*-------------------------------------------------------------------------*/

TEST_RESULT_T test(IOMATRIX_PARAMETER_T *ptTestParams)
Expand Down Expand Up @@ -637,6 +755,22 @@ TEST_RESULT_T test(IOMATRIX_PARAMETER_T *ptTestParams)
iResult = get_continuous_status_match(&(ptTestParams->uParameter.tGetContinuousStatusMatch));
}
break;

case IOMATRIX_COMMAND_Get_Continuous_Changes:
if( s_ulVerbosity!=0 )
{
uprintf("Mode: Get continuous changes\n");
}

if( ptTestParams->uParameter.tGetContinuousChanges.pvPinDescription != (void*)atPinsUnderTest )
{
uprintf("Error: the pin description handle is invalid!\n");
}
else
{
iResult = get_continuous_changes(&(ptTestParams->uParameter.tGetContinuousChanges));
}
break;
}

if( iResult==0 )
Expand Down
19 changes: 12 additions & 7 deletions iomatrix/src/main_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@

typedef enum IOMATRIX_COMMAND_ENUM
{
IOMATRIX_COMMAND_Parse_Pin_Description = 0,
IOMATRIX_COMMAND_Set_Pin = 1,
IOMATRIX_COMMAND_Get_Pin = 2,
IOMATRIX_COMMAND_Set_All_Pins = 3,
IOMATRIX_COMMAND_Get_All_Pins = 4,
IOMATRIX_COMMAND_Get_Continuous_Status_Match = 5
IOMATRIX_COMMAND_Parse_Pin_Description = 0,
IOMATRIX_COMMAND_Set_Pin = 1,
IOMATRIX_COMMAND_Get_Pin = 2,
IOMATRIX_COMMAND_Set_All_Pins = 3,
IOMATRIX_COMMAND_Get_All_Pins = 4,
IOMATRIX_COMMAND_Get_Continuous_Status_Match = 5,
IOMATRIX_COMMAND_Get_Continuous_Changes = 6
} IOMATRIX_COMMAND_T;


Expand Down Expand Up @@ -89,7 +90,10 @@ typedef struct IOMATRIX_PARAMETER_CONTINUOUS_PIN_STATUS_T
unsigned char aucList[MAX_PINS_UNDER_TEST]; /* The list with test pattern. */
}IOMATRIX_PARAMETER_GET_CONTINUOUS_STATUS_MATCH_T;


typedef struct IOMATRIX_PARAMETER_GET_CONTINUOUS_CHANGES_STRUCT
{
void *pvPinDescription; /* A handle of the pin description. */
} IOMATRIX_PARAMETER_GET_CONTINUOUS_CHANGES_T;

typedef struct IOMATRIX_PARAMETER_STRUCT
{
Expand All @@ -103,6 +107,7 @@ typedef struct IOMATRIX_PARAMETER_STRUCT
IOMATRIX_PARAMETER_SET_ALL_PINS_T tSetAllPins;
IOMATRIX_PARAMETER_GET_ALL_PINS_T tGetAllPins;
IOMATRIX_PARAMETER_GET_CONTINUOUS_STATUS_MATCH_T tGetContinuousStatusMatch;
IOMATRIX_PARAMETER_GET_CONTINUOUS_CHANGES_T tGetContinuousChanges;
} uParameter;
} IOMATRIX_PARAMETER_T;

Expand Down
4 changes: 4 additions & 0 deletions iomatrix/templates/io_matrix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ function IoMatrix:bget()
end


function IoMatrix:getContinuousChanges()
self.netx:getContinuousChanges()
end


function IoMatrix:close()
self.netx:close()
Expand Down
8 changes: 8 additions & 0 deletions iomatrix/templates/io_matrix/netx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ end



function IoMatrix_netx:getContinuousChanges()
for _, tDev in pairs(self.atDevices) do
tDev:getContinuousChanges()
end
end



function IoMatrix_netx:close()
-- No need to close something.
end
Expand Down
27 changes: 27 additions & 0 deletions iomatrix/templates/io_matrix/netx_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function IoMatrix_netx_base:_init(tLog, fnInit, fnDeinit, ulVerbose, fnCallbackP
self.IOMATRIX_COMMAND_Set_All_Pins = ${IOMATRIX_COMMAND_Set_All_Pins}
self.IOMATRIX_COMMAND_Get_All_Pins = ${IOMATRIX_COMMAND_Get_All_Pins}
self.IOMATRIX_COMMAND_Get_Continuous_Status_Match = ${IOMATRIX_COMMAND_Get_Continuous_Status_Match}
self.IOMATRIX_COMMAND_Get_Continuous_Changes = ${IOMATRIX_COMMAND_Get_Continuous_Changes}

self.strPinStatusZ = string.char(self.PINSTATUS_HIGHZ)
self.strPinStatus0 = string.char(self.PINSTATUS_OUTPUT0)
Expand Down Expand Up @@ -624,4 +625,30 @@ end



function IoMatrix_netx_base:getContinuousChanges()
local tResult

-- Collect the parameter.
self:__write_header{
self.ulVerbose, -- Verbose mode.
self.IOMATRIX_COMMAND_Get_Continuous_Changes, -- The command code.
self.hPinDescription -- Pin description handle.
}

-- Call the netX program.
self.tLog.debug('__/Output/____________________________________________________________________')
self.tPlugin:call(self.ulExecutionAddress, self.ulParameterStartAddress, self.fnCallbackMessage, 0)
self.tLog.debug('______________________________________________________________________________')

-- Get the result.
local ulResult = self.tPlugin:read_data32(self.ulParameterStartAddress)
if ulResult==0 then
tResult = true
end

return tResult
end



return IoMatrix_netx_base

0 comments on commit c93efbb

Please sign in to comment.