Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void searchDevice(String arg) throws IOException{
- String[] bases = arg.split(";");
- String[] realCoords=bases[bases.length-1].split(",");
- List<Base_Station> stations = new ArrayList<Base_Station>();
- for(String base:bases){
- if(bases[bases.length-1]==base)
- break;
- String[] base_data=base.split(",");
- base_data[6]=(base_data[6].equals("-1")?String.valueOf(-1):base_data[6]);
- Base_Station station=new Base_Station(base_data);
- station.recovering();
- stations.add(station);
- }
- List<Base_Station> stationsOK = new ArrayList<Base_Station>();
- ArrayList<String> CIDs = new ArrayList<String>(stations.size());
- for(Base_Station station:stations) {
- String bs_number = String.valueOf(Integer.parseInt(station.CID, 16)/10);
- if(!CIDs.contains(bs_number)) {
- CIDs.add(bs_number);
- stationsOK.add(station);
- }
- else {
- if(station.Rxl>stationsOK.get(CIDs.indexOf(bs_number)).Rxl) {
- stationsOK.set(CIDs.indexOf(bs_number),station);
- }
- }
- }
- CIDs.clear();
- stations.clear();
- Collections.sort(stationsOK, new Comparator<Base_Station>(){
- @Override
- public int compare(Base_Station o2, Base_Station o1) {
- return (o1.Arfc>o2.Arfc?1:(o1.Arfc<o2.Arfc?-1:0));
- }
- });
- stationsOK=stationsOK.subList(0, (stationsOK.size()>=6?6:stationsOK.size()));//оставляе� 6
- new FileWriter(file,false);
- for(Base_Station station:stationsOK) {
- Base_Station bs = new Base_Station(station.data);
- bs.recovering();
- stations.add(bs);
- }
- result(true, stationsOK);
- stationsOK=stations;
- result(false, stationsOK);
- FileWriter fw = new FileWriter(file,true);
- fw.write(realCoords[0]+" "+realCoords[1]);
- fw.close();
- }
- public static void result(boolean choice, List<Base_Station> stationsOK) throws IOException {
- List<Base_Station> stations = new ArrayList<Base_Station>();
- long a = 6378137;
- long b = 6356752;
- boolean def=true;
- double cosPhi=0;
- for(Base_Station station:stationsOK) {
- String coord=(choice?getYandexCoord(station.MCC,station.MNC,station.LAC,station.CID)+" Y":getGoogleCoord(station.MCC,station.MNC,station.LAC,station.CID)+" G");
- //System.out.println("Base Station "+station.CID+" coords: " +coord);
- def=(coord.equals(" Y")?false:def);
- def=(coord.equals(" G")?false:def);
- try {
- FileWriter fw = new FileWriter(file,true);
- fw.write(station.CID+" " +new DecimalFormat("#0.0000000").format(Double.valueOf(coord.split(" ")[0])).replace(",", ".")+" "+new DecimalFormat("#0.0000000").format(Double.valueOf(coord.split(" ")[1])).replace(",", ".") +"\r\n");
- fw.close();
- } catch (IOException ignored) {}
- double phi = Math.toRadians(Double.valueOf(coord.split(" ")[0]));
- double psi = Math.toRadians(Double.valueOf(coord.split(" ")[1]));
- //if(cosPhi==0) {
- r=a*b/Math.sqrt(b*b*Math.cos(phi)*Math.cos(phi)+a*a*Math.sin(phi)*Math.sin(phi));
- cosPhi = Math.cos(phi);
- //}
- station.coord0=new Point(phi*r,cosPhi*psi*r);
- //System.out.println("Base Station "+station.CID+" coords: " +station.coord0.x + ' ' + station.coord0.y+' '+cosPhi+' '+0.5022231252570837*psi*r);
- if(station.R>=0) {
- stations.add(station);
- }
- }
- Solve.r=r;
- String result = "Point 0 0 0";
- if(def) {
- if(stationsOK.size()==stations.size()) {
- result = Solve.solve(stationsOK, false);
- sp="RADIUS";
- }
- if(Double.valueOf(result.split(" ")[1])==0&&Double.valueOf(result.split(" ")[2])==0&&!stations.isEmpty()) {
- result = Solve.searchRxl(stationsOK, stations);
- sp="Rxl & RADIUS";
- }
- if(Double.valueOf(result.split(" ")[1])==0&&Double.valueOf(result.split(" ")[2])==0) {
- result = Solve.fullSearchRxl(stationsOK);
- sp="Rxl";
- }
- System.out.println("Successful");
- }
- FileWriter fw = new FileWriter(file,true);
- for(Base_Station station:stationsOK) {
- try {
- fw.write(station.CID+" " + station.R +" "+ station.deltaR +"\r\n");
- } catch (IOException ignored) {}
- }
- String[] answerStr = result.split(" ");
- double x = Double.valueOf(answerStr[1])/r;
- double y = Double.valueOf(answerStr[2])/r/Math.cos(x);
- fw.write(new DecimalFormat("#0.0000000").format(Math.toDegrees(x)).replace(",", ".")+" "+new DecimalFormat("#0.0000000").format(Math.toDegrees(y)).replace(",", ".")+" "+ Double.parseDouble(answerStr[3])+"\r\n");
- fw.close();
- answerStr[1]=new DecimalFormat("#0.0000000").format(Math.toDegrees(x)).replace(",", ".");
- answerStr[2]=new DecimalFormat("#0.0000000").format(Math.toDegrees(y)).replace(",", ".");
- }
- public static String getYandexCoord(String MCC, String MNC, String LAC, String CID) {
- String res="";
- try {
- URLConnection connection = new URL("http://mobile.maps.yandex.net/cellid_location/?&cellid="+Integer.parseInt(CID,16)
- +"&operatorid="+Integer.parseInt(MNC)+"&countrycode="+Integer.parseInt(MCC)+"&lac="+Integer.parseInt(LAC,16)).openConnection();
- BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String line;
- StringBuilder sb = new StringBuilder();
- while((line = br.readLine())!=null) {
- sb.append(line);
- }
- int begin = sb.toString().indexOf("latitude")+10;
- int end = sb.toString().indexOf(" ", begin)-1;
- res=sb.toString().substring(begin,end)+" ";
- begin = sb.toString().indexOf("longitude")+11;
- end = sb.toString().indexOf(" ", begin)-1;
- res+=sb.toString().substring(begin,end);
- } catch (IOException e) {
- System.out.println(e);
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement