Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement a method to change the device id #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ uint32_t Device::getSerialNumber() const {
return m_serial_number;
}

canbus::Message Device::querySetId(uint8_t id, uint32_t serial_number) {
return queryWrite<uint32_t>(OID_CAN_ID, id, serial_number);
}

canbus::Message Device::queryTransmitPeriod() {
return queryRead(OID_TRANSMIT_PERIOD);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace power_whisperpower {
static const int OID_SOFTWARE_VERSION = 0x100A;
static const int OID_SERIAL_NUMBER = 0x1018;
static const int OID_TRANSMIT_PERIOD = 0x9100;
static const int OID_CAN_ID = 0x9200;

protected:
virtual void processRead(
Expand All @@ -60,6 +61,7 @@ namespace power_whisperpower {

bool isWaiting() const;

canbus::Message querySetId(uint8_t id, uint32_t serial_number);
/** How long we have been waiting for a specific reply from the device
*/
base::Time getElapsedWaitTime() const;
Expand Down
14 changes: 14 additions & 0 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ int main(int argc, char** argv)
}
std::cout << wp_device.getConfig() << std::endl;
}
else if (cmd == "set_id") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also update the usage message at the top of the file please (add the dc-cube command as well)

if (argc != 7)
{
std::cerr << "wrong number of arguments" << std::endl;
}
power_whisperpower::Device device(device_group, device_id);
waitResult(*can_device, device, device.querySerialNumber());
uint32_t serial_number = device.getSerialNumber();
int device_new_id(std::stoi(argv[6]));
waitResult(*can_device, device, device.querySetId(device_new_id, serial_number));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we verified in live that we should send the set id query to can id 0x600 (broadcast)


// TODO: get the actual returned id
std::cout << "New device Id: " << device_new_id << std::endl;
}

return 0;
}
Expand Down