Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<cstdlib>
- #include<string>
- #include<cmath>
- #include <stdlib.h>
- using namespace std;
- void channelDecode(const string & input, string & fixed)
- {
- char A = 0;
- for (unsigned int n = 0; n < input.size() - 1; n++)
- {
- A = A + input[n];
- }
- if (A == input[input.size() - 1] )
- {
- fixed = input.substr(0, input.size() -1);
- }
- else
- {
- fixed = "Packet was corrupted and could not be decoded.";
- }
- return;
- }
- int parseLine(const string & line, const string & key)
- {
- int number1 = line.find(key);
- int number2 = line.length();
- if (number1 < 0 || number1 > number2)
- {
- return -9999;
- }
- string lineNew = line.substr(number1);
- return atoi(line.substr(number1 + 3, lineNew.find(' ') ).c_str() );
- }
- string removeUnder(const string & input)
- {
- string inF = input;
- for(int i = 0; i < input.size(); i++)
- {
- if( input [i] == '_')
- {
- inF[i] = ' ';
- }
- else
- {
- inF[i] = input[i];
- }
- }
- return inF;
- }
- int main()
- {
- ifstream infile("beacon.txt");
- ofstream outfile("beacon_clear.txt");
- string input;
- string fixed;
- bool num = true;
- do
- {
- getline(infile, input);
- if (infile.eof())
- {
- num = false;
- }
- else
- {
- fixed = input;
- channelDecode(input, fixed);
- outfile << fixed << endl;
- }
- }
- while(num);
- infile.close();
- outfile.close();
- string bcline, iline, name, key, intitle, bctitle;
- int components, val;
- ifstream beacon("beacon_clear.txt");
- ofstream result("result.txt");
- ifstream index("dataIndex.txt");
- while(getline(beacon, bcline))
- {
- ifstream index("dataIndex.txt");
- if (bcline != "Packet was corrupted and could not be decoded.")
- {
- bcline.append(" ");
- bctitle = bcline.substr(0, bcline.find(' '));
- index >> intitle;
- while (intitle != bctitle)
- {
- index >> intitle;
- }
- getline(index, iline);
- components = atoi(iline.c_str());
- index.close();
- result << removeUnder(intitle) << "\n";
- iline = iline.substr(3);
- for (int i = 0; i < components; i++)
- {
- key = iline.substr(0, 2);
- val = parseLine(bcline, key);
- iline = iline.append(" ");
- iline = iline.substr(iline.find(' ') + 1);
- name = iline.substr(0, iline.find(' '));
- iline = iline.substr(iline.find(' ') + 1);
- result << removeUnder(name) << ": " << val << "\n";
- }
- }
- result << "\n";
- }
- index.close();
- result.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement