00001 #pragma once
00002
00004 #include <string>
00005 #include <termios.h>
00006 #include <sys/types.h>
00007 #include <sys/stat.h>
00008 #include <time.h>
00009 #include <list>
00010 #include <utility>
00011 #include "pr2_msgs/BatteryServer2.h"
00012
00013 namespace willowgarage
00014 {
00015 namespace ocean
00016 {
00017 class ocean
00018 {
00019 public:
00020 static const int NMEA_MAX = 120;
00021 static const int MAXTAGLEN = 8;
00022 static const int MAXCHANNELS = 16;
00023
00024 static const int INPUT_BUF_SIZE = 128;
00025 static const int OUTPUT_BUF_SIZE = 128;
00026 static const unsigned int MAX_PACKET_LENGTH = 120;
00027 static const int BAD_PACKET = -1;
00028 static const int NO_PACKET = 0;
00029 static const int NMEA_PACKET = 1;
00030
00031 struct regPair {
00032 const std::string name;
00033 const std::string unit;
00034 const unsigned address;
00035 };
00036
00037
00038 ocean (int id, int debug = 0);
00039 ~ocean ();
00040
00041 int run ();
00042 void setDebugLevel (int);
00043 void initialize (const std::string &input_dev);
00044 void read_file (const std::string &input);
00045
00046 private:
00047 void flush (void);
00048 int get_speed (void);
00049 void set_speed (int speed);
00050 void report (int errlevel, const char *fmt, ...);
00051 char *gpsd_hexdump (void *binbuf, size_t binbuflen);
00052 void nextstate (unsigned char c);
00053 void packet_accept (int packet_type);
00054 void packet_discard ();
00055 void character_discard ();
00056 ssize_t packet_parse (size_t newdata);
00057 ssize_t packet_get ();
00058 void packet_reset ();
00059 int nmea_send (const char *fmt, ...);
00060 void nmea_add_checksum (char *sentence);
00061 time_t mkgmtime (register struct tm *t);
00062 unsigned int nmea_parse ();
00063 unsigned int processController (int count, char *field[]);
00064 unsigned int processSystem (int count, char *field[]);
00065 unsigned int processBattery (int count, char *field[]);
00066 int commTest();
00067 void resetOcean();
00068 int string_send (const char *fmt, ...);
00069
00070 private:
00071 int inputDevice;
00072 #if (FILE_LOGGING > 0)
00073 int outputFile;
00074 #endif
00075 struct termios ttyset;
00076 int currentBaudRate;
00077 int currentBaudRateIndex;
00078 int currentPort;
00079 char *idString;
00080 int debuglevel;
00081 int sentenceCount;
00082 int currentBattery;
00083
00084
00085 int packetState,
00086 packetType;
00087 unsigned char inbuffer[INPUT_BUF_SIZE + 1];
00088 unsigned char outbuffer[OUTPUT_BUF_SIZE + 1];
00089 size_t inbuflen, outbuflen;
00090 unsigned char *inbufptr;
00091 unsigned long char_counter;
00092 char tag[MAXTAGLEN];
00093 int sentenceLength;
00094 int cycleComplete;
00095 int acknowledge;
00096
00097 public:
00098 static const struct regPair regList[];
00099 static const unsigned regListLength;
00100
00101 pr2_msgs::BatteryServer2 server;
00102 };
00103 }
00104 }