SELKIELogger  1.0.0
DWSample.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Swansea University
3  *
4  * This file is part of the SELKIELogger suite of tools.
5  *
6  * SELKIELogger is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * SELKIELogger is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this SELKIELogger product.
18  * If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include <stdbool.h>
22 #include <stddef.h>
23 #include <stdio.h>
24 #include <string.h>
25 
26 #include "DWMessages.h"
27 #include "DWTypes.h"
28 
38 bool test(const char *in);
39 
46 int main(void) {
47  const char *l1 = "0618,B34D,8EE9,2DE4,2F4C\r";
48  const char *l2 = "0424,4CBA,2FC8,2F84,F09E\r";
49  const char *l3 = "001E,7FFF,80E0,0300,1689\r";
50 
51  bool rv = true;
52  rv &= test(l1);
53  rv &= test(l2);
54  rv &= test(l3);
55 
56  return rv ? 0 : 1;
57 }
58 
65 bool test(const char *in) {
66  dw_hxv thxv = {0};
67  size_t slen = strlen(in);
68  bool rv = dw_string_hxv(in, &slen, &thxv);
69 
70  uint16_t cycdat = dw_hxv_cycdat(&thxv);
71  int16_t north = dw_hxv_north(&thxv);
72  int16_t west = dw_hxv_west(&thxv);
73  int16_t vert = dw_hxv_vertical(&thxv);
74  uint16_t parity = dw_hxv_parity(&thxv);
75 
76  fprintf(stdout,
77  "Line 0x%02x: Status %02d, North: %+5.2fm, West: %+5.2fm, Vertical: "
78  "%5.2fm.\n",
79  thxv.lines, thxv.status, north / 100.0, west / 100.0, vert / 100.0);
80  fprintf(stdout, "\tCyclic data: 0x%04x. Parity bytes: 0x%04x\n", cycdat, parity);
81  return rv;
82 }
bool test(const char *in)
Definition: DWSample.c:65
int main(void)
Definition: DWSample.c:46
int16_t dw_hxv_vertical(const dw_hxv *in)
Extract vertical displacement component from HXV input line.
Definition: DWMessages.c:39
int16_t dw_hxv_west(const dw_hxv *in)
Extract west displacement component from HXV input line.
Definition: DWMessages.c:62
int16_t dw_hxv_north(const dw_hxv *in)
Extract north displacement component from HXV input line.
Definition: DWMessages.c:52
uint16_t dw_hxv_parity(const dw_hxv *in)
Extract parity word from HXV input line.
Definition: DWMessages.c:72
uint16_t dw_hxv_cycdat(const dw_hxv *in)
Extract cyclic data word from HXV input line.
Definition: DWMessages.c:31
bool dw_string_hxv(const char *in, size_t *end, dw_hxv *out)
Read a line of HXV data from string and convert.
Definition: DWTypes.c:92
Internal representation of a Datawell HXV message.
Definition: DWTypes.h:99
uint8_t status
Error count. 0 or 1 OK, 2+ error.
Definition: DWTypes.h:100
uint8_t lines
Transmitted line number.
Definition: DWTypes.h:101