OSDN Git Service

[Schematic] Add 2nd page of 2nd generation pre-amp (LW/MW).
[openi2cradio/OpenI2CRadio.git] / term_shell.c
index 39ff360..b3a6392 100644 (file)
@@ -53,13 +53,6 @@ static char xarg2[66];
 static char xarg3[66];
 static unsigned char tmparea[256];
 
-#define SHELL_CMD_NONE -1
-#define SHELL_CMD_NOTFOUND -2
-#define SHELL_CMD_ILLTOKEN -3
-#define SHELL_CMD_TOOLONG -4
-#define SHELL_CMD_OK 0
-
-#define SHELL_TOPCMDS 16
 
 static void shell_printnum(unsigned int v)
 {
@@ -68,6 +61,7 @@ static void shell_printnum(unsigned int v)
     term_printnum(s, v);
     uart_term_putstr(s);
 }
+
 /*
  * Set Frequency: Arg1 = Freq.
  */
@@ -78,7 +72,7 @@ static void term_freq(char *p)
 
     l = term_getuint(p);
     uart_term_putstr("\nSet Freq:");
-    if((l < 0) || (l > 30000)) {
+    if((l < 100) || (l > 30000)) {
         uart_term_putstr("\nE:Illegal freq range.\n");
         return;
     }
@@ -105,24 +99,68 @@ static void term_freq(char *p)
  */
 static void term_printstatus(char *p)
 {
+    update_status();
     uart_term_putstr("\nStatus:\n");
     if(setup.fm == 0){
-        uart_term_putstr("AM \nBand = ");
+        uart_term_putstr("AM \nBAND = ");
         shell_printnum(setup.amband);
-        uart_term_putstr("\nFreq = ");
+        uart_term_putstr("\nFREQ = ");
         shell_printnum(setup.amfreq);
-        uart_term_putstr("\n");
+        uart_term_putstr("KHz");
+        uart_term_putstr("\nDIFF = ");
+        shell_printnum(diffstat);
     } else {
-        uart_term_putstr("FM \nBand = ");
+        uart_term_putstr("FM \nBAND = ");
         shell_printnum(setup.fmband);
-        uart_term_putstr("\nFreq = ");
-        shell_printnum(setup.fmfreq);
-        uart_term_putstr("\n");
+        uart_term_putstr("\nFREQ = ");
+        shell_printnum(setup.fmfreq / 100);
+        uart_term_putstr(".");
+        shell_printnum(setup.fmfreq % 100);
+        uart_term_putstr("MHz");
+        uart_term_putstr("\nDIFF = ");
+        shell_printnum(diffstat);
+        uart_term_putstr("\nSTEREO = ");
+        if(stereoflag == 0) {
+           uart_term_putstr("NO");
+       } else {
+           uart_term_putstr("YES");
+       }
     }
-
+    uart_term_putstr("\nSIGNAL-LEVEL = ");
+    shell_printnum(recv_signal);
+    uart_term_putstr("dB");
+   
+    uart_term_putstr("\nCNR-LEVEL = ");
+    shell_printnum(cnrlevel);
+    uart_term_putstr("dB");
+   
+    uart_term_putstr("\nBATT = ");
+    shell_printnum(battlevel / 100);
+    uart_term_putstr(".");
+    shell_printnum(battlevel % 100);
+    uart_term_putstr("V\n");
+   
     uart_term_putstr("\n");
 }
 
+static void term_fm(char *p)
+{
+    unsigned int freq;
+    setup.fm = 0xff;
+    setup.amfreq_bank[setup.amband] = setup.amfreq;
+    freq = setup.fmfreq_bank[setup.fmband];
+    akc6955_chg_fm(setup.fm, freq);
+}
+
+static void term_am(char *p)
+{
+    unsigned int freq;
+    setup.fm = 0x00;
+    setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
+    freq = setup.amfreq_bank[setup.amband];
+    akc6955_chg_fm(setup.fm, freq);
+}
+
 
 /*
  * Poweroff.
@@ -149,6 +187,16 @@ static void term_poweron(char *p)
 {
 }
 
+
+static void term_band(char *p)
+{
+   unsigned char slen;
+   unsigned char n;
+   unsigned char band;
+   slen = shell_gettok(xarg1, p);
+}
+
+
 static unsigned char put_hexline(unsigned char *dat, unsigned long addr, unsigned char len)
 {
     unsigned char l;
@@ -370,7 +418,7 @@ const char *cmdstr[SHELL_TOPCMDS] = {
     "AM",
     "POFF",
     "PON",
-    "SEQ",
+    "DUMP",
     "LOG",
     "SCAN",
     "BAND",
@@ -379,84 +427,98 @@ const char *cmdstr[SHELL_TOPCMDS] = {
     "EXIT"
 };
 
+
+static const char shell_helpstr_help[] = "HELP [about-command]\n -- Online help.\n";
+static const char shell_helpstr_freq[] = "FREQ frequency\n -- Set frequency.\n";
+static const char shell_helpstr_stat[] = "STAT\n -- Print status.\n";
+static const char shell_helpstr_load[] = "LOAD section [S]\n -- Load settings from terminal.\n Arg2: if 'S' then Save to internal EEPROM.\n";
+static const char shell_helpstr_save[] = "SAVE section\n -- Save settings to terminal.\n";
+static const char shell_helpstr_fm[] = "FM\n -- Switch to FM.\n";
+static const char shell_helpstr_am[] = "AM\n -- Switch to AM.\n";
+static const char shell_helpstr_poff[] = "\nPOFF [savef]\n -- Power OFF.\n  savef: if 'N' then power-off without saving.\n";
+static const char shell_helpstr_pon[] = "\nPON\n -- Power ON.\n";
+static const char shell_helpstr_dump[] = "\nDUMP section [number]\n -- Dump section(s).\n";
+static const char shell_helpstr_log[] = "\nLOG\n -- View Log.\n";
+static const char shell_helpstr_scan[] = "\nSCAN [direction]\n -- DO Scan.\n    direction : UP / DOWN\n";
+static const char shell_helpstr_band[] = "\nBAND [band-name]\n -- Set band\n";
+static const char shell_helpstr_set[] = "\nSET entry [value]\n -- Set setting / viewing value.\n   value : Decimal.\n";
+static const char shell_helpstr_print[] = "\nPRINT [entry]\n -- Print system value(s).\n";
+static const char shell_helpstr_exit[] = "\nEXIT\n -- EXIT FROM SHELL.\n";
+
+
+static const char *shell_helpstr_sections[2] = {
+   "\nsection :\n    INT : Internal EEPROM\n    FTBL : Freq table\n",
+   "\n   FREQ num : Save user freq #num.\n   BAND : Save user band table."
+};
+
+
 static void cmd_printhelp(char cmdnum)
 {
-    uart_term_putstr("\nSynopsys:\n");
-    switch(cmdnum){
-        case 0:
-            uart_term_putstr("HELP [about-command]\n");
-            uart_term_putstr(" -- Online help.\n");
-            break;
-        case 1:
-            uart_term_putstr("FREQ frequency\n");
-            uart_term_putstr(" -- Set frequency.\n");
-            break;
-        case 2:
-            uart_term_putstr("\nSTAT\n");
-            uart_term_putstr(" -- Print status.\n");
-            break;
-        case 3:
-            uart_term_putstr("\nLOAD section [S]\n");
-            uart_term_putstr(" -- Load settings from terminal.\n");
-            uart_term_putstr("      Arg2: if 'S' then Save to internal EEPROM.\n");
-           break;
-        case 4:
-            uart_term_putstr("\nSAVE section\n");
-            uart_term_putstr(" -- Save settings  to terminal.\n");
-            uart_term_putstr("     section :\n");
-            uart_term_putstr("                  INT : Internal EEPROM\n");
-            uart_term_putstr("                  FTBL  : Freq table");
-            uart_term_putstr("                  FREQ num : Save user freq #num.");
-            uart_term_putstr("                  BAND        : Save user band table.");
-            break;
-        case 5:
-            uart_term_putstr("\nFM\n");
-            uart_term_putstr(" -- Change to FM\n");
-            break;
-        case 6:
-            uart_term_putstr("\nAM\n");
-            uart_term_putstr(" -- Change to AM\n");
-            break;
-        case 7:
-            uart_term_putstr("\nPOFF [savef]\n");
-            uart_term_putstr(" -- Power OFF\n");
-            uart_term_putstr("      savef: if 'N' then power-off without saving.\n");
-            break;
-        case 8:
-            uart_term_putstr("\nPON\n");
-            uart_term_putstr(" -- Power ON\n");
-            break;
-        case 9:
-            uart_term_putstr("\nSEQ\n");
-            break;
-        case 10:
-            uart_term_putstr("\nLOG\n");
-            uart_term_putstr(" -- View LOG(Reserved command)\n");
-            break;
-        case 11:
-            uart_term_putstr("\nSCAN [direction]\n");
-            uart_term_putstr(" -- DO Scan\n");
-            uart_term_putstr("    direction : UP / DOWN\n");
-            break;
-        case 12:
-            uart_term_putstr("\nBAND [band-name]\n");
-            uart_term_putstr(" -- Set band\n");
-            break;
-        case 13:
-            uart_term_putstr("\nSET offset value\n");
-            uart_term_putstr(" -- Set system value.\n");
-            break;
-        case 14:
-            uart_term_putstr("\nPRINT offset\n");
-            uart_term_putstr(" -- PRINT system value.\n");
-            break;
-        case 15:
-            uart_term_putstr("\nEXIT\n");
-            uart_term_putstr(" -- EXIT shell\n");
-            break;
-        default:
-            break;
-    }
+  const char *p;
+  unsigned char i;
+  unsigned char sectionf = 0;
+   
+   switch(cmdnum) {
+    case 0:
+      p = shell_helpstr_help;
+      break;
+    case 1:
+      p = shell_helpstr_freq;
+      break;
+    case 2:
+      p = shell_helpstr_stat;
+      break;
+    case 3:
+      p = shell_helpstr_load;
+      sectionf = 0xff;
+      break;
+    case 4:
+      p = shell_helpstr_save;
+      sectionf = 0xff;
+      break;
+    case 5:
+      p = shell_helpstr_fm;
+      break;
+    case 6:
+      p = shell_helpstr_am;
+      break;
+    case 7:
+      p = shell_helpstr_poff;
+      break;
+    case 8:
+      p = shell_helpstr_pon;
+      break;
+    case 9:
+      p = shell_helpstr_dump;
+      sectionf = 0xff;
+      break;
+    case 10:
+      p = shell_helpstr_log;
+      break;
+    case 11:
+      p = shell_helpstr_scan;
+      break;
+    case 12:
+      p = shell_helpstr_band;
+      break;
+    case 13:
+      p = shell_helpstr_set;
+      break;
+    case 14:
+      p = shell_helpstr_print;
+      break;
+    case 15:
+      p = shell_helpstr_exit;
+      break;
+    default:
+      return;
+   };
+   uart_term_putstr(p);
+   if(sectionf != 0) {
+       for(i = 0; i < 2; i++) {
+         uart_term_putstr(shell_helpstr_sections[i]);
+       }
+   }
 }
 
 static void cmd_help(char *p)
@@ -466,7 +528,7 @@ static void cmd_help(char *p)
     int f;
 
     slen = shell_gettok(xarg1, p);
-    if(slen != 0) {
+    if(slen > 1) {
         for(i = 0; i < SHELL_TOPCMDS; i++){
             f = shell_strcmp(xarg1, cmdstr[i]);
             if(f > 0) {
@@ -548,12 +610,21 @@ char term_shell(unsigned int timeout)
             case 4:
                 save_to_term(pool);
                 break;
+            case 5:
+                term_fm(pool);
+                break;
+            case 6:
+                term_am(pool);
+                break;
             case 7:
                 term_poweroff(pool);
                 break;
             case 8:
                 term_poweron(pool);
                 break;
+            case 12: // BAND
+               term_band(pool);
+               break;
             case 15: // Exit
                 uart_term_putstr("\nBye... (^^)/~~\n");
                goto _l0;