Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 434 → Rev 433

/FollowMe/trunk/analog.c
2,8 → 2,8
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
 
#include "analog.h"
#include "printf_P.h"
 
volatile uint16_t Adc0, Adc1, Adc2, Adc3, Adc4, Adc5, Adc6, Adc7;
volatile uint8_t ADReady = 1;
14,7 → 14,6
void ADC_Init(void)
{
uint8_t sreg = SREG;
printf("\r\n ADC init...");
// disable all interrupts before reconfiguration
cli();
//ADC0 ... ADC7 is connected to PortA pin 0 ... 7
37,8 → 36,6
ADC_Enable();
// restore global interrupt flags
SREG = sreg;
sei();
printf("ok");
}
 
/*****************************************************/
/FollowMe/trunk/button.c
1,6 → 1,5
#include "timer0.h"
#include "button.h"
#include "printf_P.h"
 
 
#ifdef USE_FOLLOWME
17,7 → 16,7
 
void Button_Init(void)
{
printf("\r\n BUTTON init...");
 
// set port pin as input pullup
#ifdef USE_FOLLOWME
PORTC |= (1 << PORTC6);
29,7 → 28,6
DDRC &= ~(1 << DDC3);
#endif
ButtonTimer = SetDelay(KEY_DELAY_MS);
printf("ok");
}
 
uint8_t GetButton(void)
/FollowMe/trunk/gpx.c
60,7 → 60,10
#include "gpx.h"
#include "gpx_header.h"
#include "timer0.h"
//#include "spi_slave.h"
#include "main.h"
#include "uart1.h"
#include "ubx.h"
 
