Changeset - 55d6f1467ce4
[Not reviewed]
default
0 3 0
Ethan Zonca (ethanzonca) - 9 years ago 2017-02-01 13:58:59
e@ethanzonca.com
Add friendly mode and associated timeout
3 files changed with 31 insertions and 7 deletions:
0 comments (0 inline, 0 general)
Include/config.h
Show inline comments
 
//
 
// Depth Select Configuration
 
//
 
 
#ifndef CONFIG_H
 
#define CONFIG_H
 
 
 
// --------------------------------------------------------------------------
 
// Transmitter config (si446x.c)
 
// --------------------------------------------------------------------------
 
 
// Transmit power (0-0x7F, 0mW - 40mw?)
 
#define SI446x_POWER 0x02
 
#define SI446x_POWER 0x40 // 0x40 for jake launch
 
 
#define TUNE_FREQUENCY 433500000UL
 
 
 
// Internal macros
 
#define hal_init HAL_Init
 
 
 
// Uncomment if using legacy LPS25h pressure sensor
 
//#define LPS25H
 
#define LPS25H
 
 
 
#define FRIENDLY_MODE
 
#define FRIENDLY_TIMEOUT  1800 // 1800 // seconds before reducing tx rate
 
#define FRIENDLY_TX_RATE 60000 // milliseconds tx rate after timeout elapsed
 
 
// --------------------------------------------------------------------------
 
// ADC config (adc.c)
 
// --------------------------------------------------------------------------
 
 
// Temperature sensor offset (die temperature from ambient, esimate, in Celcius)
 
#define ADC_TEMPERATURE_OFFSET -10
 
 
 
// --------------------------------------------------------------------------
 
// AX.25 config (ax25.c)
 
// --------------------------------------------------------------------------
 
 
// TX delay in milliseconds
 
#define TX_DELAY      70
 
 
// Maximum packet delay
 
#define MAX_PACKET_LEN 512  // bytes
 
 
 
// --------------------------------------------------------------------------
 
// APRS config (aprs.c)
 
// --------------------------------------------------------------------------
 
 
// Set your callsign and SSID here. Common values for the SSID are
 
// (from http://zlhams.wikidot.com/aprs-ssidguide):
 
//
 
// - Balloons:  11
 
// - Cars:       9
 
// - Home:       0
 
// - IGate:      5
 
#define S_CALLSIGN      "S"
 
#define S_CALLSIGN_ID   1
 
 
// Destination callsign: APRS (with SSID=0) is usually okay.
 
#define D_CALLSIGN      ""
 
#define D_CALLSIGN_ID   0
 
 
// Digipeating paths:
 
// (read more about digipeating paths here: http://wa8lmf.net/DigiPaths/ )
 
// The recommended digi path for a balloon is WIDE2-1 or pathless. The default
 
// is pathless. Uncomment the following two lines for WIDE2-1 path:
 
//#define DIGI_PATH1      "WIDE2"
 
//#define DIGI_PATH1_TTL  1
 
 
// Transmit the APRS sentence every X milliseconds
 
#define APRS_TRANSMIT_PERIOD 1000
 
 
 
 
 
 
#endif
 
 
// vim:softtabstop=4 shiftwidth=4 expandtab
Libraries/aprs/aprs.c
Show inline comments
 
/*
 
 * FeatherHAB 
 
 *
 
 * This file is part of FeatherHAB.
 
 *
 
 * FeatherHab is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * FeatherHab 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 Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with FeatherHAB. If not, see <http://www.gnu.org/licenses/>.
 
 * 
 
 * Ethan Zonca
 
 *
 
 */
 

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

	
 
#include "config.h"
 
#ifdef LPS25H
 
	#include "lps25h.h"
 
#else
 
	#include "bme280.h"
 
#endif
 
#include "aprs.h"
 
#include "gps.h"
 
//#include "gps.h"
 
//#include "adc.h"
 
#include "ax25.h"
 
#include "system/adc.h"
 

	
 

	
 
int32_t meters_to_feet(int32_t m)
 
{
 
  // 10000 ft = 3048 m
 
  return (float)m / 0.3048;
 
}
 

	
 
void aprs_send(void)
 
