Commit d6f60765 authored by Thomas Edwards's avatar Thomas Edwards
Browse files

Reimplemented GSM90 quick and dirty fix

parent a0ca1fb3
......@@ -20,15 +20,17 @@ int main(int argc, char* argv[]){
std::string cmd;
int baud;
char term[1];
term[0]=13;
//char term[1];
// term[0]=13;
// term[0]=182; // for GSM90
char buf[1000];
char term[2]={13,10};
std::cerr << "BAUD: ";
std::cin >> baud;
char buf[1000];
driver_serial serial = driver_serial(par.get_str("PORT_SCA"),term,1,baud);
// driver_serial serial = driver_serial("/dev/OBSDAQ",term,1,baud);
serial.set_ignnul(true);
......@@ -46,11 +48,18 @@ int main(int argc, char* argv[]){
serial.send((const char*) cmd.c_str());
// serial.receive(buf,sizeof(buf),5);
serial.receive_raw(buf,sizeof(buf),5);
serial.receive(buf,sizeof(buf),5);
//serial.receive_raw(buf,sizeof(buf),5);
std::cerr << buf << std::endl;
for (int ix=0; ix<sizeof(buf); ix++) {
std::cerr << (int)buf[ix] << " ";
}
// debug to watch for characters
// for (int ix=0; ix<sizeof(buf); ix++) {
// std::cerr << (int)buf[ix] << " ";
......
#include <iostream>
#include <algorithm>
#include <fstream>
#include <sys/stat.h>
#include <string.h>
#include <inttypes.h>
#include <stdio.h>
#include <driver_serial.hpp>
#include <Parameters_Reader.hpp>
int main(int argc, char* argv[]){
// Read from parameters file
if (argc != 2){
fprintf(stderr,"Please specify one parameter file to use !\n");
return(-1);
}
Parameters_Reader par = Parameters_Reader(argv[1]);
// grab filename
std::string filepath = par.get_str("DIR_SCA");
std::string filename;
// grab station name
std::string station_name = par.get_str("STATION_NAME");
// allocate space for commands to send
std::string cmd;
int baud;
//char term[1];
// term[0]=13;
// term[0]=182; // for GSM90
char term[2]={13,10};
// std::cerr << "BAUD: ";
// std::cin >> baud;
baud = 115200;
char buf[1000];
driver_serial serial = driver_serial(par.get_str("PORT_SCA"),term,1,baud);
// driver_serial serial = driver_serial("/dev/OBSDAQ",term,1,baud);
serial.set_ignnul(true);
// Stop
cmd = "S";
cmd=cmd+(char) 13;
serial.send((const char*) cmd.c_str());
serial.receive(buf,sizeof(buf),5);
std::cerr << buf << std::endl;
// Set to default
cmd = "&";
cmd=cmd+(char) 13;
serial.send((const char*) cmd.c_str());
serial.receive(buf,sizeof(buf),5);
std::cerr << buf << std::endl;
// Run
cmd = "R";
cmd=cmd+(char) 13;
serial.send((const char*) cmd.c_str());
serial.receive(buf,sizeof(buf),5);
std::cerr << buf << std::endl;
// Time of measurement
struct timespec recv_time;
char timebuf[31];
std::string buff_str;
char filename_buf[10];
std::ofstream file_out;
while (1){
// Wait for answer
if (serial.receive(buf, sizeof(buf), 10, &recv_time) >= 0) {
// Manage time
struct tm t = {0};
// Use gmtime_r for thread-safety
gmtime_r(&recv_time.tv_sec,&t);
strftime(timebuf, 31, "%Y %m %d %H %M %S.", &t);
sprintf(timebuf, "%s%09lu", timebuf, recv_time.tv_nsec);
// Create filename
filename = "";
strftime(filename_buf, 10, "%Y%m%d", &t);
filename = station_name+"_GSM90_"+filename_buf+".txt";
// Create full path
std::string filename_full = filepath+'/'+filename;
// std::cerr << filename_full << std::endl;
// Create directory
int pos = filename_full.find('/',1);
while (pos != std::string::npos){
mkdir(filename_full.substr(0,pos).c_str(),0777);
pos = filename_full.find('/',pos+1);
}
// Close old file, if necessary
if (file_out.is_open()) {
file_out.close();
}
file_out.open(filename_full, std::ios::out | std::ios::app);
if (!file_out.is_open()){
std::cerr << "Opening file failed: "
<< filename_full
<< std::endl;
}
buff_str = buf;
// peel any endling characters off the read buffer
buff_str.erase(std::remove(buff_str.begin(), buff_str.end(), '\n'), buff_str.end());
// push data to file
// std::cerr << timebuf << " " << buff_str << std::endl;
file_out << timebuf << " " << buff_str << std::endl;
// close file
file_out.close();
}
//std::cerr << "CMD: ";
//std::cin >> cmd;
//if (cmd.compare("QUIT")){
// break;
//}
//cmd=cmd+(char) 13;
//serial.send((const char*) cmd.c_str());
// serial.receive(buf,sizeof(buf),5);
//serial.receive_raw(buf,sizeof(buf),5);
// std::cerr << buf;
//for (int ix=0; ix<sizeof(buf); ix++) {
// std::cerr << (int)buf[ix] << " ";
//}
// debug to watch for characters
// for (int ix=0; ix<sizeof(buf); ix++) {
// std::cerr << (int)buf[ix] << " ";
// }
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment