How to read directly from Serial1? (baby steps into CASIC) #7025
Replies: 1 comment
-
Posted at 2021-12-30 by HughB I have tried exactly the same approach and nothing comes back. On Bangle1 sending CASIC commands via Serial1. write() would cause the response to come back via the GPS-raw callback but this does not happen on Bangle 2. Something we need @gfwilliams to comment on in the new year. Posted at 2021-12-30 by HilmarSt I'm very interested in GPS topics (see my comments in http://forum.espruino.com/conversations/370398/ ) and wondering what's meant with "CASIC"? Posted at 2021-12-30 by Mark_M I've google-translated this document https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/datasheet/unit/Multimode_satellite_navigation_receiver_cn.pdf There is description of both textual CAS* and binary CASIC messages and commands. Posted at 2021-12-30 by Mark_M @hughb, I suspect we do not get response because b) the particular chip cannot not talk in CASIC mode. Just in NMEA. Posted at 2021-12-30 by HughB
All programming datasheets are like this. As I said in one of my other comments its rather like being taught to play chess with only a list of the moves, and no example of a real game.
Its a correct assumption. Its actually documented. Look at CFG-PRT. There are 2 types. One for enquiry and one for setting. The inquiry version has no payload - so length is set to 0x00, 0x00 and payload is left to blank. So far I have been trying CFG-PRT and CFG-RATE with no payload. Calculating the checksum is a bit tricky, but when the payload is zero bytes you dont need to do the loop bit of the calculation. Here's the examples of what I have been trying so far.
I have found an example of the manufacturer sending assisted GPS data. Posted at 2021-12-30 by HughB
Sure - but the Bangle 1 GPS chip would respond with a NACK if you sent a badly constructed command. So the fact that we get no response at all means either a) the Bangle is not configured to send the commands or receive the responses (this could be a HW or SW issue) or b) the chip has to be put into some mode to respond to the requests c) the chip does not support these commands for some reason. But having found the smoking gun on the Assisted GPS data app - it looks like they are supported. Posted at 2021-12-30 by HilmarSt Thank you for the spec! Posted at 2021-12-30 by Mark_M @HilmarSt I don't think it is possible to simultaneously communicate with multiple baud rates on same UART. I tried to switch the port to all documented baud rates, all works, though not stable above 57K. Posted at 2021-12-30 by Mark_M @hughb, Bangle 1 GPS chip is swiss UBlox. Much more accurately documented. This chinese ZhongKe AT6558 is completely different beast, barely documented even in Mandarine.
example
Posted at 2021-12-30 by HughB
The AT6558, the Bangle 2 GPS chip.
Done on separate post. Posted at 2021-12-30 by HughB
That would explain why we get no response. Needs checking with @gfwilliams. Posted at 2021-12-30 by Mark_M @hughb I am looking into CFG-PRT, there is interesting item
to me it looks like a way to configure the chip to work in CASIC or in NMEA, or in both. It looks like the chip is preconfigured to work in Text protocol (NMEA) only. There is CAS10 command that can do factory default to restart. That may turn on text and binary both. Posted at 2021-12-30 by HughB Wow - well spotted ! Posted at 2021-12-30 by Mark_M thanks!
this tells me U16 should be put as little first. Hmmm... is it this way everywhere? and in ckSum = 0x010B0038; Posted at 2021-12-30 by HughB The doc say id << 24, but when its goes through the different msg types it always puts class followed by id together in every table. Its a bit confusing and easy to read the check sum as class << 24 when in fact its msg_id << 24. It looks to me like the initial part of the chksum calc is done as:
which matches the doc:
In this instance msg_id is 0x01, msg_class is 0x0B Attachments: Posted at 2021-12-30 by HughB This is why I think my chksum for CFG-PRT is correct.
Posted at 2021-12-30 by Mark_M My doc v3.6 on pg 27 says:
But the same doc v4.2 from the site says
confusing! Posted at 2021-12-31 by Mark_M So. I think the binary protocol is simply disabled for UART0 that is connected to NRF. May be there is a way to enable it by reset it to factory defaults. But the question is - why I cannot read from Serial1 ? Posted at 2021-12-31 by HughB I have: Posted at 2021-12-31 by @fanoush
I'd guess it is not, maybe bangle firmware does not pass unknown data to you and just discards it. You could maybe verify it by reconfiguring Serial1 to use different harmless pins and try to setup Serial2 (second nrf52840 uart) to use GPS pins, then hopefully bangle firmware will not interfere when using Serial2. BTW I did not try, this is just a guess. Posted at 2021-12-31 by Mark_M @fanoush I cannot find that C code for Bangle that is responsible for getting GPS data. Could you help me? Posted at 2022-01-01 by HilmarSt I've found something interesting in https://github.com/espruino/Espruino/blob/master/libs/banglejs/jswrap_bangle.c
Maybe that's what you are looking for. Posted at 2022-01-02 by Mark_M Thanks HilmarSt. But this looks like it is for UBlox. BangleJS2 has AT6558. Posted at 2022-01-02 by HilmarSt It's defined for Posted at 2022-01-02 by @fanoush
github has quite nice search, you can go to https://github.com/espruino/Espruino and it topleft corner enter e.g. ublox or casic or nmea and click 'in this repository' As for using Serial2 - instead of finding random pins for Serial1 it could also work to configure just rx or tx, so do Serial1.setup with just Posted at 2022-01-02 by HilmarSt Both, the github search and the search in Espruino-master.zip returns no results for AT6558. For "casic" or "uranus" it finds only one result: May be Posted at 2022-01-02 by @fanoush Yes, there is no code that would handle CASIC binary protocol for AT6558, only NMEA is used so far for bangle2 and also ublox protocol for v1. And almost everything for banglejs watches is in libs/banglejs (and some js stuff in libs/js/banglejs). F5 was something like version 0. Posted at 2022-01-02 by HughB
Do you mean there is no specific code for either in the firmware. For B1 we send UBLOX commands via serial1.write() via a javascript app called gpssetup: https://github.com/espruino/BangleApps/blob/master/apps/gpssetup/gpssetup.js For Bangle 2 we should be able to do the same approach for but different bits and bytes as per the CASIC protocol. The quest we have is how to setup the AT6558 so that it accepts both CAS and CASIC instructions. The problem we have at the moment is that the chip appears to be told not to listen or respond to CASIC instructions and the only way to comfigure it to respond is to send a CASIC instriction.
This sounds promising. I would not have a lot of confidence in how to code that; but if someone can get the Bangle 2 AT6558 to respond to CASIC instructions (over Serial1,write(), or Serial2.write()) I'm reasonably confident I could figure out how to put the AT6558 into a power saving mode and reduce its battery drain and build a Bangle 2 version of gpssetup. Posted at 2022-01-02 by Mark_M My understanding BANGLEJS_Q3 means Bangle JS2. And Q3 watch has AT6558 chip for GPS. But, main question was - is jswrap_banglejs_gps_character(char ch) function assigned to Serial1 input for all time? Can it be unassigned by Serial1.removeAllListeners(); ? Posted at 2022-01-02 by HughB
What C code are you referring to ? The C code just sets up the pipes. What flows through the pipes (UBX or CASIC) is sent via javascript in function calls to Serial1.write(...)- isn't it ? Posted at 2022-01-02 by Mark_M I am not saying about GPS chip input, I am about output, what GPS chip sends to Serial1 and how it is processed.
That 0xB5 is specific to UBX, for CASIC it should be two bytes 0xBA 0xCE. Posted at 2022-01-02 by HughB Got it ! Bingo - thats the bug. The firmware assumes the Bangle 2 GPS talks UBLOX and throws the responses away if not. There should be a more generic way of doing this in the future. Thats why we get no apparent response when we send CASIC commands. If you agree I will log an issue and reference this thread. Posted at 2022-01-02 by Mark_M I agree. Posted at 2022-01-02 by @fanoush
interesting, it is the type specifier EV_SERIAL1 The way it is done is quite complicated, here the Posted at 2022-01-02 by @fanoush
That's why I was suggesting switching GPS output to Serial2 as a quick workaround to test CASIC commands. something like this should work once gps is enabled
then the data will arrive to Serial2 instead where you can handle it yourself Posted at 2022-01-03 by Mark_M @fanoush. Great! This redirection to Serial2 works!
Posted at 2022-01-03 by Mark_M First success! CASIC response received and parsed.
some pause
Posted at 2022-01-03 by @fanoush oh, the Serial2.setup silently steals pins from Serial1, I was expecting it to throw some error instead but this is even easier Posted at 2022-01-03 by HughB @Mark_M - brilliant ! I can see you had a late night. Many thanks for sharing. Just about to give it a go. I got bogged down in trying to shut the NMEA output up and failed miserably, so didn't make much progress. I have logged the firmware issue at: Posted at 2022-01-03 by Mark_M to shut NMEA output you can use CAS06 with 0 for all types. now I am starting working to make some functions. I will try to change mode to Car (CFG-NAVX). I tried GPS during driving, it is very slow, I can drive for like 30 sec at 40kph, but it still shows 18. Stubborn. Posted at 2022-01-03 by HughB
I got CAS06 as product information. I think its CAS03 to set the outputs None of these attempts worked for me.
I can see gnss.setSentencesAll("0"); in your code, so assume that works for you.
Not to worry, I'm more interested in the CASIC controls to get the NAV frequency down to once every 2 minutes. I'm working on trying to get a checksum function to work. Posted at 2022-01-03 by HughB here's my variation of your code. Attempted to print out the checksum in Hex as it makes it
Here's the output
Posted at 2022-01-03 by @fanoush
https://stackoverflow.com/questions/1908492/unsigned-integer-in-javascript Posted at 2022-01-03 by HughB
sounds like need todo >>> 0 at the end of the checksum calculation in parseCasic. Posted at 2022-01-03 by @fanoush or store it to Uint32 array element instead of reading from it (which does nothing helpful) Posted at 2022-01-05 by Mark_M
I doubt it is possible.
Posted at 2024-10-11 by @gfwilliams Resuming this conversation on https://forum.espruino.com/conversations/400068/ I have some nice reliable comms now without the Serial2 hack |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-12-30 by Mark_M
To work with CASIC it needs to read/write binary data into GPS chip.
We can write into Serial1. But.
When I try to read directly from it I get nothing.
Here some output like bunch of pieces of NMEA messages is expected.
But nothing comes in.
When I set callback on 'GPS-raw' I receive them.
But it is not what I am looking for. I need to get raw bytes from Serial1.
'GPS-raw' does some parsing into string lines. That is what I am trying to avoid.
Beta Was this translation helpful? Give feedback.
All reactions