From 91fb2d40f286c1f3b0af9146d66d424f4e8c5c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sat, 3 Aug 2013 22:18:11 +0100 Subject: Implement the correct checksum algorithm. Unlike what I though, OneTouch2 does not use CRC32 Sick algorithm, but a very stupid full 16-bit modulo sum of the bytes in the reply. This is very simple and does not require GPLv3 code at all. --- test/test_lifescan.py | 7 ++++--- test/test_otultra2.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/test_lifescan.py b/test/test_lifescan.py index 774567d..a7446e0 100644 --- a/test/test_lifescan.py +++ b/test/test_lifescan.py @@ -20,10 +20,11 @@ from glucometerutils import exceptions class TestOTUltra2(unittest.TestCase): def testChecksum(self): checksum = lifescan_common.calculate_checksum(bytes('T', 'ascii')) - self.assertEqual(0x5400, checksum) + self.assertEqual(0x0054, checksum) - checksum = lifescan_common.calculate_checksum(bytes('TestString', 'ascii')) - self.assertEqual(0x0643, checksum) + checksum = lifescan_common.calculate_checksum( + bytes('T "SAT","08/03/13","22:12:00 "', 'ascii')) + self.assertEqual(0x0608, checksum) if __name__ == '__main__': unittest.main() diff --git a/test/test_otultra2.py b/test/test_otultra2.py index 6ffea83..98fffc8 100644 --- a/test/test_otultra2.py +++ b/test/test_otultra2.py @@ -48,7 +48,7 @@ class TestOTUltra2(unittest.TestCase): def testInvalidSerialNumber(self): self.mock_readline.return_value = bytes( - '@ "12345678O" E105\r', 'ascii') + '@ "12345678O" 0297\r', 'ascii') self.assertRaises(lifescan_common.InvalidSerialNumber, self.device.get_serial_number) -- cgit v1.2.3