-
Notifications
You must be signed in to change notification settings - Fork 19.5k
AP_RangeFinder: Add GRF250/GRF500 serial driver #30043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rishabsingh3003
wants to merge
5
commits into
ArduPilot:master
Choose a base branch
from
rishabsingh3003:lightware_grf_serial
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
afb1213
AP_LightWareSerial: Move LightWareSerial base class from AP_Proximity
rishabsingh3003 e04b622
ardupilotwaf: add AP_LightWareSerial library
rishabsingh3003 d7d081c
AP_Proximity: Remove LightWareSerial base class from AP_Proximity
rishabsingh3003 aef8a77
AP_RangeFinder: Add support for LightWare GRF250/500
rishabsingh3003 468b162
AP_Periph: Include AP_LightWareSerial library
rishabsingh3003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -13,72 +13,72 @@ | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "AP_Proximity_LightWareSerial.h" | ||
#include "AP_LightWareSerial.h" | ||
|
||
#if AP_PROXIMITY_LIGHTWARE_SF45B_ENABLED || AP_RANGEFINDER_LIGHTWARE_GRF_ENABLED | ||
|
||
#if HAL_PROXIMITY_ENABLED | ||
#include <AP_Common/AP_Common.h> | ||
#include <AP_HAL/AP_HAL.h> | ||
#include <AP_HAL/utility/sparse-endian.h> | ||
#include <AP_Math/crc.h> | ||
#include <GCS_MAVLink/GCS.h> | ||
|
||
extern const AP_HAL::HAL& hal; | ||
|
||
#define PROXIMITY_LIGHTWARE_HEADER 0xAA | ||
#define LIGHTWARE_HEADER 0xAA | ||
|
||
// send message to sensor | ||
void AP_Proximity_LightWareSerial::send_message(uint8_t msgid, bool write, const uint8_t *payload, uint16_t payload_len) | ||
void AP_LightWareSerial::send_message(uint8_t msgid, bool write, const uint8_t *payload, uint16_t payload_len) | ||
{ | ||
if ((_uart == nullptr) || (payload_len > PROXIMITY_LIGHTWARE_PAYLOAD_LEN_MAX)) { | ||
if ((_uart_ref == nullptr) || (payload_len > LIGHTWARE_PAYLOAD_LEN_MAX)) { | ||
return; | ||
} | ||
|
||
// check for sufficient space in outgoing buffer | ||
if (_uart->txspace() < payload_len + 6U) { | ||
if (_uart_ref->txspace() < payload_len + 6U) { | ||
return; | ||
} | ||
|
||
// write header | ||
_uart->write((uint8_t)PROXIMITY_LIGHTWARE_HEADER); | ||
uint16_t crc = crc_xmodem_update(0, PROXIMITY_LIGHTWARE_HEADER); | ||
_uart_ref->write((uint8_t)LIGHTWARE_HEADER); | ||
uint16_t crc = crc_xmodem_update(0, LIGHTWARE_HEADER); | ||
|
||
// write flags including payload length | ||
const uint16_t flags = ((payload_len+1) << 6) | (write ? 0x01 : 0); | ||
_uart->write(LOWBYTE(flags)); | ||
_uart_ref->write(LOWBYTE(flags)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just leave this named |
||
crc = crc_xmodem_update(crc, LOWBYTE(flags)); | ||
_uart->write(HIGHBYTE(flags)); | ||
_uart_ref->write(HIGHBYTE(flags)); | ||
crc = crc_xmodem_update(crc, HIGHBYTE(flags)); | ||
|
||
// msgid | ||
_uart->write(msgid); | ||
_uart_ref->write(msgid); | ||
crc = crc_xmodem_update(crc, msgid); | ||
|
||
// payload | ||
if ((payload_len > 0) && (payload != nullptr)) { | ||
for (uint16_t i = 0; i < payload_len; i++) { | ||
_uart->write(payload[i]); | ||
_uart_ref->write(payload[i]); | ||
crc = crc_xmodem_update(crc, payload[i]); | ||
} | ||
} | ||
|
||
// checksum | ||
_uart->write(LOWBYTE(crc)); | ||
_uart->write(HIGHBYTE(crc)); | ||
_uart_ref->write(LOWBYTE(crc)); | ||
_uart_ref->write(HIGHBYTE(crc)); | ||
} | ||
|
||
// process one byte received on serial port | ||
// returns true if a complete message has been received | ||
// state is stored in _msg structure | ||
bool AP_Proximity_LightWareSerial::parse_byte(uint8_t b) | ||
bool AP_LightWareSerial::parse_byte(uint8_t b) | ||
{ | ||
// check that payload buffer is large enough | ||
static_assert(ARRAY_SIZE(_msg.payload) == PROXIMITY_LIGHTWARE_PAYLOAD_LEN_MAX, "AP_Proximity_LightWareSerial: check _msg.payload array size"); | ||
static_assert(ARRAY_SIZE(_msg.payload) == LIGHTWARE_PAYLOAD_LEN_MAX, "AP_LightWareSerial: check _msg.payload array size"); | ||
|
||
// process byte depending upon current state | ||
switch (_parse_state) { | ||
|
||
case ParseState::HEADER: | ||
if (b == PROXIMITY_LIGHTWARE_HEADER) { | ||
if (b == LIGHTWARE_HEADER) { | ||
_crc_expected = crc_xmodem_update(0, b); | ||
_parse_state = ParseState::FLAGS_L; | ||
} | ||
|
@@ -94,7 +94,7 @@ bool AP_Proximity_LightWareSerial::parse_byte(uint8_t b) | |
_msg.flags_high = b; | ||
_crc_expected = crc_xmodem_update(_crc_expected, b); | ||
_msg.payload_len = UINT16_VALUE(_msg.flags_high, _msg.flags_low) >> 6; | ||
if ((_msg.payload_len == 0) || (_msg.payload_len > PROXIMITY_LIGHTWARE_PAYLOAD_LEN_MAX)) { | ||
if ((_msg.payload_len == 0) || (_msg.payload_len > LIGHTWARE_PAYLOAD_LEN_MAX)) { | ||
// invalid payload length, abandon message | ||
_parse_state = ParseState::HEADER; | ||
} else { | ||
|
@@ -141,4 +141,5 @@ bool AP_Proximity_LightWareSerial::parse_byte(uint8_t b) | |
return false; | ||
} | ||
|
||
#endif // HAL_PROXIMITY_ENABLED | ||
#endif // AP_PROXIMITY_LIGHTWARE_SF45B_ENABLED || AP_RANGEFINDER_LIGHTWARE_GRF_ENABLED | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create an
AP_LightWareSerial_config.h
and a newAP_LIGHTWARESERIAL_ENABLED
define (set to(AP_PROXIMITY_LIGHTWARE_SF45B_ENABLED || AP_RANGEFINDER_LIGHTWARE_GRF_ENABLED)
)