fixed battery voltage display,

ignoring firstline when parsing response message
main
Jonas Arnold 4 years ago
parent 8cc965ef51
commit decb1f3b17
  1. 2
      ADIS_Csharp/RobotClientWpf/Views/MainView.xaml
  2. 12
      ADIS_Csharp/RobotLib/Battery/DevBattery.cs
  3. 19
      ADIS_ESP32_Eclipse/main/robo_wrapper.c

@ -23,7 +23,7 @@
</GroupBox>
<GroupBox Header="Robot battery" Margin="10" HorizontalAlignment="Right" Width="180">
<StackPanel Orientation="Horizontal">
<TextBox x:Name="tbRoboVoltage" Height="25" Width="150" FontSize="30" IsReadOnly="True" TextWrapping="NoWrap" HorizontalAlignment="Left"/>
<TextBox x:Name="tbRoboVoltage" Height="25" Width="100" FontSize="15" IsReadOnly="True" TextWrapping="NoWrap" HorizontalAlignment="Left">NaN</TextBox>
<Label Content="V" Margin="10 0"/>
</StackPanel>
</GroupBox>

@ -45,14 +45,18 @@ namespace RobotLib.Battery
{
if (fromTopic == TOPIC_ROBO_RESP_BATTERY)
{
var parsedVoltageString = GetValueFromMesage<string>("voltage", message);
if (parsedVoltageString == null) parsedVoltageString = "?";
var parsedString = GetValueFromMesage<string>("voltage", message);
if (parsedString == null) parsedString = "?";
// example message = "Battery: 1.25 V"
var valueUnit = message.Trim().Split(' ');
var valueUnit = parsedString.Trim().Split(' ');
string voltage = valueUnit[0].Trim();
float fVoltage = float.NaN;
this.Voltage = float.Parse(voltage);
if(float.TryParse(voltage, out fVoltage))
{
this.Voltage = fVoltage;
}
}
}

@ -114,16 +114,8 @@ bool Robo_Wrapper_GetBatteryVoltage(unsigned char *voltage){
}
static bool getValueOfStatusResponse(unsigned char* response, const unsigned char* key, unsigned char* value, size_t valueStringLen){
int16_t pos = McuUtility_strFind(response, (unsigned char*)key);
unsigned char extractedString[50] = "";
if(pos == -1){ // error string not found = -1
ESP_LOGE(TAG, "Could not find key %s in response.", key);
return false;
}
unsigned char *p;
p = (unsigned char*)response + pos;
p = (unsigned char*)response;
// skip first line (if the keyword would also appear in the headline, this is an issue)
while(*p!='\n'){
@ -131,6 +123,14 @@ static bool getValueOfStatusResponse(unsigned char* response, const unsigned cha
}
p+=1; // skip newline
// find key
int16_t pos = McuUtility_strFind(p, (unsigned char*)key);
if(pos == -1){ // error string not found = -1
ESP_LOGE(TAG, "Could not find key %s in response.", key);
return false;
}
p+=pos; // move pointer to found key
// skip until colon
while(true){
if(*p==':'){
@ -147,6 +147,7 @@ static bool getValueOfStatusResponse(unsigned char* response, const unsigned cha
}
// extract value
unsigned char extractedString[50] = "";
uint8_t i = 0;
while(true){
if(*p == '\n'){

Loading…
Cancel
Save