@@ -25,6 +25,16 @@ namespace Alf {
2525// / Length of the success/failure prefix that's returned in RPC calls
2626constexpr size_t PREFIX_LENGTH = 8 ;
2727
28+ // / Converts a 32-bit hex number string (possibly with 0x prefix)
29+ inline uint32_t convertHexString (const std::string& string)
30+ {
31+ uint64_t n = std::stoul (string, nullptr , 16 );
32+ if (n > std::numeric_limits<uint32_t >::max ()) {
33+ BOOST_THROW_EXCEPTION (std::out_of_range (" Parameter does not fit in 32-bit unsigned int" ));
34+ }
35+ return n;
36+ }
37+
2838// / We use this in a few places because DIM insists on non-const char*
2939inline std::vector<char > toCharBuffer (const std::string& string, bool addTerminator = true )
3040{
@@ -161,7 +171,7 @@ class RegisterReadRpc: DimRpcInfoWrapper
161171
162172 uint32_t readRegister (uint64_t registerAddress)
163173 {
164- setString (std::to_string ( registerAddress));
174+ setString (( boost::format ( " %u " ) % registerAddress). str ( ));
165175 return boost::lexical_cast<uint32_t >(stripPrefix (getString ()));
166176 }
167177};
@@ -176,8 +186,7 @@ class RegisterWriteRpc: DimRpcInfoWrapper
176186
177187 void writeRegister (uint64_t registerAddress, uint32_t registerValue)
178188 {
179- auto string = std::to_string (registerAddress) + ' ,' + std::to_string (registerValue);
180- setString (string);
189+ setString ((boost::format (" %u,%u" ) % registerAddress % registerValue).str ());
181190 getString ();
182191 }
183192};
@@ -192,8 +201,7 @@ class RegisterWriteBlockRpc: DimRpcInfoWrapper
192201
193202 void writeRegister (uint64_t registerAddress, uint32_t registerValue)
194203 {
195- auto string = std::to_string (registerAddress) + ' ,' + std::to_string (registerValue);
196- setString (string);
204+ setString ((boost::format (" %u,%u" ) % registerAddress % registerValue).str ());
197205 getString ();
198206 }
199207};
@@ -223,8 +231,7 @@ class ScaWriteRpc: DimRpcInfoWrapper
223231
224232 std::string write (uint32_t command, uint32_t data)
225233 {
226- auto string = std::to_string (data) + ' ,' + std::to_string (command);
227- setString (string);
234+ setString ((boost::format (" 0x%x,0x%x" ) % command % data).str ());
228235 return stripPrefix (getString ());
229236 }
230237};
@@ -239,7 +246,7 @@ class ScaGpioWriteRpc: DimRpcInfoWrapper
239246
240247 std::string write (uint32_t data)
241248 {
242- setString (std::to_string ( data));
249+ setString (( boost::format ( " 0x%x " ) % data). str ( ));
243250 return stripPrefix (getString ());
244251 }
245252};
0 commit comments