Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <REL_Linux_SUSI.h>
00038 #include <diagnostic_msgs/DiagnosticStatus.h>
00039 #include <std_msgs/UInt16.h>
00040
00041 #include <ros/ros.h>
00042 #include <boost/bind.hpp>
00043
00044 struct SharedData
00045 {
00046 SharedData():
00047 pins(0),
00048 status(0){};
00049 enum {tcpu,tsys,taux};
00050 uint16_t tempTypes;
00051 float temp[3];
00052 bool hasIO;
00053 DWORD pins, status;
00054 };
00055
00056 int init_susi(SharedData& shared)
00057 {
00058 if (!SusiDllInit())
00059 {
00060 ROS_ERROR("Cannot initialize advantech SUSI drivers.");
00061 return 1;
00062 }
00063
00064 bool hasHwm(SusiHWMAvailable());
00065 shared.tempTypes = 0;
00066 if (!hasHwm)
00067 {
00068 ROS_WARN("No HWM available");
00069 }
00070 else
00071 {
00072 float retVal;
00073 SusiHWMGetTemperature(0, &retVal, &shared.tempTypes);
00074 }
00075
00076 shared.hasIO = SusiIOAvailable();
00077 if (!shared.hasIO)
00078 {
00079 ROS_WARN("No IO available");
00080 }
00081 else
00082 {
00083
00084 DWORD mask(0);
00085 DWORD pins(0xFF);
00086
00087 {
00088 ROS_ERROR("Unable to set pins to output.");
00089 }
00090 }
00091
00092 return 0;
00093 }
00094
00095 void getTemperature(SharedData& shared)
00096 {
00097 if (TCPU & shared.tempTypes)
00098 {
00099 SusiHWMGetTemperature(TCPU, &shared.temp[SharedData::tcpu], NULL);
00100 }
00101 if (TSYS & shared.tempTypes)
00102 {
00103 SusiHWMGetTemperature(TSYS, &shared.temp[SharedData::tsys], NULL);
00104 }
00105 if (TAUX & shared.tempTypes)
00106 {
00107 SusiHWMGetTemperature(TAUX, &shared.temp[SharedData::taux], NULL);
00108 }
00109 }
00110
00111 void handleGPIO(SharedData& shared, const std_msgs::UInt16::ConstPtr& data)
00112 {
00113 if (shared.hasIO)
00114 {
00115 DWORD pins = (data->data & 0xFF00) >> 8;
00116 DWORD status = (data->data & 0x00FF);
00117 shared.pins = pins;
00118 shared.status = status;
00119 ROS_INFO("Set gpio: %d, %d",pins, status);
00120
00121
00122
00123 }
00124 }
00125
00126 int main(int argc, char* argv[])
00127 {
00128 ros::init(argc,argv,"advantech_io");
00129
00130 SharedData shared;
00131 if (init_susi(shared))
00132 {
00133 SusiDllUnInit();
00134 return -1;
00135 };
00136
00137 ros::NodeHandle nh;
00138
00139 ros::Publisher diagnostics = nh.advertise<diagnostic_msgs::DiagnosticStatus>("advantech_diagnostic",1);
00140 ros::Subscriber gpio = nh.subscribe<std_msgs::UInt16>("gpio", 1, boost::bind(&handleGPIO,boost::ref(shared),_1));
00141
00142 ros::Rate rate(10);
00143
00144 std::string temps[3] = {"TCPU","TSYS","TAUX"};
00145 diagnostic_msgs::DiagnosticStatus status;
00146 status.level = status.OK;
00147 status.name = "AdvantechBoard";
00148 status.message = "Temperature report";
00149 status.hardware_id = "AdvantechSUSI";
00150 for(int i=0;i<3;++i) status.values.push_back(diagnostic_msgs::KeyValue());
00151
00152 DWORD mask(0x0);
00153 while (ros::ok())
00154 {
00155 getTemperature(shared);
00156
00157
00158 std::ostringstream out;
00159 for(int i=0;i<3;++i)
00160 {
00161 out.str("");
00162 out<<shared.temp[i];
00163 status.values[i].key = temps[i];
00164 status.values[i].value = out.str();
00165 }
00166 diagnostics.publish(status);
00167 DWORD pins(0xFF);
00168 SusiIOSetDirectionMulti(pins,&mask);
00169 if (!SusiIOSetDirectionMulti(pins,&mask))
00170 {
00171 ROS_ERROR("Unable to set pins to output.");
00172 }
00173
00174 ROS_INFO("Set gpio: %d, %d",shared.pins, shared.status);
00175 int result = SusiIOWriteMulti(0xFF, 0x0);
00176 if (result != 0)
00177 ROS_INFO("SusiIOWriteMulti() failed\n");
00178
00179 rate.sleep();
00180 ros::spinOnce();
00181 }
00182
00183 SusiDllUnInit();
00184 return 0;
00185 }
00186