Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
companion-software
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
CATS
companion-software
Commits
d57caebe
Commit
d57caebe
authored
8 months ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
contact deletion
parent
33bd949b
No related branches found
Branches containing commit
No related tags found
1 merge request
!2
Storage
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/controller.rs
+1
-2
1 addition, 2 deletions
src/controller.rs
src/storage.rs
+21
-5
21 additions, 5 deletions
src/storage.rs
with
22 additions
and
7 deletions
src/controller.rs
+
1
−
2
View file @
d57caebe
...
@@ -237,8 +237,7 @@ impl Element for Controller {
...
@@ -237,8 +237,7 @@ impl Element for Controller {
(
View
::
ContactView
(
cv
,
contact_id
,
_
),
k
)
=>
{
(
View
::
ContactView
(
cv
,
contact_id
,
_
),
k
)
=>
{
if
cv
.key_push
(
k
)
{
if
cv
.key_push
(
k
)
{
// TODO delete contact
self
.storage
.delete_contact
(
*
contact_id
);
// self.storage.contacts((.contacts.remove(*contact_id);
self
.cur_view
=
View
::
new_contacts
(
*
contact_id
,
&
self
.storage
.contacts
());
self
.cur_view
=
View
::
new_contacts
(
*
contact_id
,
&
self
.storage
.contacts
());
}
}
...
...
This diff is collapsed.
Click to expand it.
src/storage.rs
+
21
−
5
View file @
d57caebe
...
@@ -40,12 +40,27 @@ impl Storage {
...
@@ -40,12 +40,27 @@ impl Storage {
if
contact
.id
>=
usize
::
from
(
len
)
{
if
contact
.id
>=
usize
::
from
(
len
)
{
assert!
(
usize
::
from
(
len
)
<
MAX_CONTACTS
);
assert!
(
usize
::
from
(
len
)
<
MAX_CONTACTS
);
self
.contact_header.num_contacts
+=
1
;
self
.contact_header.num_contacts
+=
1
;
self
.contact_header
.write
(
self
);
let
ch
=
self
.contact_header
;
ch
.write
(
self
);
}
}
contact
.write
(
self
);
contact
.write
(
self
);
}
}
pub
fn
delete_contact
(
&
mut
self
,
contact_id
:
usize
)
{
assert!
(
contact_id
<
self
.contacts_len
());
// Shift every contact down
for
mut
c
in
self
.contacts
()
.skip
(
contact_id
+
1
)
{
c
.id
-=
1
;
c
.write
(
self
);
}
self
.contact_header.num_contacts
-=
1
;
let
ch
=
self
.contact_header
;
ch
.write
(
self
);
}
pub
fn
contacts
(
&
self
)
->
ContactIter
{
pub
fn
contacts
(
&
self
)
->
ContactIter
{
ContactIter
::
new
(
self
.contact_header.num_contacts
.into
())
ContactIter
::
new
(
self
.contact_header.num_contacts
.into
())
}
}
...
@@ -66,7 +81,7 @@ impl Storage {
...
@@ -66,7 +81,7 @@ impl Storage {
}
}
}
}
fn
write_data
(
&
self
,
start_addr
:
usize
,
buf
:
&
[
u8
])
{
fn
write_data
(
&
mut
self
,
start_addr
:
usize
,
buf
:
&
[
u8
])
{
let
start_sector
=
start_addr
/
SECTOR_SIZE
;
let
start_sector
=
start_addr
/
SECTOR_SIZE
;
let
num_sectors
=
buf
.len
()
/
SECTOR_SIZE
+
1
;
let
num_sectors
=
buf
.len
()
/
SECTOR_SIZE
+
1
;
let
diff
=
start_addr
%
SECTOR_SIZE
;
let
diff
=
start_addr
%
SECTOR_SIZE
;
...
@@ -98,7 +113,7 @@ impl Storage {
...
@@ -98,7 +113,7 @@ impl Storage {
buf
buf
}
}
fn
write_sector
(
&
self
,
start_addr
:
usize
,
buf
:
&
[
u8
;
4096
])
{
fn
write_sector
(
&
mut
self
,
start_addr
:
usize
,
buf
:
&
[
u8
;
4096
])
{
let
addr
:
u32
=
(
start_addr
-
FLASH_START
)
.try_into
()
.unwrap
();
let
addr
:
u32
=
(
start_addr
-
FLASH_START
)
.try_into
()
.unwrap
();
let
sector_size
=
u32
::
try_from
(
SECTOR_SIZE
)
.unwrap
();
let
sector_size
=
u32
::
try_from
(
SECTOR_SIZE
)
.unwrap
();
assert!
(
addr
%
sector_size
==
0
);
assert!
(
addr
%
sector_size
==
0
);
...
@@ -111,6 +126,7 @@ impl Storage {
...
@@ -111,6 +126,7 @@ impl Storage {
// Up to 100 contacts
// Up to 100 contacts
// 2 byte CRC checksum
// 2 byte CRC checksum
#[derive(Copy,
Clone)]
struct
ContactHeader
{
struct
ContactHeader
{
num_contacts
:
u8
,
num_contacts
:
u8
,
}
}
...
@@ -131,7 +147,7 @@ impl ContactHeader {
...
@@ -131,7 +147,7 @@ impl ContactHeader {
}
}
}
}
fn
write
(
&
self
,
storage
:
&
Storage
)
{
fn
write
(
&
self
,
storage
:
&
mut
Storage
)
{
let
mut
buf
=
[
0
;
CONTACT_HEADER_SIZE
];
let
mut
buf
=
[
0
;
CONTACT_HEADER_SIZE
];
buf
[
0
]
=
self
.num_contacts
;
buf
[
0
]
=
self
.num_contacts
;
let
checksum
=
X25
.checksum
(
&
[
self
.num_contacts
]);
let
checksum
=
X25
.checksum
(
&
[
self
.num_contacts
]);
...
@@ -186,7 +202,7 @@ impl Contact {
...
@@ -186,7 +202,7 @@ impl Contact {
})
})
}
}
fn
write
(
&
self
,
storage
:
&
Storage
)
{
fn
write
(
&
self
,
storage
:
&
mut
Storage
)
{
let
start_addr
=
CONTACT_HEADER_START
+
CONTACT_HEADER_SIZE
+
self
.id
*
CONTACT_LENGTH
;
let
start_addr
=
CONTACT_HEADER_START
+
CONTACT_HEADER_SIZE
+
self
.id
*
CONTACT_LENGTH
;
let
mut
buf
=
[
0
;
CONTACT_LENGTH
];
let
mut
buf
=
[
0
;
CONTACT_LENGTH
];
...
...
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