src/AduProtocol.c
/**
 * Handler for the "RPy" or "RPyn" command, which responds with the status of
 * input line n (where n is '0', '1', '2', or '3') on port y (where y is 'A' or
 * 'B'). If n is not provided, the response contains the 4-bit binary value of
 * port y. If n is provided, the response contains a single binary value of the
 * requested line.
 *
 * @post On success, populates the response buffer with the port status
 *
 * @param[in] args The non-fixed portion of the command string (if any)
 *
 * @return Returns true on success or false on failure
 */


@post On success, populates the response buffer with the port status

@param[in] args The non-fixed portion of the command string (if any)

@return Returns true on success or false on failure
@post On success populates the response buffer with the port status @param [ in ] args The non - fixed portion of the command string ( if any ) @return Returns true on success or false on failure
static bool HandlerReadSinglePort(const char *args)
{
    BoardDebugPrint("Hit %s\r\n", __func__);
    bool success = false;
    size_t len = strlen(args);
    if (len >= 1 && len <= 2)
    {
        uint8_t portValue = GetInputPortValue(args[0]);
        if (portValue != 0xff)
        {
            if (len == 2)
            {
                char *endptr;
                unsigned long line = strtoul(&args[1], &endptr, 10);
                if (*endptr == '\0' && line < INPUT_PORT_NUM_PINS)
                {
                    WriteResponseBinary((portValue & (1 << line)) != 0, 1);
                    success = true;
                }
                else
                {
                    BoardDebugPrint("%s: Invalid pin: %s\r\n", __func__, &args[1]);
                }
            }
            else
            {
                WriteResponseBinary(portValue, INPUT_PORT_NUM_PINS);
                success = true;
            }
        }
    }
    else
    {
        BoardDebugPrint("%s: Invalid length %u\r\n", __func__, (unsigned)len);
    }
    return success;
}
static bool HandlerReadSinglePort ( const char * args ) { BoardDebugPrint ( " \r \n " , __func__ ) ; bool success = false ; size_t len = strlen ( args ) ; if ( len >= 1 && len <= 2 ) { uint8_t portValue = GetInputPortValue ( args [ 0 ] ) ; if ( portValue != 0xff ) { if ( len == 2 ) { char * endptr ; unsigned long line = strtoul ( & args [ 1 ] , & endptr , 10 ) ; if ( * endptr == ' \0 ' && line < INPUT_PORT_NUM_PINS ) { WriteResponseBinary ( ( portValue & ( 1 << line ) ) != 0 , 1 ) ; success = true ; } else { BoardDebugPrint ( " \r \n " , __func__ , & args [ 1 ] ) ; } } else { WriteResponseBinary ( portValue , INPUT_PORT_NUM_PINS ) ; success = true ; } } } else { BoardDebugPrint ( " \r \n " , __func__ , ( unsigned ) len ) ; } return success ; }
Handler for the "RPy" or "RPyn" command, which responds with the status of
 input line n (where n is '0', '1', '2', or '3') on port y (where y is 'A' or
 'B').
Handler for the " RPy " or " RPyn " command which responds with the status of input line n ( where n is ' 0 ' ' 1 ' ' 2 ' or ' 3 ' ) on port y ( where y is ' A ' or ' B ' ) .
// We only accept the formats "RPy" or "RPyn", where y is the port to read // ('A' or 'B') and n is the line to read ('0', '1', '2', or '3') // If requesting a specific input line // Check that the conversion was valid and in range // If requesting all four input lines on the port