No changes between revisions
//Designs/skrysohledac2/SW/AVRProject.dsp
0,0 → 1,133
# Microsoft Developer Studio Project File - Name="AVRProject" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
 
# TARGTYPE "Win32 (x86) External Target" 0x0106
 
CFG=AVRProject - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "AVRProject.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "AVRProject.mak" CFG="AVRProject - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "AVRProject - Win32 Release" (based on "Win32 (x86) External Target")
!MESSAGE "AVRProject - Win32 Debug" (based on "Win32 (x86) External Target")
!MESSAGE
 
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
 
!IF "$(CFG)" == "AVRProject - Win32 Release"
 
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Cmd_Line "NMAKE /f AVRProject.mak"
# PROP BASE Rebuild_Opt "/a"
# PROP BASE Target_File "AVRProject.exe"
# PROP BASE Bsc_Name "AVRProject.bsc"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Cmd_Line "make"
# PROP Rebuild_Opt ""
# PROP Target_File "AVRProject.exe"
# PROP Bsc_Name ""
# PROP Target_Dir ""
 
!ELSEIF "$(CFG)" == "AVRProject - Win32 Debug"
 
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Cmd_Line "NMAKE /f AVRProject.mak"
# PROP BASE Rebuild_Opt "/a"
# PROP BASE Target_File "AVRProject.exe"
# PROP BASE Bsc_Name "AVRProject.bsc"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Cmd_Line "make"
# PROP Rebuild_Opt "make clean"
# PROP Target_File "AVRProject.exe"
# PROP Bsc_Name ""
# PROP Target_Dir ""
 
!ENDIF
 
# Begin Target
 
# Name "AVRProject - Win32 Release"
# Name "AVRProject - Win32 Debug"
 
!IF "$(CFG)" == "AVRProject - Win32 Release"
 
!ELSEIF "$(CFG)" == "AVRProject - Win32 Debug"
 
!ENDIF
 
# Begin Group "Source Files"
 
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
 
SOURCE=.\gpstest.c
# End Source File
# End Group
# Begin Group "Header Files"
 
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
 
SOURCE=.\global.h
# End Source File
# End Group
# Begin Group "Resource Files"
 
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# Begin Source File
 
SOURCE=..\..\gps.c
# End Source File
# Begin Source File
 
SOURCE=..\..\gps.h
# End Source File
# Begin Source File
 
SOURCE=.\makefile
# End Source File
# Begin Source File
 
SOURCE=..\..\nmea.c
# End Source File
# Begin Source File
 
SOURCE=..\..\nmea.h
# End Source File
# Begin Source File
 
SOURCE=..\..\tsip.c
# End Source File
# Begin Source File
 
SOURCE=..\..\tsip.h
# End Source File
# End Group
# End Target
# End Project
//Designs/skrysohledac2/SW/AVRProject.dsw
0,0 → 1,29
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
 
###############################################################################
 
Project: "AVRProject"=.\AVRProject.dsp - Package Owner=<4>
 
Package=<5>
{{{
}}}
 
Package=<4>
{{{
}}}
 
###############################################################################
 
Global:
 
Package=<5>
{{{
}}}
 
Package=<3>
{{{
}}}
 
###############################################################################
 
