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

📄 main.c

📁 用ATMEL 的 AVR MEGA168做RDS解码程序.
💻 C
📖 第 1 页 / 共 3 页
字号:
            if (j >= 1 && j <= 204) {
              for(i = 0; i < sizeof(alternativeFrequencyCodes); i++) {
                if (alternativeFrequencyCodes[i] == j) {
                  break;
                } 
                if (alternativeFrequencyCodes[i] == 0) {
                  alternativeFrequencyCodes[i] = j;
                  printf_P(PSTR("AF: 0x%02X, "), alternativeFrequencyCodes[i]);
                  
                  m = 875 + j;
                  printf_P(PSTR("%u.%uMHz.\r\n"), m / 10, m % 10);
                  break;
                }
              }
            }
            
            if (j == 224 && alternativeFrequencyCodes[25] != j) {
              alternativeFrequencyCodes[25] = 224;
              printf_P(PSTR("AF: 0x%02X, This station has no alternate frequenties.\r\n"), j);
            }
          }
          
          //TODO: LF/MF untested because lack of LM/MF station
          //Station transmits on LF/MF
          if (block3 == 250 && alternativeFrequencyCodes[26] != block3) {
            alternativeFrequencyCodes[26] = block3;
            j = block3 / 256;
            
            printf_P(PSTR("AF: 0x%02X 0x%02X, "), block3, j);
            
            //LF 153kHz-279kHz in 9 KHz steps
            if (j >= 1 && j <= 15) {
              m = 144 + (j * 9);
              printf_P(PSTR("%uKHz.\r\n"), m);
            } else
            //MF 531KHz-1602kHz in 9 KHz steps
            if (j >= 16 && j <= 135) {
              m = 387 + (j * 9);
              printf_P(PSTR("%uKHz.\r\n"), m);
            }
          }
        }
        //version B contains PI code in block3
  
      } else
      //Type 1 groups: Programme Item Number and slow labelling codes
      if (groupType == 1) {
      
        if (groupVersion == 'A') {
          //TODO: 5 bit Radio Paging Codes, bits 0-4 block2
          
          //TODO: Add textual description of LA
          //Linkage Actuator
          if (linkageActuator != (block3 & _BV(15))) {
            linkageActuator = (block3 & _BV(15));
            printf_P(PSTR("LA: 0x%02X\r\n"), linkageActuator);
          }
          
          //store variant code, bits 13-15
          i = (block3 / 0x2000) & 0x07;
          
          //TODO: Paging
          if (i == 0) {
            
            //TODO: Add textual description of ECC code
            //Extended Country Code, bits 0-7 block3
            if (extendedCountryCode != (block3 & 0xFF)) {
              extendedCountryCode = (block3 & 0xFF);
              printf_P(PSTR("ECC: 0x%02X\r\n"), extendedCountryCode);
            }
            
          
          } else 
          //TODO: TMC identification
          if (i == 1) {
          
          } else
          //TODO: Paging identification
          if (i == 2) {
          
          } else
          //TODO: Language codes
          if (i == 3) {
          
          } else
          //TODO: not assigned
          if (i == 4) {
          
          } else
          //TODO: not assigned
          if (i == 5) {
          
          } else
          //TODO: For use by broadcasters
          if (i == 6) {
          
          } else
          //TODO: Identification of EWS channel
          if (i == 7) {
          
          }
        }
        
        //TODO: Programme Item Number, block 4
      
      } else 
      //Type 2 groups: RadioText
      if (groupType == 2) {
      
        //text version A or B, bit 5 block 2
        if (block2 & 0x10) 
          textVersion = 'B';
        else
          textVersion = 'A';
        
        //block2 bit 0-3
        textSegmentAddress = (block2 & 0x0F);
        
        //clean radioText when version changes
        if (textVersionPrevious != 0 &&
            textVersionPrevious != textVersion) {
            
          for(i = 0; i < sizeof(radioText); i++) {
            radioText[i] = 0;
           }
           
          textSegmentAddressPrevious = 0;
          textSegmentAddress0Seen = 0;
        }
        
        //detected new start of text segment, normally address 0x00
        if (textSegmentAddressPrevious > textSegmentAddress) {
            
          if (groupVersion == 'A')
            h = 64;
          else
            h = 32;
          
          //detect new radioText
          j = 0;
          for (i = 0; i < h; i++) {
            if (radioText[i] != 0 && radioText[i] != ' ') {
              if (radioText[i] != radioTextPrevious[i]) {
                j = 1;
                break;
              }
            }
          }
          
          //only print when we have received address 0 once.
          if (textSegmentAddress0Seen == 0)
            j = 0;
           
          if (j) {
            printf_P(PSTR("RT%c: "), textVersion);

            for (i = 0; i < h; i++) {
            
              if (radioText[i] == 0) 
                break;
              else if (!(radioText[i] == '\r' || radioText[i] == '\n'))
                printf_P(PSTR("%c"), radioText[i]);

                
              radioTextPrevious[i] = radioText[i];
            }
            printf_P(PSTR("\r\n"));
          }
          
          
        }
        
        //64 bit messages in block 3 & 4
        if (groupVersion == 'A') {
          
          radioText[(textSegmentAddress * 4)] = block3 / 256;
          radioText[(textSegmentAddress * 4) + 1] = block3;
          radioText[(textSegmentAddress * 4) + 2] = block4 / 256;
          radioText[(textSegmentAddress * 4) + 3] = block4;
          
          //fill bytes smaller then textSegmentAddress with spaces when they are '0'
          if (textSegmentAddress > 0) {
            for (i = 0; i < (textSegmentAddress - 1) * 4; i++) {
              if (radioText[i] == 0)
                radioText[i] = ' ';
            }
          }
          
        }
        //TODO: 32 bit messages not tested because of lack station transmitting it.
        //32 bit messages in block 4
        else {
          radioText[(textSegmentAddress * 2)] = block4 / 256;
          radioText[(textSegmentAddress * 2) + 1] = block4;
          
          //fill bytes smaller then textSegmentAddress with spaces when they are '0'
          if (textSegmentAddress > 0) {
            for (i = 0; i < (textSegmentAddress - 1) * 2; i++) {
              if (radioText[i] == 0)
                radioText[i] = ' ';
            }
          }
          
        }
        
        if (textSegmentAddress == 0)
          textSegmentAddress0Seen = 1;
        
        
        textVersionPrevious = textVersion;
        textSegmentAddressPrevious = textSegmentAddress;
        
      } else
      //Type 3A groups: Application identification for Open data
      if (groupType == 3 && groupVersion == 'A') {
      
      } else
      //Type 3B groups: Open Data Application
      if (groupType == 3 && groupVersion == 'B') {
      
      } else
      //Type 4A groups : Clock-time and date
      if (groupType == 4 && groupVersion == 'A') {
      
        //bits 0-5 are in block4 as bits 6-11
        utcMinutes = (block4  / 64) & 0x3F;
      
        if (utcMinutesPrevious != utcMinutes) {
        
          utcMinutesPrevious = utcMinutes;
        
          //bits 0-14 are in block3 as bits 1-15
          //bits 15-16 are in block2 as bits 0-1
          modifiedJulianDay = (block3 / 2) + (block2 & 0x03) * 32768;
          
          //bits 0-3 are in block4 as bits 12-15
          //bit 4 is in block3 as bit 1
          utcHours = (block4 / 4096) + (block3 & 0x01) * 16;
          
          //local time offset are bits 0-4 in block 4
          localTimeOffset = block4 & 0x1F;
          //sign is in bit 5 of block4, 0=+ 1=-
          if (block4 & 0x20) 
            localSign = '-';
          else
            localSign = '+';
          
          //multiply by 30 so that we have offset in minutes (offset is in multiples of .5 hours)
          localTimeOffset *= 30;
  
          printf_P(PSTR("CT: 0x%01X%04X%04X, "), (block2 & 0x03), block3, block4);
          
          //Modified Julian date to year-month-day conversion
          utcYear = floor((modifiedJulianDay - 15078.2) / 365.25);
          utcMonth = floor((modifiedJulianDay - 14956.1 - floor(utcYear * 365.25)) / 30.6001);
          utcDay = modifiedJulianDay - 14956 - floor(utcYear * 365.25) - floor(utcMonth * 30.6001);
        
          if (utcMonth == 14 || utcMonth == 15)
            i = 1; 
          else 
            i = 0;
        
          utcYear = utcYear + i + 1900;
          utcMonth = utcMonth - 1 - (i * 12);
  
          printf_P(PSTR("UTC %04u-%02u-%02u (MJD %u) %02u:%02u:00 %c%02u:%02u, "),
                   utcYear, utcMonth, utcDay,
                   modifiedJulianDay,
                   utcHours, utcMinutes, localSign,
                   localTimeOffset / 60, localTimeOffset % 60);
          
          //TODO: half hour timezones and negative timezones not tested because lack of station transmitting it.
          //lets calulate local time
          if (localSign == '-') {
            localHours = utcHours - (localTimeOffset / 60);
            localMinutes = utcMinutes - (localTimeOffset % 60);
          } else {
            localHours = utcHours + (localTimeOffset / 60);
            localMinutes = utcMinutes + (localTimeOffset % 60);
          }
          
          if (localMinutes < 0) {
            localMinutes += 60;
            localHours--;
          }
            
          if (localMinutes > 59) {
            localMinutes -= 60;
            localHours++;
          }
          
          if (localHours < 0)
            localHours += 24;
  
          if (localHours > 23)
            localHours -= 24;
            
          printf_P(PSTR("TIME %02u:%02u:00\r\n"), localHours, localMinutes);
        }

      } else
      //Type 4B groups: Open data application
      if (groupType == 4 && groupVersion == 'B') {
        
      } else
      //Type 5 groups: Transparent data channels or ODA
      if (groupType == 5) {
      
      } else
      //Type 6 groups: In-house applications or ODA
      if (groupType == 6) {
      
      } else 
      //Type 7A groups: Radio Paging or ODA
      if (groupType == 7 && groupVersion == 'A') {
      
      } else 
      //Type 7B groups: Open data application
      if (groupType == 7 && groupVersion == 'B') {
      
      } else 
      //Type 8 groups: Traffic Message Channel or ODA
      if (groupType == 8) {
      
      } else 
      //Type 9 groups: Emergency warning systems or ODA
      if (groupType == 9) {
      
      } else 
      //Type 10A groups: Programme Type Name
      if (groupType == 10 && groupVersion == 'A') {
      
      } else
      //Type 10B groups: Open data
      if (groupType == 10 && groupVersion == 'A') {
      
      } else
      //Type 11 groups: Open Data Application
      if (groupType == 11) {
      
      } else 
      //Type 12 groups: Open Data Application
      if (groupType == 12) {
      
      } else 
      //Type 13A groups: Enhanced Radio Paging or ODA
      if (groupType == 13 && groupVersion == 'A') {
      
      } else
      //Type 13B groups: Open Data Application
      if (groupType == 13 && groupVersion == 'B') {
      
      } else
      //Type 14 groups: Enhanced Other Networks information
      if (groupType == 14) {
      
      } else
      //Type 15A groups: 'currently unavailable'
      if (groupType == 15 && groupVersion == 'A') {
      
      } else
      //Type 15B groups: Fast basic tuning and switching information
      if (groupType == 15 && groupVersion == 'B') {
      
      }
    } else {
      sei();
    }
    
    
  }
}

⌨️ 快捷键说明

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