Skip to content

Commit 486fc3c

Browse files
committed
Add temperature monitoring for the new firmware.
1 parent 6b2e971 commit 486fc3c

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

arx_control/aspCommon.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,31 @@ std::string ATmega::get_version() {
195195
}
196196

197197

198+
float ATmega::get_temperature() {
199+
float temp_C = -99.0;
200+
if( _fd < 0 ) {
201+
return temp_C;
202+
}
203+
204+
atmega::buffer cmd, resp;
205+
cmd.command = atmega::COMMAND_READ_TEMPERATURE;
206+
cmd.size = 0;
207+
208+
int n = atmega::send_command(_fd, &cmd, &resp, ATMEGA_OPEN_MAX_ATTEMPTS, ATMEGA_OPEN_WAIT_MS);
209+
if( (n == 0) || (resp.command & atmega::COMMAND_FAILURE) ) {
210+
std::cerr << "Warning: " << atmega::strerror(resp.command) << std::endl;
211+
return temp_C;
212+
}
213+
214+
if( resp.size != sizeof(float) ) {
215+
std::cerr << "Warning: response is not float sized" << std::endl;
216+
return temp_C;
217+
}
218+
219+
::memcpy(&temp_C, resp.buffer, sizeof(float));
220+
return temp_C;
221+
}
222+
198223
bool ATmega::transfer_spi(const char* inputs, char* outputs, int size) {
199224
if( _fd < 0 ) {
200225
return false;

arx_control/aspCommon.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class ATmega {
7272
}
7373
bool open();
7474
std::string get_version();
75+
float get_temperature();
7576
bool transfer_spi(const char* inputs, char* outputs, int size);
7677
std::list<uint8_t> list_rs485_devices();
7778
bool read_rs485(uint8_t addr, char* data, int* size);

arx_control/listATmegaSN.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ATmega devices.
1010
*****************************************************/
1111

1212
#include <iostream>
13+
#include <iomanip>
1314
#include <stdexcept>
1415
#include <string>
1516
#include <cstring>
@@ -25,6 +26,15 @@ int main(int argc, char* argv[]) {
2526
/*************************
2627
* Command line parsing *
2728
*************************/
29+
bool temps = false;
30+
for(int i=1; i<argc; i++) {
31+
std::string temp = std::string(argv[i]);
32+
if( temp[0] == '-' ) {
33+
if( (temp == "-t") || (temp == "--temperatures") ) {
34+
temps = true;
35+
}
36+
}
37+
}
2838

2939
/************************
3040
* ATmega device listing *
@@ -57,8 +67,25 @@ int main(int argc, char* argv[]) {
5767
for(int i=0; i<std::min((uint16_t) 8, (uint16_t) resp.size); i++) {
5868
sn.push_back((char) resp.buffer[i]);
5969
}
60-
std::cout << "Found " << sn << " at " << dev_name << std::endl;
70+
std::cout << "Found " << sn << " at " << dev_name;
71+
}
72+
73+
if( temps ) {
74+
cmd.command = atmega::COMMAND_READ_TEMPERATURE;
75+
cmd.size = 0;
76+
77+
int n = atmega::send_command(fd, &cmd, &resp, std::min(3, ATMEGA_OPEN_MAX_ATTEMPTS), ATMEGA_OPEN_WAIT_MS);
78+
if( (n > 0) && (resp.command & atmega::COMMAND_FAILURE) == 0 ) {
79+
float temp_C = -99.0;
80+
if( resp.size == sizeof(float) ) {
81+
::memcpy(&temp_C, &(resp.buffer[0]), sizeof(float));
82+
}
83+
std::cout << std::setprecision(3) << " at " << temp_C << " C";
84+
}
6185
}
86+
87+
std::cout << std::endl;
88+
6289
} catch(const std::exception& e) {}
6390

6491
atmega::close(fd);

0 commit comments

Comments
 (0)