Пример #1
0
static void list_commands(BaseChannel *chp, const ShellCommand *scp) {

  while (scp->sc_name != NULL) {
    shellPrint(chp, scp->sc_name);
    shellPrint(chp, " ");
    scp++;
  }
}
Пример #2
0
/**
 * @brief Shell thread function.
 *
 * @param[in] p pointer to a @p BaseChannel object
 * @return Termination reason.
 * @retval RDY_OK terminated by command.
 * @retval RDY_RESET terminated by reset condition on the I/O channel.
 */
static msg_t shell_thread(void *p) {
  int n;
  msg_t msg = RDY_OK;
  BaseChannel *chp = ((ShellConfig *)p)->sc_channel;
  const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
  char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH];
  char *args[SHELL_MAX_ARGUMENTS + 1];

  shellPrintLine(chp, "");
  shellPrintLine(chp, "ChibiOS/RT Shell");
  while (TRUE) {
    shellPrint(chp, "ch> ");
    if (shellGetLine(chp, line, sizeof(line))) {
      shellPrint(chp, "\nlogout");
      break;
    }
    lp = strtok_r(line, " \009", &tokp);
    cmd = lp;
    n = 0;
    while ((lp = strtok_r(NULL, " \009", &tokp)) != NULL) {
      if (n >= SHELL_MAX_ARGUMENTS) {
        shellPrintLine(chp, "too many arguments");
        cmd = NULL;
        break;
      }
      args[n++] = lp;
    }
    args[n] = NULL;
    if (cmd != NULL) {
      if (strcasecmp(cmd, "exit") == 0) {
        if (n > 0)
          usage(chp, "exit");
        break;
      }
      else if (strcasecmp(cmd, "help") == 0) {
        if (n > 0)
          usage(chp, "help");
        shellPrint(chp, "Commands: help exit ");
        list_commands(chp, local_commands);
        if (scp != NULL)
          list_commands(chp, scp);
        shellPrintLine(chp, "");
      }
      else if (cmdexec(local_commands, chp, cmd, n, args) &&
          ((scp == NULL) || cmdexec(scp, chp, cmd, n, args))) {
        shellPrint(chp, cmd);
        shellPrintLine(chp, " ?");
      }
    }
  }
  chSysLock();
  chEvtBroadcastI(&shell_terminated);
  return msg;
}
Пример #3
0
void comRead(unsigned char * data, unsigned long len)
{
    static unsigned char msg[7];
    static unsigned char msgLen = 0;
    int i;
    
    for (i = 0; i < len; i++)
    {
        if (msgLen < 5)
        {
            if (data[i] != 0xFF)
            {
                msgLen = 0;
                shellPrint("NOT FF %d ", i);
                continue;
            }
            else
            {
                msgLen++;
            }
        }
        else
        {
            msg[msgLen-5] = data[i];
            msgLen++;
            
            if (msgLen >= 12)
            {
                rfidRcvMsg(msg);
                
                msgLen = 0;
            }
        }
    }
}
Пример #4
0
/******************************************************************************
 *############################################################################*
 *#                             Public functions                             #*
 *############################################################################*
 ******************************************************************************/
DropRules
DropRules_new(Var v)
{
    DropRules ret;
    VarValidator valid;
    
    shellPrint(LEVEL_ERRORSTACK, "For drop rules.");
    
    ret = MALLOC(sizeof(pv_DropRules));
    
    valid = VarValidator_new();
    VarValidator_declareIntVar(valid, "needground", 0);
    VarValidator_declareIntVar(valid, "denyground", 0);
    VarValidator_declareIntVar(valid, "groundconnex", 0);
    VarValidator_declareArrayVar(valid, "ground_entities");
    VarValidator_declareArrayVar(valid, "allowed_entities");
    VarValidator_validate(valid, v);
    VarValidator_del(valid);
    
    ret->needground = ((Var_getValueInt(Var_getArrayElemByCName(v, "needground")) == 0) ? FALSE : TRUE);
    ret->denyground = ((Var_getValueInt(Var_getArrayElemByCName(v, "denyground")) == 0) ? FALSE : TRUE);
    ret->groundconnexity = ((Var_getValueInt(Var_getArrayElemByCName(v, "groundconnex")) == 0) ? FALSE : TRUE);
    ret->ground_entities = createEntityList(Var_getArrayElemByCName(v, "ground_entities"));
    ret->allowed_entities = createEntityList(Var_getArrayElemByCName(v, "allowed_entities"));
    
    shellPopErrorStack();
    
    return ret;
}
Пример #5
0
/******************************************************************************
 *############################################################################*
 *#                             Public functions                             #*
 *############################################################################*
 ******************************************************************************/
void
gltextInit()
{
    _fonts = PtrArray_newFull(3, 2, (PtrFunc)GlFont_del, (PtrCmpFunc)GlFont_cmp);
    _textrenders = PtrArray_newFull(10, 5, (PtrFunc)GlTextRender_delFinal, NULL);
    
    shellPrint(LEVEL_INFO, "Text module loaded.");
}
Пример #6
0
/*----------------------------------------------------------------------------*/
void
gltextUninit()
{
    PtrArray_clear(_textrenders);       /*to avoid callbacks on font deleting*/
    PtrArray_del(_fonts);
    PtrArray_del(_textrenders);
    
    shellPrint(LEVEL_INFO, "Text module unloaded.");
}
Пример #7
0
/*----------------------------------------------------------------------------*/
void
glscreenSetVideo(Gl2DSize* width, Gl2DSize* height, Bool* fullscreen)
{
    Uint32 flags = SDL_OPENGL | SDL_RESIZABLE;
    Bool er = FALSE;

    /*TODO: see about other than 32bpp*/
    /*TODO: check if a mode is available before switching to it*/
    
    /*we do the change in 3 times to be soft with the driver*/
    global_screen = SDL_SetVideoMode(global_screenwidth, global_screenheight, 32, flags);
    if(global_screen == NULL)
    {
        er = TRUE;
    }
    else
    {
        SDL_Delay(100);
        global_screen = SDL_SetVideoMode(*width, *height, 32, flags);
        if(global_screen == NULL)
        {
            er = TRUE;
        }
        else if (*fullscreen)
        {
            flags = SDL_OPENGL | SDL_FULLSCREEN;
            SDL_Delay(100);
            global_screen = SDL_SetVideoMode(*width, *height, 32, flags);
            if(global_screen == NULL)
            {
                er = TRUE;
            }
        }
    }
    
    if (er)
    {
        shellPrintf(LEVEL_ERROR, "Unable to initialize screen surface with this format: %d*%d %s.", *width, *height, (*fullscreen) ? "fullscreen" : "windowed");
        shellPrint(LEVEL_ERROR, "Trying with standard format: 800*600 windowed.");
        *width = 800;
        *height = 600;
        *fullscreen = FALSE;
        global_screen = SDL_SetVideoMode(800, 600, 32, SDL_OPENGL | SDL_RESIZABLE);
        if (global_screen == NULL)
        {
            error("glscreen", "glscreenSetVideo", "Unable to initialize screen surface.");
            /*TODO: try the first mode available in the modes list*/
        }
    }

    _fullscreen = *fullscreen;
    global_screenwidth = *width;
    global_screenheight = *height;

    SDL_WM_SetCaption("StormWar "PACKAGE_VERSION, "StormWar");
}
Пример #8
0
/*----------------------------------------------------------------------------*/
static void
datasCallback(Var v)
{
    PtrArrayPos i;
    String s;
    Var vl;
    
    if (inited)
    {
#ifdef DEBUG_I18N
        processDebug();
        PtrArray_clear(debug_missing);
        PtrArray_clear(debug_notused);
#endif
        
        PtrArray_clear(elems);

        if (v == NULL)
        {
            return;
        }
    
        Var_resolveLink(v);
        if (Var_getType(v) != VAR_ARRAY)
        {
            shellPrintf(LEVEL_ERROR, "Internationalization reference isn't an array: %s", Var_gets(v));
            Var_setArray(v);
        }
        
        s = String_newBySizedCopy(_language, 2);
        vl = Var_getArrayElemByName(v, s);
        if (vl == NULL)
        {
            if (_language[0] != 'e' || _language[1] != 'n')
            {
                shellPrint(LEVEL_ERROR, "Local language translations not found, using default.");
            }
            String_del(s);
            return;
        }
        
        Var_resolveLink(vl);
        if (Var_getType(vl) != VAR_ARRAY)
        {
            shellPrintf(LEVEL_ERROR, "Internationalization variable isn't an array: %s", Var_gets(vl));
            Var_setArray(vl);
        }
        
        for (i = 0; i < Var_getArraySize(vl); i++)
        {
            i18nAdd(Var_getArrayElemByPos(vl, i));
        }
        String_del(s);
    }
}
Пример #9
0
/*----------------------------------------------------------------------------*/
void
envUninit()
{
    thunderboltUninit();
    flockingUninit();
    skyboxUninit();
    
    PtrArray_del(_lights);
    
    shellPrint(LEVEL_INFO, "Environment module unloaded.");
}
Пример #10
0
static void cmd_info(BaseChannel *chp, int argc, char *argv[]) {

  (void)argv;
  if (argc > 0) {
    usage(chp, "info");
    return;
  }

  shellPrint(chp, "Kernel version: ");
  shellPrintLine(chp, CH_KERNEL_VERSION);
#ifdef __GNUC__
  shellPrint(chp, "GCC Version:    ");
  shellPrintLine(chp, __VERSION__);
#endif
  shellPrint(chp, "Architecture:   ");
  shellPrintLine(chp, CH_ARCHITECTURE_NAME);
#ifdef CH_CORE_VARIANT_NAME
  shellPrint(chp, "Core Variant:   ");
  shellPrintLine(chp, CH_CORE_VARIANT_NAME);
#endif
#ifdef PLATFORM_NAME
  shellPrint(chp, "Platform:       ");
  shellPrintLine(chp, PLATFORM_NAME);
#endif
#ifdef BOARD_NAME
  shellPrint(chp, "Board:          ");
  shellPrintLine(chp, BOARD_NAME);
#endif
}
Пример #11
0
void rfidRcvMsg(unsigned char msg[])
{
    unsigned long id;
    unsigned char lossPower;
    int i;

    if ((msg[0] ^ msg[1] ^ msg[2] ^ msg[3] ^ msg[4] ^ msg[5]) != msg[6])
    {
        shellPrint("check error ");
        return;
    }

    id = (unsigned long)msg[5] 
      | ((unsigned long)msg[4] << 8)
      | ((unsigned long)msg[3] << 16)
      | ((unsigned long)msg[2] << 24);

    lossPower = msg[1] & 0x80 ?  1 : 0;

    for (i = 0; i < g_labelNum; i++)
    {
        if (g_label[i].id == id)
        {
            g_label[i].lossPower = lossPower;
            g_label[i].msgCount[9]++;
            
            return;
        }
    }
    
    if (g_labelNum < TALBE_NUM)
    {
        g_label[g_labelNum].id = id;
        g_label[g_labelNum].lossPower = lossPower;
        
        for (i = 0;  i < 10; i++)
        {
            g_label[g_labelNum].msgCount[i] = 2;
        }
        
        g_label[g_labelNum].keepSecond = 0;

        g_labelNum++;
    }
}
Пример #12
0
/*----------------------------------------------------------------------------*/
void
i18nUninit()
{
    if (inited)
    {
        inited = FALSE;
        
#ifdef DEBUG_I18N
        processDebug();
        PtrArray_del(debug_missing);
        PtrArray_del(debug_notused);
#endif
        
        PtrArray_del(elems);

        shellPrint(LEVEL_INFO, "Internationalization module unloaded.");
    }
}
Пример #13
0
static void
processDebug()
{
    PtrArrayIterator it;
    
    if (PtrArray_SIZE(elems) == 0)
    {
        shellPrint(LEVEL_DEBUG, "Internationalization had no element set.");
    }
    else
    {
        for (it = PtrArray_START(debug_missing); it != PtrArray_STOP(debug_missing); it++)
        {
            shellPrintf(LEVEL_DEBUG, "Missing translation: %s", String_get(*(String*)it));
        }
        for (it = PtrArray_START(debug_notused); it != PtrArray_STOP(debug_notused); it++)
        {
            shellPrintf(LEVEL_DEBUG, "Unused translation: %s", String_get(*(String*)it));
        }
    }
}
Пример #14
0
/*----------------------------------------------------------------------------*/
void
gltextSetFonts(Var vfonts)
{
    unsigned int i;
    
    shellPrintf(LEVEL_ERRORSTACK, "In font set loading from variable: %s", Var_gets(vfonts));
    
    Var_resolveLink(vfonts);
    if (Var_getType(vfonts) != VAR_ARRAY)
    {
        shellPrint(LEVEL_ERROR, "Font set variable not of array type.");
        shellPopErrorStack();
        return;
    }
    
    for (i = 0; i < Var_getArraySize(vfonts); i++)
    {
        gltextAddFont(Var_getArrayElemByPos(vfonts, i));
    }

    shellPopErrorStack();
}
Пример #15
0
/**
 * @brief Prints a string with a final newline.
 *
 * @param[in] chp pointer to a @p BaseChannel object
 * @param[in] msg pointer to the string
 */
void shellPrintLine(BaseChannel *chp, const char *msg) {

  shellPrint(chp, msg);
  shellPrint(chp, "\r\n");
}
Пример #16
0
static void usage(BaseChannel *chp, char *p) {

  shellPrint(chp, "Usage: ");
  shellPrintLine(chp, p);
}
Пример #17
0
/******************************************************************************
 *############################################################################*
 *#                             Screen functions                             #*
 *############################################################################*
 ******************************************************************************/
void
glscreenInit()
{
    char buf[50];
    SDL_VideoInfo* info;
    SDL_Rect** modes;
    
    _fullscreen = FALSE;
    global_screenwidth = 800;
    global_screenheight = 600;

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0);
    
    /*global_screen = SDL_SetVideoMode(800, 600, 32, SDL_OPENGL | SDL_RESIZABLE);*/
    glscreenSetVideo(&global_screenwidth, &global_screenheight, &_fullscreen);

    if(global_screen == NULL)
    {
        printf("%s\n", SDL_GetError());
        error("glscreen", "glscreenInit", "Can't initialize screen surface.");
    }
    
    /*declare to core*/
    MOD_ID = coreDeclareModule("screen", NULL, NULL, shellCallback, NULL, NULL, NULL);
    FUNC_VIDEOMODE = coreDeclareShellFunction(MOD_ID, "setvideomode", VAR_VOID, 3, VAR_INT, VAR_INT, VAR_INT);

    /*driver info*/
    if (SDL_VideoDriverName(buf, 50) != NULL)
    {
        shellPrintf(LEVEL_INFO, " -> SDL graphical driver:                         %s", buf);
    }
    
    /*video modes available*/
    modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL);
    if (modes == (SDL_Rect**)0)
    {
        shellPrintf(LEVEL_ERROR, "No video modes listed, going on anyway.");
    }
    else if (modes != (SDL_Rect**)-1)
    {
        int i;
        Uint16 oldw = 0, oldh = 0;  /*for unique displaying*/
        
        shellPrint(LEVEL_INFO, " -> Video modes available in fullscreen:");
        for (i = 0; modes[i]; ++i)
        {
            if ((oldw != modes[i]->w) | (oldh != modes[i]->h))
            {
                oldw = modes[i]->w;
                oldh = modes[i]->h;
                shellPrintf(LEVEL_INFO, "     %d*%d", oldw, oldh);
            }
        }
    }
    
    /*video capabilities info*/
    if ((info = (SDL_VideoInfo*)SDL_GetVideoInfo()) != NULL)
    {
        shellPrintf(LEVEL_INFO, " -> Window manager available:                     %s", (info->wm_available) ? "yes" : "no");
        shellPrintf(LEVEL_INFO, " -> Hardware surfaces support:                    %s", (info->hw_available) ? "yes" : "no");
        if (info->hw_available)
        {
            shellPrintf(LEVEL_INFO, " -> Hardware blits accelerated:                   %s", (info->blit_hw) ? "yes" : "no");
            shellPrintf(LEVEL_INFO, " -> Hardware alpha blits accelerated:             %s", (info->blit_hw_A) ? "yes" : "no");
            shellPrintf(LEVEL_INFO, " -> Software to hardware blits accelerated:       %s", (info->blit_sw) ? "yes" : "no");
            shellPrintf(LEVEL_INFO, " -> Software to hardware alpha blits accelerated: %s", (info->blit_sw_A) ? "yes" : "no");
            shellPrintf(LEVEL_INFO, " -> Color fills accelerated:                      %s", (info->blit_fill) ? "yes" : "no");
            shellPrintf(LEVEL_INFO, " -> Video memory available in kB:                 %d", info->video_mem);
        }
    }
}
Пример #18
0
/*----------------------------------------------------------------------------*/
void
openglUninit()
{
    shellPrint(LEVEL_INFO, "OpenGL module unloaded.");
}
Пример #19
0
/*----------------------------------------------------------------------------*/
void
glscreenUninit()
{
    global_screen = SDL_SetVideoMode(800, 600, 32, SDL_OPENGL);
    shellPrint(LEVEL_INFO, "Screen module unloaded.");
}