//Designs/skrysohledac2/SW/AVRProject.sln
0,0 → 1,20

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AVRProject", "AVRProject.vcproj", "{38E1D1A1-FC7A-4A6C-9127-1A1C2FEF668D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{38E1D1A1-FC7A-4A6C-9127-1A1C2FEF668D}.Debug|Win32.ActiveCfg = Debug|Win32
{38E1D1A1-FC7A-4A6C-9127-1A1C2FEF668D}.Debug|Win32.Build.0 = Debug|Win32
{38E1D1A1-FC7A-4A6C-9127-1A1C2FEF668D}.Release|Win32.ActiveCfg = Release|Win32
{38E1D1A1-FC7A-4A6C-9127-1A1C2FEF668D}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
//Designs/skrysohledac2/SW/AVRProject.vcproj
0,0 → 1,137
<?xml version="1.0" encoding="windows-1250"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="AVRProject"
ProjectGUID="{38E1D1A1-FC7A-4A6C-9127-1A1C2FEF668D}"
Keyword="MakeFileProj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="0"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
>
<Tool
Name="VCNMakeTool"
BuildCommandLine="make"
ReBuildCommandLine="make make clean"
CleanCommandLine=""
Output="AVRProject.exe"
PreprocessorDefinitions=""
IncludeSearchPath=""
ForcedIncludes=""
AssemblySearchPath=""
ForcedUsingAssemblies=""
CompileAsManaged=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="0"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
>
<Tool
Name="VCNMakeTool"
BuildCommandLine="make"
ReBuildCommandLine="make "
CleanCommandLine=""
Output="AVRProject.exe"
PreprocessorDefinitions=""
IncludeSearchPath=""
ForcedIncludes=""
AssemblySearchPath=""
ForcedUsingAssemblies=""
CompileAsManaged=""
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="gpstest.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl"
>
<File
RelativePath="global.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
>
<File
RelativePath="..\..\gps.c"
>
</File>
<File
RelativePath="..\..\gps.h"
>
</File>
<File
RelativePath="..\..\lcd_hd44780.c"
>
</File>
<File
RelativePath="..\..\lcd_hd44780.h"
>
</File>
<File
RelativePath="makefile"
>
</File>
<File
RelativePath="..\..\nmea.c"
>
</File>
<File
RelativePath="..\..\nmea.h"
>
</File>
<File
RelativePath="..\..\rprintf.c"
>
</File>
<File
RelativePath="..\..\rprintf.h"
>
</File>
<File
RelativePath="..\..\tsip.c"
>
</File>
<File
RelativePath="..\..\tsip.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
//Designs/skrysohledac2/SW/global.h
0,0 → 1,46
 
//*****************************************************************************
//
// File Name : 'global.h'
// Title : AVR project global include
// Author : Pascal Stang
// Created : 7/12/2001
// Revised : 9/30/2002
// Version : 1.1
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// Description : This include file is designed to contain items useful to all
// code files and projects.
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
 
#ifndef GLOBAL_H
#define GLOBAL_H
//
// global AVRLIB defines
#include "avrlibdefs.h"
// global AVRLIB types definitions
#include "avrlibtypes.h"
 
// project/system dependent defines
 
// back-door way to enable floating-point print support
#define RPRINTF_FLOAT
 
// CPU clock speed
//#define F_CPU 16000000 // 16MHz processor
//#define F_CPU 14745000 // 14.745MHz processor
#define F_CPU 8000000 // 8MHz processor
//#define F_CPU 7372800 // 7.37MHz processor
//#define F_CPU 4000000 // 4MHz processor
//#define F_CPU 3686400 // 3.69MHz processor
//#define F_CPU 1000000
 
 
#define CYCLES_PER_US ((F_CPU+500000)/1000000) // cpu cycles per microsecond
 
#endif
//Designs/skrysohledac2/SW/gpstest.c
0,0 → 1,148
//*****************************************************************************
// File Name : gpstest.c
//
// Title : example usage of gps processing library functions
// Revision : 1.0
// Notes :
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// Revision History:
// When Who Description of change
// ----------- ----------- -----------------------
// 10-Sep-2002 pstang Created the program
//*****************************************************************************
 
//----- Include Files ---------------------------------------------------------
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
#include <avr/interrupt.h> // include interrupt support
//#include <math.h>
#include <stdlib.h>
#include <stdio.h>
 
#include "global.h" // include our global settings
#include "uart2.h" // include dual-uart function library
#include "rprintf.h" // include printf function library
#include "timer.h" // include timer function library (timing, PWM, etc)
#include "gps.h" // include gps data support
#include "tsip.h" // include TSIP gps packet handling
#include "nmea.h" // include NMEA gps packet handling
#include "vt100.h" // include VT100 terminal commands
 
#include <util/delay.h>
 
 
// LCD Library
#include "lcd_hd44780.h"
 
static int lcd_putc_stream(char c, FILE *unused)
{
return lcd_putc(c);
}
 
// Define Output Stream to LCD
static FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putc_stream, NULL, _FDEV_SETUP_WRITE);
 
// uartRxOverflow is a global variable defined in uart.c/uart2.c
// we define it here as <extern> here so that we can use its value
// in code contained in this file
extern unsigned short uartRxOverflow[2];
 
void gpsTsipTest(void);
void gpsNmeaTest(void);
 
 
//----- Begin Code ------------------------------------------------------------
int main(void)
{
sbi(DDRC, 0); // sets PC0 to be an output
cbi(PORTC, 0); // sets PC0 to output a HIGH
_delay_ms(100);
sbi(PORTC, 0); // sets PC0 to output a LOW
_delay_ms(100);
cbi(PORTC, 0); // sets PC0 to output a HIGH
_delay_ms(100);
sbi(PORTC, 0); // sets PC0 to output a LOW
_delay_ms(100);
// initialize our libraries
// initialize the UART (serial port)
// uartInit();
uart1Init();
 
sbi(DDRC, 1); // sets PC0 to be an output
cbi(PORTC, 1); // sets PC0 to output a HIGH
_delay_ms(100);
sbi(PORTC, 1); // sets PC0 to output a LOW
_delay_ms(100);
cbi(PORTC, 1); // sets PC0 to output a HIGH
_delay_ms(100);
sbi(PORTC, 1); // sets PC0 to output a LOW
_delay_ms(100);
 
// set the baud rate of UART 0 for our debug/reporting output
// uartSetBaudRate(0,9600);
// set uart0SendByte as the output for all rprintf statements
// rprintfInit(uart0SendByte);
 
// initialize the timer system
timerInit();
// initialize vt100 library
// vt100Init();
// print a little intro message so we know things are working
// vt100ClearScreen();
// rprintf("\r\nWelcome to GPS Test!\r\n");
// timerPause(1000);
 
lcd_init(); // Init LCD (interface and display module)
rprintfInit(lcd_putc);
rprintfProgStrM("Ahoj..."); rprintfCRLF();
_delay_ms(500);
lcd_clear();
 
// run example gps processing loop
// (pick the one appropriate for your GPS packet format)
gpsNmeaTest();
return 0;
}
 
 
void gpsNmeaTest(void)
{
// set the baud rate of UART 1 for NMEA
uartSetBaudRate(1,4800);
 
// clear screen
// vt100ClearScreen();
// initialize gps library
gpsInit();
// initialize gps packet decoder
nmeaInit();
 
/*
DDRA = 0b11110101; // sets PA0 O, PA1 I, PA2 O
cbi(PORTA, 0); // sets PC0 to output a LOW
sbi(PORTA, 2); // sets PC2 to output a HIGH
*/
DDRD = 0b10100000; // sets PD7 O, PD6 I, PD5 O
cbi(PORTD, 7); // sets PD7 to output a LOW
sbi(PORTD, 5); // sets PD5 to output a HIGH
 
// begin gps packet processing loop
while(1)
{
// process received gps packets until receive buffer is exhausted
while( nmeaProcess(uartGetRxBuffer(1))== NMEA_NODATA);
if((inb(PIND) & 0b01000000)==0)
gpsInfoPrintLCD();
else
gpsInfoPrintLCD2();
 
sbi(DDRC, 0); // sets PC0 to be an output
cbi(PORTC, 0); // sets PC0 to output a LOW
_delay_ms(5);
sbi(PORTC, 0); // sets PC0 to output a HIGH
}
}
 
//Designs/skrysohledac2/SW/lcdconf.h
0,0 → 1,104
/*! \file lcdconf.h \brief Character LCD driver configuration. */
//*****************************************************************************
//
// File Name : 'lcdconf.h'
// Title : Character LCD driver for HD44780/SED1278 displays
// (usable in mem-mapped, or I/O mode)
// Author : Pascal Stang - Copyright (C) 2000-2002
// Created : 11/22/2000
// Revised : 4/30/2002
// Version : 1.1
// Target MCU : Atmel AVR series
// Editor Tabs : 4
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************
 
#ifndef LCDCONF_H
#define LCDCONF_H
 
// Define type of interface used to access the LCD
// LCD_MEMORY_INTERFACE:
// To use this mode you must supply the necessary hardware to connect the
// LCD to the CPU's memory bus. The CONTROL and DATA registers of the LCD
// (HD44780 chip) must appear in the CPU's memory map. This mode is faster
// than the port interface but requires a little extra hardware to make it
// work. It is especially useful when your CPU is already configured to
// use an external memory bus for other purposes (like accessing memory).
//
// LCD_PORT_INTERFACE:
// This mode allows you to connect the control and data lines of the LCD
// directly to the I/O port pins (no interfacing hardware is needed),
// but it generally runs slower than the LCD_MEMORY_INTERFACE.
// Depending on your needs, when using the LCD_PORT_INTERFACE, the LCD may
// be accessed in 8-bit or 4-bit mode. In 8-bit mode, one whole I/O port
// (pins 0-7) is required for the LCD data lines, but transfers are faster.
// In 4-bit mode, only I/O port pins 4-7 are needed for data lines, but LCD
// access is slower. In either mode, three additional port pins are
// required for the LCD interface control lines (RS, R/W, and E).
 
// Enable one of the following interfaces to your LCD
//#define LCD_MEMORY_INTERFACE
#define LCD_PORT_INTERFACE
 
// Enter the parameters for your chosen interface'
// if you chose the LCD_PORT_INTERFACE:
#ifdef LCD_PORT_INTERFACE
#ifndef LCD_CTRL_PORT
// port and pins you will use for control lines
#define LCD_CTRL_PORT PORTC
#define LCD_CTRL_DDR DDRC
#define LCD_CTRL_RS 2
#define LCD_CTRL_RW 3
#define LCD_CTRL_E 4
#endif
#ifndef LCD_DATA_POUT
// port you will use for data lines
#define LCD_DATA_POUT PORTA
#define LCD_DATA_PIN PINA
#define LCD_DATA_DDR DDRA
// access mode you will use (default is 8bit unless 4bit is selected)
#define LCD_DATA_4BIT
#endif
#endif
 
// if you chose the LCD_MEMORY_INTERFACE:
#ifdef LCD_MEMORY_INTERFACE
#ifndef LCD_CTRL_ADDR
// CPU memory address of the LCD control register
#define LCD_CTRL_ADDR 0x1000
#endif
#ifndef LCD_DATA_ADDR
// CPU memory address of the LCD data register
#define LCD_DATA_ADDR 0x1001
#endif
#endif
 
 
// LCD display geometry
// change these definitions to adapt settings
#define LCD_LINES 2 // visible lines
#define LCD_LINE_LENGTH 16 // line length (in characters)
// cursor position to DDRAM mapping
#define LCD_LINE0_DDRAMADDR 0x00
#define LCD_LINE1_DDRAMADDR 0x40
#define LCD_LINE2_DDRAMADDR 0x14
#define LCD_LINE3_DDRAMADDR 0x54
 
// LCD delay
// This delay affects how quickly accesses are made to the LCD controller.
// The HD44780 LCD controller requires an access time of at least 1us.
// LCD_DELAY should be scaled to take at least half that time (500us).
// Each NOP takes 1 CPU clock cycle to execute. Thus, at 4MHz, you should
// use at least 2 NOPs, at 8MHz at least 4 NOPs, etc.
// You can also use the delay_us(xx) command for longer access times.
 
// LCD_DELAY is now automatically set in lcd.h,
// however, if you define it here, this definition will override the automatic setting
 
// use this for a fail-safe delay
//#define LCD_DELAY delay_us(5);
 
#endif
//Designs/skrysohledac2/SW/makefile
0,0 → 1,95
# Makefile for AVR function library development and examples
# Author: Pascal Stang
#
# For those who have never heard of makefiles: a makefile is essentially a
# script for compiling your code. Most C/C++ compilers in the world are
# command line programs and this is even true of programming environments
# which appear to be windows-based (like Microsoft Visual C++). Although
# you could use AVR-GCC directly from the command line and try to remember
# the compiler options each time, using a makefile keeps you free of this
# tedious task and automates the process.
#
# For those just starting with AVR-GCC and not used to using makefiles,
# I've added some extra comments above several of the makefile fields which
# you will have to deal with.
 
########### change this lines according to your project ##################
#put the name of the target mcu here (at90s8515, at90s8535, attiny22, atmega603 etc.)
# MCU = atmega163
# MCU = atmega161
MCU = atmega128
 
#put the name of the target file here (without extension)
# Your "target" file is your C source file that is at the top level of your code.
# In other words, this is the file which contains your main() function.
 
TRG = gpstest
 
#put your C sourcefiles here
# Here you must list any C source files which are used by your target file.
# They will be compiled in the order you list them, so it's probably best
# to list $(TRG).c, your top-level target file, last.
 
SRC = $(AVRLIB)/buffer.c $(AVRLIB)/uart2.c $(AVRLIB)/rprintf.c $(AVRLIB)/timer.c $(AVRLIB)/vt100.c $(AVRLIB)/tsip.c $(AVRLIB)/nmea.c $(AVRLIB)/gps.c $(AVRLIB)/lcd_hd44780.c $(TRG).c
 
#put additional assembler source file here
# The ASRC line allows you to list files which contain assembly code/routines that
# you would like to use from within your C programs. The assembly code must be
# written in a special way to be usable as a function from your C code.
 
ASRC =
 
#additional libraries and object files to link
# Libraries and object files are collections of functions which have already been
# compiled. If you have such files, list them here, and you will be able to use
# use the functions they contain in your target program.
 
LIB =
 
#additional includes to compile
INC =
 
#assembler flags
ASFLAGS = -Wa, -gstabs
 
#compiler flags
CPFLAGS = -g -Os -Wall -Wstrict-prototypes -I$(AVRLIB) -Wa,-ahlms=$(<:.c=.lst)
 
