Textdatei in internen Speicher downloaden

  • Antworten:170
  • Bentwortet
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 18:08:36 via Website

Soweit bin ich noch gar nicht gekommen...

Hier wäre der Code der Klasse, ist allerdings sehr lang:

package com.example.antennarotorcontrol;

/*
* Function to process simple two line TLE into array
*/

public class TleManualImport {

public String[] processTLE(String TleData){


    /*

    initialSatValues.put("satname","ISS ZARYA");
        initialSatValues.put("linenr1","1");
        initialSatValues.put("satnr1","25544");
        initialSatValues.put("class","U");
        initialSatValues.put("launchyr","98");
        initialSatValues.put("launchnr","067");
        initialSatValues.put("launchpc","A");
        initialSatValues.put("epochyr","13");
        initialSatValues.put("epochday","122.90694444");
        initialSatValues.put("ftdmm","-0.00013045");
        initialSatValues.put("stdmm","0.0");
        initialSatValues.put("drag","-0.00022198");
        initialSatValues.put("eph","0");
        initialSatValues.put("ele","734");
        initialSatValues.put("chksum1","4");
        initialSatValues.put("linenr2","2");
        initialSatValues.put("satnr2","25544");
        initialSatValues.put("incl","51.6485");
        initialSatValues.put("ra","332.9137");
        initialSatValues.put("ecc","0.0007705");
        initialSatValues.put("peri","230.2991");
        initialSatValues.put("ma","320.0573");
        initialSatValues.put("mm","15.517388");
        initialSatValues.put("revnr","628276");
        initialSatValues.put("chksum2","7");
        initialSatValues.put("notes","ISS Notes");
        initialSatValues.put("active","1");
     */

    String sat_satname=""; // Line 750
    String sat_linenr1="1";
    String sat_satnr1=""; // Line 855
    String sat_class="U";
    String sat_launchyr="";  // Line 678
    String sat_launchnr=""; // Line 679
    String sat_launchpc=""; // Line 680
    String sat_epochyr=""; // Line 598
    String sat_epochday=""; // Line 536 + 579
    String sat_ftdmm=""; // Line 481
    String sat_stdmm=""; // Line 395
    String sat_drag=""; // Line 226
    String sat_eph="0";
    String sat_ele=""; // Line 312
    String sat_chksum1=""; // Line 313 but is never used
    String sat_linenr2="2";
    String sat_satnr2=""; // Line 856
    String sat_incl=""; // Line 937
    String sat_ra=""; // Line 1017
    String sat_ecc=""; // Line 1053
    String sat_peri=""; // Line 1135
    String sat_ma=""; // Line 1219
    String sat_mm=""; // Line 1301
    String sat_revnr=""; // Line 1402
    String sat_chksum2=""; // Line  but is never used
    String sat_notes="Notes";
    String sat_active="1";


    // TleData = "DNEPR OBJECT AE\n" +
    //          "1 39444U 13066AE 13356.63932284 .00003516 00000-0 48553-3 0 179\n" +
    //          "2 39444 97.7977 68.2567 0064856 95.8356 265.0220 14.77291204 3390\n" +

    String clipboard_raw = TleData;

    // replace all instances of \n and \r with a single space character
    clipboard_raw = clipboard_raw.replaceAll("\n", " ");
    clipboard_raw = clipboard_raw.replaceAll("\r", " ");

    // add one final space and \n to indicate the end of the text
    clipboard_raw = clipboard_raw + " \n";

    // find the position of the first non-space character
    Integer readpos=0;
    String readchar="";
    Integer lastpos = clipboard_raw.length();
    Integer foundbegin=0;
    Integer errors=0;
    Integer startpos=0;
    Integer tle_lines = 0;
    String field_value="";
    Integer field_len;
    Integer space_counter;
    Integer build_tle_beginpos;
    Integer build_tle_endpos;

    String good_tle=""; // output tle that's build up gradually and correct
    String build_tle=""; // building a single tle from read arguments until it's complete
    Integer marker1,marker2;


    if (lastpos < (10+65+65))
    {
        // not enough characters for a TLE set

    } else {
        // perhaps one TLE set

        while ((readpos < lastpos) && (foundbegin==0))
        {

            // read char
            readchar=clipboard_raw.substring(readpos,readpos+1);  // find

            // skip until we don't see spaces anymore
            if (!(readchar.equals(" ")))
            {
                // character is not a space, mark this as the begin
                foundbegin = 1;
                startpos=readpos;
                break;
            }
            readpos++;

        }


        // recreate TLE based on fixed format of 24,69,69 and other known positions
        if (foundbegin == 1)
        {
            // run through text, inserting fake newline characters as we go
            // startpos still holds the position of the starting character
            readpos=startpos;
            errors=0;

            while (readpos < lastpos)
            {

                tle_lines++;

                // so we have a bunch of characters that have been stripped from line breaks
                // and multiple consecutive spaces may have been trimmed to just one.
                // here's how we break it all up and reconstruct a correctly formatted TLE

                // first we try to find the end of the BSTAR drag term and the Ephemeris type.
                //
                // what we're looking for is:  [unk-nr][minus][unk-nr][space][zero][space]
                // where the unk-nr are single-digit numeric values.
                //

                // Step 1a - see if we can find the position of '[space][zero][space]'

                readpos=readpos + 25; // skip over the description

                marker1=clipboard_raw.indexOf(" 0 ",readpos);

                if (marker1 == -1)
                {
                    // sequence not found, this is not TLE data, abort
                    errors++;
                    break;
                }

                // keep track of how far we've searched towards the end
                build_tle_endpos=marker1 + 2; // // pos of the space right after the ephemeris (64)

                // marker found, let's see if two positions earlier we see a '-' (minus)

                if (!(clipboard_raw.substring(marker1-2,marker1-1).equals("-")))
                {
                    // //Log.e("marker","BSTAR - not found");
                    errors++;
                    break;

                }

                // create the BSTAR field
                field_len=8;

                // go back to the beginning of the field, prefixed by a space character

                marker2=clipboard_raw.lastIndexOf(" ",marker1-2);
                if (marker2 == -1)
                {
                    // sequence not found, this is not TLE data, abort
                    errors++;
                    break;
                } else {
                    if (marker2 + 1 < marker1 - field_len)
                    {
                        // too far away, doesn't look like a tle
                        errors++;
                        break;
                    }
                }

                // keep track of how far we've searched towards the beginning
                build_tle_beginpos=marker2; // pos of the space in front of BSTAR value (not field)

                // copy the field from the raw input string
                field_value=clipboard_raw.substring(marker2+1,marker1);

                // add leading spaces if required
                space_counter=field_len-field_value.length();
                while (space_counter>0)
                {
                    field_value = " " + field_value;
                    space_counter--;
                }
                // Enter the first values (BSTAR + Ephemeris) into the build_tle string
                build_tle=field_value + " 0 ";
                sat_drag = field_value;



                //Log.e("field","BSTAR = [" + field_value + "]");


                // build_tle_beginpos is now at the space in front of the BSTAR field (53)

                // Step 2 - find the element set number and modulo
                field_len=5;

                // search for the first value that is non-space after build_tle_endpos
                readpos = build_tle_endpos;
                while (readpos < build_tle_endpos + field_len)
                {
                    // read the next character
                    if (clipboard_raw.substring(readpos,readpos+1).equals(" "))
                    {
                        // not interested in spaces
                        readpos++;

                        if (readpos >= build_tle_endpos + field_len)
                        {
                            // gone too far, not a TLE data set, abort
                            errors++;
                            break;
                        }
                    } else {
                        // found something
                        marker1 = readpos; // marks the beginning of these two fields
                        break;
                    }

                }


                if (errors != 0)
                {
                    // stop processing if this doesn't look like valid TLE data
                    readpos = lastpos;
                    break;
                }

                // determine the end of the set number and modulo fields

                // find the next space, start searching after marker1
                marker2 = clipboard_raw.indexOf(" ",marker1+1);
                if (marker2 == -1)
                {
                    // not found, abort
                    errors++;
                    break;
                } else {
                    if (marker2 > marker1 + field_len + 2)
                    {
                        // gone too far, not TLE, abort
                        errors++;
                        break;
                    }

                }

                // keep track of how far we've searched toward the end
                build_tle_endpos=marker2; // pos of the space after the modulo character on line 1

                // copy the field from the raw input string
                field_value=clipboard_raw.substring(marker1,marker2);


                // add leading spaces if required
                space_counter=field_len-field_value.length();
                while (space_counter>0)
                {
                    field_value = " " + field_value;
                    space_counter--;

                }



                //Log.e("field","SetNr + Mod = [" + field_value + "]");

                // append these fields (RevNr and Modulo line1) + CRLF to the build_tle string
                build_tle=build_tle + field_value + "#";

                sat_ele = field_value.substring(0, field_value.length()-1); // First 3 characters of string is element set number
                sat_chksum1 = field_value.substring(field_value.length()-1); // Last number is modulo checksum

                // Step 3 - find the 2nd time derivative of mean motion (before BSTAR drag term)
                field_len=8;

                // search for a space character before tle_build_beginpos
                // build_tle_beginpos is now at the space in front of the BSTAR field (53)


                // find the end of the field (where the last number can be found)
                // search for the first value that is non-space before bstar drag
                readpos = build_tle_beginpos;
                while (readpos > build_tle_beginpos - field_len)
                {
                    // read the previous character
                    if (clipboard_raw.substring(readpos,readpos+1).equals(" "))
                    {
                        // not interested in spaces
                        readpos--;

                        if (readpos <= build_tle_beginpos - field_len)
                        {
                            // gone too far, not a TLE data set, abort
                            errors++;
                            break;
                        }
                    } else {
                        // found something
                        marker2 = readpos; // marks the end of the field
                        break;
                    }

                }


                if (errors != 0)
                {
                    // stop processing if this doesn't look like valid TLE data
                    readpos = lastpos;
                    break;
                }


                // go back to the beginning of the field, prefixed by a space character
                marker1=clipboard_raw.lastIndexOf(" ",marker2-2);
                if (marker1 == -1)
                {
                    // sequence not found, this is not TLE data, abort
                    errors++;
                    break;
                } else {
                    if (marker1 + 1 < marker2 - (field_len + 1))
                    {
                        // too far away, doesn't look like a tle
                        errors++;
                        break;
                    }
                }


                // copy the field from the raw input string
                field_value=clipboard_raw.substring(marker1+1,marker2+1);
                //Log.e("field","2nd tdmm = [" + field_value + "]");

                // keep track of how far we've searched towards the beginning
                build_tle_beginpos=marker1; // pos of the space in front of value (not field)


                // add leading spaces if required
                space_counter=field_len-field_value.length();
                while (space_counter>0)
                {
                    field_value = " " + field_value;
                    space_counter--;

                }

                // build_tle_beginpos is now at the space in front of the 2tddmm field (44)

                // prepend this field (2nd tdmm) to the build_tle string
                build_tle = field_value + " " + build_tle;

                sat_stdmm = field_value;






                // Step 4 - find the 1st tdmm (before 2nd tdmm)
                field_len=10;

                // search for a space character before tle_build_beginpos
                // build_tle_beginpos = pos of the space in front of 2nd tdmm value (not field)


                // find the end of the field (where the last number can be found)
                // search for the first value that is non-space before 2nd tdmm
                readpos = build_tle_beginpos;
                while (readpos > build_tle_beginpos - field_len)
                {
                    // read the previous character
                    if (clipboard_raw.substring(readpos,readpos+1).equals(" "))
                    {

                        // not interested in spaces
                        readpos--;

                        if (readpos <= build_tle_beginpos - field_len)
                        {
                            // gone too far, not a TLE data set, abort
                            errors++;
                            break;
                        }
                    } else {
                        // found something
                        marker2 = readpos; // marks the end of the field
                        break;
                    }

                }


                if (errors != 0)
                {
                    // stop processing if this doesn't look like valid TLE data
                    readpos = lastpos;
                    break;
                }


                // go back to the beginning of the field, prefixed by a space character
                marker1=clipboard_raw.lastIndexOf(" ",marker2-2);
                if (marker1 == -1)
                {
                    // sequence not found, this is not TLE data, abort
                    errors++;
                    break;
                } else {
                    if (marker1 + 1 < marker2 - field_len)
                    {
                        // too far away, doesn't look like a tle
                        errors++;
                        break;
                    }
                }

                // keep track of how far we've searched towards the beginning
                build_tle_beginpos=marker1; // pos of the space in front of value (not field)

                // copy the field from the raw input string
                field_value=clipboard_raw.substring(marker1+1,marker2+1);


                // add leading spaces if required
                space_counter=field_len-field_value.length();
                while (space_counter>0)
                {
                    field_value = " " + field_value;

                    space_counter--;
                }

                //Log.e("field","1st tdmm = [" + field_value + "]");

                // prepend this field (1st tdmm) to the build_tle string
                build_tle = field_value + " " + build_tle;

                sat_ftdmm = field_value;








                // Step 5a - find the epoch day fraction (before 1st tdmm)
                field_len=8; // only the decimals behind the dot (the fraction)

                // search for a dot character before tle_build_beginpos
                // build_tle_beginpos = pos of the space in front of value (not field)
                marker2=build_tle_beginpos;


                // go back to the beginning of the field, prefixed by a space character
                marker1=clipboard_raw.lastIndexOf(".",marker2-2);
                if (marker1 == -1)
                {
                    // sequence not found, this is not TLE data, abort
                    errors++;
                    break;
                } else {

                    if (marker1 + 2 < marker2 - field_len)
                    {
                        // too far away, doesn't look like a tle
                        errors++;
                        break;
                    }
                }

                // keep track of how far we've searched towards the beginning
                build_tle_beginpos=marker1; // pos of the dot in front of value (not field)

                // copy the field from the raw input string
                field_value=clipboard_raw.substring(marker1,marker1+field_len+1);

                //Log.e("field","day frac = [" + field_value + "]");

                // add trailing spaces if required
                //space_counter=field_len-field_value.length();
                //while (space_counter>0)
                //{
                //  field_value = field_value + " ";
                //  space_counter--;
                //}



                // prepend this field (day fraction) to the build_tle string
                build_tle = field_value + " " + build_tle;

                sat_epochday = field_value;






                // Step 5b - find the epoch day (integers)

                marker1=build_tle_beginpos;
                marker2=build_tle_beginpos;

                // check if the SECOND position before the dot is a space (day < 10)
                if (clipboard_raw.substring(marker1-1,marker1).equals(" "))
                {
                    // day integer is 1-9    YY  D.FFFFFFFF
                    marker1=marker1-1;
                    field_value="  ";
                } else {
                    // day >= 10
                    if (clipboard_raw.substring(marker1-2,marker1-1).equals(" "))
                    {
                        // day integer is 10-99    YY DD.FFFFFFFF
                        marker1=marker1-2;
                        field_value=" ";
                    } else {
                        // day integer is 100-365    YYDDD.FFFFFFFF
                        marker1=marker1-3;
                        field_value="";
                    }
                }

                // keep track of how far we've searched towards the beginning
                build_tle_beginpos=marker1; // pos of the first (of three, with padding) characters of the epoch day


                // copy the field from the raw input string
                field_value = field_value + clipboard_raw.substring(marker1,marker2);
                //Log.e("field","day int = [" + field_value + "]");

                // prepend this field (day) to the build_tle string
                build_tle = field_value + build_tle;

                sat_epochday = field_value + sat_epochday;



                // Step 5c - add the epoch year (integers)

                marker1=build_tle_beginpos-2;
                marker2=build_tle_beginpos;

                // keep track of how far we've searched towards the beginning
                build_tle_beginpos=marker1-1; // pos of the first (of two) characters of the epoch year

                // copy the field from the raw input string
                field_value = clipboard_raw.substring(marker1,marker2);
                //Log.e("field","ep year = [" + field_value + "]");

                // prepend this field (day) to the build_tle string
                build_tle = " " + field_value + build_tle;

                sat_epochyr = field_value;





                // Step 6 - find Launch Year-Nr-Piece (before epoch year)
                field_len=8;

                // build_tle_beginpos = pos of the space in front of epoch year value

                // find the end of the field (where the last number can be found)
                // search for the first value that is non-space before epoch year
                readpos = build_tle_beginpos;
                while (readpos > build_tle_beginpos - field_len)
                {
                    // read the previous character
                    if (clipboard_raw.substring(readpos,readpos+1).equals(" "))
                    {

                        // not interested in spaces
                        readpos--;

                        if (readpos <= build_tle_beginpos - field_len)
                        {
                            // gone too far, not a TLE data set, abort
                            errors++;
                            break;
                        }
                    } else {
                        // found something
                        marker2 = readpos; // marks the end of the field
                        break;
                    }

                }


                if (errors != 0)
                {
                    // stop processing if this doesn't look like valid TLE data
                    readpos = lastpos;
                    break;
                }


                // go back to the beginning of the field, prefixed by a space character
                marker1=clipboard_raw.lastIndexOf(" ",marker2-4);
                if (marker1 == -1)
                {
                    // sequence not found, this is not TLE data, abort
                    errors++;
                    break;
                } else {
                    if (marker1 + 1 < marker2 - field_len)
                    {
                        // too far away, doesn't look like a tle
                        errors++;
                        break;
                    }
                }

                // keep track of how far we've searched towards the beginning
                build_tle_beginpos=marker1; // pos of the space in front of value (not field)

                // copy the field from the raw input string
                field_value=clipboard_raw.substring(marker1+1,marker2+1);


                // add trailing spaces if required
                space_counter=field_len-field_value.length();
                while (space_counter>0)
                {
                    field_value = field_value + " ";
                    space_counter--;
                }
                //Log.e("field","launch = [" + field_value + "]");

                // prepend this field (launch) to the build_tle string
                build_tle = field_value + build_tle;
                sat_launchyr = field_value.substring(0, field_value.length()-6); // first 2 numbers
                sat_launchnr = field_value.substring(2, field_value.length()-3); // second 3 numbers
                sat_launchpc = field_value.substring(field_value.length()-3); // last 3 characters

                // Step 7 - add line number + Satellite Norad Number (before launch year-nr-piece)
                field_len=6;

                // search for a space character before tle_build_beginpos
                // build_tle_beginpos = pos of the space in front of epoch year value
                marker2=build_tle_beginpos;

                // go back to the beginning of the field, prefixed by a space character
                marker1=clipboard_raw.lastIndexOf(" ",marker2-2);
                if (marker1 == -1)
                {
                    // sequence not found, this is not TLE data, abort
                    errors++;
                    break;
                } else {
                    if (marker1 + 1 < marker2 - field_len)
                    {
                        // too far away, doesn't look like a tle
                        errors++;
                        break;
                    }
                }



                // copy the field from the raw input string
                field_value=clipboard_raw.substring(marker1,marker2);


                // add trailing spaces if required
                space_counter=field_len-field_value.length();
                while (space_counter>0)
                {
                    field_value = field_value + " ";
                    space_counter--;
                }

                // keep track of how far we've searched towards the beginning
                build_tle_beginpos=marker1-1; // pos of the number '1' at the beginning of line 1

                //Log.e("field","sat id = [" + field_value + "]");

                // prepend this field (launch-nr) to the build_tle string
                build_tle = "1" + field_value + " " + build_tle;
                sat_launchnr = "1" + field_value;


                // Step 8 - add the satellite description (before the '1' line number)
                field_len=24;

                // read everything from 'startpos' onwards

                // copy the field from the raw input string
                field_value = clipboard_raw.substring(startpos,build_tle_beginpos-1);

                // add trailing spaces if required
                space_counter=field_len-field_value.length();
                while (space_counter>0)
                {
                    field_value = field_value + " ";
                    space_counter--;
                }

                //Log.e("field","sat desc = " + field_value);


                // prepend this field (sat description) to the build_tle string
                build_tle = field_value + "#" + build_tle;
                sat_satname = field_value;


                // that's it for the description line and the first TLE line
                // let's add the fields from the last TLE data line

                // build_tle_endpos now contains the position of the very last character of
                // TLE data line 1 (probably a space)

                // Step 9 - add the '2' line number

                // search for the first value that is non-space after build_tle_endpos,
                // this should only be 1 or 2 positions further
                readpos = build_tle_endpos;
                while (readpos < build_tle_endpos + 3)
                {
                    // read the next character
                    if (clipboard_raw.substring(readpos,readpos+1).equals(" "))
                    {
                        // not interested in spaces
                        readpos++;

                        if (readpos >= build_tle_endpos + 3)
                        {
                            // gone too far, not a TLE data set, abort
                            errors++;
                            break;
                        }
                    } else {
                        // found something

                        // check if character is a '2'
                        if (clipboard_raw.substring(readpos,readpos+1).equals("2"))
                        {
                            // looking good

                            // confirm that the next value is a space
                            if (clipboard_raw.substring(readpos+1,readpos+2).equals(" "))
                            {
                                // found '2' surrounded by spaces, this is correct
                                field_value="2";
                                marker1 = readpos + 1; // marks the position of the space after the '2' number
                                break;
                            } else {
                                // doesn't look like TLE data, abort
                                errors++;
                                break;
                            }
                        }
                    }

                }


                if (errors != 0)
                {
                    // stop processing if this doesn't look like valid TLE data
                    readpos = lastpos;
                    break;
                }

                // keep track of how far we've searched towards the end
                build_tle_endpos=marker1; // pos of the space after the line number on data line 2

                // prepend this field (line nr) to the build_tle string
                build_tle = build_tle + field_value;


                // Step 10 - add the satellite norad id (after '2' on line 2)
                field_len=5;

                // search for a space character after tle_build_endpos
                // build_tle_endpos = pos of the space right after '2' on line 2
                marker1=build_tle_endpos;


                // find the next space character
                marker2=clipboard_raw.indexOf(" ",marker1+1);


                if (marker2 == -1)
                {
                    // sequence not found, this is not TLE data, abort
                    errors++;
                    break;
                } else {

                    if (marker2 + 1 < marker1 - field_len)
                    {
                        // too far away, doesn't look like a tle
                        errors++;
                        break;
                    }
                }

                // keep track of how far we've searched towards the end
                build_tle_endpos=marker2; // pos of the space

                // copy the field from the raw input string
                field_value=clipboard_raw.substring(marker1+1,marker2);


                //Log.e("field","sat id2 = [" + field_value +"]");

                // append this field (norad sat id) to the build_tle string
                build_tle = build_tle + " " + field_value;
                sat_satnr1 = field_value;
                sat_satnr2 = field_value;

                // Step 11 - add the Inclination (after norad sat id on line 2)
                // can have up to two leading spaces
                // ends at fixed position
                field_len=8;

                field_value="";
                // search for the first value that is non-space after build_tle_endpos,
                // this should only be 1 or 2 positions further
                readpos = build_tle_endpos;
                while (readpos < build_tle_endpos + field_len)
                {
                    // read the next character
                    if (clipboard_raw.substring(readpos,readpos+1).equals(" "))
                    {
                        // detected a space character

                        readpos++;

                        if (readpos >= build_tle_endpos + field_len)
                        {
                            // gone too far, not a TLE data set, abort
                            errors++;
                            break;
                        }
                    } else {
                        // found something

                        marker1 = readpos; // marks the beginning of this field
                        break;
                    }

                }

                if (errors != 0)
                {
                    // stop processing if this doesn't look like valid TLE data
                    readpos = lastpos;
                    break;
                }


                // determine the end of inclination field

                // find the next space, start searching after marker1
                marker2 = clipboard_raw.indexOf(" ",marker1+1);
                if (marker2 == -1)
                {
                    // not found, abort
                    errors++;
                    break;
                } else {
                    if (marker2 > marker1 + field_len + 2)
                    {
                        // gone too far, not TLE, abort
                        errors++;
                        break;
                    }

                }

                // include leading spaces
                readpos=marker2-marker1; // re-use the readpos variable for this calculation
                while (readpos < field_len)
                {
                    field_value=field_value+" ";
                    readpos++;
                }


                // keep track of how far we've searched toward the end
                build_tle_endpos=marker2; // pos of the space after the inclination

                // copy the field from the raw input string
                field_value=field_value+clipboard_raw.substring(marker1,marker2);
                //Log.e("field","inclination = [" + field_value + "]");

                // append this field (inclination) to the build_tle string
                build_tle = build_tle + " " + field_value;
                sat_incl = field_value;

                // Step 12 - add the RAAN (after inclination)
                // can have up to two leading spaces
                // ends at fixed position
                field_len=8;

                field_value="";
                // search for the first value that is non-space after build_tle_endpos,
                // this should only be 1 or 2 positions further
                readpos = build_tle_endpos;
                while (readpos < build_tle_endpos + field_len)
                {
                    // read the next character
                    if (clipboard_raw.substring(readpos,readpos+1).equals(" "))
                    {
                        // detected a space character
                        readpos++;

                        if (readpos >= build_tle_endpos + field_len)
                        {
                            // gone too far, not a TLE data set, abort
                            errors++;
                            break;
                        }
                    } else {
                        // found something

                        marker1 = readpos; // marks the beginning of this field
                        break;
                    }

                }

                if (errors != 0)
                {
                    // stop processing if this doesn't look like valid TLE data
                    readpos = lastpos;
                    break;
                }


                // determine the end of RAAN field

                // find the next space, start searching after marker1
                marker2 = clipboard_raw.indexOf(" ",marker1+1);
                if (marker2 == -1)
                {
                    // not found, abort
                    errors++;
                    break;
                } else {
                    if (marker2 > marker1 + field_len + 2)
                    {
                        // gone too far, not TLE, abort
                        errors++;
                        break;
                    }

                }

                // include leading spaces
                readpos=marker2-marker1; // re-use the readpos variable for this calculation

                while (readpos < field_len)
                {
                    field_value=field_value+" ";
                    readpos++;

                }

                // keep track of how far we've searched toward the end
                build_tle_endpos=marker2; // pos of the space after the inclination

                // copy the field from the raw input string
                field_value=field_value+clipboard_raw.substring(marker1,marker2);
                //Log.e("field","RAAN = [" + field_value + "]");

                // append this field (RAAN) to the build_tle string
                build_tle = build_tle + " " + field_value;
                sat_ra = field_value;


                // Step 13 - eccentricity
                field_len=7;

                // search for a space character after tle_build_endpos
                marker1=build_tle_endpos;

                // find the next space character
                marker2=clipboard_raw.indexOf(" ",marker1+1);

                if (marker2 == -1)
                {
                    // sequence not found, this is not TLE data, abort
                    errors++;
                    break;
                } else {

                    if (marker2 + 1 < marker1 - field_len)
                    {
                        // too far away, doesn't look like a tle
                        errors++;
                        break;
                    }
                }

                // keep track of how far we've searched towards the end
                build_tle_endpos=marker2; // pos of the space

                // copy the field from the raw input string
                field_value=clipboard_raw.substring(marker1+1,marker2);

                //Log.e("field","eccentricity = [" + field_value + "]");

                // append this field (eccentricity) to the build_tle string
                build_tle = build_tle + " " + field_value;

                sat_ecc = field_value;

                // step 14 - argument of perigee

                // can have up to two leading spaces
                // ends at fixed position
                field_len=8;

                field_value="";
                // search for the first value that is non-space after build_tle_endpos,
                // this should only be 1 or 2 positions further
                readpos = build_tle_endpos;
                while (readpos < build_tle_endpos + field_len)
                {
                    // read the next character
                    if (clipboard_raw.substring(readpos,readpos+1).equals(" "))
                    {
                        // detected a space character

                        readpos++;

                        if (readpos >= build_tle_endpos + field_len)
                        {
                            // gone too far, not a TLE data set, abort
                            errors++;
                            break;
                        }
                    } else {
                        // found something

                        marker1 = readpos; // marks the beginning of this field
                        break;
                    }

                }

                if (errors != 0)
                {
                    // stop processing if this doesn't look like valid TLE data
                    readpos = lastpos;
                    break;
                }


                // determine the end of argument of perigee field

                // find the next space, start searching after marker1
                marker2 = clipboard_raw.indexOf(" ",marker1+1);
                if (marker2 == -1)
                {
                    // not found, abort
                    errors++;
                    break;
                } else {
                    if (marker2 > marker1 + field_len + 2)
                    {
                        // gone too far, not TLE, abort
                        errors++;
                        break;
                    }

                }

                // include leading spaces
                readpos=marker2-marker1; // re-use the readpos variable for this calculation

                while (readpos < field_len)
                {
                    field_value=field_value+" ";
                    readpos++;
                }

                // keep track of how far we've searched toward the end
                build_tle_endpos=marker2; // pos of the space after the argument of perigee

                // copy the field from the raw input string
                field_value=field_value+clipboard_raw.substring(marker1,marker2);
                //Log.e("field","arg p = [" + field_value + "]");

                // append this field (arg p) to the build_tle string
                build_tle = build_tle + " " + field_value;

                sat_peri = field_value;



                // step 15 - mean anomaly

                // can have up to two leading spaces
                // ends at fixed position
                field_len=8;

                field_value="";
                // search for the first value that is non-space after build_tle_endpos,
                // this should only be 1 or 2 positions further
                readpos = build_tle_endpos;
                while (readpos < build_tle_endpos + field_len)
                {
                    // read the next character
                    if (clipboard_raw.substring(readpos,readpos+1).equals(" "))
                    {
                        // detected a space character

                        readpos++;

                        if (readpos >= build_tle_endpos + field_len)
                        {
                            // gone too far, not a TLE data set, abort
                            errors++;
                            break;
                        }
                    } else {
                        // found something

                        marker1 = readpos; // marks the beginning of this field
                        break;
                    }

                }

                if (errors != 0)
                {
                    // stop processing if this doesn't look like valid TLE data
                    readpos = lastpos;
                    break;
                }


                // determine the end of argument of perigee field

                // find the next space, start searching after marker1
                marker2 = clipboard_raw.indexOf(" ",marker1+1);
                if (marker2 == -1)
                {
                    // not found, abort
                    errors++;
                    break;
                } else {
                    if (marker2 > marker1 + field_len + 2)
                    {
                        // gone too far, not TLE, abort
                        errors++;
                        break;
                    }

                }

                // include leading spaces
                readpos=marker2-marker1; // re-use the readpos variable for this calculation

                while (readpos < field_len)
                {
                    field_value=field_value+" ";
                    readpos++;
                }

                // keep track of how far we've searched toward the end
                build_tle_endpos=marker2; // pos of the space after the mean anomaly

                // copy the field from the raw input string
                field_value=field_value+clipboard_raw.substring(marker1,marker2);
                //Log.e("field","mean an = [" + field_value + "]");

                // append this field (mean anomaly) to the build_tle string
                build_tle = build_tle + " " + field_value;

                sat_ma = field_value;


                // step 16 - mean motion

                // can have up to two leading spaces
                // ends at fixed position
                field_len=11;

                field_value="";

                //             53         64   69
                //           52|          |    |
                //     ma     |mmmmmmmmmmmrrrrrM
                //     80.5063 13.99471632525847\n"

                // build_tle_endpos  =  pos of the space after the mean anomaly

                marker1 = build_tle_endpos;
                marker2 = clipboard_raw.indexOf(".",marker1);
                if (marker2 == -1)
                {
                    // not found, abort
                    errors++;
                    break;
                } else {
                    if (marker2 > marker1 + field_len + 2)
                    {
                        // gone too far, not TLE, abort
                        errors++;
                        break;
                    }
                }
                // search backwards to find out how many integers there are in front of the dot


                // marker2 is where the dot is
                marker1=marker2;
                marker1--;


                if (clipboard_raw.substring(marker1,marker1+1).equals(" "))
                {
                    // first character before the dot is a space, integer is < 0
                    field_value="   ";

                } else {

                    marker1--;
                    if (clipboard_raw.substring(marker1,marker1+1).equals(" "))
                    {
                        // second character before the dot is a space, integer is < 10
                        field_value=" ";

                    } else {
                        marker1--;
                        if (clipboard_raw.substring(marker1,marker1+1).equals(" "))
                        {
                            // third character before the dot is a space, integer is between 10 - 99
                            field_value="";

                        } else {
                            // no way we can have three integer characters in front of the dot, invalide TLE, abort
                            errors++;
                            break;
                        }
                    }
                }

                // now that we know how many integers we have in front of the dot we can reconstruct the field

                // copy the field from the raw input string
                field_value=field_value+clipboard_raw.substring(marker1+1,(marker2 + field_len - 2));
                //Log.e("field","mean motion = [" + field_value + "]");

                // keep track of how far we've searched toward the end
                build_tle_endpos=marker2 + field_len - 3; // pos of the last character of mean motion


                // append this field (mean motion) to the build_tle string
                build_tle = build_tle + " " + field_value;

                sat_mm = field_value;


                // Step 17 - revnumber and modulo
                field_len=6;

                field_value="";
                marker1 = build_tle_endpos+1; // marker1 is the first value of revnr (can be space)

                // see if there's a space between mean motion and revnr

                if (clipboard_raw.substring(marker1,marker1+1).equals(" "))
                {
                    // space found at marker1, revnr is not 5 characters

                    // add leading spaces
                    field_value="";
                    // search for the first value that is non-space after marker1,
                    // this should only be 1-4 positions further
                    readpos = marker1;
                    while (readpos < build_tle_endpos + field_len)
                    {
                        // read the next character
                        if (clipboard_raw.substring(readpos,readpos+1).equals(" "))
                        {
                            // detected a space character

                            readpos++;

                            if (readpos >= build_tle_endpos + field_len)
                            {
                                // gone too far, not a TLE data set, abort
                                errors++;
                                break;
                            }
                        } else {
                            // found something

                            marker1 = readpos; // marks the beginning of this field
                            break;
                        }

                    }

                    if (errors != 0)
                    {
                        // stop processing if this doesn't look like valid TLE data
                        readpos = lastpos;
                        break;
                    }


                } else {
                    // revnr starts immediatly at marker1
                    // find the next space (as this will indicate the end of the line)
                    // marker1 is the position of the first value of revnr
                }

                // find the next space, start searching after marker1
                marker2 = clipboard_raw.indexOf(" ",marker1);
                if (marker2 == -1)
                {
                    // not found, abort
                    errors++;
                    break;
                } else {
                    if (marker2 > marker1 + field_len + 2)
                    {
                        // gone too far, not TLE, abort
                        errors++;
                        break;
                    }
                }


                // include leading spaces
                readpos=marker2-marker1; // re-use the readpos variable for this calculation

                while (readpos < field_len)
                {
                    field_value=field_value+" ";
                    readpos++;
                }


                // copy the field from the raw input string
                field_value=field_value+clipboard_raw.substring(marker1,marker2);


                //Log.e("field","revnr and modulo = [" + field_value + "]");


                // keep track of how far we've searched toward the end
                build_tle_endpos=marker2; // pos of the space after the modulo on line 2


                // append this field (revnr) to the build_tle string
                build_tle = build_tle + field_value;

                sat_revnr = field_value;



                // reached the end of reading one full TLE data set

                build_tle=build_tle+"#";

                //Log.e("total-1",""+build_tle.substring(0,24+1));
                //Log.e("total-2",""+build_tle.substring(25,25+69+1));
                //Log.e("total-3",""+build_tle.substring(25+1+69,25+1+69+69+1));


                good_tle = good_tle + build_tle;  // append to the good TLE set


                if ((build_tle_endpos + (10+65+65)) <  lastpos)
                {
                    // enough characters for another run
                    startpos=build_tle_endpos+1; // point to the first character of the description
                    readpos=startpos;
                } else {
                    // not enough remaining characters for there to be a valid TLE present

                    break;
                }

            }


        }

        if (errors==0)
        {

            // Intent TM = new Intent(TleManualImport.this, TleUpdate.class);
            // TM.putExtra("target","clipboard");
            // TM.putExtra("clipboard",good_tle);
            // startActivityForResult(TM, 0);
            // return good_tle;

        }
    }

    String[] values = {sat_satname,sat_linenr1,sat_satnr1,sat_class,sat_launchyr,sat_launchnr,sat_launchpc,sat_epochyr,sat_epochday,sat_ftdmm,sat_stdmm,sat_drag,
            sat_eph,sat_ele,sat_chksum1,sat_linenr2,sat_satnr2,sat_incl,sat_ra,sat_ecc,sat_peri,sat_ma,sat_mm,sat_revnr,sat_chksum2,sat_notes,sat_active};

    // String[] values = good_tle.split(" ");

    return values;

}

}

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 18:15:49 via Website

habe es mir nicht angsehen .
Warum wider alles in einer neuen Klasse?

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 18:18:32 via Website

Ich finde es übersichtlicher. Macht man das üblicherweise anders? Wie gesagt, diesen Code habe ich bekommen und den wollte ich implementieren.

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 18:38:09 via Website

OK deine sache nur hast du dann wider den geichen overhead wie bei der anderen Klasse.

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 18:41:10 via Website

Naja du magst recht haben. Aber hier wird nur einmal ein String übergeben und dann wieder zurückgegeben.
Trotzdem funktioniert es noch immer nicht... Das ist ja zum Verzweifeln :-(

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 18:48:07 via Website

Wo wie rufst du denn die Klasse und Methode auf?
Und was genau geht nicht?

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 18:51:55 via Website

ok habe es gesehen in deiner MainActivity.
Frage ist den in dem string was drin?

geht denn überhaupt dein lesen jetzt?

— geändert am 16.04.2020, 18:57:38

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 18:57:15 via Website

Die werden in der onCreate aufgerufen. Das App stürzt nach wie vor ab. Wenn ich die drei Zeilen in der MainActivity wieder auskommentiere und den String tleElement manuell mit einem Wert versehe und dann an die Methode processTle übergebe, so stürzt nichts ab.

Code in der onCreate der MainActivity:
TleManualImport tleFunction = new TleManualImport();
//ReadTxtFile readTxtFile = new ReadTxtFile();
//readTxtFile.readFile();
//tleFunction.processTLE(readTxtFile.threeLineElement);
String tleElement = "SAUDISAT 1C (SO-50)\n" +
"1 27607U 02058C 20106.54414103 .00000007 00000-0 21737-4 0 9999\n" +
"2 27607 64.5556 206.7081 0055918 193.7297 166.2289 14.75625318931442\n";
String[] SatData = tleFunction.processTLE(tleElement);

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 19:01:00 via Website

deine lese methode ist immer noch falsch ohne den context an die Klasse zu übergeben wirst du nie etwas lesen.

— geändert am 16.04.2020, 19:06:17

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 19:09:33 via Website

Hab grad nochmal meine Test-app nur mit Download und Lesen getestet. Klar, hier ist der gesamte Code in der MainActivity. Hier wird die Textdatei allerdings in /Downloads Ordner gespeichert. Kann es vielleicht damit was auf sich haben? Ich meine, dass der Aufruf

File textfile = new File(context.getExternalFilesDir(null).getAbsolutePath(), "amateur.txt");

einfach einen falschen Pfad zurückgibt? Wäre ja auch irgendwie naheliegend mit der null object reference

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 19:13:09 via Website

du hast keinen Context.
dann müsste es in etwa so ausehen bein objekt erstellen.
ReadTxtFile readTxtFile = new ReadTxtFile(this);

schaue dir meine code beispiele an.

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 19:18:10 via Website

zeige deine lese Klasse nochmal so wie sie jetzt ist.

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 19:23:12 via Website

Bitteschön.
public class ReadTxtFile {

private Context context;

private String TLE1;
private String TLE2;
private String TLE3;
String threeLineElement;

private void ReadTxtFile(Context c){

    this.context = c;
    this.TLE1 = TLE1;
    this.TLE2 = TLE2;
    this.TLE3 = TLE3;
    this.threeLineElement = threeLineElement;
}

/***
 *
 * GETTER
 */

private String getTLE1() {return TLE1;}
private String getTLE2() {return TLE2;}
private String getTLE3() {return TLE3;}
private String getThreeLineElement() {return threeLineElement;}

// READ TLE-SAT DATA FILE
public void readFile() throws IOException {
    if (isExternalStorageReadable()) {
        StringBuilder sb = new StringBuilder(69);
        File textfile = new File(context.getExternalFilesDir(null).getAbsolutePath(), "amateur.txt");

        if (textfile.exists()) {

            FileInputStream fis = new FileInputStream(textfile);

            if (fis != null) {
                InputStreamReader isr = new InputStreamReader(fis);
                BufferedReader buff = new BufferedReader(isr);
                String line = null;

                while ((line = buff.readLine()) != null) {
                    sb.append(line + "\n");
                }
                fis.close();
            }
        }
        else {
            Log.i("mylog", "File not found");
        }

        String[] sbLines = sb.toString().split("\n");
        TLE1 = sbLines[0];
        Log.d("myLog", "TLE1: " + TLE1);
        TLE2 = sbLines[1];
        Log.d("myLog", "TLE2: " + TLE2);
        TLE3 = sbLines[2];
        Log.d("myLog", "TLE3: " + TLE3);
        //SharedFunctions.threeLineElement = TLE1 + "\n" + TLE2 + "\n" + TLE3 + "\n";
        //Log.d("myLog","threeLineElement: "+SharedFunctions.threeLineElement);
        //threeLineElement = "SAUDISAT 1C (SO-50)\n" +
        //        "1 27607U 02058C   20106.54414103  .00000007  00000-0  21737-4 0  9999\n" +
        //        "2 27607  64.5556 206.7081 0055918 193.7297 166.2289 14.75625318931442\n";
        //tvHamSatMenu.setText(sbLines[3]);
        //tvTestBox.setText(line[3]);
        //char test = sb.charAt(3);
        //String sTest = String.valueOf(test);
        //tvTestBox.setText(sb);
    }
}
Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 19:28:52 via Website

Wo fehlt der Context?
Habe über Context gelesen aber das hab ich ehrlichgesagt nicht verstanden. Soll dass der Zustand der Activity sein?

— geändert am 16.04.2020, 19:29:33

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 19:30:08 via Website

OK und warum benutzt du beim Objekt erstellen den Standart Konstruktor ? Und nicht deinen mit Context übergabe, kann nie gehen.
OOP Grundlagen würde ich sagen.

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 19:31:18 via Website

lese was ich schreibe.

ReadTxtFile readTxtFile = new ReadTxtFile(this);

noch mal nicht.

Hilfreich?
Kommentieren
Ludy
  • Admin
  • Forum-Beiträge: 7.958

16.04.2020, 19:34:39 via Website

So Leute, ich habe etwas gespielt, der Download läuft aync, was das lesen der Datei fehllaufen lassen kann.

Habe es so gelöst (Models bitte ignoriere;-)):

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tvText = (TextView) findViewById(R.id.tvText);

    startDownloading();

    // WARTE 5 Sekunden
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            Models models = readTxtFile.readFile(getBaseContext());
            Log.e("t", models.getModels().get(0).lineOne.trim());
        }
    }, 5000);
}

Gruß Ludy (App Entwickler)

Mein Beitrag hat dir geholfen? Lass doch ein "Danke" da.☺

☕ Buy Me A Coffee ☕

Lebensmittelwarnung-App

✨Meine Wunschliste✨

📲Telegram NextPit News📲

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 19:37:49 via Website

@Jokel: Hab ich ausprobiert aber dann kommt folgender Fehler:

ReadTxtFile() in ReadTxtFile cannot be applied to 'com.examples.antennarotorcontrol.Mainactivity
Create constructor

Über eine Empfehlung für guten Lesestoff bezgl. OOP wäre ich sehr dankbar.

— geändert am 16.04.2020, 19:41:43

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 19:43:24 via Website

ReadTxtFile readTxtFile = new ReadTxtFile(MainActivity.this);
oder wie deine Klasse heist.

du bist scheinbar in einer Callback und da wird das einfache this falsch sein.

— geändert am 16.04.2020, 19:48:16

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 19:53:18 via Website

ReadTxtFile() in ReadTxtFile cannot be applied to 'com.examples.antennarotorcontrol.Mainactivity

der fehler sagt du willst den standart constructor aufrufen den es nicht gibt. stimmt auch deiner braucht einen Übergabe wert.

den benutzt du aber nicht.

ps mache den constructor mal public damit du ihn auch benutzen kannst.
auch sichtbar ist von ausen.

— geändert am 16.04.2020, 19:59:50

Hilfreich?
Kommentieren
Ludy
  • Admin
  • Forum-Beiträge: 7.958

16.04.2020, 22:19:44 via Website

So ich habe mal was gebastelt zum lernen, ich hoffe es hilft etwas: https://github.com/Ludy87/MyApplication4/tree/master/app/src/main/java/org/astra_g/myapplication

Gruß Ludy (App Entwickler)

Mein Beitrag hat dir geholfen? Lass doch ein "Danke" da.☺

☕ Buy Me A Coffee ☕

Lebensmittelwarnung-App

✨Meine Wunschliste✨

📲Telegram NextPit News📲

Hilfreich?
patrickk83
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 22:39:19 via Website

Ich sollte das ganze Projekt neu planen. Ich denke, ich habe als zu kompliziert bedacht. Das ganze Downloaden und Auslesen werde ich in einer Activity durchführen, die nach dem Click auf das entsprechende Listview in der MainActivity aufgerufen wird.
Vielleicht könnte ihr mir aber bei der Planung weiterhelfen...
- Die MainActivity wird lediglich ein Listview mit einigen Menüpunkten beinhalten, die mit einem
onClicklistener aufgerufen werden (jeweils eine eigene Activity). Desweiteren eine GPS-Abfrage des aktuellen
Standorts.
- Die wichtigste Activity (nennen wir sie mal Activity2) soll dann die Textdatei downloaden, diese Datei auswerten und dann mit Hilfe dieser Daten neue Listview-Elemente erstellen. Hier liegt sicher der Schwerpunkt des ganzen Codes.
Die Textdatei beinhaltet genau 222 Zeilen. Jeweils drei Zeilen gehören zusammen (es handelt sich um Satellitendaten). Es sind also Daten für 74 Satelliten in dieser Textdatei gespeichert.
Der Code für die Auswertung benötigt nun einen String, indem die drei Zeilen zusammengefasst wurden. Mit dem aktuellen Standort und diesem String werden verschiedene Parameter berechnet (z.B. die Flugbahn und "Aufgang/Untergang" in Bezug auf den Standort). Gewisse berechnete Parameter werden dann in dieser Activity2 benötigt, um in jedem Listview die ensprechenden Textfelder zu befüllen.
Es werden also insgesamt 74 Listview-Elemente benötigt (soll man das mit einer Schleife lösen?).
Damit es nicht "zu einfach wird", müssen diese Listview-Elemente nach Datum bzw. Uhrzeit sortiert werden. Sozusagen, welcher Satellite passiert den eigenen Standort als nächstes, übernächstes, usw. Ist der Pass vorüber so soll das Listview-Element gelöscht werden.

Hänge noch Bilder an um das Ganze zu visualisieren. Ich benötige eine gescheide Struktur um das Projekt koordinieren zu können.

imageimageimage

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 22:45:20 via Website

Hallo @Ludy auch du benutzt den Standart Konstruktor.
Den eigenen benutzt du auch nicht.

Dafür übergibt du der lesemethode den context das geht natürlich auch.

Ist im Grunde aber das selbe als den Kontext dem kostruchtur zu geben und in der Kasse zu Speichen.

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 22:47:00 via Website

Er hat das Prinzip von OOP noch nicht verstanden.

Ob er da mit dem Model Prinzip zurecht kommt. Wir werden sehen.

— geändert am 16.04.2020, 23:14:59

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 22:47:03 via Website

Wie soll ich das öffnen? Über New-Project from Version Control - Git ?

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 22:49:39 via Website

patrickk83 hast du es denn nun mit dem public probiert. Mit private wird es nicht gehen.
Habe ich leider nicht gleich gesehen.

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 22:53:11 via Website

Ja, hab den Construktor geändert:

public void ReadTxtFile(Context c){

Und den Aufruf in der MainActivity auch:

ReadTxtFile readTxtFile = new ReadTxtFile(MainActivity.this);

Fehler: ReadTxtFile() in ReadTxtFile cannot be applied to com.example.antennarotorcontrol.MainActivity
Create constructor

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 22:58:49 via Website

Kann nicht sein ich habe das öfters so gemacht. Soltte gehen. Heute ist esmir zu spät werde es morgen mal testen.

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 23:01:01 via Website

Alles klar. Hab ich aber definitiv so im Code stehen. Ich check gerade mal den Code von Ludy. Die Main verstehe ich soweit bis auf Model model : models.getModels()
Kenne den ":" Operator oder wie sich das hier nennt nicht.

@Jokel: Danke vielmals für die Unterstützung einstweilen

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 23:03:45 via Website

Aber ein costruktor hat auch kein void. Der gibt nie etwas zurück.
Somit ist es kein kostruktor nur eine Methode die so heißt.

Nach das void weg.

— geändert am 16.04.2020, 23:05:26

Hilfreich?
patrickk83
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 23:07:31 via Website

Das macht Ludy leider auch falsch. Er benutzt aber den Standart automatisch erstellten.

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 23:08:18 via Website

Uuups, hab ich übersehen. Ah, jetzt will er ein try/catch. Werde da mal bisserl basteln.
@Ludy: Der Code ist sehr verständlich geschrieben, danke dafür

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 23:17:27 via Website

Stürzt trotzdem ab... :-) Ist ja nicht normal der blöde Code. Ich kann ja mal versuchen ob ich das ganze Projekt auf github laden kann wenn Interesse besteht. Werde das aber auch morgen versuchen.
Danke euch beiden nochmals!!

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 23:18:46 via Website

Wo bei was stürzt er ab. Welche Fehler Meldung

— geändert am 16.04.2020, 23:19:43

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 23:20:22 via Website

Im Debugger-Modus:
String tleElement = readTxtFile.threeLineElement; da stürzt es ab

Hier nochmal der Code in der MainActivity:

TleManualImport tleFunction = new TleManualImport();
    ReadTxtFile readTxtFile = new ReadTxtFile(MainActivity.this);
    try {
        readTxtFile.readFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String tleElement = readTxtFile.threeLineElement;

    String[] SatData = tleFunction.processTLE(tleElement); //tleElement

— geändert am 16.04.2020, 23:24:53

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 23:28:16 via Website

In RuntimeInit.java stürzt die App dann ab:

        public void run() {
        try {
            mMethod.invoke(null, new Object[] { mArgs });
        } catch (IllegalAccessException ex) {
            throw new RuntimeException(ex);
        } catch (InvocationTargetException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            } else if (cause instanceof Error) {
                throw (Error) cause;
            }
            throw new RuntimeException(ex);
        }
Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 23:33:31 via Website

Der Fehler ist in der Read Klasse nicht in der main.

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 23:34:29 via Website

Schau in der Klasse ob auch richtig gelesen wird.

Hilfreich?
patrickk83
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 23:41:55 via Website

Wo in deinem Code ist der Code?
Das sieht mir nach deiner Android Methode aus die dir der Debugger anzeigt.

Frage zu deiner lese klasse.
Wird denn da auch die Variable threeLineElement gezetzt.
In deinem letzten Code war das nicht so.

War der Meinung das der auskommentiert war.

— geändert am 16.04.2020, 23:44:14

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 23:45:04 via Website

Nein die Variable wurde nicht gesetzt. Versuche es mal mit gesetzter Variable.

Hat auch nicht geklappt

— geändert am 16.04.2020, 23:46:45

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 23:47:50 via Website

Wie mit was setz du die zeige die Klasse

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 23:48:47 via Website

public void readFile() throws IOException {
    if (isExternalStorageReadable()) {
        try {
            StringBuilder sb = new StringBuilder(69);
            File textfile = new File(context.getExternalFilesDir(null).getAbsolutePath(), "amateur.txt");

            if (textfile.exists()) {

                FileInputStream fis = new FileInputStream(textfile);

                if (fis != null) {
                    InputStreamReader isr = new InputStreamReader(fis);
                    BufferedReader buff = new BufferedReader(isr);
                    String line = null;

                    while ((line = buff.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                    fis.close();
                }
            } else {
                Log.i("mylog", "File not found");
            }

            String[] sbLines = sb.toString().split("\n");
            TLE1 = sbLines[0];
            Log.d("myLog", "TLE1: " + TLE1);
            TLE2 = sbLines[1];
            Log.d("myLog", "TLE2: " + TLE2);
            TLE3 = sbLines[2];
            Log.d("myLog", "TLE3: " + TLE3);
            threeLineElement = TLE1 + "\n" + TLE2 + "\n" + TLE3 + "\n";

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

16.04.2020, 23:55:39 via Website

Wenn ich mir den string ansehe denn du aus kommentiert hast und das was du zurück gibst ist das nur die Hälfte von dem was erwartet wird.

threeLineElement = "SAUDISAT 1C (SO-50)\n" + "1 27607U 02058C 20106.54414103 .00000007 00000-0 21737-4 0 9999\n" + "2 27607 64.5556 206.7081 0055918 193.7297 166.2289 14.75625318931442\n";

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

16.04.2020, 23:59:53 via Website

Warum das?
TLE1 ist die erste Zeile der Textdatei (SAUDISAT 1C (SO-50))
TLE2 die Zweite (1 27607U 02058C 20106.54414103 .00000007 00000-0 21737-4 0 9999)
TLE3 die Dritte (2 27607 64.5556 206.7081 0055918 193.7297 166.2289 14.75625318931442)

und die drei TLE's habe ich in den String threelineelement kopiert inkl. einem \n

Hilfreich?
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

17.04.2020, 00:02:13 via Website

Du must schon in die Variablen mit dem Debugger reinschauen und schauen was da drin steht. Wozu hast du einen degugger und preackpoints.

Hilfreich?
Kommentieren
patrickk83
  • Forum-Beiträge: 93

17.04.2020, 00:08:10 via Website

OK, die TLE Variablen sind null....

Hilfreich?
Kommentieren
Ludy
  • Admin
  • Forum-Beiträge: 7.958

17.04.2020, 05:43:27 via Website

Jokel

Hallo @Ludy auch du benutzt den Standart Konstruktor.
Den eigenen benutzt du auch nicht.

Bei einer Methode in der Klasse, baue ich nie einen Konstruktor, im Projekt habe ich es schlicht vergessen zu entfernen, habe gerade das Projekt neu gepusht.

Ob er da mit dem Model Prinzip zurecht kommt. Wir werden sehen.

Das Model-Prinzip ist für das Projekt von Patrick das Beste was es gibt, alles andere wird wie man sieht sehr unübersichtlich.

patrickk83

Wie soll ich das öffnen? Über New-Project from Version Control - Git ?

Du sollst dir das anschauen, zum "kopieren" ist es nicht gedacht - eventuell abtippen ;-)

OK, die TLE Variablen sind null....

Wird sie immer sein, denn wie schon mal weiter vorne geschrieben, der Downloadmanager ist asnychron, das heißt der Code läuft weiter ohne auf diesen zu warten. Daher habe ich - wie auch im Git-Projekt - das mit einem Handler gelöst.

Es gibt noch andere Alternativen zum Downloadmanger - die könnte ich dir heute Abend vielleicht auf Git laden.

Gruß Ludy (App Entwickler)

Mein Beitrag hat dir geholfen? Lass doch ein "Danke" da.☺

☕ Buy Me A Coffee ☕

Lebensmittelwarnung-App

✨Meine Wunschliste✨

📲Telegram NextPit News📲

Hilfreich?
patrickk83
Kommentieren
patrickk83
  • Forum-Beiträge: 93

17.04.2020, 07:44:21 via Website

Hab es geschafft das Projekt auf github zu laden falls sich das jemand gerne ansehen möchte: https://github.com/patrickk83/AntennaRotorControl

Hilfreich?
JokelLudy
Kommentieren
Ludy
  • Admin
  • Forum-Beiträge: 7.958

17.04.2020, 07:51:25 via Website

Moin,

bin gerade Mal durch die Klassen geflogen - ist ausbaufähig.

  1. Der Schreibstil ist schmerzlich, kann man aber lernen.
  2. Das richtige/sinnvolle Auslagern in Methoden und Klassen solltest du dir angewöhnen, sonst blickst du selber nicht mehr durch.

Ich werde mir nachher nen frok anlegen und cmpilieren und ggf. bei mir dann pushen.

Gruß Ludy (App Entwickler)

Mein Beitrag hat dir geholfen? Lass doch ein "Danke" da.☺

☕ Buy Me A Coffee ☕

Lebensmittelwarnung-App

✨Meine Wunschliste✨

📲Telegram NextPit News📲

Hilfreich?
patrickk83
Kommentieren
Jokel
  • Forum-Beiträge: 1.530

17.04.2020, 08:27:14 via Website

Ludy Ja jetzt hast auch du gesehen das es nicht unbedingt am asyncon liegt.

Viel mehr wie er Code auslagert. Er hat ja schon ewig gebraucht das über haut die Klasse geht er richtig darauf zugreifen kann. Das er auch echte logische Fehler hat im Code war eigentlich klar.

Das das Model Prinzip für seinen Fall super ist steht außer Frage.

Auch ob du nun das mit oder ohne kostruktor machst ist eigentlich auch egal. Wichtig ist das auf irgendeine Weise der Context übergeben wird.

Wenn ich Zeit habe werde ich mir sein Projekt auch ansehen habe ich noch nicht.

— geändert am 17.04.2020, 08:33:07

Hilfreich?
Kommentieren