Beispiel #1
0
int main(int argc, char *argv[])
{
    if(argc != 3){
        printf("args invalid\n");
        return 0;
    }

    unsigned long addr = utl_str2int(argv[1]);
    int size = utl_str2int(argv[2]);

    printf("read from 0x%lX, size %d\n", addr, size);


    int fd = open("/dev/phy_mem", O_RDONLY);
    if(fd < 0){
        printf("phy_mem open fail\n");
        return 0;
    }

    addr = addr & 0xFFFFFFFFFFFFFFF8L;
    if(size > 256){
        size = 256;
    }
    if(size == 0){
        size = 8;
    }
    size = (size + 7) & 0xFFFFFFF8;

    __off64_t off = lseek64(fd, (__off64_t)addr, SEEK_SET);
    if(off < 0){
        printf("lseek fail\n");
        return 0;
    }

    unsigned int buf[256 / 4];
    int read_size = read(fd, (char*)buf, size);
    if(read_size < 0){
        printf("read failed\n");
        return 0;
    }

    int i;
    for(i = 0; i< size / 8; i++){
        printf("%#lX:\t\t %08x  %08x \n", addr + i * 8, buf[2 * i], buf[2 * i + 1]);
    }

    close(fd);


    return 0;
}
Beispiel #2
0
/******************************************************************************
**
** Function         bta_ag_process_at
**
** Description      Parse AT commands.  This function will take the input
**                  character string and parse it for AT commands according to
**                  the AT command table passed in the control block.
**
**
** Returns          void
**
******************************************************************************/
void bta_ag_process_at(tBTA_AG_AT_CB *p_cb)
{
    UINT16      idx;
    UINT8       arg_type;
    char        *p_arg;
    INT16       int_arg = 0;
    /* loop through at command table looking for match */
    for (idx = 0; p_cb->p_at_tbl[idx].p_cmd[0] != 0; idx++)
    {
        if (!utl_strucmp(p_cb->p_at_tbl[idx].p_cmd, p_cb->p_cmd_buf))
        {
            break;
        }
    }

    /* if there is a match; verify argument type */
    if (p_cb->p_at_tbl[idx].p_cmd[0] != 0)
    {
        /* start of argument is p + strlen matching command */
        p_arg = p_cb->p_cmd_buf + strlen(p_cb->p_at_tbl[idx].p_cmd);

        /* if no argument */
        if (p_arg[0] == 0)
        {
            arg_type = BTA_AG_AT_NONE;
        }
        /* else if arg is '?' and it is last character */
        else if (p_arg[0] == '?' && p_arg[1] == 0)
        {
            /* we have a read */
            arg_type = BTA_AG_AT_READ;
        }
        /* else if arg is '=' */
        else if (p_arg[0] == '=' && p_arg[1] != 0)
        {
            if (p_arg[1] == '?' && p_arg[2] == 0)
            {
                /* we have a test */
                arg_type = BTA_AG_AT_TEST;
            }
            else
            {
                /* we have a set */
                arg_type = BTA_AG_AT_SET;

                /* skip past '=' */
                p_arg++;
            }
        }
        else
            /* else it is freeform argument */
        {
            arg_type = BTA_AG_AT_FREE;
        }

        /* if arguments match command capabilities */
        if ((arg_type & p_cb->p_at_tbl[idx].arg_type) != 0)
        {
            /* if it's a set integer check max, min range */
            if (arg_type == BTA_AG_AT_SET &&
                    p_cb->p_at_tbl[idx].fmt == BTA_AG_AT_INT)
            {
                int_arg = utl_str2int(p_arg);
                if (int_arg < (INT16) p_cb->p_at_tbl[idx].min ||
                        int_arg > (INT16) p_cb->p_at_tbl[idx].max)
                {
                    /* arg out of range; error */
                    (*p_cb->p_err_cback)(p_cb->p_user, FALSE, NULL);
                }
                else
                {

                    (*p_cb->p_cmd_cback)(p_cb->p_user, idx, arg_type, p_arg, int_arg);
                }
            }
            else
            {
                (*p_cb->p_cmd_cback)(p_cb->p_user, idx, arg_type, p_arg, int_arg);
            }
        }
        /* else error */
        else
        {
            (*p_cb->p_err_cback)(p_cb->p_user, FALSE, NULL);
        }
    }
    /* else no match call error callback */
    else
    {
        (*p_cb->p_err_cback)(p_cb->p_user, TRUE, p_cb->p_cmd_buf);
    }
}