Example #1
0
File: Shell.c Project: SzAllen/Iap2
void Shell_Init()
{
	static FnDef g_CmdTable[] = 
	{
		  {(void*)Shell_SetDebugBit	, "SetDebugBit(int nIndex, Bool isEnable)"}
		 ,{(void*)Shell_BleConnect		, "BleConnect(uint32 id1; uint32 id2; uint32 id3, uint32 id4, uint32 id4)"}
		 ,{(void*)Debug_Set			, "SetDebugLev(uint8 level/*1=UTP|BLE|OTA;2=USBDEV|USBHOST|USB_DRV...*/)"}

		 ,{(void*)Null, ""}
		 ,{(void*)Shell_Reset		, "Reset()"}
		 ,{(void*)Shell_SetBootFlag	, "SetBootFlag(Bool isAArea)"}
		 ,{(void*)Mcu_SetState		, "SetMcuState(uint8 state/*1=WORK,2=STDANBY,3=IDEL*/)"}
		 ,{(void*)Boot_WriteTestMode, "SetTestMode(Bool isTestModeEnable)"}
		 ,{(void*)Shell_SetPrintfFlag, "SetPrintfFlag(Bool isDefaultPrintf)"}
		 ,{(void*)Shell_SetPmu		, "SetPmu(uint8 pmuState)"}

		 ,{(void*)Null, ""}
		 ,{(void*)Shell_BlePostCmd	, "BleSendCmd(uint8 cmd, int len, uint8 data1, uint8 data2)"}
		 ,{(void*)Shell_GetOemInfo	, "GetOemInfo()"}
		 ,{(void*)Ble_Dump			, "DumpPmu()"}
		 ,{(void*)Iap_Dump			, "DumpIap()"}
		 
		 ,{(void*)Null, ""}
		 ,{(void*)Shell_GetTempPwdEmail	, "GetTempPwdEmail()"}
		 ,{(void*)Shell_WriteSecuInfo	, "SetPwd(const char* pPsw, const char* pEmail, Bool isTempPsw)"}
		 ,{(void*)Shell_SetPhoneID		, "SetPhoneID(const char* pPhoneId)"}
		 ,{(void*)Shell_SetPwdEnalbe	, "EnablePwd(uint8 isPswEnalbe)"}
		 ,{(void*)Shell_VerifyPsw		, "VerifyPwd(uint8_t *pwd)"}
		 ,{(void*)Shell_SetSyncLedEnable, "SetSyncLedEnable(Bool isEnable, Bool isModifiedSdCardByPc)"}
		 ,{(void*)Shell_BleEnable		, "BleEnable(Bool isEnable)"}
		 ,{(void*)Nvd_WritePartNumber	, "SetPartNumber(uint8 cap/*1=16G;2=32G;3=64G;4=128G*/, uint8_t color/*1=WHT,2=BLK,3=RED*/)"}
		 ,{(void*)Shell_NvdErase		, "NvdErase()"}
		 ,{(void*)Nvd_Dump				, "DumpNvd()"}
		 ,{(void*)Shell_BleConnect		, "BleConnect(uint32 id1; uint32 id2; uint32 id3, uint32 id4, uint32 id4)"}
		 ,{(void*)Shell_ForceLightingPortToDeviceMode			, "Force()"}
	};
	
	CmdLine_Init(g_CmdTable, sizeof(g_CmdTable) / sizeof(FnDef), True, (OutPutFun)Printf);

	if(g_OemInfo.m_isDefaultPrintf)
	{
		Printf = __Printf;
		g_dwDebugLevel = g_OemInfo.m_dwDebugLevel;
		//Debug_Set(1);
	}
	else
	{
		//Debug_Set(0);
		g_dwDebugLevel = 0;
		Printf = Printf_None;
	}
}
Example #2
0
void try_process (struct instance *o)
{
    CmdLine c;
    if (!CmdLine_Init(&c)) {
        goto fail0;
    }
    
    // append exec
    if (!CmdLine_Append(&c, o->exec)) {
        goto fail1;
    }
    
    // append tapdev
    if (!CmdLine_Append(&c, "--tapdev") || !CmdLine_Append(&c, o->ifname)) {
        goto fail1;
    }
    
    // append arguments
    NCDValue *arg = NCDValue_ListFirst(o->args);
    while (arg) {
        // append argument
        if (!CmdLine_Append(&c, NCDValue_StringValue(arg))) {
            goto fail1;
        }
        arg = NCDValue_ListNext(o->args, arg);
    }
    
    // terminate cmdline
    if (!CmdLine_Finish(&c)) {
        goto fail1;
    }
    
    // start process
    if (!BProcess_Init(&o->process, o->i->params->manager, (BProcess_handler)process_handler, o, ((char **)c.arr.v)[0], (char **)c.arr.v, o->user)) {
        ModuleLog(o->i, BLOG_ERROR, "BProcess_Init failed");
        goto fail1;
    }
    
    CmdLine_Free(&c);
    
    // set started
    o->started = 1;
    
    return;
    
fail1:
    CmdLine_Free(&c);
fail0:
    // retry
    o->started = 0;
    BReactor_SetTimer(o->i->params->reactor, &o->timer);
}
int build_cmdline (struct instance *o, CmdLine *c)
{
    // init cmdline
    if (!CmdLine_Init(c)) {
        goto fail0;
    }
    
    // append stdbuf part
    if (!build_stdbuf_cmdline(c, o->exec)) {
        goto fail1;
    }
    
    // append user arguments
    NCDValue *arg = NCDValue_ListFirst(o->args);
    while (arg) {
        if (NCDValue_Type(arg) != NCDVALUE_STRING) {
            ModuleLog(o->i, BLOG_ERROR, "wrong type");
            goto fail1;
        }
        
        // append argument
        if (!CmdLine_Append(c, NCDValue_StringValue(arg))) {
            goto fail1;
        }
        
        arg = NCDValue_ListNext(o->args, arg);
    }
    
    // append interface name
    if (!CmdLine_Append(c, "-i") || !CmdLine_Append(c, o->ifname)) {
        goto fail1;
    }
    
    // append config file
    if (!CmdLine_Append(c, "-c") || !CmdLine_Append(c, o->conf)) {
        goto fail1;
    }
    
    // terminate cmdline
    if (!CmdLine_Finish(c)) {
        goto fail1;
    }
    
    return 1;
    
fail1:
    CmdLine_Free(c);
fail0:
    return 0;
}
Example #4
0
static int build_cmdline (NCDModuleInst *i, NCDValue *cmd_arg, char **exec, CmdLine *cl)
{
    if (NCDValue_Type(cmd_arg) != NCDVALUE_LIST) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    
    // read exec
    NCDValue *exec_arg = NCDValue_ListFirst(cmd_arg);
    if (!exec_arg) {
        ModuleLog(i, BLOG_ERROR, "missing executable name");
        goto fail0;
    }
    if (NCDValue_Type(exec_arg) != NCDVALUE_STRING) {
        ModuleLog(i, BLOG_ERROR, "wrong type");
        goto fail0;
    }
    if (!(*exec = strdup(NCDValue_StringValue(exec_arg)))) {
        ModuleLog(i, BLOG_ERROR, "strdup failed");
        goto fail0;
    }
    
    // start cmdline
    if (!CmdLine_Init(cl)) {
        ModuleLog(i, BLOG_ERROR, "CmdLine_Init failed");
        goto fail1;
    }
    
    // add header
    if (!CmdLine_Append(cl, *exec)) {
        ModuleLog(i, BLOG_ERROR, "CmdLine_Append failed");
        goto fail2;
    }
    
    // add additional arguments
    NCDValue *arg = exec_arg;
    while (arg = NCDValue_ListNext(cmd_arg, arg)) {
        if (NCDValue_Type(arg) != NCDVALUE_STRING) {
            ModuleLog(i, BLOG_ERROR, "wrong type");
            goto fail2;
        }
        
        if (!CmdLine_Append(cl, NCDValue_StringValue(arg))) {
            ModuleLog(i, BLOG_ERROR, "CmdLine_Append failed");
            goto fail2;
        }
    }
    
    // finish
    if (!CmdLine_Finish(cl)) {
        ModuleLog(i, BLOG_ERROR, "CmdLine_Finish failed");
        goto fail2;
    }
    
    return 1;
    
fail2:
    CmdLine_Free(cl);
fail1:
    free(*exec);
fail0:
    return 0;
}