FactbirdHQ / atat

no_std crate for parsing AT commands
Apache License 2.0
116 stars 32 forks source link

Unable to parse URC as bytes #210

Open cacharle opened 3 months ago

cacharle commented 3 months ago

I am failing to make a response struct that will parse to my desired URC:

#[derive(AtatUrc)]
pub enum Urc {
    #[at_urc("+QIND")]
    OTAStatus(OTAStatus),
}

#[derive(AtatResp)]
pub struct OTAStatus {
    bytes: heapless_bytes::Bytes<256>,
}

Gives me some of the following errors when parsing:

[ERROR] - Parsing URC FAILED: b"+QIND: \"FOTA\",\"HTTPSTART\""
[ERROR] - Parsing URC FAILED: b"+QIND: \"FOTA\",\"DOWNLOADING\",91%"
[ERROR] - Parsing URC FAILED: b"+QIND: \"FOTA\",\"HTTPEND\",0"

I have also tried to properly parse the fields of the response like so:

#[derive(AtatResp)]
pub struct OTAStatus {
    fota: heapless::String<4>, // "FOTA"
    event: heapless::String<16>, // HTTPSTART, DOWNLOADING, HTTPEND, START, UPDATING, END
    arg: Option<heapless::String<16>>, // percentage for download and update, result code for httpend and end
    status1: Option<u8>,
    status2: Option<u8>,
}

or tried to not have any fields in the struct. I always get the same errors

I am a new user of this crate so I may be missing something obvious

cacharle commented 3 months ago

It is able to parse it if I don't specify any struct in the URC enum:

#[derive(AtatUrc)]
pub enum Urc {
    #[at_urc("+QIND")]
    OTAStatus,
}

But of course, I don't get any of the informations I want with this so it's not great.

cacharle commented 3 months ago

Okay, looking has some previous code that could parse it, I think this specific URC is terminated by a \r instead of \r\n.

I now have #[at_urc("+QIND", termination = "\r")] but it still fails to parse.

cacharle commented 3 months ago

Also tried to copy the default urc parser in my code and replace the \r\n by \r but it wasn't successful