{
 
  struct s_address addresses[] = { 
 
    {D_CALLSIGN, D_CALLSIGN_ID},  // Destination callsign
 
    {"", S_CALLSIGN_ID},  // Source callsign (-11 = balloon, -9 = car)
 
		//{S_CALLSIGN, S_CALLSIGN_ID},
 
#ifdef DIGI_PATH1
 
    {DIGI_PATH1, DIGI_PATH1_TTL}, // Digi1 (first digi in the chain)
 
#endif
 
#ifdef DIGI_PATH2
 
    {DIGI_PATH2, DIGI_PATH2_TTL}, // Digi2 (second digi in the chain)
 
#endif
 
  };
 

	
 
  strncpy(addresses[1].callsign, S_CALLSIGN, 7);
 
  
 
  // emz: modified this to get the size of the first address rather than the size of the struct itself, which fails
 
  ax25_send_header(addresses, sizeof(addresses)/sizeof(addresses[0]));
 
  ax25_send_byte(',');
 

	
 
  char tmpBuffer[128];
 
  tmpBuffer[0] = ',';
 
  tmpBuffer[1] = '\0';
 

	
 
  #ifdef FRIENDLY_MODE
 
    if(HAL_GetTick() > 1000 * FRIENDLY_TIMEOUT)
 
    {
 
	  snprintf(tmpBuffer, 128, "KD8TDF");
 
	  ax25_send_string(tmpBuffer);
 
    }
 
  #endif
 

	
 
  ax25_send_byte(',');
 

	
 
  // Latitude
 
  snprintf(tmpBuffer, 128, "%ld,", gps_getdata()->latitude);
 
  ax25_send_string(tmpBuffer);
 
  
 
  // Longitude
 
  snprintf(tmpBuffer, 128, "%ld,", gps_getdata()->longitude);
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Speed
 
  snprintf(tmpBuffer, 128, "%d,", gps_getdata()->speed);
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Altitude
 
  snprintf(tmpBuffer, 128, "%d,", gps_getdata()->altitude);
 
  ax25_send_string(tmpBuffer);
 

	
 

	
 
#ifdef LPS25H
 
  // Pressure
 
  snprintf(tmpBuffer, 128, "%d,", lps25h_get_pressure());
 
  ax25_send_string(tmpBuffer);
 
  
 
  // Temperature
 
  snprintf(tmpBuffer, 128, "%d,", bme280_get_temperature());
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Humidity
 
  snprintf(tmpBuffer, 128, "0,");
 
  ax25_send_string(tmpBuffer);
 

	
 
#else
 
  // Pressure
 
  snprintf(tmpBuffer, 128, "%d,", bme280_get_pressure());
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Temperature
 
  snprintf(tmpBuffer, 128, "%d,", bme280_get_temperature());
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Humidity
 
  snprintf(tmpBuffer, 128, "%d,", bme280_get_humidity());
 
  ax25_send_string(tmpBuffer);
 
#endif
 

	
 
  // HDOP
 
  snprintf(tmpBuffer, 128, "%u,", gps_getdata()->pdop);
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Heading
 
  snprintf(tmpBuffer, 128, "%u,", gps_getdata()->heading);
 
  ax25_send_string(tmpBuffer);
 

	
 
  // Vbatt
 
  snprintf(tmpBuffer, 128, "%u,", adc_get_vbatt());
 
  ax25_send_string(tmpBuffer);
 

	
 
  ax25_send_footer();
 
  ax25_flush_frame();
 
}
 

	
 
// vim:softtabstop=4 shiftwidth=4 expandtab 
Source/main.c
Show inline comments
 
/*
 
 * FeatherHAB
 
 *
 
 * This file is part of FeatherHAB.
 
 *
 
 * FeatherHab is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * FeatherHab 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 Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with FeatherHAB. If not, see <http://www.gnu.org/licenses/>.
 
 *
 
 * Ethan Zonca
 
 *
 
 */
 
 
#include "stm32f0xx_hal.h"
 
 
#include "config.h"
 
#include "error.h"
 
 
#ifdef LPS25H
 
	#include "lps25h.h"
 
#else
 
	#include "bme280.h"
 
#endif
 
#include "gps.h"
 
 
#include "system/gpio.h"
 
#include "system/sysclk.h"
 
#include "system/watchdog.h"
 
#include "system/uart.h"
 
#include "system/adc.h"
 
 
#include "si446x/si446x.h"
 
#include "aprs/aprs.h"
 
#include "aprs/afsk.h"
 
 
 
int main(void)
 
{
 
  hal_init();
 
  sysclock_init();
 
  gpio_init();
 
  adc_init();
 
  afsk_init();
 
  si446x_init();
 
  si446x_init();
 
  gps_poweron();
 
 
  #ifdef LPS25H
 
    lps25h_init();
 
  #else
 
    bme280_init();
 
  #endif
 
 
  // Software timers
 
  uint32_t last_transmission = HAL_GetTick();
 
  uint32_t last_led = HAL_GetTick();
 
 
  uint32_t transmission_rate = 700;
 
  uint32_t is_friendly = 0;
 
 
  while (1)
 
  {
 
	  // Blink LEDs
 
	  if(HAL_GetTick() - last_transmission > 700)
 
	  #ifdef FRIENDLY_MODE
 
	  	  if(!is_friendly && HAL_GetTick() > 1000 * FRIENDLY_TIMEOUT)
 
	  	  {
 
	  		  transmission_rate = FRIENDLY_TX_RATE;
 
	  		  is_friendly = 1;
 
	  	  }
 
	  #endif
 
 
	  // Transmit RF packet
 
	  if(HAL_GetTick() - last_transmission > transmission_rate)
 
	  {
 
		  gps_update_data(); // Will always return at 1hz rate (default measurement rate)
 
 
		  #ifdef LPS25H
 
		  	  lps25h_read();
 
		  #else
 
		  	  bme280_update();
 
		  #endif
 
 
		  while(afsk_busy()); // ensure previous message finished
 
		  aprs_send();
 
 
		  last_transmission = HAL_GetTick();
 
	  }
 
 
	  // Blink LEDs
 
	  if(HAL_GetTick() - last_led > 100)
 
	  {
 
		  HAL_GPIO_TogglePin(LED_POWER);
 
		  last_led = HAL_GetTick();
 
	  }
 
 
	  if(afsk_request_cwoff())
 
		  si446x_cw_off();
 
 
	  // High-frequency function calls
 
	  watchdog_feed();
 
  }
 
}
 
 
 
// vim:softtabstop=4 shiftwidth=4 expandtab
0 comments (0 inline, 0 general)