basisdata.cpp
来自「this the code of bootstation」· C++ 代码 · 共 360 行
CPP
360 行
// BasisData.cpp : implementation file
//
#include "stdafx.h"
#include <math.h>
#include "Bodenstation2.h"
#include "BasisData.h"
#include <fstream.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBasisData dialog
CBasisData::CBasisData(CWnd* pParent /*=NULL*/)
: CDialog(CBasisData::IDD, pParent)
{
//{{AFX_DATA_INIT(CBasisData)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CBasisData::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBasisData)
DDX_Control(pDX, IDC_CMBPORT, m_port);
DDX_Control(pDX, IDC_DATA, m_showdata);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBasisData, CDialog)
//{{AFX_MSG_MAP(CBasisData)
ON_CBN_SELCHANGE(IDC_CMBPORT, OnSelchangeCmbport)
ON_BN_CLICKED(IDC_BTN_DIST, OnBtnDist)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBasisData message handlers
void CBasisData::OnSelchangeCmbport()
{
// TODO: Add your control notification handler code here
}
void CBasisData::OnOK()
{
// TODO: Add extra validation here
// Vaiable zur Bestimmung ob Funktion korrekt durchlaufen wurden...bTest = FALSE -> Fehler aufgetretten
char msg[82];
int j=0;
memset(msg,0,sizeof(msg));
mygps.R_RMC_flag=true;
// mygps.SetDebug ( bTest );
int port=1;
//port=m_port.GetItemData();
mygps.bTest = mygps.Open( 1, 4800 , 8, 0, 0 );
//for (j=0;j<10;j++)
//while (mygps.bTest)
{
for ( int i = 0; i<10; i++)
{
//memset(msg,0,sizeof(msg));
mygps.ReadData(msg,164);
mygps.PrintOverview ( msg );
//basis_long=mygps.long_f;
//basis_lat=mygps.lat_f;
// mygps.latitude[10]='\0';
// mygps.longitude[11]='\0';
sprintf(msg,"%c\t%f\t%f\n",mygps.stat,mygps.lat_f,mygps.long_f);
m_showdata.SetWindowText(msg);
if(!mygps.R_RMC_flag)
break;
}
//Sleep(2000);
}
mygps.Close();
//CDialog::OnOK();
}
void CBasisData::OnCancel()
{
// TODO: Add extra cleanup here
mygps.bTest=false;
CDialog::OnCancel();
}
LRESULT CBasisData::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::WindowProc(message, wParam, lParam);
}
void CBasisData::OnBtnDist()
{
// TODO: Add your control notification handler code here
char temp[32];
char g_valid_wert;
float f_long, f_lat;
int g_zeit=0;
char read_ch;
float lat_basis, long_basis;
int lat_b_i, long_b_i;
double a_z_5=0,a_z_b=0;
double w_z_b=0,w_z_5=0;
float long_v_5, lat_v_5;
bool flag_valid = false;
int nr_a;
ofstream write_dist;
ifstream read_pos;
lat_b_i=int(mygps.lat_f/100);
long_b_i=int(mygps.long_f/100);
lat_basis=mygps.lat_f-lat_b_i*100;
long_basis=mygps.long_f-long_b_i*100;
write_dist.open("Rechnung_A_W.txt");
//write_dist<<"Basis:"<<'\t'<<"Longitude:"<<'\t'<<basis_long<<'\t'<<"Latitude"<<'\t'
// <<basis_lat<< '\t' << endl;
write_dist<<"Zeit"<< '\t'<<"Longitude"<< '\t'<<"Latitude"<< '\t'<<"valid_wert"<<'\t'
<<"Abstand_z_vor_5 punk"<< '\t'<<"Winkel_z_vor_5_punk"<<'\t'
<<"Abstand_z_basis"<< '\t'<<"Winkel_z_basis"<<'\t'<<endl;
read_pos.open("Ausgabe_3.xls");//
for(int i=0; i<24; i++ ){
for(int k=0;k<32;k++){
temp[k]='\t';
}
read_pos>>temp;
}//for(int i=0; i<25; i++ ){
while (read_pos.get(read_ch)){
int j;
for (j=0;j<22;j++){
read_pos>>temp;
if(j==0){
g_zeit=atoi(temp);
}
if(j==12){
for (int a=0;a<32;a++){
if(temp[a]==',')
temp[a]='.';
}
f_long=float(atof(temp));
}//if(j==12){
if(j==13){
if(temp[0]=='E'){
f_long=f_long*1;
}//if(temp[0]=='E')
else{//if(temp[0]=='E')
if(temp[0]=='W'){
f_long=f_long*(-1);
}//if(temp[0]=='W')
else{//if(temp[0]=='W'){
f_long=0;
}//else if(temp[0]=='W'){
}//else{//if(temp[0]=='E')
}//if(j==13){
if(j==14){
for (int b=0;b<32;b++){
if(temp[b]==',')
temp[b]='.';
}
f_lat=float(atof(temp));
}//if(j==14){
if(j==15){
if(temp[0]=='N'){
f_lat=f_lat*1;
}//if(temp[0]=='N')
else{//if(temp[0]=='N')
if(temp[0]=='S'){
f_lat=f_lat*(-1);
}//if(temp[0]=='S')
else{//if(temp[0]=='S'){
f_lat=0;
}//else if(temp[0]=='S'){
}//else{//if(temp[0]=='N')
}//if(j==15){
if(j==16){
if(temp[0]!='A' && temp[0]!='V'){
g_valid_wert='U';
}
else{
g_valid_wert=temp[0];
}
if(temp[0]!='A'){
f_long=0;
f_lat=0;
a_z_5=0;
w_z_5=0;
a_z_b=0;
w_z_b=0;
}//if(temp[0]!='A'){
else{//if(temp[0]!='A'){
//rechnen Abstand und Winkel
if (!flag_valid){
flag_valid=true;
//a_z_b = distance(f_long, f_lat, basis_long,basis_lat, &w_z_b);
nr_a = 0;
long_v_5 = f_long;
lat_v_5 = f_lat;
a_z_b = distance(f_long, f_lat, long_basis,lat_basis, &w_z_b);
}//if (!flag_valid){
else{//if (!flag_valid){
if(nr_a==5){
a_z_5 = distance_d(f_long, f_lat, long_v_5,lat_v_5, &w_z_5);
a_z_b = distance(f_long, f_lat, long_basis,lat_basis, &w_z_b);
long_v_5 = f_long;
lat_v_5 = f_lat;
nr_a = 0;
}//if(nr_a==5){
else{//if(nr_a==5){
a_z_5 = 0;
w_z_5 = 0;
a_z_b = 0;
w_z_b = 0;
}//else{//if(nr_a==5){
}//else{//if (!flag_valid){
nr_a++;
}//else{//if(temp[0]!='A'){
}//if(j==16){
}//for (j=0;j<23;j++){
write_dist<<g_zeit<<'\t'<<f_long<<'\t'<<f_lat<<'\t'<<g_valid_wert<<'\t'
<<a_z_5<<'\t'<<w_z_5<<'\t'<<a_z_b<<'\t'<<w_z_b<<'\t'<<endl;
}//while (read.get(read_ch)){
read_pos.close();
write_dist.close();
}
double CBasisData::distance_d(double longitude1, double latitude1,double longitude2, double latitude2, double *angle)
{ double m_Longitude1, m_Latitude1;
double m_Longitude2, m_Latitude2;
double m_RadLo1, m_RadLa1;
double m_RadLo2, m_RadLa2;
double Ec1;
double Ed1;
m_Longitude1 = longitude1;
m_Latitude1 = latitude1;
m_RadLo1 = longitude1 * PI/180.0;
m_RadLa1 = latitude1 * PI/180.0;
Ec1 = P_R + (E_R - P_R) * (90.0-m_Latitude1) / 90.0;
Ed1 = Ec1 * cos(m_RadLa1);
m_Longitude2 = longitude2;
m_Latitude2 = latitude2;
m_RadLo2 = longitude2 * PI/180.0;
m_RadLa2 = latitude2 * PI/180.0;
double dx = (m_RadLo2 - m_RadLo1) * Ed1;
double dy = (m_RadLa2 - m_RadLa1) *Ec1;
double out = sqrt(dx * dx + dy * dy);
if( angle != NULL)
{
*angle = atan(fabs(dx/dy))*180.0/PI;
double dLo = m_Longitude2 - m_Longitude1;
double dLa = m_Latitude2 - m_Latitude1;
if(dLo > 0 && dLa <= 0)
{
*angle =(90.0 - *angle) + 90.0;
}
else if(dLo <= 0 && dLa < 0)
{
*angle = *angle + 180.0;
}
else if(dLo < 0 && dLa >= 0)
{
*angle =(90. - *angle) + 270;
}
}
return out;
}
double CBasisData::distance(
float longitude1, float latitude1,
float longitude2, float latitude2,
double *angle)
{
double m_LoDeg1 = int(longitude1/100);
double m_LoMin1 = (longitude1 - m_LoDeg1*100)/60.0;
double m_longitude1= m_LoDeg1+m_LoMin1;
double m_LoDeg2 = int(longitude2/100);
double m_LoMin2 = (longitude2 - m_LoDeg2*100)/60.0;
double m_longitude2= m_LoDeg2+m_LoMin2;
double m_LaDeg1 = int(latitude1/100);
double m_LaMin1 = (latitude1-m_LaDeg1*100)/60;
double m_latitude1 = m_LaDeg1+m_LaMin1;
double m_LaDeg2 = int(latitude2/100);
double m_LaMin2 = (latitude2-m_LaDeg2*100)/60;
double m_latitude2 = m_LaDeg2+m_LaMin2;
return distance_d(
m_longitude1, m_latitude1, m_longitude2,m_latitude2, angle);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?