Skip to content
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

validate_response implementation is problematic? #1

Open
szescxz opened this issue Nov 16, 2023 · 4 comments
Open

validate_response implementation is problematic? #1

szescxz opened this issue Nov 16, 2023 · 4 comments

Comments

@szescxz
Copy link

szescxz commented Nov 16, 2023

Tested with commit 4333888 on aarch64, applied a small patch to see what's going on:

--- a/quectel-timesync.c
+++ b/quectel-timesync.c
@@ -117,3 +117,4 @@
 	if (strlen("\"2023/10/07,23:07:16+08,1\"") != response_len) {
+		if (debug) fprintf(stdout, "example = %ld, actual = %d\n", strlen("\"2023/10/07,23:07:16+08,1\""), response_len);
 		return -1;
 	}

Result:

# quectel-timesync -v -p /dev/ttyUSB3
example = 26, actual = 27
Invalid response: "2023/11/16,07:05:34+32,0"
@szescxz
Copy link
Author

szescxz commented Nov 17, 2023

After digging further I realized my modem is using CRLF while quectel-timesync only handles LF.

--- a/quectel-timesync.c
+++ b/quectel-timesync.c

@@ -105,6 +105,9 @@ int read_response(int fd, const char *response, char *buf, int buf_size)
 				break;
 			case READ_STATE_CONTENT:
 				if (input_char == '\n') {
+					if (*(ptr - 1) == '\r')
+						ptr--;
+
 					*ptr = '\0';
 					return ptr - buf;
 				} else {

@szescxz szescxz closed this as completed Nov 17, 2023
@blocktrron
Copy link
Member

blocktrron commented Nov 17, 2023

@szescxz I'll look info this. Can you tell me which modem you are seeing this behavior on?

@blocktrron blocktrron reopened this Nov 17, 2023
@szescxz
Copy link
Author

szescxz commented Nov 18, 2023

RM520N-GL, works if applied the patch above. Although I'll need to ensure quectel-timesync has exclusive access to the serial port, but that would be another story.

@blocktrron
Copy link
Member

I think we have the same modem around. I'll check.

herbetom added a commit to herbetom/quectel-timesync that referenced this issue Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants