Example #1
0
int main(int argc, char **argv)
{
  // Read google list and create simple frequency list
  {
    google_frequency=new Hash<int>();
    FILE *fh=fopen64(argv[1],"r");
    if (fh==NULL)
      {
	perror("Error opening frequency list");
	_exit(errno);
      }
    if (read_frequency(google_frequency,fh)==-1)
      {
	perror("Error reading syllable list");
	_exit(errno);
      }
    fclose(fh);
  }
  // Write hash to disk
  Queue<Pstring> *keys=google_frequency->keys();
  FILE *fh=fopen(argv[2],"w");
  while (keys->isEmpty()==false)
    {
      Pstring key=keys->remove();
      fprintf(fh,"%.*s\t%d\n",key.getLength(),key.getValue(),google_frequency->getValue(key));
    }
  delete(keys);
  google_frequency->statistics();
  delete(google_frequency);
  fclose(fh);
  return 0;
}
Example #2
0
int main()
{
    uint8_t addr[5];
    uint8_t buf[32];

    WDTCTL = WDTHOLD | WDTPW;
    //DCOCTL = CALDCO_16MHZ;
    //BCSCTL1 = CALBC1_16MHZ;
    DCOCTL = CALDCO_1MHZ;
    BCSCTL1 = CALBC1_1MHZ;
    BCSCTL2 = DIVS_0;  // SMCLK = DCOCLK/1
        BCSCTL3 = LFXT1S_2;  // ACLK = VLOCLK/1
        BCSCTL3 &= ~(XT2OF|LFXT1OF);


    //init the ADC
    //ADC_init();
    Temp_ADC_init();
    freq_timerA_init();//init freq timer stuff

//stuff for cal
const unsigned * const info_seg_a = (unsigned *)0x10C0;     // Address of info segement A
//const unsigned * const info_seg_a = (unsigned *)0x10DA;     // Address of info segement A
    const unsigned * const info_seg_a_end = info_seg_a + 32;    // 32 words in each segment
    

const TCAL * const cal = (TCAL *)(verify_info_chk(info_seg_a, info_seg_a_end) \
         ? 0 \
         : find_tag(info_seg_a, info_seg_a_end, 0x08));
    const long cc_scale  = cal ? 3604480L / (cal->t8515 - cal->t3015) : 0;
    const long cf_scale  = cal ? 6488064L / (cal->t8515 - cal->t3015) : 0;
    const long cc_offset = cal ? 1998848L - (cal->t3015 * cc_scale) : 0;
    const long cf_offset = cal ? 5668864L - (cal->t3015 * cf_scale) : 0;
    const long ck_offset = cc_offset + 17901158L;


    wdtsleep = 0;

    // SPI (USI) uses SMCLK, prefer SMCLK=DCO (no clock division)
    user = 0xFE;

    /* Initial values for nRF24L01+ library config variables */
    rf_crc = RF24_EN_CRC; // CRC enabled, 8-bit
    //| RF24_CRCO;
    rf_addr_width      = 5;
    //rf_speed_power     = RF24_SPEED_1MBPS | RF24_POWER_MAX;
    rf_speed_power      = RF24_SPEED_MIN | RF24_POWER_MAX;
    rf_channel         = 120;
    msprf24_init();  // All RX pipes closed by default
    msprf24_set_pipe_packetsize(0, 0);
    msprf24_open_pipe(0, 1);  // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs
    // Note: Pipe#0 is hardcoded in the transceiver hardware as the designated "pipe" for a TX node to receive
    // auto-ACKs.  This does not have to match the pipe# used on the RX side.

    // Transmit to 0xDEADBEEF00
    msprf24_standby();
    user = msprf24_current_state();
    //addr[0] = 'r'; addr[1] = 'a'; addr[2] = 'd'; addr[3] = '0'; addr[4] = '1';
    memcpy(addr, "\xDE\xAD\xBE\xEF\x00", 5);
    w_tx_addr(addr);
    w_rx_addr(0, addr);  // Pipe 0 receives auto-ack's, autoacks are sent back to the TX addr so the PTX node
    // needs to listen to the TX addr on pipe#0 to receive them.
    buf[0] = '0';
    //buf[1]='\0';
    buf[2] = '\0';
    buf[4] = '\0';
    while(1) {
        if (rf_irq & RF24_IRQ_FLAGGED) {  // Just acknowledging previous packet here
            msprf24_get_irq_reason();
            msprf24_irq_clear(RF24_IRQ_MASK);
            user = msprf24_get_last_retransmits();
        } else {  // WDT sleep completed, send a new packet
            //if (buf[0] == '1')
            //	buf[0] = '0';
            //else
            //	buf[0] = '1';

            //buf[] = snprintf(buf,32,"%d",ADC_read());
            adc_val = ADC_read();
            
            //adc_val = 1023;
            //buf[0] = (uint8_t)(adc_val>>8);//get high byte
            //buf[1] = (uint8_t)(adc_val);//low byte
            //buf[0]=(uint8_t)(adc_val>>2);//8 bits?
            
            //F
            //buf[1]= ((48724L * adc_val) -  30634388L) >> 16;
            buf[0]=((cf_scale * adc_val) + cf_offset) >> 16; //calibrated
            
            //celsius
            //buf[1]=((27069L * adc_val) -  18169625L) >> 16; 
                //calibrated
                buf[1]= ((cc_scale * adc_val) + cc_offset) >> 16;
            
            //uint16_t tempfreq;
            uint32_t tempfreq;
            //tempfreq = (uint16_t)read_frequency();
            tempfreq = read_frequency();
            //tempfreq = (uint16_t)read_avg_freq(6);
            //tempfreq = (uint16_t)read_avg_freq(6);
            buf[2]= (uint8_t)tempfreq; //get low byte
            buf[3]= (uint8_t)(tempfreq>>8);//get high byte
            tempfreq = read_avg_freq(6);
            buf[4]= (uint8_t)tempfreq; //get low byte
            buf[5]= (uint8_t)(tempfreq>>8);//get high byte
            
            w_tx_payload(32, buf);
            msprf24_activate_tx();
        }

        wdt_sleep(10);  //
    }
    return 0;
}