Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Robobin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
plw1g21
Robobin
Commits
5d577645
Commit
5d577645
authored
5 months ago
by
Paul-Winpenny
Browse files
Options
Downloads
Patches
Plain Diff
Update ConnectionPageViewModel.cs
parent
7483fcb1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
App/RobobinApp/ViewModels/ConnectionPageViewModel.cs
+26
-23
26 additions, 23 deletions
App/RobobinApp/ViewModels/ConnectionPageViewModel.cs
with
26 additions
and
23 deletions
App/RobobinApp/ViewModels/ConnectionPageViewModel.cs
+
26
−
23
View file @
5d577645
...
...
@@ -449,21 +449,22 @@ namespace RobobinApp.ViewModels
catch
(
Exception
ex
)
{
Debug
.
WriteLine
(
$"Read attempt
{
attempt
}
failed:
{
ex
.
Message
}
"
);
if
(
attempt
==
retryCount
)
// Attempt to reconnect after a failed read
if
(
await
TryReconnect
())
{
Debug
.
WriteLine
(
"Max retry attempts reached for reading. Attempting reconnection..."
);
if
(
await
TryReconnect
())
{
Debug
.
WriteLine
(
"Reconnected successfully. Retrying read operation."
);
return
await
ReadOperationAsync
(
retryCount
);
// Retry after reconnection
}
Debug
.
WriteLine
(
"Reconnection failed. Returning failure."
);
return
"Failure"
;
Debug
.
WriteLine
(
"Reconnected successfully. Retrying read operation."
);
continue
;
// Continue to the next attempt after reconnect
}
await
Task
.
Delay
(
1000
);
Debug
.
WriteLine
(
"Reconnection failed. Returning failure."
);
return
"Failure"
;
}
// Wait before the next attempt
await
Task
.
Delay
(
1000
);
}
return
"Failure"
;
return
"Failure"
;
// This will only be reached if all attempts failed without reconnection
}
private
async
Task
<
string
>
WriteOperationAsync
(
string
command
,
string
arguments
=
""
,
int
retryCount
=
3
)
...
...
@@ -476,7 +477,7 @@ namespace RobobinApp.ViewModels
string
joinedData
=
$"
{
command
}
:
{
arguments
}
"
;
byte
[]
data
=
Encoding
.
UTF8
.
GetBytes
(
joinedData
);
Debug
.
WriteLine
(
$"WRITE COMMAND
{
joinedData
}
,
UUID:
{
WriteCharacteristic
.
Uuid
}
"
);
Debug
.
WriteLine
(
$"WRITE COMMAND
{
joinedData
}
UUID:
{
WriteCharacteristic
.
Uuid
}
"
);
for
(
int
attempt
=
1
;
attempt
<=
retryCount
;
attempt
++)
{
...
...
@@ -489,21 +490,22 @@ namespace RobobinApp.ViewModels
catch
(
Exception
ex
)
{
Debug
.
WriteLine
(
$"Write attempt
{
attempt
}
failed:
{
ex
.
Message
}
"
);
if
(
attempt
==
retryCount
)
// Attempt to reconnect after a failed write
if
(
await
TryReconnect
())
{
Debug
.
WriteLine
(
"Max retry attempts reached for writing. Attempting reconnection..."
);
if
(
await
TryReconnect
())
{
Debug
.
WriteLine
(
"Reconnected successfully. Retrying write operation."
);
return
await
WriteOperationAsync
(
command
,
arguments
,
retryCount
);
// Retry after reconnection
}
Debug
.
WriteLine
(
"Reconnection failed. Returning failure."
);
return
"Failure"
;
Debug
.
WriteLine
(
"Reconnected successfully. Retrying write operation."
);
continue
;
// Continue to the next attempt after reconnect
}
await
Task
.
Delay
(
1000
);
Debug
.
WriteLine
(
"Reconnection failed. Returning failure."
);
return
"Failure"
;
}
// Wait before the next attempt
await
Task
.
Delay
(
1000
);
}
return
"Failure"
;
return
"Failure"
;
// This will only be reached if all attempts failed without reconnection
}
private
async
Task
<
bool
>
TryReconnect
()
...
...
@@ -587,6 +589,7 @@ namespace RobobinApp.ViewModels
WriteCharacteristic
=
null
;
ReadWriteService
=
null
;
IsWifiNetworkSelectionVisible
=
false
;
ScanDevices
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment