论坛风格切换切换到宽版
  • 50265阅读
  • 200回复

安卓手机卫星跟踪APP——ZhuiXing——试用版发布 [复制链接]

上一主题 下一主题
离线BI3OJW
发帖
195
只看该作者 40楼 发表于: 2015-11-16
ZhuiXing.apk (769 K) 下载次数:71
进度报告:利用手机传感器,实现指向的显示。可显示手机指向的方位角,仰角。
下一步整合卫星方位角,仰角的计算与显示。
离线bg6lqv
发帖
172
只看该作者 41楼 发表于: 2015-11-18
回 BI3OJW 的帖子
BI3OJW:[图片]
进度报告:利用手机传感器,实现指向的显示。可显示手机指向的方位角,仰角。
下一步整合卫星方位角,仰角的计算与显示。 (2015-11-16 15:27) 

只要搞通星历算法,用【易安卓】编写安卓应用那是非常的简单,何必去费力的JAVA 和 eclipse!期待你的国产安卓卫星追踪应用!!
呼号:BG6LQV
设备:Yeasu FT-817 FT857D  FT920 AOR5000  Hackrf ONE  Airspy mini  RTL2832
天线:  HF+6m:Moxon   YP3    3波段蛛网
       70cm:4x13 ele DK7ZB's YAGI  10圈 Helical Antenna
       1.8米 网状抛物面天线 +1.2GHz 1.7GHz 螺旋馈源 + 2.3GHz 3.4GHz 5.7GHz OK1DFC 馈源
QTH:河南省南阳市
离线BI3OJW
发帖
195
只看该作者 42楼 发表于: 2015-11-18
回 bg6lqv 的帖子
bg6lqv:只要搞通星历算法,用【易安卓】编写安卓应用那是非常的简单,何必去费力的JAVA 和 eclipse!期待你的国产安卓卫星追踪应用!![表情] (2015-11-18 09:50) 

对,工具是次要的。
不过前段时间找了几个简单的安卓开发工具都不太好用。咬牙开始学java和eclipse,现在刚刚入门,似乎没想象中的那么复杂。
算法在前面所发的excel里,都是公式,套进去就OK了,有时间你也可以试试
离线BI3OJW
发帖
195
只看该作者 43楼 发表于: 2015-11-20

ZhuiXing.apk (772 K) 下载次数:29
进度报告:测试做出来了,初步试验有些许误差,请各位试用。
错误报告请跟帖回复。
可以手动更改经纬度。但星历目前不能更新,下一步会改进。
下一楼贴源码,有兴趣朋友的可以自己改进。
离线BI3OJW
发帖
195
只看该作者 44楼 发表于: 2015-11-20
package com.example.zhuixing;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity implements SensorEventListener{
    
    private SensorManager aSensorManager;  
    private SensorManager mSensorManager;    
    //需要两个Sensor
    private Sensor accelerometer; // 加速度传感器
    private Sensor magnetic; // 地磁场传感器
    private TextView text1;
    private TextView text2;
    private TextView text3;
    private TextView text4;
    private TextView text5;
    private TextView text6;
    private TextView text7;
    double yhjd;
    double yhwd;
    String timep;
    String xingli;
    double qingjiao;
    double chijing ;
    double pianxinlv;
    double jddfj;
    double pjdj;
    double mrrxqs;
    float[] accelerometerValues = new float[3];  
    float[] magneticFieldValues = new float[3];  
    float[] accelerometerValuesA = new float[3];  
    float[] magneticFieldValuesA = new float[3];  
    float[] Azmvalues = new float[3];  
    float[] R1 = new float[9];  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text1 = (TextView) findViewById(R.id.textView1);
        text2 = (TextView) findViewById(R.id.textView2);
        text3 = (TextView) findViewById(R.id.textView3);
        text4 = (TextView) findViewById(R.id.textView4);
        text5 = (TextView) findViewById(R.id.textView5);
        // 实例化传感器管理者
        aSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        accelerometer = aSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        magnetic = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

        yhjd=115.0/180*Math.PI ;
        yhwd=38.5/180*Math.PI;

        timep ="15320.21688976";
        qingjiao = 97.4616/180*Math.PI;//轨道倾角
        chijing= 327.0550/180*Math.PI;//升交点赤经
        pianxinlv = 0.0018254;//轨道偏心率
        jddfj = 53.0309/180*Math.PI;//近地点幅角
        pjdj = 77.2607/180*Math.PI;//平近点角
        mrrxqs = 15.11850825;//每日绕行圈数
          
    }
    protected void onResume() {
        // TODO Auto-generated method stub
        // 注册监听
        aSensorManager.registerListener(this, accelerometer,
                SensorManager.SENSOR_DELAY_NORMAL);
        mSensorManager.registerListener(this, magnetic,
                SensorManager.SENSOR_DELAY_NORMAL);
        super.onResume();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        // 解除注册
        aSensorManager.unregisterListener(this);
        mSensorManager.unregisterListener(this);
        super.onPause();
    }

    public void onSensorChanged(SensorEvent event) {
        
        // TODO Auto-generated method stub
        synchronized (this){
            float[] tmpvalues = new float[3];  
             tmpvalues[0] = event.values[0];
             tmpvalues[1] = event.values[1];
             tmpvalues[2] = event.values[2];

            if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
                accelerometerValues = tmpvalues;    
                
            }
            if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
                magneticFieldValues = tmpvalues;
                
            }
                  
            calculateOrientation();
        }
            
    }

        @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // TODO Auto-generated method stub

    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    private  void calculateOrientation() {
        accelerometerValuesA[0] = (float) (accelerometerValuesA[0]*0.9
                +accelerometerValues[0] *0.1);
        accelerometerValuesA[1] = (float) (accelerometerValuesA[1]*0.9
                +accelerometerValues[1] *0.1);
        accelerometerValuesA[2] = (float) (accelerometerValuesA[2]*0.9
                +accelerometerValues[2] *0.1);
        
        magneticFieldValuesA[0] = (float) (magneticFieldValuesA[0]*0.95
                +magneticFieldValues[0] *0.05);
        magneticFieldValuesA[1] = (float) (magneticFieldValuesA[1]*0.9
                +magneticFieldValues[1] *0.1);
        magneticFieldValuesA[2] = (float) (magneticFieldValuesA[2]*0.9
                +magneticFieldValues[2] *0.1);
        
        SensorManager.getRotationMatrix(R1, null, accelerometerValues, magneticFieldValues);          
        SensorManager.getOrientation(R1, Azmvalues);  
        
        // 要经过一次数据格式的转换,转换为度  
        Azmvalues[0] = Math.round(((float) Math.toDegrees(Azmvalues[0])+354)%360);
        Azmvalues[1] = Math.round(-1*(float) Math.toDegrees(Azmvalues[1]));
        Azmvalues[2] = (float) Math.toDegrees(Azmvalues[2]);
        

        Date date = new Date();  
        SimpleDateFormat from = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
        String times = from.format(date);
        text2.setText("当前时间:"+times);
        long timeN =  date.getTime();
        //计算当前儒略历timeNow
        double timeNow=(double)(timeN)/1000/3600/24+2440587.5;
        //timeNow=2457344.83898148;
        //计算平近点角时儒略历timeJ星历生成时。
        String nian =timep.substring(0,2);
        String ri = timep.substring(2);
        int ye=Integer.valueOf(nian)+2000;
        int a = (int) (ye/100);
        int b = (int)(2-a+a/4);
        double timeJ=(int)(365.25*(ye+4716))+(int)(30.6001*2)+2+b-1524.5
                +Double.valueOf(ri);
        ///    轨道根数
        double t=(timeJ-2451545)/36525;
        double hengxingshi = 280.46061837+360.98564736629*(timeJ-2451545)
                +0.000387933*t*t-t*t*t/38710000;
        double cfqjd =(360- hengxingshi%360)/180*Math.PI;//春分圈地理经度, 弧度
        double GM=398603000000000.0;
        double wxjsd=mrrxqs *2 *Math.PI/24/3600;//卫星角速度, 弧度每秒
        double banchangzhou=Math.pow(GM/wxjsd/wxjsd,0.333333333333);//半长轴
        double dqbj=6378137.0;//地球半径
        double gjddsj=timeJ-pjdj/2/Math.PI/mrrxqs;//过近地点时间
        double sjcjdd=timeNow-gjddsj;//时间差     过近地点
        double sjcxl=timeNow-timeJ;//时间差   星历
        double jddfjbhl=4.97*Math.pow((dqbj/banchangzhou),3.5)
                *(5*Math.pow(Math.cos(qingjiao),2)-1)
                /Math.pow((1-Math.pow(pianxinlv,2)),2);//近地点幅角变化率
        double xzjddfj=jddfj+sjcxl*jddfjbhl/180*Math.PI;//修正后 的近地点幅角(弧度制)
        double gjddhqs=(sjcjdd*mrrxqs)%1;//过近地点后圈数
        double sspjdj=gjddhqs*Math.PI*2;//实时平近点角,弧度
        //double pjdjE=Math.acos(
            //    (pianxinlv+Math.cos(sspjdj))/(1+pianxinlv*Math.cos(sspjdj))
                //);//弧度
        double zjdjS=2*Math.atan(
                Math.sqrt((1+pianxinlv)/(1-pianxinlv))*Math.tan(sspjdj/2)
                );//真近点角,弧度
        double wxfj=(xzjddfj+zjdjS+2*Math.PI)%(2*Math.PI) ;//卫星幅角,弧度
        double xiuzheng1=0;
        if ((wxfj>0.5*Math.PI )&(wxfj<Math.PI )) xiuzheng1=Math.PI ;
        if ((wxfj>Math.PI )&(wxfj<1.5*Math.PI )) xiuzheng1=-1*Math.PI ;
        double wxxzjdbl=Math.atan(Math.cos(qingjiao)*Math.tan(wxfj))
                +xiuzheng1;//卫星旋转经度变量
        double gdpmjdl= -9.95*Math.pow(dqbj/banchangzhou,3.5)
                *Math.cos(qingjiao)
                /Math.pow(1-pianxinlv*pianxinlv, 2)
                *Math.PI /180;//轨道平面进动率
        double wxjd=((chijing+cfqjd+wxxzjdbl
                -sjcxl*360.98563/180*Math.PI
                +sjcxl*gdpmjdl+Math.PI )%(Math.PI *2)+Math.PI *2)%(Math.PI *2)-Math.PI ;
        double wxwd=Math.asin(Math.sin(qingjiao)*Math.sin(wxfj));
        double dxj=Math.acos(Math.sin(yhwd)*Math.sin(wxwd)
                +Math.cos(yhwd)*Math.cos(wxwd)*Math.cos(yhjd-wxjd));//地心角
        double dxjlr=banchangzhou*(1-pianxinlv*Math.cos(sspjdj));        
        double Elv=Math.atan(
                (dxjlr*Math.cos(dxj)-dqbj)/dqbj/Math.sin(dxj)
                );//用户仰角,度数单位
        double jdc=(wxjd-yhjd+2*Math.PI )%(2*Math.PI);
        double wdyz=yhwd*Math.cos(jdc);
        double Azm=(Math.asin(Math.sin(jdc)
                *Math.sin((0.5*Math.PI-wxwd))/Math.sin(dxj))+2*Math.PI )%(2*Math.PI );
        if (wxwd<wdyz) {
            Azm = (Math.PI *3 -Azm)%(2*Math.PI );
        }

        text3.setText("手机方位角:"+Math.round(Azmvalues[0])+"\t仰    角:"+Math.round(Azmvalues[1])
                +"\n卫星方位角:"+Math.round(Azm*180/Math.PI)+"\t仰      角:"+Math.round(Elv*180/Math.PI)
                +"\n卫星经度:"+Math.round(wxjd*180/Math.PI)+"\t卫星纬度:"+Math.round(wxwd*180/Math.PI)
        +"\n用户经度:"+Math.round(yhjd*180/Math.PI)+"\t用户纬度:"+Math.round(yhwd*180/Math.PI)
        +"\n内置紫丁香2号星历,2015-11-27前有效,错误报告请跟帖。");
        
        
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void FinishClick(View v){
        finish();
    }
    public void SetupClick(View v){

        EditText editText1 = (EditText) findViewById(R.id.editText1);
        EditText editText2 = (EditText) findViewById(R.id.editText2);
        EditText editText3 = (EditText) findViewById(R.id.editText3);
        yhjd= Double.parseDouble(editText1.getText().toString())/180*Math.PI;
        yhwd= Double.parseDouble(editText2.getText().toString())/180*Math.PI;
        xingli=editText3.getText().toString();
        //text4.setText(xingli.substring(0,40));
        
        
    }
    
}
离线BG4WYJ
发帖
1080
只看该作者 45楼 发表于: 2015-11-20
真的很佩服楼主                      
姓名:冯斌
呼号:BG4WYJ/5
Q Q:154231051
手机:153久二二0607久
离线BG6LQZ
发帖
2728
只看该作者 46楼 发表于: 2015-11-20
楼主是学习的榜样
呼号:BG6LQZ
QTH:河南省南阳市
Phone:155叁久久888伍六
离线BI3OJW
发帖
195
只看该作者 47楼 发表于: 2015-11-21
首先在网站:http://lilacsat.hit.edu.cn/tle/lilacsat.txt   下载星历,保存为lilacsat.txt,保存在手机SD卡根目录。

然后安装软件: ZhuiXing.apk (774 K) 下载次数:41
安装后如图:

然后按照说明设置自己的经纬度。需要时,可以手动更新星历。更新后如正确则如下图:

如果错误,软件会闪退
离线BI3OJW
发帖
195
只看该作者 48楼 发表于: 2015-11-21
接下来一段时间,我打算做个八木天线,软件会暂停更新,不过有错误报告的话,我会尽快改进。
下面是源码,有兴趣的朋友可以自己改进。
离线BI3OJW
发帖
195
只看该作者 49楼 发表于: 2015-11-21
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.zhuixing.MainActivity"  >  
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CQ CQ CQ,This is BI3OJW." />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_below="@+id/textView2"
        android:layout_marginTop="5dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView3"
        android:layout_below="@+id/textView3"
        android:layout_marginTop="5dp"
        android:text="轨道根数 "/>

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView4"
        android:layout_below="@+id/textView4"
        android:layout_marginTop="5dp"
        android:text="内置紫丁香2号星历和定州经纬度。\n下方输入经纬度后按位置设置。\n星历文件名为lilacsat.txt,放于SD卡根目录后按更新星历。\n错误报告请发生至wj0312@163.com。" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:layout_alignParentRight="true"
        android:layout_marginRight="5dp"
        android:onClick="FinishClick"
        android:text="结束程序" />
    
     <EditText
        android:id="@+id/editText1"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/button1"
        android:layout_below="@+id/textView5"
        android:layout_marginTop="5dp"
        android:ems="10"
        android:text="115" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="5dp"
        android:ems="10"
        android:text="38.5" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button2"
        android:layout_alignBottom="@+id/button2"
        android:layout_centerHorizontal="true"
        android:onClick="UpdateClick"
        android:text="更新星历" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView5"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:onClick="SetupClick"
        android:text="位置设置" />

</RelativeLayout>
离线BI3OJW
发帖
195
只看该作者 50楼 发表于: 2015-11-21
package com.example.zhuixing;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity implements SensorEventListener{
    
    private SensorManager aSensorManager;  
    private SensorManager mSensorManager;    
    //需要两个Sensor
    private Sensor accelerometer; // 加速度传感器
    private Sensor magnetic; // 地磁场传感器
    private TextView text1;
    private TextView text2;
    private TextView text3;
    private TextView text4;
    private TextView text5;
    private TextView text6;
    private TextView text7;
    double yhjd;
    double yhwd;
    String timep;
    String xingli;
    double qingjiao;
    double chijing ;
    double pianxinlv;
    double jddfj;
    double pjdj;
    double mrrxqs;
    float[] accelerometerValues = new float[3];  
    float[] magneticFieldValues = new float[3];  
    float[] accelerometerValuesA = new float[3];  
    float[] magneticFieldValuesA = new float[3];  
    float[] Azmvalues = new float[3];  
    float[] R1 = new float[9];  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text1 = (TextView) findViewById(R.id.textView1);
        text2 = (TextView) findViewById(R.id.textView2);
        text3 = (TextView) findViewById(R.id.textView3);
        text4 = (TextView) findViewById(R.id.textView4);
        text5 = (TextView) findViewById(R.id.textView5);
        // 实例化传感器管理者
        aSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        accelerometer = aSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        magnetic = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

        yhjd=115.0/180*Math.PI ;
        yhwd=38.5/180*Math.PI;

        timep ="15320.21688976";
        qingjiao = 97.4616/180*Math.PI;//轨道倾角
        chijing= 327.0550/180*Math.PI;//升交点赤经
        pianxinlv = 0.0018254;//轨道偏心率
        jddfj = 53.0309/180*Math.PI;//近地点幅角
        pjdj = 77.2607/180*Math.PI;//平近点角
        mrrxqs = 15.11850825;//每日绕行圈数
          
    }
    protected void onResume() {
        // TODO Auto-generated method stub
        // 注册监听
        aSensorManager.registerListener(this, accelerometer,
                SensorManager.SENSOR_DELAY_NORMAL);
        mSensorManager.registerListener(this, magnetic,
                SensorManager.SENSOR_DELAY_NORMAL);
        super.onResume();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        // 解除注册
        aSensorManager.unregisterListener(this);
        mSensorManager.unregisterListener(this);
        super.onPause();
    }

    public void onSensorChanged(SensorEvent event) {
        
        // TODO Auto-generated method stub
        synchronized (this){
            float[] tmpvalues = new float[3];  
             tmpvalues[0] = event.values[0];
             tmpvalues[1] = event.values[1];
             tmpvalues[2] = event.values[2];

            if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
                accelerometerValues = tmpvalues;    
                
            }
            if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
                magneticFieldValues = tmpvalues;
                
            }
                  
            calculateOrientation();
        }
            
    }

        @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
            // TODO Auto-generated method stub

    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    private  void calculateOrientation() {
        accelerometerValuesA[0] = (float) (accelerometerValuesA[0]*0.9
                +accelerometerValues[0] *0.1);
        accelerometerValuesA[1] = (float) (accelerometerValuesA[1]*0.9
                +accelerometerValues[1] *0.1);
        accelerometerValuesA[2] = (float) (accelerometerValuesA[2]*0.9
                +accelerometerValues[2] *0.1);
        
        magneticFieldValuesA[0] = (float) (magneticFieldValuesA[0]*0.95
                +magneticFieldValues[0] *0.05);
        magneticFieldValuesA[1] = (float) (magneticFieldValuesA[1]*0.9
                +magneticFieldValues[1] *0.1);
        magneticFieldValuesA[2] = (float) (magneticFieldValuesA[2]*0.9
                +magneticFieldValues[2] *0.1);
        
        SensorManager.getRotationMatrix(R1, null, accelerometerValues, magneticFieldValues);          
        SensorManager.getOrientation(R1, Azmvalues);  
        
        // 要经过一次数据格式的转换,转换为度  
        Azmvalues[0] = Math.round(((float) Math.toDegrees(Azmvalues[0])+354)%360);
        Azmvalues[1] = Math.round(-1*(float) Math.toDegrees(Azmvalues[1]));
        Azmvalues[2] = (float) Math.toDegrees(Azmvalues[2]);
        

        Date date = new Date();  
        SimpleDateFormat from = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
        String times = from.format(date);
        text2.setText("当前时间:"+times);
        long timeN =  date.getTime();
        //计算当前儒略历timeNow
        double timeNow=(double)(timeN)/1000/3600/24+2440587.5;
        //timeNow=2457344.83898148;
        //计算平近点角时儒略历timeJ星历生成时。
        String nian =timep.substring(0,2);
        String ri = timep.substring(2);
        int ye=Integer.valueOf(nian)+2000;
        int a = (int) (ye/100);
        int b = (int)(2-a+a/4);
        double timeJ=(int)(365.25*(ye+4716))+(int)(30.6001*2)+2+b-1524.5
                +Double.valueOf(ri);
        ///    轨道根数
        double t=(timeJ-2451545)/36525;
        double hengxingshi = 280.46061837+360.98564736629*(timeJ-2451545)
                +0.000387933*t*t-t*t*t/38710000;
        double cfqjd =(360- hengxingshi%360)/180*Math.PI;//春分圈地理经度, 弧度
        double GM=398603000000000.0;
        double wxjsd=mrrxqs *2 *Math.PI/24/3600;//卫星角速度, 弧度每秒
        double banchangzhou=Math.pow(GM/wxjsd/wxjsd,0.333333333333);//半长轴
        double dqbj=6378137.0;//地球半径
        double gjddsj=timeJ-pjdj/2/Math.PI/mrrxqs;//过近地点时间
        double sjcjdd=timeNow-gjddsj;//时间差     过近地点
        double sjcxl=timeNow-timeJ;//时间差   星历
        double jddfjbhl=4.97*Math.pow((dqbj/banchangzhou),3.5)
                *(5*Math.pow(Math.cos(qingjiao),2)-1)
                /Math.pow((1-Math.pow(pianxinlv,2)),2);//近地点幅角变化率
        double xzjddfj=jddfj+sjcxl*jddfjbhl/180*Math.PI;//修正后 的近地点幅角(弧度制)
        double gjddhqs=(sjcjdd*mrrxqs)%1;//过近地点后圈数
        double sspjdj=gjddhqs*Math.PI*2;//实时平近点角,弧度
        //double pjdjE=Math.acos(
            //    (pianxinlv+Math.cos(sspjdj))/(1+pianxinlv*Math.cos(sspjdj))
                //);//弧度
        double zjdjS=2*Math.atan(
                Math.sqrt((1+pianxinlv)/(1-pianxinlv))*Math.tan(sspjdj/2)
                );//真近点角,弧度
        double wxfj=(xzjddfj+zjdjS+2*Math.PI)%(2*Math.PI) ;//卫星幅角,弧度
        double xiuzheng1=0;
        if ((wxfj>0.5*Math.PI )&(wxfj<Math.PI )) xiuzheng1=Math.PI ;
        if ((wxfj>Math.PI )&(wxfj<1.5*Math.PI )) xiuzheng1=-1*Math.PI ;
        double wxxzjdbl=Math.atan(Math.cos(qingjiao)*Math.tan(wxfj))
                +xiuzheng1;//卫星旋转经度变量
        double gdpmjdl= -9.95*Math.pow(dqbj/banchangzhou,3.5)
                *Math.cos(qingjiao)
                /Math.pow(1-pianxinlv*pianxinlv, 2)
                *Math.PI /180;//轨道平面进动率
        double wxjd=((chijing+cfqjd+wxxzjdbl
                -sjcxl*360.98563/180*Math.PI
                +sjcxl*gdpmjdl+Math.PI )%(Math.PI *2)+Math.PI *2)%(Math.PI *2)-Math.PI ;
        double wxwd=Math.asin(Math.sin(qingjiao)*Math.sin(wxfj));
        double dxj=Math.acos(Math.sin(yhwd)*Math.sin(wxwd)
                +Math.cos(yhwd)*Math.cos(wxwd)*Math.cos(yhjd-wxjd));//地心角
        double dxjlr=banchangzhou*(1-pianxinlv*Math.cos(sspjdj));        
        double Elv=Math.atan(
                (dxjlr*Math.cos(dxj)-dqbj)/dqbj/Math.sin(dxj)
                );//用户仰角,度数单位
        double jdc=(wxjd-yhjd+2*Math.PI )%(2*Math.PI);
        double wdyz=yhwd*Math.cos(jdc);
        double Azm=(Math.asin(Math.sin(jdc)
                *Math.sin((0.5*Math.PI-wxwd))/Math.sin(dxj))+2*Math.PI )%(2*Math.PI );
        if (wxwd<wdyz) {
            Azm = (Math.PI *3 -Azm)%(2*Math.PI );
        }

        text3.setText("手机方位角:"+Math.round(Azmvalues[0])+"\t仰    角:"+Math.round(Azmvalues[1])
                +"\n卫星方位角:"+Math.round(Azm*180/Math.PI)+"\t仰      角:"+Math.round(Elv*180/Math.PI)
                +"\n卫星经度:"+Math.round(wxjd*180/Math.PI)+"\t卫星纬度:"+Math.round(wxwd*180/Math.PI)
        +"\n用户经度:"+Math.round(yhjd*180/Math.PI)+"\t用户纬度:"+Math.round(yhwd*180/Math.PI)
        );
        
        
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void FinishClick(View v){
        finish();
    }
    public void SetupClick(View v){

        EditText editText1 = (EditText) findViewById(R.id.editText1);
        EditText editText2 = (EditText) findViewById(R.id.editText2);
        //EditText editText3 = (EditText) findViewById(R.id.editText3);
        yhjd= Double.parseDouble(editText1.getText().toString())/180*Math.PI;
        yhwd= Double.parseDouble(editText2.getText().toString())/180*Math.PI;
        //xingli=editText3.getText().toString();
        //text4.setText(xingli.substring(0,40));
        
        
    }
    public void UpdateClick(View v){

        String urlStr="http://lilacsat.hit.edu.cn/tle/lilacsat.txt";  
        File f=null;
        f= new File("/sdcard/lilacsat.txt");//这是对应文件名
        InputStream in = null;
        try {
           in = new BufferedInputStream(new FileInputStream(f));
        } catch (FileNotFoundException e3) {
           // TODO Auto-generated catch block
           e3.printStackTrace();
        }
        BufferedReader br = null;
        try {
        br = new BufferedReader(new InputStreamReader(in, "gb2312"));
          } catch (UnsupportedEncodingException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
        }
        String tmp;
        

        try {
           //while((tmp=br.readLine())!=null){
            tmp=br.readLine();
            
            xingli=tmp;
            //在这对tmp操作
            tmp=br.readLine();
            timep =tmp.substring(18,32);
            tmp=br.readLine();
            qingjiao=Double.valueOf(tmp.substring(8,16))/180*Math.PI;
            chijing=Double.valueOf(tmp.substring(17,25))/180*Math.PI;
            pianxinlv=Double.valueOf("0."+tmp.substring(26,33));
            jddfj=Double.valueOf(tmp.substring(34,42))/180*Math.PI;
            pjdj=Double.valueOf(tmp.substring(43,51))/180*Math.PI;
            mrrxqs=Double.valueOf(tmp.substring(52,63));
            //qingjiao = 97.4616/180*Math.PI;//轨道倾角
            //chijing= 327.0550/180*Math.PI;//升交点赤经
            //pianxinlv = 0.0018254;//轨道偏心率
            //jddfj = 53.0309/180*Math.PI;//近地点幅角
            //pjdj = 77.2607/180*Math.PI;//平近点角
            //mrrxqs = 15.11850825;//每日绕行圈数
              
            br.close();
            in.close();
            text4.setText("更新完成——"+xingli
                    +"\n星历时间:"+timep
                    +"\n轨道倾角:"+qingjiao*180/Math.PI
                    +"\n升交点赤经:"+chijing*180/Math.PI
                    +"\n轨道偏心率:"+pianxinlv
                    +"\n近地点幅角:"+jddfj*180/Math.PI
                    +"\n平近点角:"+pjdj*180/Math.PI
                    +"\n每日绕行圈数:" + mrrxqs );
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        
        
    }
    public static String ReadTxtFile(String strFilePath)
    {
        String path = strFilePath;
        String content = ""; //文件内容字符串
            //打开文件
            File file = new File(path);
            //如果path是传递过来的参数,可以做一个非目录的判断
            if (file.isDirectory())
            {
                Log.d("TestFile", "The File doesn't not exist.");
            }
            else
            {
                try {
                    InputStream instream = new FileInputStream(file);
                    if (instream != null)
                    {
                        InputStreamReader inputreader = new InputStreamReader(instream);
                        BufferedReader buffreader = new BufferedReader(inputreader);
                        String line;
                        //分行读取
                        while (( line = buffreader.readLine()) != null) {
                            content += line + "\n";
                        }                
                        instream.close();
                    }
                }
                catch (java.io.FileNotFoundException e)
                {
                    Log.d("TestFile", "The File doesn't not exist.");
                }
                catch (IOException e)
                {
                     Log.d("TestFile", e.getMessage());
                }
            }
            return content;
    }
}
离线BG9AGZ
发帖
282
只看该作者 51楼 发表于: 2015-11-23
佩服,业余无线电能说的很多人包括很多大佬和老前辈,但能做的没几个,而且代码已经开源,有了准确的指向,三单元天线,大仰角都有可能收到强信号。

[ 此帖被BG9AGZ在2015-11-23 09:48重新编辑 ]
学而不思则罔,思而不学则殆,再多的知识不表达,不表现出来,时间久了慢慢就会全部忘记,最后还是什么都不会,知识也是有保质期的。
离线刘文政
发帖
66
只看该作者 52楼 发表于: 2015-11-23
感谢楼主为卫星业余无线电做的贡献!
离线BA7KW
发帖
16335
只看该作者 53楼 发表于: 2015-12-05
恭喜恭喜!
BA7KW  张建华
BA7KW"at"163.com
离线bg1qua
发帖
321
只看该作者 54楼 发表于: 2016-01-05
离线Nemo_01
发帖
680
只看该作者 55楼 发表于: 2016-01-26
记号记号,感谢楼主辛勤劳动
BI7ISS
离线bh1uys
发帖
17
只看该作者 56楼 发表于: 2016-02-24
持续关注楼主的更新进程
Callsign:BH1UYS/ KG5NJP
RIG: X108G TG-UV2
ATT: K8DX VERTICAL
离线bg7eyd
只看该作者 57楼 发表于: 2016-02-25
能做到选星不?
离线bg7edd
发帖
1036
只看该作者 58楼 发表于: 2016-02-26
学习了。
呼号:BG7EDD
电话:13974864444
E-MAIL:13974864444@139.com
地址:湖南省长沙市天心区黄兴南路6号移动公司
邮编:410002
离线BI3OJW
发帖
195
只看该作者 59楼 发表于: 2016-09-21
回 bg7eyd 的帖子
bg7eyd:能做到选星不?[表情] (2016-02-25 12:01)

能!(补充到八个字。)