Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages | Examples

sysinfo.c

Example of proc functions.
/*
 * sysinfo.c - System Information Turbo application
 *
 * Copyright (C) 2003 BLADOX, s.r.o.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

/* 
TODO:
SIM ICCID
SIM MSISDN
ME imsi
Turbo - free progmem, eeprom, ram
*/

#include <config.h>
#include <turbo/turbo.h>

#include <stdlib.h>
#include <string.h>

/* *INDENT-OFF* */

lc_char PROGMEM lc_Mem_Info[]={
        LC_EN("System Info")
        LC_END
};

lc_char PROGMEM lc_Turbo_Info[]={
        LC_EN("Turbo")
        LC_END
};

lc_char PROGMEM lc_ME_Info[]={
        LC_EN("ME")
        LC_END
};

lc_char PROGMEM lc_SIM_Info[]={
        LC_EN("SIM")
        LC_END
};

lc_char PROGMEM lc_Config_Info[]={
        LC_EN("Config")
        LC_END
};

lc_char PROGMEM lc_Turbo_Set[]={
        LC_EN("Settings")
        LC_END
};

lc_char PROGMEM lc_Text_len[]={
        LC_EN("Text Length")
        LC_END
};

lc_char PROGMEM lc_Nr_seqs[]={
        LC_EN("#Seqs")
        LC_END
};

lc_char PROGMEM lc_MT_Fetch[]={
        LC_EN("MT Fetch")
        LC_END
};

lc_char PROGMEM lc_MT_Fetch_On[]={
        LC_EN("Set On")
        LC_END
};

lc_char PROGMEM lc_MT_Fetch_Off[]={
        LC_EN("Set Off")
        LC_END
};

/* *INDENT-ON* */

u8 PROGMEM t_y[] = "Y\n";
u8 PROGMEM t_n[] = "N\n";

u8 PROGMEM t_tp[] = "TP: ";
u8 PROGMEM t_atr[] = "ATR: ";
u8 PROGMEM t_sst[] = "SST: ";
u8 PROGMEM t_me_sst[] = "ME SST: ";
u8 PROGMEM t_me_speed_def[] = "Speed: Default\n";
u8 PROGMEM t_me_speed_enh[] = "Speed: Enhanced\n";
u8 PROGMEM t_card_phase[] = "Card Phase: ";
u8 PROGMEM t_sim_clock[] = "Clock: ";
u8 PROGMEM t_ver_hwd[] = "HWD Version: ";
u8 PROGMEM t_ver_loader[] = "Loader Version: ";
u8 PROGMEM t_flash[] = "#Flash: ";
u8 PROGMEM t_status[] = "#Status: ";

u8 PROGMEM t_net[] = "NET: ";
u8 PROGMEM t_img[] = "IMG: ";
u8 PROGMEM t_cable[] = "CABLE: ";
u8 PROGMEM t_alpha[] = "ALPHA: ";
u8 PROGMEM t_bin_choice[] = "BINCHOICE: ";
u8 PROGMEM t_timer[] = "TIMER: ";
u8 PROGMEM t_browser[] = "BROWSER: ";
u8 PROGMEM t_fake_pb[] = "FAKE PB: ";

u8 PROGMEM t_progmem[] = "PROGMEM: ";
u8 PROGMEM t_ram[] = "RAM: ";
u8 PROGMEM t_eeprom[] = "EEPROM: ";
u8 PROGMEM t_malloc[] = "MALLOC: ";

u8 display_text_x (u8 * text)
{
  u8 ret = display_text (text, NULL);

  if (ret == APP_END)
    return APP_END;
  return APP_BACK;
}

u8 set_text_len (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    u8 *res;
    u8 j;
    u8 buf[16];
    u8 buf1[4];

    memcpy (buf, locale (lc_Text_len), strlen (locale (lc_Text_len)) + 1);
    res = sprinti (buf1, proc_8 (PROC_8_DISPLAY_TEXT_LEN));
    *res = '\0';
    res = get_input (buf, 1, 3, buf1, Q_GET_INPUT_DIGITS);
    if (res == ENULL)
      return APP_END;
    if (res != NULL)
    {
      j = res[0] - 1;
      res++;                    //len
      res++;                    //dcs
      res[j] = '\0';
      j = atoi (res);
      set_proc_8 (PROC_8_DISPLAY_TEXT_LEN, j);
    }
    return APP_BACK;
  }
}

u8 set_nr_seqs (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    u8 *res;
    u8 j;
    u8 buf[16];
    u8 buf1[4];

    memcpy (buf, locale (lc_Nr_seqs), strlen (locale (lc_Nr_seqs)) + 1);
    res = sprinti (buf1, proc_8 (PROC_8_SEQS));
    *res = '\0';
    res = get_input (buf, 1, 2, buf1, Q_GET_INPUT_DIGITS);
    if (res == ENULL)
      return APP_END;
    if (res != NULL)
    {
      j = res[0] - 1;
      res++;                    //len
      res++;                    //dcs
      res[j] = '\0';
      j = atoi (res);
      set_proc_8 (PROC_8_SEQS, j);
    }
    return APP_BACK;
  }
}

SNodeP n_mt_fetch_unset;
SNodeP n_mt_fetch_set;

u8 swap_mt_fetch (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    set_proc_8 (PROC_8_MT_FETCH, !proc_8 (PROC_8_MT_FETCH));
  }
}

u8 set_mt_fetch (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    if (proc_8 (PROC_8_MT_FETCH))
      spider_append_r (ctx, &n_mt_fetch_unset);
    else
      spider_append_r (ctx, &n_mt_fetch_set);
  }
  else if (action == APP_LEAVE)
  {
    spider_clear_r (ctx);
  }
}

u8 sysinfo_turbo (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    u8 *t = buf_B ();
    u8 *r;
    u8 i;

    r = t;

    r = sprints (r, t_ver_hwd);
    r = sprinti (r, version_hwd ());
    r = sprintc (r, '\n');

    r = sprints (r, t_ver_loader);
    r = sprinti (r, version_loader ());
    r = sprintc (r, '\n');

    r = sprints (r, t_flash);
    r = sprinti (r, proc_16 (PROC_16_NR_FLASHINGS));
    r = sprintc (r, '\n');

    r = sprints (r, t_status);
    r = sprinti (r, proc_16 (PROC_16_STATUS_COUNT));
    r = sprintc (r, '\n');

    r = sprints (r, t_progmem);
    r = sprinti (r, proc_16 (PROC_16_MAX_PROGMEM));
    r = sprintc (r, '/');
    r = sprinti (r, proc_16 (PROC_16_FREE_PROGMEM));
    r = sprintc (r, '\n');

    r = sprints (r, t_ram);
    r = sprinti (r, proc_16 (PROC_16_MAX_RAM));
    r = sprintc (r, '/');
    r = sprinti (r, proc_16 (PROC_16_FREE_RAM));
    r = sprintc (r, '\n');

    r = sprints (r, t_eeprom);
    r = sprinti (r, proc_16 (PROC_16_MAX_EEPROM));
    r = sprintc (r, '/');
    r = sprinti (r, proc_16 (PROC_16_FREE_EEPROM));
    r = sprintc (r, '\n');

    r = sprints (r, t_malloc);
    r = sprinti (r, proc_16 (PROC_16_MAX_MALLOC));
    r = sprintc (r, '/');
    r = sprinti (r, proc_16 (PROC_16_FREE_MALLOC));
    r = sprintc (r, '\n');

    r = sprintc (r, '\0');

    return display_text_x (t);
  }
  return APP_OK;
}

u8 sysinfo_me (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    u8 *t = buf_B ();
    u8 *r;
    u8 *tp;
    u8 i;

    dbsp ("SYSINFO\n");
    r = t;

    r = sprints (r, t_tp);
    tp = terminal_profile ();
    for (i = 0; i < tp[0]; i++)
    {
      r = sprintc (r, ' ');
      r = sprintch (r, tp[i + 1]);
    }
    r = sprintc (r, '\n');

    if (proc_8 (PROC_8_ME_SPEED) == 0)
      r = sprints (r, t_me_speed_def);
    else
      r = sprints (r, t_me_speed_enh);

    r = sprints (r, t_me_sst);
    r = sprinti (r, proc_8 (PROC_8_ME_SST));
    r = sprintc (r, '\n');

#if 0
    switch (img_sup)
    {
      case IMG_SUP_NONE:
        r = sprints (r, t_s25);
        break;
      case IMG_SUP_5F50:
        r = sprints (r, t_s26);
        break;
      case IMG_SUP_4F20:
        r = sprints (r, t_s27);
        break;
      case IMG_SUP_INS:
        r = sprints (r, t_s28);
        break;
    }
#endif
    r = sprintc (r, '\0');

    return display_text_x (t);
  }
  return APP_OK;
}

u8 sysinfo_sim (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    u8 *t = buf_B ();
    u8 *r;
    u8 *s;
    u8 i;

    dbsp ("SYSINFO\n");
    r = t;
    //SST
    r = sprints (r, t_card_phase);
    r = sprinti (r, proc_8 (PROC_8_CARD_PHASE));
    r = sprintc (r, '\n');

    r = sprints (r, t_sim_clock);
    // |0xF0 means that was not requested with STATUS
    r = sprintch (r, proc_8 (PROC_8_CLOCK_SETTING));
    r = sprintc (r, '\n');

    s = sim_sst ();
    r = sprints (r, t_sst);
    for (i = 1; i <= s[0]; i++)
    {
      r = sprintc (r, ' ');
      r = sprintch (r, s[i]);
    }
    r = sprintc (r, '\n');

    s = sim_atr ();
    r = sprints (r, t_atr);
    for (i = 1; i <= s[0]; i++)
    {
      r = sprintc (r, ' ');
      r = sprintch (r, s[i]);
    }
    r = sprintc (r, '\n');

    r = sprintc (r, '\0');
    return display_text_x (t);
  }
  return APP_OK;
}

u8 sysinfo_config (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    u8 *t = buf_B ();
    u8 *r;

    dbsp ("CONFIGINFO\n");
    r = t;

    r = sprints (r, t_img);
    if (proc_8 (PROC_8_CONFIG_IMG))
      r = sprints (r, t_y);
    else
      r = sprints (r, t_n);

    r = sprints (r, t_cable);
    if (proc_8 (PROC_8_CONFIG_CABLE))
      r = sprints (r, t_y);
    else
      r = sprints (r, t_n);

    r = sprints (r, t_fake_pb);
    if (proc_8 (PROC_8_CONFIG_FAKE_PHONEBOOK))
      r = sprints (r, t_y);
    else
      r = sprints (r, t_n);

    r = sprints (r, t_alpha);
    if (proc_8 (PROC_8_CONFIG_ALPHA))
      r = sprints (r, t_y);
    else
      r = sprints (r, t_n);

    r = sprints (r, t_bin_choice);
    if (proc_8 (PROC_8_CONFIG_BINARY_CHOICE))
      r = sprints (r, t_y);
    else
      r = sprints (r, t_n);

    r = sprints (r, t_timer);
    if (proc_8 (PROC_8_CONFIG_TIMER))
      r = sprints (r, t_y);
    else
      r = sprints (r, t_n);

    r = sprints (r, t_browser);
    if (proc_8 (PROC_8_CONFIG_LAUNCH_BROWSER))
      r = sprints (r, t_y);
    else
      r = sprints (r, t_n);

    r = sprints (r, t_net);
    if (proc_8 (PROC_8_CONFIG_NETWORKING))
      r = sprints (r, t_y);
    else
      r = sprints (r, t_n);

    r = sprintc (r, '\0');

    return display_text_x (t);
  }
  return APP_OK;
}

SNodeP n_1 = { lc_Mem_Info, NULL };
SNodeP n_3 = { lc_Turbo_Set, NULL };
SNodeP n_3_1 = { lc_Text_len, set_text_len };
SNodeP n_3_2 = { lc_Nr_seqs, set_nr_seqs };
SNodeP n_3_3 = { lc_MT_Fetch, set_mt_fetch };
SNodeP n_2_1 = { lc_Turbo_Info, sysinfo_turbo };
SNodeP n_2_2 = { lc_ME_Info, sysinfo_me };
SNodeP n_2_3 = { lc_SIM_Info, sysinfo_sim };
SNodeP n_2_4 = { lc_Config_Info, sysinfo_config };

SNodeP n_mt_fetch_set = { lc_MT_Fetch_On, swap_mt_fetch };
SNodeP n_mt_fetch_unset = { lc_MT_Fetch_Off, swap_mt_fetch };

/* *INDENT-OFF* */
SEdgeP sysinfo_edges_p[] = {
  {&n_1, &n_2_1},               // Sysinfo/TURBO
  {&n_1, &n_2_2},               // Sysinfo/ME
  {&n_1, &n_2_3},               // Sysinfo/SIM
  {&n_1, &n_2_4},               // Sysinfo/Config
  {&n_1, &n_3},                 // Sysinfo/Set
  {&n_3, &n_3_1},               // Sysinfo/Set/Text len
  {&n_3, &n_3_2},               // Sysinfo/Set/#seqs
  {&n_3, &n_3_3},               // Sysinfo/Set/mt fetch
  NULL
};
/* *INDENT-ON* */

void action_menu (void *data)
{
  SCtx *c = spider_init ();

  if (c == NULL)
    return;

  c->n = &n_1;
  c->eP = &sysinfo_edges_p;

  spider (c);
}

void turbo_handler (u8 action, void *data)
{
  switch (action)
  {
    case ACTION_INSERT_MENU:
      insert_menu (locale (lc_Mem_Info));
      break;
    case ACTION_MENU_SELECTION:
      stk_thread (action_menu, data);
      break;
    default:
      break;
  }
}


Copyright © 2004-2006 BLADOX
Turbo version 1.2