Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Sep 14, 2020
1 parent c9eca2e commit 937b26d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lwgps/src/lwgps/lwgps.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
#define CRC_ADD(_gh, ch) (_gh)->p.crc_calc ^= (uint8_t)(ch)
#define TERM_ADD(_gh, ch) do { \
if ((_gh)->p.term_pos < (sizeof((_gh)->p.term_str) - 1)) { \
(_gh)->p.term_str[(_gh)->p.term_pos++] = (ch); \
(_gh)->p.term_str[(_gh)->p.term_pos] = 0; \
(_gh)->p.term_str[(_gh)->p.term_pos] = (ch);\
(_gh)->p.term_str[++(_gh)->p.term_pos] = 0; \
} \
} while (0)
#define TERM_NEXT(_gh) do { (_gh)->p.term_str[((_gh)->p.term_pos = 0)] = 0; (_gh)->p.term_num++; } while (0)
#define TERM_NEXT(_gh) do { (_gh)->p.term_str[((_gh)->p.term_pos = 0)] = 0; ++(_gh)->p.term_num; } while (0)

#define CIN(x) ((x) >= '0' && (x) <= '9')
#define CIHN(x) (((x) >= '0' && (x) <= '9') || ((x) >= 'a' && (x) <= 'f') || ((x) >= 'A' && (x) <= 'F'))
Expand Down Expand Up @@ -113,7 +113,7 @@ static lwgps_float_t
prv_parse_lat_long(lwgps_t* gh) {
lwgps_float_t ll, deg, min;

ll = prv_parse_float_number(gh, NULL); /* Parse value as double */
ll = prv_parse_float_number(gh, NULL); /* Parse value as double */
deg = FLT((int)((int)ll / 100)); /* Get absolute degrees value, interested in integer part only */
min = ll - (deg * FLT(100)); /* Get remaining part from full number, minutes */
ll = deg + (min / FLT(60.0)); /* Calculate latitude/longitude */
Expand Down Expand Up @@ -236,10 +236,10 @@ prv_parse_term(lwgps_t* gh) {
uint8_t index, term_num = gh->p.term_num - 4; /* Normalize term number from 4-19 to 0-15 */
uint16_t value;

index = 4 * (gh->p.data.gsv.stat_num - 1) + term_num / 4; /* Get array index */
index = ((gh->p.data.gsv.stat_num - 1) << 0x02) + (term_num >> 2); /* Get array index */
if (index < sizeof(gh->sats_in_view_desc) / sizeof(gh->sats_in_view_desc[0])) {
value = (uint16_t)prv_parse_number(gh, NULL); /* Parse number as integer */
switch (term_num % 4) {
switch (term_num & 0x03) {
case 0:
gh->sats_in_view_desc[index].num = value;
break;
Expand Down Expand Up @@ -435,7 +435,8 @@ lwgps_init(lwgps_t* gh) {
* \param[in] gh: GPS handle structure
* \param[in] data: Received data
* \param[in] len: Number of bytes to process
* \param[in] evt_fn: Event function to notify application layer
* \param[in] evt_fn: Event function to notify application layer.
* This parameter is available only if \ref LWGPS_CFG_STATUS is enabled
* \return `1` on success, `0` otherwise
*/
uint8_t
Expand Down

0 comments on commit 937b26d

Please sign in to comment.