#linker flags
# LDFLAGS = -Wl,-Map=$(TRG).map,--cref
LDFLAGS = -Wl,-Map=$(TRG).map,--cref -lm
#PRINTF_LIB = -Wl,-u,vfprintf -lprintf_flt
########### you should not need to change the following line #############
include $(AVRLIB)/make/avrproj_make
###### dependecies, add any dependencies you need here ###################
# Dependencies tell the compiler which files in your code depend on which
# other files. When you change a piece of code, the dependencies allow
# the compiler to intelligently figure out which files are affected and
# need to be recompiled. You should only list the dependencies of *.o
# files. For example: uart.o is the compiled output of uart.c and uart.h
# and therefore, uart.o "depends" on uart.c and uart.h. But the code in
# uart.c also uses information from global.h, so that file should be listed
# in the dependecies too. That way, if you alter global.h, uart.o will be
# recompiled to take into account the changes.
 
buffer.o : buffer.c buffer.h
uart.o : uart.c uart.h global.h
uart2.o : uart2.c uart2.h global.h
rprintf.o : rprintf.c rprintf.h
a2d.o : a2d.c a2d.h
timer.o : timer.c timer.h global.h
pulse.o : pulse.c pulse.h timer.h global.h
lcd.o : lcd.c lcd.h lcdconf.h global.h
i2c.o : i2c.c i2c.h global.h
spi.o : spi.c spi.h global.h
swpwm.o : swpwm.c swpwm.h global.h
servo.o : servo.c servo.h global.h
swuart.o : swuart.c swuart.h global.h
tsip.o : tsip.c tsip.h global.h
nmea.o : nmea.c nmea.h global.h
vt100.o : vt100.c vt100.h global.h
gps.o : gps.c gps.h global.h
lcd_hd44780.o : lcd_hd44780.c lcd_hd44780.h global.h
$(TRG).o : $(TRG).c global.h
//Designs/skrysohledac2/SW/utm.c
0,0 → 1,389
/************************************************************************
*
* File: Utm.cpp
* RCS: $Header: /cvsroot/stelvio/stelvio/NavStar/Utm.cpp,v 1.1 2001/03/18 20:07:03 steve_l Exp $
* Author: Steve Loughran
* Created: 2001
* Language: C++
* Package:
* Status: Experimental
* @doc
*
************************************************************************/
 
/*
This is code to do UTM conversion.
 
I took this code from Jason Bevins' GPS thing which blagged the VB algorithms
from the Mapping Datum Transformation Software (MADTRAN) program,
written in PowerBasic. To get the source code for MADTRAN, go to:
 
http://164.214.2.59/publications/guides/MADTRAN/index.html
this version retains the core algorithms as static functions
 
*/
 
#include "stdafx.h"
#include "Common.h"
#include "osgb.h"
#include "utm.h"
#include <math.h>
 
// Some constants used by these functions.
static const double fe = 500000.0;
static const double ok = 0.9996;
 
// An array containing each vertical UTM zone.
static char cArray[] = "CDEFGHJKLMNPQRSTUVWX";
 
 
/////////////////////////////////////////////////////////////////////////////
// Miscellaneous functions for these UTM conversion formulas.
 
double CalculateESquared (double a, double b)
{
return ((a * a) - (b * b)) / (a * a);
}
 
 
double CalculateE2Squared (double a, double b)
{
return ((a * a) - (b * b)) / (b * b);
}
 
 
double denom (double es, double sphi)
{
double sinSphi = sin (sphi);
return sqrt (1.0 - es * (sinSphi * sinSphi));
}
 
 
double sphsr (double a, double es, double sphi)
{
double dn = denom (es, sphi);
return a * (1.0 - es) / (dn * dn * dn);
}
 
 
double sphsn (double a, double es, double sphi)
{
double sinSphi = sin (sphi);
return a / sqrt (1.0 - es * (sinSphi * sinSphi));
}
 
 
double sphtmd (double ap, double bp, double cp, double dp, double ep,
double sphi)
{
return (ap * sphi) - (bp * sin (2.0 * sphi)) + (cp * sin (4.0 * sphi))
- (dp * sin (6.0 * sphi)) + (ep * sin (8.0 * sphi));
}
 
 
//=======================================================================
// Purpose:
// This function converts the specified lat/lon coordinate to a UTM
// coordinate.
// Parameters:
// double a:
// Ellipsoid semi-major axis, in meters. (For WGS84 datum, use 6378137.0)
// double f:
// Ellipsoid flattening. (For WGS84 datum, use 1 / 298.257223563)
// int& utmXZone:
// Upon exit, this parameter will contain the hotizontal zone number of
// the UTM coordinate. The returned value for this parameter is a number
// within the range 1 to 60, inclusive.
// char& utmYZone:
// Upon exit, this parameter will contain the zone letter of the UTM
// coordinate. The returned value for this parameter will be one of:
// CDEFGHJKLMNPQRSTUVWX.
// double& easting:
// Upon exit, this parameter will contain the UTM easting, in meters.
// double& northing:
// Upon exit, this parameter will contain the UTM northing, in meters.
// double lat, double lon:
// The lat/lon coordinate to convert.
// Notes:
// - The code in this function is a C conversion of some of the source code
// from the Mapping Datum Transformation Software (MADTRAN) program,
// written in PowerBasic. To get the source code for MADTRAN, go to:
//
// http://164.214.2.59/publications/guides/MADTRAN/index.html
//
// and download MADTRAN.ZIP
// - If the UTM zone is out of range, the y-zone character is set to the
// asterisk character ('*').
//=======================================================================
 
