[Git][NTPsec/ntpsec][master] 6 commits: libparse: add get_msb_ushort(), with tests.
Gary E. Miller
gitlab at mg.gitlab.com
Tue May 16 01:04:20 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
e728abbe by Gary E. Miller at 2017-05-15T17:00:18-07:00
libparse: add get_msb_ushort(), with tests.
- - - - -
44f1d154 by Gary E. Miller at 2017-05-15T17:10:17-07:00
tests: use the right get_msb_*short()
- - - - -
891e1cc6 by Gary E. Miller at 2017-05-15T17:10:38-07:00
change "(unsigned short)getshort()' to get_msb_ushort()
- - - - -
16bd0afc by Gary E. Miller at 2017-05-15T17:34:09-07:00
binio: move 2 private "static short getshort()" into one lib function.
- - - - -
4cfe47fb by Gary E. Miller at 2017-05-15T17:41:29-07:00
tests: add test for getmsb_short()
- - - - -
0c3eb76b by Gary E. Miller at 2017-05-15T17:50:01-07:00
remove pointless casts of (unsigned char*) to (unsigned char *).
- - - - -
5 changed files:
- include/binio.h
- libparse/binio.c
- libparse/clk_trimtsip.c
- ntpd/refclock_generic.c
- tests/libparse/binio.c
Changes:
=====================================
include/binio.h
=====================================
--- a/include/binio.h
+++ b/include/binio.h
@@ -17,7 +17,9 @@ int32_t get_lsb_int32 (unsigned char **);
#define get_lsb_uint16( _x_ ) ((uint16_t) get_lsb_int16( _x_ ))
#define get_lsb_uint32( _x_ ) ((uint32_t) get_lsb_int32( _x_ ))
-long get_msb_short (unsigned char **);
+unsigned short get_msb_ushort(unsigned char *);
+short getmsb_short(unsigned char *);
+long get_msb_short(unsigned char **);
#endif
/*
=====================================
libparse/binio.c
=====================================
--- a/libparse/binio.c
+++ b/libparse/binio.c
@@ -47,6 +47,22 @@ get_lsb_int32(
return retval;
}
+unsigned short
+get_msb_ushort(
+ unsigned char *p
+ )
+{
+ return (unsigned short) get_msb_short(&p);
+}
+
+short
+getmsb_short(
+ unsigned char *p
+ )
+{
+ return get_msb_short(&p);
+}
+
long
get_msb_short(
unsigned char **bufpp
=====================================
libparse/clk_trimtsip.c
=====================================
--- a/libparse/clk_trimtsip.c
+++ b/libparse/clk_trimtsip.c
@@ -164,14 +164,6 @@ inp_tsip(
return PARSE_INP_SKIP;
}
-static short
-getshort(
- unsigned char *p
- )
-{
- return (short) get_msb_short(&p);
-}
-
/*
* cvt_trimtsip
*
@@ -216,7 +208,7 @@ cvt_trimtsip(
case CMD_RCURTIME:
{ /* GPS time */
l_fp secs;
- int week = getshort((unsigned char *)&mb(4));
+ int week = getmsb_short(&mb(4));
l_fp utcoffset;
l_fp gpstime;
@@ -316,15 +308,21 @@ cvt_trimtsip(
unsigned char *lbp;
/* UTC correction data - derive a leap warning */
- int tls = t->t_gpsutc = (unsigned short) getshort((unsigned char *)&mb(12)); /* current leap correction (GPS-UTC) */
- int tlsf = t->t_gpsutcleap = (unsigned short) getshort((unsigned char *)&mb(24)); /* new leap correction */
+ /* current leap correction (GPS-UTC) */
+ int tls = t->t_gpsutc = get_msb_ushort(&mb(12));
+
+ /* new leap correction */
+ int tlsf = t->t_gpsutcleap = get_msb_ushort(&mb(24));
- t->t_weekleap = (unsigned short) getshort((unsigned char *)&mb(20)); /* week no of leap correction */
+ /* week no of leap correction */
+ t->t_weekleap = get_msb_ushort(&mb(20));
if (t->t_weekleap < GPSWRAP)
t->t_weekleap = (unsigned short)(t->t_weekleap + GPSWEEKS);
- t->t_dayleap = (unsigned short) getshort((unsigned char *)&mb(22)); /* day in week of leap correction */
- t->t_week = (unsigned short) getshort((unsigned char *)&mb(18)); /* current week no */
+ /* day in week of leap correction */
+ t->t_dayleap = get_msb_ushort(&mb(22));
+ /* current week no */
+ t->t_week = get_msb_ushort(&mb(18));
if (t->t_week < GPSWRAP)
/* coverity[copy_paste_error] */
t->t_week = (unsigned short)(t->t_weekleap + GPSWEEKS);
=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -4889,14 +4889,6 @@ getdbl(
return uval.dv;
}
-static short
-getshort(
- unsigned char *p
- )
-{
- return (short) get_msb_short(&p);
-}
-
/*--------------------------------------------------
* trimbletsip_message - process trimble messages
*/
@@ -4975,7 +4967,8 @@ trimbletsip_message(
{
case CMD_RCURTIME:
t = ap(pbuffer, sizeof(pbuffer), t, "%f, %d, %f",
- getflt((unsigned char *)&mb(0)), getshort((unsigned char *)&mb(4)),
+ getflt((unsigned char *)&mb(0)),
+ getmsb_short(&mb(4)),
getflt((unsigned char *)&mb(6)));
break;
@@ -5118,11 +5111,11 @@ trimbletsip_message(
case CMD_RUTCPARAM:
{
float t0t = getflt((unsigned char *)&mb(14));
- short wnt = getshort((unsigned char *)&mb(18));
- short dtls = getshort((unsigned char *)&mb(12));
- short wnlsf = getshort((unsigned char *)&mb(20));
- short dn = getshort((unsigned char *)&mb(22));
- short dtlsf = getshort((unsigned char *)&mb(24));
+ short wnt = getmsb_short(&mb(18));
+ short dtls = getmsb_short(&mb(12));
+ short wnlsf = getmsb_short(&mb(20));
+ short dn = getmsb_short(&mb(22));
+ short dtlsf = getmsb_short(&mb(24));
if ((int)t0t != 0)
{
=====================================
tests/libparse/binio.c
=====================================
--- a/tests/libparse/binio.c
+++ b/tests/libparse/binio.c
@@ -335,6 +335,96 @@ TEST(binio, get_msb_short4) {
TEST_ASSERT_EQUAL_HEX64( -0x8000L, ret );
}
+TEST(binio, getmsb_short0) {
+ int ret;
+ unsigned char zero[2] = { 0, 0};
+
+ ret = getmsb_short( zero);
+
+ TEST_ASSERT_EQUAL_INT( 0, ret );
+}
+
+TEST(binio, getmsb_short1) {
+ int ret;
+ unsigned char zero[2] = { 2, 1};
+
+ ret = getmsb_short( zero);
+
+ TEST_ASSERT_EQUAL_INT( 0x0201L, ret );
+}
+
+TEST(binio, getmsb_short2) {
+ int ret;
+ unsigned char zero[2] = { 1, 2};
+
+ ret = getmsb_short( zero);
+
+ TEST_ASSERT_EQUAL_INT( 0x0102L, ret );
+}
+
+TEST(binio, getmsb_short3) {
+ int ret;
+ unsigned char zero[2] = { 0xff, 0xff};
+
+ ret = getmsb_short( zero);
+
+ TEST_ASSERT_EQUAL_INT( -1, ret );
+}
+
+TEST(binio, getmsb_short4) {
+ int ret;
+ unsigned char zero[2] = { 0x80, 0};
+
+ ret = getmsb_short( zero);
+
+ TEST_ASSERT_EQUAL_INT( -0x8000L, ret );
+}
+
+TEST(binio, get_msb_ushort0) {
+ uint32_t ret;
+ unsigned char zero[2] = { 0, 0};
+
+ ret = get_msb_ushort( zero);
+
+ TEST_ASSERT_EQUAL_HEX32( 0, ret );
+}
+
+TEST(binio, get_msb_ushort1) {
+ uint32_t ret;
+ unsigned char zero[2] = { 2, 1};
+
+ ret = get_msb_ushort( zero);
+
+ TEST_ASSERT_EQUAL_HEX32( 0x0201UL, ret );
+}
+
+TEST(binio, get_msb_ushort2) {
+ uint32_t ret;
+ unsigned char zero[2] = { 1, 2};
+
+ ret = get_msb_ushort( zero);
+
+ TEST_ASSERT_EQUAL_HEX32( 0x0102UL, ret );
+}
+
+TEST(binio, get_msb_ushort3) {
+ uint32_t ret;
+ unsigned char zero[2] = { 0xff, 0xff};
+
+ ret = get_msb_ushort( zero);
+
+ TEST_ASSERT_EQUAL_HEX32( 0x0FFFFUL, ret );
+}
+
+TEST(binio, get_msb_ushort4) {
+ uint32_t ret;
+ unsigned char zero[2] = { 0x80, 0};
+
+ ret = get_msb_ushort( zero);
+
+ TEST_ASSERT_EQUAL_HEX32( 0x8000UL, ret );
+}
+
TEST_GROUP_RUNNER(binio) {
/* LSB int tests */
RUN_TEST_CASE(binio, get_lsb_int160);
@@ -374,4 +464,17 @@ TEST_GROUP_RUNNER(binio) {
RUN_TEST_CASE(binio, get_msb_short2);
RUN_TEST_CASE(binio, get_msb_short3);
RUN_TEST_CASE(binio, get_msb_short4);
+
+ RUN_TEST_CASE(binio, getmsb_short0);
+ RUN_TEST_CASE(binio, getmsb_short1);
+ RUN_TEST_CASE(binio, getmsb_short2);
+ RUN_TEST_CASE(binio, getmsb_short3);
+ RUN_TEST_CASE(binio, getmsb_short4);
+
+ RUN_TEST_CASE(binio, get_msb_ushort0);
+ RUN_TEST_CASE(binio, get_msb_ushort1);
+ RUN_TEST_CASE(binio, get_msb_ushort2);
+ RUN_TEST_CASE(binio, get_msb_ushort3);
+ RUN_TEST_CASE(binio, get_msb_ushort4);
+
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/08e137821fa89cd78f8d9d49fc162981c6b4a54c...0c3eb76b1ad63c8081ce3cfdda84400b85d117ec
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/08e137821fa89cd78f8d9d49fc162981c6b4a54c...0c3eb76b1ad63c8081ce3cfdda84400b85d117ec
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170516/26b5a8ec/attachment.html>
More information about the vc
mailing list