-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from iq-motion-control/persistent_memory
Persistent memory
- Loading branch information
Showing
4 changed files
with
150 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
Copyright 2019 IQinetics Technologies, Inc [email protected] | ||
This file is part of the IQ C++ API. | ||
IQ C++ API is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
IQ C++ API is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* | ||
Name: client_communication.cpp | ||
Last update: 4/12/2019 by Matthew Piccoli | ||
Author: Matthew Piccoli | ||
Contributors: Raphael Van Hoffelen | ||
*/ | ||
|
||
#include "client_communication.hpp" | ||
|
||
int8_t ParseMsg(uint8_t* rx_data, uint8_t rx_length, | ||
ClientEntryAbstract** entry_array, uint8_t entry_length) | ||
{ | ||
uint8_t type_idn = rx_data[0]; | ||
uint8_t sub_idn = rx_data[1]; | ||
uint8_t obj_idn = rx_data[2] >> 2; // high 6 bits are obj_idn | ||
Access dir = static_cast<Access>(rx_data[2] & 0b00000011); // low two bits | ||
|
||
// if we have a reply (we only parse replies here) | ||
if(dir == kReply) | ||
{ | ||
// if sub_idn is within array range (safe to access array at this location) | ||
if(sub_idn < entry_length) | ||
{ | ||
// if there is a ClientEntry object at this sub_idn | ||
if(entry_array[sub_idn] != nullptr) | ||
{ | ||
// if the type and obj identifiers match | ||
if(entry_array[sub_idn]->type_idn_ == type_idn && | ||
entry_array[sub_idn]->obj_idn_ == obj_idn) | ||
{ | ||
// ... then we have a valid message | ||
entry_array[sub_idn]->Reply(&rx_data[3],rx_length-3); | ||
return 1; // I parsed something | ||
} | ||
} | ||
} | ||
} | ||
return 0; // I didn't parse anything | ||
} | ||
|
||
int8_t ParseMsg(uint8_t* rx_data, uint8_t rx_length, | ||
ClientEntryAbstract& entry) | ||
{ | ||
uint8_t type_idn = rx_data[0]; | ||
uint8_t sub_idn = rx_data[1]; | ||
uint8_t obj_idn = rx_data[2] >> 2; // high 6 bits are obj_idn | ||
Access dir = static_cast<Access>(rx_data[2] & 0b00000011); // low two bits | ||
|
||
// if we have a reply (we only parse replies here) | ||
if(dir == kReply) | ||
{ | ||
// if the type and obj identifiers match | ||
if(entry.type_idn_ == type_idn && | ||
entry.obj_idn_ == obj_idn && entry.sub_idn_ == sub_idn) | ||
{ | ||
// ... then we have a valid message | ||
entry.Reply(&rx_data[3],rx_length-3); | ||
return 1; // I parsed something | ||
} | ||
} | ||
return 0; // I didn't parse anything | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright 2019 IQinetics Technologies, Inc [email protected] | ||
This file is part of the IQ C++ API. | ||
IQ C++ API is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
IQ C++ API is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* | ||
Name: persistent_memory_client.hpp | ||
Last update: 4/12/2019 by Matthew Piccoli | ||
Author: Matthew Piccoli | ||
Contributors: Raphael Van Hoffelen | ||
*/ | ||
|
||
#ifndef PERSISTENT_MEMORY_CLIENT_HPP_ | ||
#define PERSISTENT_MEMORY_CLIENT_HPP_ | ||
|
||
#include "client_communication.hpp" | ||
|
||
const uint8_t kTypePersistentMemory = 11; | ||
|
||
class PowerMonitorClient: public ClientAbstract{ | ||
public: | ||
PowerMonitorClient(uint8_t obj_idn): | ||
ClientAbstract( kTypePersistentMemory, obj_idn), | ||
erase_( kTypePersistentMemory, obj_idn, kSubErase), | ||
revert_to_default_( kTypePersistentMemory, obj_idn, kSubRevertToDefault) | ||
{}; | ||
|
||
// Client Entries | ||
// Control commands | ||
ClientEntryVoid erase_; | ||
ClientEntryVoid revert_to_default_; | ||
|
||
|
||
void ReadMsg(uint8_t* rx_data, uint8_t rx_length) | ||
{ | ||
static const uint8_t kEntryLength = kSubRevertToDefault+1; | ||
ClientEntryAbstract* entry_array[kEntryLength] = { | ||
&erase_, // 0 | ||
&revert_to_default_ // 1 | ||
}; | ||
|
||
ParseMsg(rx_data, rx_length, entry_array, kEntryLength); | ||
} | ||
|
||
private: | ||
static const uint8_t kSubErase = 0; | ||
static const uint8_t kSubRevertToDefault = 1; | ||
}; | ||
|
||
#endif /* PERSISTENT_MEMORY_CLIENT_HPP_ */ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.