⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commands.c

📁 linux下的dvb收看解析软件代码; 带参考程序
💻 C
📖 第 1 页 / 共 2 页
字号:
}static char **Tokenise(char *arguments, int *argc){    int currentarg = 0;    char *start = arguments;    char *end;    char t;    while (*start)    {        /* Trim spaces from the start */        for (; *start && isspace(*start); start ++);        /* Work out the end of the argument (Very simplistic for the moment no quotes allowed) */        for (end = start; *end && !isspace(*end); end ++);        t = end[0];        end[0] = 0;        args[currentarg] = strdup(start);        end[0] = t;        start = end;        currentarg ++;        if (currentarg >= MAX_ARGS)        {            int i;            for ( i = 0; i < MAX_ARGS; i ++)            {                free(args[i]);            }            *argc = 0;            return NULL;        }    }    *argc = currentarg;    return args;}static char *Trim(char *str){    char *result;    char *end;    /* Trim spaces from the start of the address */    for(result = str; *result && isspace(*result); result ++);    /* Trim spaces from the end of the address */    for (end = result + (strlen(result) - 1); (result != end) && isspace(*end); end --)    {        *end = 0;    }    return result;}/************************** Command Functions ********************************/static void CommandQuit(int argc, char **argv){    quit = TRUE;}static void CommandServices(int argc, char **argv){    ServiceEnumerator_t enumerator = ServiceEnumeratorGet();    Service_t *service;    do    {        service = ServiceGetNext(enumerator);        if (service)        {            fprintf(rl_outstream, "%4x: %s\n", service->id, service->name);            ServiceFree(service);        }    }    while(service && !ExitProgram);    ServiceEnumeratorDestroy(enumerator);}static void CommandMultiplex(int argc, char **argv){    if (CurrentMultiplex == NULL)    {        fprintf(rl_outstream, "No multiplex currently selected!\n");    }    else    {        ServiceEnumerator_t enumerator = ServiceEnumeratorForMultiplex(CurrentMultiplex->freq);        Service_t *service;        do        {            service = ServiceGetNext(enumerator);            if (service)            {                fprintf(rl_outstream, "%4x: %s\n", service->id, service->name);                ServiceFree(service);            }        }        while(service && !ExitProgram);        ServiceEnumeratorDestroy(enumerator);    }}static void CommandSelect(int argc, char **argv){    Service_t *service;    service = SetCurrentService(argv[0]);    if (service)    {        fprintf(rl_outstream, "Name      = %s\n", service->name);        fprintf(rl_outstream, "ID        = %04x\n", service->id);    }    else    {        fprintf(rl_outstream, "Could not find \"%s\"\n", argv[0]);    }}static void CommandCurrent(int argc, char **argv){	if ( CurrentService)	{		fprintf(rl_outstream, "Current Service : \"%s\" (0x%04x) Multiplex: %f MHz\n",			CurrentService->name, CurrentService->id, (double)CurrentMultiplex->freq / 1000000.0);	}	else	{		fprintf(rl_outstream, "No current service\n");	}}static void CommandPids(int argc, char **argv){    Service_t *service;    service = ServiceFindName(argv[0]);    if (service)    {        bool cached = TRUE;        int i;        int count;        PID_t *pids;        pids = CachePIDsGet(service, &count);        if (pids == NULL)        {            count = ServicePIDCount(service);            cached = FALSE;        }        fprintf(rl_outstream, "%d PIDs for \"%s\" %s\n", count, argv[0], cached ? "(Cached)":"");        if (count > 0)        {            if (!cached)            {                pids = calloc(count, sizeof(PID_t));                if (pids)                {                    ServicePIDGet(service, pids, &count);                }                else                {                    fprintf(rl_outstream, "No memory to retrieve PIDs\n");                }            }            for (i = 0; i < count; i ++)            {                fprintf(rl_outstream, "%2d: %d %d %d\n", i, pids[i].pid, pids[i].type, pids[i].subtype);            }            if (!cached)            {                free(pids);            }        }        ServiceFree(service);    }    else    {        fprintf(rl_outstream, "Could not find \"%s\"\n", argv[0]);    }}static void CommandStats(int argc, char **argv){    int i;    fprintf(rl_outstream, "PSI/SI Processor Statistics\n"                          "---------------------------\n");    for (i = 0; i < PIDFilterIndex_Count; i ++)    {        fprintf(rl_outstream, "\t%-15s : %d\n", PIDFilterNames[i], PIDFilters[i]->packetsprocessed);    }    fprintf(rl_outstream, "\n");    fprintf(rl_outstream, "Service Filter Statistics\n"                          "-------------------------\n");    for (i = 0; i < MAX_OUTPUTS; i ++)    {        if ((!Outputs[i].name) || (Outputs[i].type != OutputType_Service))        {            continue;        }        fprintf(rl_outstream, "\t%-15s : %d\n", Outputs[i].name, Outputs[i].filter->packetsoutput);    }    fprintf(rl_outstream, "\n");    fprintf(rl_outstream, "Manual Output Statistics\n"                          "------------------------\n");    for (i = 0; i < MAX_OUTPUTS; i ++)    {        if ((!Outputs[i].name) || (Outputs[i].type != OutputType_Manual))        {            continue;        }        fprintf(rl_outstream, "\t%-15s : %d\n", Outputs[i].name, Outputs[i].filter->packetsoutput);    }    fprintf(rl_outstream, "\n");    fprintf(rl_outstream, "Total packets processed: %d\n", TSFilter->totalpackets);    fprintf(rl_outstream, "Approximate TS bitrate : %gMbs\n", ((double)TSFilter->bitrate / (1024.0 * 1024.0)));}static void CommandAddOutput(int argc, char **argv){    Output_t *output = NULL;    printlog(LOG_DEBUGV,"Name = \"%s\" Destination = \"%s\"\n", argv[0], argv[1]);    output = OutputAllocate(argv[0], OutputType_Manual, argv[1]);    if (!output)    {        fprintf(rl_outstream, "Failed to add output, reason \"%s\"\n", OutputErrorStr);    }}static void CommandRmOutput(int argc, char **argv){    Output_t *output = NULL;    if (strcmp(argv[0], PrimaryService) == 0)    {        fprintf(rl_outstream, "Cannot remove the primary output!\n");        return;    }    output = OutputFind(argv[0], OutputType_Manual);    if (output == NULL)    {        return;    }    OutputFree(output);}static void CommandOutputs(int argc, char **argv){    int i;    for (i = 0; i < MAX_OUTPUTS; i ++)    {        if (Outputs[i].name && (Outputs[i].type == OutputType_Manual))        {            fprintf(rl_outstream, "%10s : %s\n",Outputs[i].name,                   UDPOutputDestination((void*)Outputs[i].filter->oparg));        }    }}static void CommandAddPID(int argc, char **argv){    Output_t *output = OutputFind(argv[0], OutputType_Manual);    if (output)    {        int i;        i = ParsePID(argv[1]);        if (i < 0)        {            return;        }        OutputAddPID(output, (uint16_t)i);    }}static void CommandRmPID(int argc, char **argv){    Output_t *output = OutputFind(argv[0], OutputType_Manual);    if (output)    {        int i;        i = ParsePID(argv[1]);        if (i < 0)        {            return;        }        OutputRemovePID(output, (uint16_t)i);    }}static void CommandOutputPIDs(int argc, char **argv){    int i;    Output_t *output = NULL;    int pidcount;    uint16_t *pids;    char *name;    name = Trim(argv[0]);    output = OutputFind(name, OutputType_Manual);    if (!output)    {        return;    }    OutputGetPIDs(output, &pidcount, &pids);    fprintf(rl_outstream, "PIDs for \'%s\' (%d):\n", name, pidcount);    for (i = 0; i <pidcount; i ++)    {        fprintf(rl_outstream, "0x%x\n", pids[i]);    }}static void CommandAddSSF(int argc, char **argv){    Output_t *output = NULL;    printlog(LOG_DEBUGV,"Name = \"%s\" Destination = \"%s\"\n", argv[0], argv[1]);    output = OutputAllocate(argv[0], OutputType_Service, argv[1]);    if (!output)    {        fprintf(rl_outstream, "Failed to add output, reason \"%s\"\n", OutputErrorStr);    }}static void CommandRemoveSSF(int argc, char **argv){    Output_t *output = NULL;    Service_t *oldService;    if (strcmp(argv[0], PrimaryService) == 0)    {        fprintf(rl_outstream, "You cannot remove the primary service!\n");        return;    }    output = OutputFind(argv[0], OutputType_Service);    if (output == NULL)    {        return;    }    OutputGetService(output, &oldService);    OutputFree(output);    if (oldService)    {        ServiceFree(oldService);    }}static void CommandSSFS(int argc, char **argv){    int i;    for (i = 0; i < MAX_OUTPUTS; i ++)    {        if (Outputs[i].name && (Outputs[i].type == OutputType_Service))        {            Service_t *service;            OutputGetService(&Outputs[i], &service);            fprintf(rl_outstream, "%10s : %s (%s)\n",Outputs[i].name,                   UDPOutputDestination((void*)Outputs[i].filter->oparg),                   service ? service->name:"<NONE>");        }    }}static void CommandSetSSF(int argc, char **argv){    Output_t *output = NULL;    char *outputName = argv[0];    char *serviceName;    Service_t *service, *oldService = NULL;    serviceName = strchr(outputName, ' ');    if (!serviceName)    {        fprintf(rl_outstream, "No service specified!");        return;    }    serviceName[0] = 0;    for (serviceName ++;*serviceName && isspace(*serviceName); serviceName ++);    if (strcmp(outputName, PrimaryService) == 0)    {        fprintf(rl_outstream, "Use \'select\' to change the primary service!\n");        return;    }    output = OutputFind(outputName, OutputType_Service);    if (output == NULL)    {        fprintf(rl_outstream, "Failed to find output %s\n", outputName);        return;    }    service = ServiceFindName(serviceName);    if (service == NULL)    {        fprintf(rl_outstream, "Failed to find service %s\n", serviceName);        return;    }    OutputGetService(output, &oldService);    if (OutputSetService(output, service))    {        fprintf(rl_outstream, "Failed to set service, reason %s\n", OutputErrorStr);    }    if (oldService)    {        ServiceFree(oldService);    }}static void CommandFEStatus(int argc, char **argv){    fe_status_t status;    unsigned int ber, strength, snr;    DVBFrontEndStatus(DVBAdapter, &status, &ber, &strength, &snr);    fprintf(rl_outstream,"Tuner status:  %s%s%s%s%s%s\n",             (status & FE_HAS_SIGNAL)?"Signal, ":"",             (status & FE_TIMEDOUT)?"Timed out, ":"",             (status & FE_HAS_LOCK)?"Lock, ":"",             (status & FE_HAS_CARRIER)?"Carrier, ":"",             (status & FE_HAS_VITERBI)?"VITERBI, ":"",             (status & FE_HAS_SYNC)?"Sync, ":"");    fprintf(rl_outstream, "BER = %d Signal Strength = %d SNR = %d\n", ber, strength, snr);}static void CommandHelp(int argc, char **argv){    int i;    if (argc)    {        int commandFound = 0;        for (i = 0; commands[i].command; i ++)        {            if (strcasecmp(commands[i].command,argv[0]) == 0)            {                fprintf(rl_outstream, "%s\n\n", commands[i].longhelp);                commandFound = 1;                break;            }        }        if (!commandFound)        {            fprintf(rl_outstream, "No help for unknown command \"%s\"\n", argv[0]);        }    }    else    {        for (i = 0; commands[i].command; i ++)        {            fprintf(rl_outstream, "%10s - %s\n", commands[i].command, commands[i].shorthelp);        }    }}static int ParsePID(char *argument){    char *formatstr;    int pid;    if ((argument[0] == '0') && (tolower(argument[1])=='x'))    {        argument[1] = 'x';        formatstr = "0x%hx";    }    else    {        formatstr = "%hd";    }    if (sscanf(argument, formatstr, &pid) == 0)    {        fprintf(rl_outstream, "Failed to parse \"%s\"\n", argument);        return -1;    }    return pid;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -