power_node.h
Go to the documentation of this file.
00001 
00002 #pragma once
00003 
00004 #include <time.h>
00005 #include "ros/ros.h"
00006 #include "pr2_power_board/PowerBoardCommand.h"
00007 #include "boost/thread/mutex.hpp"
00008 
00009 class Interface 
00010 {
00011   public:
00012 
00013     struct ifreq interface;
00014     int recv_sock;
00015     int send_sock;
00016     Interface(const char* ifname);
00017     ~Interface() {Close();}
00018     void Close();
00019     int Init(sockaddr_in *port_address, sockaddr_in *broadcast_address);
00020     int InitReceive();
00021     void AddToReadSet(fd_set &set, int &max_sock) const;
00022     bool IsReadSet(fd_set set) const;
00023     sockaddr_in ifc_address;
00024 };
00025 
00026 
00027 class Device 
00028 {
00029   public:
00030     ros::Time message_time;
00031     
00032     const TransitionMessage &getTransitionMessage()
00033     {
00034       return tmsg;
00035     }
00036     void setTransitionMessage(const TransitionMessage &newtmsg);
00037     
00038     const PowerMessage &getPowerMessage()
00039     {
00040       return pmsg;
00041     }
00042     void setPowerMessage(const PowerMessage &newpmsg);
00043     
00044     Device();
00045     ~Device() { };
00046   private:
00047     bool tmsgset;
00048     TransitionMessage tmsg;
00049     bool pmsgset;
00050     PowerMessage pmsg;  //last power message recived from device
00051 };
00052 
00053 
00054 class PowerBoard
00055 {
00056   public:
00057     PowerBoard( const ros::NodeHandle node_handle, unsigned int serial_number = 0 );
00058     bool commandCallback( pr2_power_board::PowerBoardCommand::Request &req_,
00059                           pr2_power_board::PowerBoardCommand::Response &res_);
00060     void init();
00061     void collectMessages();
00062     void sendMessages();
00063     int collect_messages();
00064     int process_message(const PowerMessage *msg, int len);
00065     int process_transition_message(const TransitionMessage *msg, int len);
00066     const char* master_state_to_str(char state);
00067     const char* cb_state_to_str(char state);
00068     int list_devices(void);
00069     int send_command(unsigned int serial_number, int circuit_breaker, const std::string &command, unsigned flags);
00070 
00071   private:
00072     ros::NodeHandle node_handle;
00073     ros::ServiceServer service;
00074     ros::Publisher diags_pub;
00075     ros::Publisher state_pub;
00076 
00077     pr2_power_board::PowerBoardCommand::Request req_;
00078     pr2_power_board::PowerBoardCommand::Response res_;
00079     boost::mutex library_lock_;
00080     unsigned int serial_number;
00081 };


pr2_power_board
Author(s): Curt Meyers, Blaise Gassend
autogenerated on Thu Jun 6 2019 21:11:02