void LatLonToUtm (double a, double f, int& utmXZone, char& utmYZone,
double& easting, double& northing, double lat, double lon)
{
double recf;
double b;
double eSquared;
double e2Squared;
double tn;
double ap;
double bp;
double cp;
double dp;
double ep;
double olam;
double dlam;
double s;
double c;
double t;
double eta;
double sn;
double tmd;
double t1, t2, t3, t6, t7;
double nfn;
 
if (lon <= 0.0) {
utmXZone = 30 + (int)(lon / 6.0);
} else {
utmXZone = 31 + (int)(lon / 6.0);
}
if (lat < 84.0 && lat >= 72.0) {
// Special case: zone X is 12 degrees from north to south, not 8.
utmYZone = cArray[19];
} else {
utmYZone = cArray[(int)((lat + 80.0) / 8.0)];
}
if (lat >= 84.0 || lat < -80.0) {
// Invalid coordinate; the vertical zone is set to the invalid
// character.
utmYZone = '*';
}
 
double latRad = lat * deg2rad;
double lonRad = lon * deg2rad;
recf = 1.0 / f;
b = a * (recf - 1.0) / recf;
eSquared = CalculateESquared (a, b);
e2Squared = CalculateE2Squared (a, b);
tn = (a - b) / (a + b);
ap = a * (1.0 - tn + 5.0 * ((tn * tn) - (tn * tn * tn)) / 4.0 + 81.0 *
((tn * tn * tn * tn) - (tn * tn * tn * tn * tn)) / 64.0);
bp = 3.0 * a * (tn - (tn * tn) + 7.0 * ((tn * tn * tn)
- (tn * tn * tn * tn)) / 8.0 + 55.0 * (tn * tn * tn * tn * tn) / 64.0)
/ 2.0;
cp = 15.0 * a * ((tn * tn) - (tn * tn * tn) + 3.0 * ((tn * tn * tn * tn)
- (tn * tn * tn * tn * tn)) / 4.0) / 16.0;
dp = 35.0 * a * ((tn * tn * tn) - (tn * tn * tn * tn) + 11.0
* (tn * tn * tn * tn * tn) / 16.0) / 48.0;
ep = 315.0 * a * ((tn * tn * tn * tn) - (tn * tn * tn * tn * tn)) / 512.0;
olam = (utmXZone * 6 - 183) * deg2rad;
dlam = lonRad - olam;
s = sin (latRad);
c = cos (latRad);
t = s / c;
eta = e2Squared * (c * c);
sn = sphsn (a, eSquared, latRad);
tmd = sphtmd (ap, bp, cp, dp, ep, latRad);
t1 = tmd * ok;
t2 = sn * s * c * ok / 2.0;
t3 = sn * s * (c * c * c) * ok * (5.0 - (t * t) + 9.0 * eta + 4.0
* (eta * eta)) / 24.0;
if (latRad < 0.0) nfn = 10000000.0; else nfn = 0;
northing = nfn + t1 + (dlam * dlam) * t2 + (dlam * dlam * dlam
* dlam) * t3 + (dlam * dlam * dlam * dlam * dlam * dlam) + 0.5;
t6 = sn * c * ok;
t7 = sn * (c * c * c) * (1.0 - (t * t) + eta) / 6.0;
easting = fe + dlam * t6 + (dlam * dlam * dlam) * t7 + 0.5;
if (northing >= 9999999.0) northing = 9999999.0;
}
 
//=======================================================================
// Purpose:
// This function converts the specified lat/lon coordinate to a UTM
// coordinate in the WGS84 datum. (See the comment block for the
// LatLonToUtm() member function.)
//=======================================================================
 
void LatLonToUtmWGS84 (int& utmXZone, char& utmYZone,
double& easting, double& northing, double lat, double lon)
{
LatLonToUtm (6378137.0, 1 / 298.257223563, utmXZone, utmYZone,
easting, northing, lat, lon);
}
 
 
 
 
//=======================================================================
// Purpose:
// This function converts the specified UTM coordinate to a lat/lon
// coordinate.
// Pre:
// - utmXZone must be between 1 and 60, inclusive.
// - utmYZone must be one of: CDEFGHJKLMNPQRSTUVWX
// Parameters:
// double a:
// Ellipsoid semi-major axis, in meters. (For WGS84 datum, use 6378137.0)
// double f:
// Ellipsoid flattening. (For WGS84 datum, use 1 / 298.257223563)
// int utmXZone:
// The horizontal zone number of the UTM coordinate.
// char utmYZone:
// The vertical zone letter of the UTM coordinate.
// double easting, double northing:
// The UTM coordinate to convert.
// double& lat:
// Upon exit, lat contains the latitude.
// double& lon:
// Upon exit, lon contains the longitude.
// Notes:
// The code in this function is a C conversion of some of the source code
// from the Mapping Datum Transformation Software (MADTRAN) program, written
// in PowerBasic. To get the source code for MADTRAN, go to:
//
// http://164.214.2.59/publications/guides/MADTRAN/index.html
//
// and download MADTRAN.ZIP
//=======================================================================
 
void UtmToLatLon (double a, double f, int utmXZone, char utmYZone,
double easting, double northing, double& lat, double& lon)
{
double recf;
double b;
double eSquared;
double e2Squared;
double tn;
double ap;
double bp;
double cp;
double dp;
double ep;
double nfn;
double tmd;
double sr;
double sn;
double ftphi;
double s;
double c;
double t;
double eta;
double de;
double dlam;
double olam;
 
recf = 1.0 / f;
b = a * (recf - 1) / recf;
eSquared = CalculateESquared (a, b);
e2Squared = CalculateE2Squared (a, b);
tn = (a - b) / (a + b);
ap = a * (1.0 - tn + 5.0 * ((tn * tn) - (tn * tn * tn)) / 4.0 + 81.0 *
((tn * tn * tn * tn) - (tn * tn * tn * tn * tn)) / 64.0);
bp = 3.0 * a * (tn - (tn * tn) + 7.0 * ((tn * tn * tn)
- (tn * tn * tn * tn)) / 8.0 + 55.0 * (tn * tn * tn * tn * tn) / 64.0)
/ 2.0;
cp = 15.0 * a * ((tn * tn) - (tn * tn * tn) + 3.0 * ((tn * tn * tn * tn)
- (tn * tn * tn * tn * tn)) / 4.0) / 16.0;
dp = 35.0 * a * ((tn * tn * tn) - (tn * tn * tn * tn) + 11.0
* (tn * tn * tn * tn * tn) / 16.0) / 48.0;
ep = 315.0 * a * ((tn * tn * tn * tn) - (tn * tn * tn * tn * tn)) / 512.0;
if ((utmYZone <= 'M' && utmYZone >= 'C')
|| (utmYZone <= 'm' && utmYZone >= 'c')) {
nfn = 10000000.0;
} else {
nfn = 0;
}
tmd = (northing - nfn) / ok;
sr = sphsr (a, eSquared, 0.0);
ftphi = tmd / sr;
double t10, t11, t14, t15;
for (int i = 0; i < 5; i++) {
t10 = sphtmd (ap, bp, cp, dp, ep, ftphi);
sr = sphsr (a, eSquared, ftphi);
ftphi = ftphi + (tmd - t10) / sr;
}
sr = sphsr (a, eSquared, ftphi);
sn = sphsn (a, eSquared, ftphi);
s = sin (ftphi);
c = cos (ftphi);
t = s / c;
eta = e2Squared * (c * c);
de = easting - fe;
t10 = t / (2.0 * sr * sn * (ok * ok));
t11 = t * (5.0 + 3.0 * (t * t) + eta - 4.0 * (eta * eta) - 9.0 * (t * t)
* eta) / (24.0 * sr * (sn * sn * sn) * (ok * ok * ok * ok));
lat = ftphi - (de * de) * t10 + (de * de * de * de) * t11;
t14 = 1.0 / (sn * c * ok);
t15 = (1.0 + 2.0 * (t * t) + eta) / (6 * (sn * sn * sn) * c
* (ok * ok * ok));
dlam = de * t14 - (de * de * de) * t15;
olam = (utmXZone * 6 - 183.0) * deg2rad;
lon = olam + dlam;
lon *= rad2deg;
lat *= rad2deg;
}
 
//=======================================================================
// Purpose:
// This function converts the specified UTM coordinate to a lat/lon
// coordinate in the WGS84 datum. (See the comment block for the
// UtmToLatLon() member function.
//=======================================================================
 
void UtmToLatLonWGS84 (int utmXZone, char utmYZone, double easting,
double northing, double& lat, double& lon)
{
UtmToLatLon (6378137.0, 1 / 298.257223563, utmXZone, utmYZone,
easting, northing, lat, lon);
}
 
//=======================================================================
/**
@func Build a position string
@parm target. must be 30 characters or longer.
*/
//=======================================================================
 
void CUtmPoint::GetString(TCHAR *position) const
{
_stprintf(position,
_T("%02d%c %06d %07d"),
m_xzone, m_yzone,
(int)m_easting,
(int)m_northing);
}
 
//=======================================================================
/**
@func get the position of a UTM point
@parm point out
*/
//=======================================================================
 
void CUtmPoint::ToPosition(CPosition &pos) const
{
double lat,lon;
UtmToLatLonWGS84(m_xzone,m_yzone,m_easting,m_northing,
lat,lon);
pos.Clear();
pos.SetLatitude(lat);
pos.SetLongitude(lon);
}
 
//=======================================================================
/**
@func turn a position into a UTM point
@parm position
@rdesc true if it was in range
*/
//=======================================================================
 
bool CUtmPoint::FromPosition(const CPosition &pos)
{
Clear();
if(!IsPositionInUtmSpace(pos))
return false;
LatLonToUtmWGS84(m_xzone,m_yzone,m_easting,m_northing,
pos.GetLatitude(),
pos.GetLongitude());
return true;
}
//Designs/skrysohledac2/SW/utm.h
0,0 → 1,102
/************************************************************************
*
* File: utm.h
* RCS: $Header: /cvsroot/stelvio/stelvio/NavStar/Utm.h,v 1.2 2002/04/23 05:02:00 steve_l Exp $
* Author: Steve Loughran
* Created: 2001
* Language: C++
* Package:
* Status: Experimental
* @doc
*
************************************************************************/
#pragma once
 
//=======================================================================
/**
* UTM support goes here
*/
//=======================================================================
class CUtmPoint
{
protected:
double m_easting;
double m_northing;
int m_xzone;
char m_yzone;
public:
 
//=======================================================================
//=======================================================================
CUtmPoint()
{Clear();}
 
//=======================================================================
//=======================================================================
CUtmPoint(const CPosition &p)
{
FromPosition(p);
}
 
//=======================================================================
//=======================================================================
CUtmPoint(const CUtmPoint& that)
{
m_easting=that.m_easting;
m_northing=that.m_northing;
m_xzone=that.m_xzone;
m_yzone=that.m_yzone;
}
 
//=======================================================================
//=======================================================================
void Clear()
{
m_easting=m_northing=0;
m_xzone=0;
m_yzone=0;
}
 
//=======================================================================
/**
@func Build a position string
@parm target. must be 30 characters or longer.
*/
//=======================================================================
 
void GetString(TCHAR *position) const;
 
//=======================================================================
/**
@func get the position of a UTM point
@parm point out
*/
//=======================================================================
 
void ToPosition(CPosition &pos) const;
 
//=======================================================================
/**
@func turn a position into a UTM point
@parm position
@rdesc true if it was in range
*/
//=======================================================================
 
bool FromPosition(const CPosition &pos);
 
//=======================================================================
/**
range test
*/
//=======================================================================
 
static bool IsPositionInUtmSpace(const CPosition &pos)
{ return pos.GetLatitude()<=84 && pos.GetLatitude()>=-80;}
 
 
 
};
 
 
 
//Designs/skrysohledac2/SW/.
Property changes:
Added: svn:ignore
+gpstest.map
+gpstest.o
+zobrazeni.xls
+AVRProject.ncb
+AVRProject.suo
+AVRProject.vcproj.KAKLNBXP.kakl.user
+gpstest.bin
+gpstest.cof
+gpstest.eep
+gpstest.elf
+gpstest.hex
+gpstest.lst