//________________________________________________________________________________________________________________________________________
// Function: GPX_DocumentInit(GPX_Document_t *)
92,9 → 95,6
{
 
uint8_t retvalue = 0;
uint16_t i;
int8_t c;
const prog_char *str;
 
if(doc == NULL) return(0);
GPX_DocumentInit(doc); // intialize the document with resetvalues
103,13 → 103,8
if(doc->file != NULL) // could the file be opened?
{
retvalue = 1; // the document could be created on the drive.
doc->state = GPX_DOC_OPENED; // change document state to opened. At next a placemark has to be opened.
str = GPX_DOCUMENT_HEADER; // write the gpx-header to the document..
for(i= 0; i < sizeof(GPX_DOCUMENT_HEADER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
doc->state = GPX_DOC_OPENED; // change document state to opened. At next a placemark has to be opened.
fwrite_((void*)GPX_DOCUMENT_HEADER, sizeof(GPX_DOCUMENT_HEADER)-1,1,doc->file);// write the gpx-header to the document.
}
 
return(retvalue);
128,9 → 123,6
{
 
uint8_t retvalue = 1;
uint16_t i;
int8_t c;
const prog_char *str;
 
if(doc == NULL) return(0);
 
149,12 → 141,7
case GPX_DOC_OPENED: // close the file on the memorycard
if(doc->file != NULL)
{
str = GPX_DOCUMENT_FOOTER; // write the gpx-footer to the document.
for(i= 0; i < sizeof(GPX_DOCUMENT_FOOTER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document.
fclose_(doc->file);
retvalue = 1;
}
182,11 → 169,6
{
 
uint8_t retvalue = 0;
uint16_t i;
int8_t c;
const prog_char *str;
 
 
if(doc->state == GPX_DOC_OPENED)
{
if(doc->file != NULL)
193,12 → 175,7
{
doc->state = GPX_DOC_TRACK_OPENED;
retvalue = 1;
str = GPX_TRACK_HEADER;
for(i= 0; i < sizeof(GPX_TRACK_HEADER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file);
}
}
return(retvalue);
217,9 → 194,6
{
 
uint8_t retvalue = 0;
uint16_t i;
int8_t c;
const prog_char *str;
 
if(doc->state == GPX_DOC_TRACK_OPENED)
{
226,12 → 200,8
if(doc->file != NULL)
{
doc->state = GPX_DOC_OPENED;
str = GPX_TRACK_FOOTER;
for(i= 0; i < sizeof(GPX_TRACK_FOOTER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file);
retvalue = 1;
}
}
 
251,9 → 221,6
{
 
uint8_t retvalue = 0;
uint16_t i;
int8_t c;
const prog_char *str;
 
if(doc->state == GPX_DOC_TRACK_OPENED)
{
260,12 → 227,7
if(doc->file != NULL)
{
doc->state = GPX_DOC_TRACKSEGMENT_OPENED;
str = GPX_TRACKSEGMENT_HEADER;
for(i = 0; i < sizeof(GPX_TRACKSEGMENT_HEADER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file);
retvalue = 1;
}
}
285,22 → 247,12
{
 
uint8_t retvalue = 0;
uint16_t i;
int8_t c;
const prog_char *str;
 
 
if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
{
if(doc->file != NULL)
{
doc->state = GPX_DOC_TRACK_OPENED;
str = GPX_TRACKSEGMENT_FOOTER;
for(i = 0; i < sizeof(GPX_TRACKSEGMENT_FOOTER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file);
retvalue = 1;
}
}
/FollowMe/trunk/gpx_header.h
1,5 → 1,3
// all constant strings are within the flash to save space in the sram
#include <avr/pgmspace.h>
//________________________________________________________________________________________________________________________________________
//
// Definition of gpx-header and footer elements for documents
7,7 → 5,7
//________________________________________________________________________________________________________________________________________
 
 
const prog_char GPX_DOCUMENT_HEADER[] =
const int8_t GPX_DOCUMENT_HEADER[] =
{
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\r\n"
"<gpx creator=\"NC\" version=\"1.0\" >\r\n"
25,7 → 23,7
// footer of an gpx-file.
//
//________________________________________________________________________________________________________________________________________
const prog_char GPX_DOCUMENT_FOOTER[] =
const int8_t GPX_DOCUMENT_FOOTER[] =
{
"</gpx>\r\n"
};
36,7 → 34,7
//
//________________________________________________________________________________________________________________________________________
 
const prog_char GPX_TRACK_HEADER[] =
const int8_t GPX_TRACK_HEADER[] =
{
"<trk>\r\n"
"<name>Flight</name>\r\n"
47,7 → 45,7
// Footer of a track
//
//________________________________________________________________________________________________________________________________________
const prog_char GPX_TRACK_FOOTER[] =
const int8_t GPX_TRACK_FOOTER[] =
{
"</trk>\r\n"
};
57,7 → 55,7
// Header of a track segment
//
//________________________________________________________________________________________________________________________________________
const prog_char GPX_TRACKSEGMENT_HEADER[] =
const int8_t GPX_TRACKSEGMENT_HEADER[] =
{
"<trkseg>\r\n"
};
67,7 → 65,7
// Footer of a track segment
//
//________________________________________________________________________________________________________________________________________
const prog_char GPX_TRACKSEGMENT_FOOTER[] =
const int8_t GPX_TRACKSEGMENT_FOOTER[] =
{
"</trkseg>\r\n"
};
/FollowMe/trunk/kml.c
118,9 → 118,6
{
 
uint8_t retvalue = 0;
uint16_t i;
int8_t c;
const prog_char *str;
 
if(doc == NULL) return(0);
 
130,14 → 127,10
if(doc->file != NULL) // could the file be opened?
{
retvalue = 1; // the document could be created on the drive.
doc->state = KML_DOC_OPENED; // change document state to opened. At next a placemark has to be opened.
str = KML_DOCUMENT_HEADER; // write the KML-header to the document.
for(i= 0; i < sizeof(KML_DOCUMENT_HEADER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
doc->state = KML_DOC_OPENED; // change document state to opened. At next a placemark has to be opened.
fwrite_((void*)KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file);// write the KML-header to the document.
}
 
return(retvalue);
}
 
154,9 → 147,6
{
 
uint8_t retvalue = 1;
uint16_t i;
int8_t c;
const prog_char *str;
 
if(doc == NULL) return(0);
 
175,12 → 165,7
case KML_DOC_OPENED: // close the file on the memorycard
if(doc->file != NULL)
{
str = KML_DOCUMENT_FOOTER; // write the KML- footer to the document.
for(i= 0; i < sizeof(KML_DOCUMENT_FOOTER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
fwrite_((void*)KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document.
fclose_(doc->file);
retvalue = 1;
}
208,10 → 193,6
uint8_t KML_PlaceMarkOpen(KML_Document_t *doc)
{
uint8_t retvalue = 0;
uint16_t i;
int8_t c;
const prog_char *str;
 
if(doc->state == KML_DOC_OPENED)
{
if(doc->file != NULL)
218,12 → 199,7
{
doc->state = KML_DOC_PLACEMARK_OPENED;
retvalue = 1;
str = KML_PLACEMARK_HEADER;
for(i= 0; i < sizeof(KML_PLACEMARK_HEADER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
fwrite_((void*)KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file);
}
}
return(retvalue);
241,10 → 217,7
uint8_t KML_PlaceMarkClose(KML_Document_t *doc)
{
 
uint8_t retvalue = 0;
uint16_t i;
int8_t c;
const prog_char *str;
uint8_t retvalue = 0; // close the Placemark-tag of the corosponding document.
 
if(doc->state == KML_DOC_PLACEMARK_OPENED)
{
251,15 → 224,11
if(doc->file != NULL)
{
doc->state = KML_DOC_OPENED;
str = KML_PLACEMARK_FOOTER;
for(i= 0; i < sizeof(KML_PLACEMARK_FOOTER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
fwrite_((void*)KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file);
retvalue = 1;
}
}
 
return(retvalue);
}
 
276,9 → 245,6
{
 
uint8_t retvalue = 0;
uint16_t i;
int8_t c;
const prog_char *str;
 
if(doc->state == KML_DOC_PLACEMARK_OPENED)
{
285,12 → 251,7
if(doc->file != NULL)
{
doc->state = KML_DOC_LINESTRING_OPENED;
str = KML_LINESTRING_HEADER;
for(i= 0; i < sizeof(KML_LINESTRING_HEADER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
fwrite_((void*)KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file);
retvalue = 1;
}
}
310,9 → 271,6
{
 
uint8_t retvalue = 0;
uint16_t i;
int8_t c;
const prog_char *str;
 
if(doc->state == KML_DOC_LINESTRING_OPENED)
{
319,12 → 277,7
if(doc->file != NULL)
{
doc->state = KML_DOC_PLACEMARK_OPENED;
str = KML_LINESTRING_FOOTER;
for(i= 0; i < sizeof(KML_LINESTRING_FOOTER); i++)
{
c = (int8_t)pgm_read_byte(str++); // get byte from flash
fputc_(c, doc->file); // and write that to sd-card
}
fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file);
retvalue = 1;
}
}
345,6 → 298,7
 
uint8_t retvalue = 0;
int8_t string[50];
// int32_t rel_altitude = 0;
 
if(doc == NULL) return(0);
 
377,6 → 331,7
}
}
}
 
return(retvalue);
}
 
397,7 → 352,7
switch(doc->state)
{
case KML_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically
retval = KML_DocumentOpen("default.kml",doc); // open the kml-document with a standardname.
retval = KML_DocumentOpen("default.kml",doc); // open the kml-document with a standardname.
break;
 
case KML_DOC_OPENED: // if a document has been opened before but no placemark exists:
/FollowMe/trunk/kml_header.h
1,12 → 1,9
// all constant strings are within the flash to save space in the sram
#include <avr/pgmspace.h>
 
//________________________________________________________________________________________________________________________________________
//
//
// Definition of KML header and footer elements for documents, placemarks and linestrings
//
//
//________________________________________________________________________________________________________________________________________
const prog_char KML_DOCUMENT_HEADER[] =
const int8_t KML_DOCUMENT_HEADER[] =
{
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
"<kml xmlns=\"http://earth.google.com/kml/2.2\">\r\n"
22,11 → 19,11
};
 
//________________________________________________________________________________________________________________________________________
//
//
// footer of an KML- file.
//
//
//________________________________________________________________________________________________________________________________________
const prog_char KML_DOCUMENT_FOOTER[] =
const int8_t KML_DOCUMENT_FOOTER[] =
{
"</Document>\r\n"
"</kml>\r\n"
33,11 → 30,11
};
 
//________________________________________________________________________________________________________________________________________
//
//
// Header of an placemark
//
//
//________________________________________________________________________________________________________________________________________
const prog_char KML_PLACEMARK_HEADER[] =
const int8_t KML_PLACEMARK_HEADER[] =
{
"<Placemark>\r\n"
"<name>Flight</name>\r\n"
45,11 → 42,11
};
 
//________________________________________________________________________________________________________________________________________
//
//
// Footer of an placemark
//
//
//________________________________________________________________________________________________________________________________________
const prog_char KML_PLACEMARK_FOOTER[] =
const int8_t KML_PLACEMARK_FOOTER[] =
{
"</Placemark>\r\n"
};
56,11 → 53,11
 
 
//________________________________________________________________________________________________________________________________________
//
//
// Header of an linestring
//
//
//________________________________________________________________________________________________________________________________________
const prog_char KML_LINESTRING_HEADER[] =
const int8_t KML_LINESTRING_HEADER[] =
{
"<LineString>\r\n"
"<tessellate>1</tessellate>\r\n"
69,11 → 66,11
};
 
//________________________________________________________________________________________________________________________________________
//
//
// Footer of an linestring
//
//
//________________________________________________________________________________________________________________________________________
const prog_char KML_LINESTRING_FOOTER[] =
const int8_t KML_LINESTRING_FOOTER[] =
{
"\r\n</coordinates>"
"\r\n</LineString>\r\n"
/FollowMe/trunk/main.c
36,7 → 36,7
static uint16_t FollowMe_Timer = 0;
 
// disable interrupts global
//cli();
cli();
 
// disable watchdog
MCUSR &=~(1<<WDRF);
55,16 → 55,17
// enable interrupts global
sei();
 
LEDRED_OFF;
LEDGRN_ON;
 
// try to initialize the FAT 16 filesystem on the SD-Card
Fat16_Init();
 
// initialize the settings
Settings_Init();
// initialize logging (needs settings)
Logging_Init();
 
LEDRED_OFF;
LEDGRN_ON;
 
#ifdef USE_SDLOGGER
printf("\r\n\r\nHW: SD-Logger");
#endif
/FollowMe/trunk/makefile
76,7 → 76,7
 
##########################################################################################################
# List C source files here. (C dependencies are automatically generated.)
SRC = main.c uart0.c uart1.c printf_P.c timer0.c menu.c led.c ubx.c analog.c button.c crc16.c ssc.c sdc.c fat16.c gps.c settings.c logging.c kml.c gpx.c
SRC = main.c uart0.c uart1.c printf_P.c timer0.c menu.c led.c ubx.c analog.c button.c crc16.c ssc.c sdc.c fat16.c gps.c settings.c logging.c kml.c
##########################################################################################################
 
 
/FollowMe/trunk/timer0.c
66,8 → 66,8
 
CountMilliseconds = 0;
 
 
SREG = sreg;
sei();
}
 
 
/FollowMe/trunk/uart0.c
7,7 → 7,6
 
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>
#include <stdarg.h>
#include <string.h>
29,6 → 28,7
#define FALSE 0
#define TRUE 1
 
uint8_t text[100]; // globally used text buffer
 
//int8_t test __attribute__ ((section (".noinit")));
uint8_t Request_VerInfo = FALSE;
55,12 → 55,11
UART_VersionInfo_t UART_VersionInfo;
 
uint16_t DebugData_Timer;
uint16_t DebugData_Interval = 0; // in 1ms
uint16_t DebugData_Interval = 500; // in 1ms
 
Waypoint_t FollowMe;
 
// keep lables in flash to save 512 bytes of sram space
const prog_uint8_t ANALOG_LABEL[32][16] =
const uint8_t ANALOG_LABEL[32][16] =
{
//1234567890123456
"Analog_Ch0 ", //0
175,8 → 174,6
 
// restore global interrupt flags
SREG = sreg;
sei();
printf("\r\n UART0 init...ok");
}
 
/****************************************************************/
503,9 → 500,7
}
if(Request_DebugLabel != 0xFF) // Texte für die Analogdaten
{
uint8_t label[16]; // local sram buffer
memcpy_P(label, ANALOG_LABEL[Request_DebugLabel], 16); // read lable from flash to sram buffer
SendOutData('A', FM_ADDRESS, 2, (uint8_t *) &Request_DebugLabel, sizeof(Request_DebugLabel), label, 16);
SendOutData('A', FM_ADDRESS, 2, (uint8_t *) &Request_DebugLabel, sizeof(Request_DebugLabel), ANALOG_LABEL[Request_DebugLabel], 16);
Request_DebugLabel = 0xFF;
}
if(Request_ExternalControl && txd_complete)
/FollowMe/trunk/uart0.h
22,6 → 22,7
extern uint8_t PcAccess;
extern uint8_t RemotePollDisplayLine;
 
extern uint8_t text[100]; // globally used text buffer
 
typedef struct
{
/FollowMe/trunk/uart1.c
3,7 → 3,6
 
#include "main.h"
#include "uart1.h"
#include "printf_P.h"
#include "ubx.h"
 
 
12,7 → 11,6
/****************************************************************/
void USART1_Init (void)
{
printf("\r\n UART1 init...");
// USART1 Control and Status Register A, B, C and baud rate register
uint8_t sreg = SREG;
uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * USART1_BAUD) - 1);
72,8 → 70,7
 
// restore global interrupt flags
SREG = sreg;
sei();
printf("ok");
 
}
 
/****************************************************************/
/FollowMe/trunk/ubx.c
208,13 → 208,11
/********************************************************/
void UBX_Init(void)
{
printf("\r\n UBX init...");
// mark msg buffers invalid
UbxSol.Status = INVALID;
UbxPosLlh.Status = INVALID;
UbxVelNed.Status = INVALID;
GPSData.Status = INVALID;
printf("ok");
}
 
/********************************************************/