Exemplo n.º 1
0
int main(void) {    
    
    Config32MHzClock(); // Setup the 32MHz Clock. Should really be using 2MHz...
    
    // Setup output and input ports.
    LEDPORT.DIRSET = 0xFF; 
    LEDPORT.OUT = 0xFF;
    AD9835_PORT.DIRCLR = 0x40;
    PORTC.DIRSET = 0x04;

    // Start up the timer.
    init_timer();
    
    sensors.begin();
    sensors.requestTemperatures();
    
    // Wait a bit before starting the AD9835.
    // It seems to take a few hundred ms to 'boot up' once power is applied.
    _delay_ms(500); 
    
    // Configure the AD9835, and start in sleep mode.
    AD9835_Setup();
    AD9835_Sleep();
    
    // Setup the AD9835 for our chosen datamode.
    TX_Setup();
    AD9835_Awake();
    
    // Broadcast a bit of carrier.
    _delay_ms(1000);
    
    TXString("Booting up...\n"); // Kind of like debug lines.
    
    // Start up the GPS RX UART.
    init_gps();
    
    // Turn Interrupts on.
    PMIC.CTRL = PMIC_HILVLEN_bm | PMIC_LOLVLEN_bm;
    sei();
    
    sendNMEA("$PUBX,00"); // Poll the UBlox5 Chip for data.
    
    //TXString("GPS Active, Interrupts On.\n");
    
    int found_sensors = sensors.getDeviceCount();
    
    //sprintf(tx_buffer,"Found %u sensors.\n",found_sensors);
   // TXString(tx_buffer);
    unsigned int counter = 0; // Init out TX counter.
    
 
    while(1){
        // Identify every few minutes
        if ((counter%30 == 0)&&(data_mode != FALLBACK)) TXString("DE VK5VZI Project Horus HAB Launch - projecthorus.org \n");
    
	    // Read ADC PortA pin 0, using differential, signed input mode. Negative input comes from pin 1, which is tied to ground. Use VCC/1.6 as ref.
	    uint16_t temp = readADC(); 
	    float bat_voltage = (float)temp * 0.001007572056668* 8.5;
        floatToString(bat_voltage,1,voltString);
   
    
    
        // Collect GPS data
        
        gps.f_get_position(&lat, &lon);
	    sats = gps.sats();
	    if(sats>2){LEDPORT.OUTCLR = 0x80;}
	    speed = gps.f_speed_kmph();
	    altitude = (long)gps.f_altitude();
	    gps.crack_datetime(0, 0, 0, &time[0], &time[1], &time[2]);
	    
	    floatToString(lat, 5, latString);
	    floatToString(lon, 5, longString);
	    
        sensors.requestTemperatures();
        _intTemp = sensors.getTempC(internal);
        _extTemp = sensors.getTempC(external);
        if (_intTemp!=85 && _intTemp!=127 && _intTemp!=-127 && _intTemp!=999) intTemp = _intTemp;
        if (_extTemp!=85 && _extTemp!=127 && _extTemp!=-127 && _extTemp!=999) extTemp = _extTemp;
	    
	    if(data_mode != FALLBACK){
	    
            // Construct our Data String
            sprintf(tx_buffer,"$$DARKSIDE,%u,%02d:%02d:%02d,%s,%s,%ld,%d,%d,%d,%d,%s",counter++,time[0], time[1], time[2],latString,longString,altitude,speed,sats,intTemp,extTemp,voltString);
            
            
            // Calculate the CRC-16 Checksum
            char checksum[10];
            snprintf(checksum, sizeof(checksum), "*%04X\n", gps_CRC16_checksum(tx_buffer));
         
            // And copy the checksum onto the end of the string.
            memcpy(tx_buffer + strlen(tx_buffer), checksum, strlen(checksum) + 1);
        }else{
            // If our battery is really low, we don't want to transmit much data, so limit what we TX to just an identifier, battery voltage, and our position.
            
            sprintf(tx_buffer, "DE VK5VZI HORUS8 %s %s %s %ld", bat_voltage, latString, longString,altitude);
        }
        
        // Blinky blinky...
        LEDPORT.OUTTGL = 0x20;
        
        // Transmit!
        TXString(tx_buffer);
       
        
        sendNMEA("$PUBX,00"); // Poll the UBlox5 Chip for data again.
        
        /*
        // Check the battery voltage. If low, switch to a more reliable mode.
        if((bat_voltage < BATT_THRESHOLD) && (data_mode != RELIABLE_MODE)){
            new_mode = RELIABLE_MODE;
            // This string should be changed if the 'reliable' mode is changed.
            TXString("Battery Voltage Below 9V. Switching to DominoEX8.\n");
        }
        */
        // Perform a mode switch, if required. 
        // Done here to allow for mode changes to occur elsewhere.
        if(new_mode != -1){
            data_mode = new_mode;
            TX_Setup();
            new_mode = -1;
        }
        
        // And wait a little while before sending the next string.
        // Don't delay for domino - synch stuffs up otherwise
        if(data_mode != DOMINOEX8){
            _delay_ms(1000);
        }
        
        
    }

    
}
Exemplo n.º 2
0
void loop() {
  LED_Status(LED_GREEN,0);
  if (Serial.available()) {
	readCommand();
	// "command" now contains the full command
      commandClean[0]='\0';
      int i = 0;
      int j = 0;
      while (command[i] != '\n' && i<128 && j<60){
        if (command[i] != char(32)){
          commandClean[j] = command[i];
          j++;
        }
        i++;
      }
      commandClean[j] = '\n';
   
      // Send to transmitter     
      LED_Status(LED_GREEN,0);
      unsigned int CHECKSUM = gps_CRC16_checksum(commandClean);  // Calculates the checksum for this datastring
      char checksum_str[6];
      sprintf(checksum_str, "*%04X\n", CHECKSUM);
      strcat(commandClean,checksum_str); 
	  Serial.println(commandClean);
      rtty_txstring (commandClean);  
      LED_Status(LED_OFF,0);

	  // Send to Mobile Phone
      unsigned long m = millis(); 
      if ((m - gblSMSElapsed) > WAIT_SMS) {
		if (glb_phone_trans == LOW){
			// Send to mobile phone
			mobPhone.println(PHONE_AT);          // wakes up phone
			LED_Status(LED_GREEN,250);
			LED_Status(LED_OFF,250);
			mobPhone.println(PHONE_DELETE_SMS);  // deletes message at index of 1
			LED_Status(LED_GREEN,250);
			LED_Status(LED_OFF,250);
			mobPhone.println(PHONE_SET_SMS_TXT_MODE_COMMAND); // Puts phone into SMS mode
			LED_Status(LED_GREEN,250);
			LED_Status(LED_OFF,500);    
			mobPhone.println(PHONE_SMS_NUMBER); // My number
			LED_Status(LED_GREEN,250);
			LED_Status(LED_OFF,500);    
			mobPhone.print(commandClean);         //data
			mobPhone.write(byte(26));             // (signals end of message)
			LED_Status(LED_GREEN,250);
			LED_Status(LED_OFF,500);
			mobPhone.println(PHONE_SEND_SMS);     // Sends message at index of 1
		}
		gblSMSElapsed = millis();
      }

  } else {
    LED_Status(LED_OFF,0);
    LED_Status(LED_GREEN,500);
  }
  
  phoneTX();
  LED_Status(LED_OFF,0);
}