Can't send Raw Telegram Request through CAPL on CANoe - request

EDIT: The main problem has been solved, but I stilla have a question, check the third attempt to see it.
I'm trying to send a Diagnostic Request that is not defined on my Diagnostic Description.
I have the following on my script:
variables
{
//Diagnostic Request that doesn't exist on the .cdd
diagRequest ReadParameter Parameter_Req;
}
on preStart
{
//Sets Diganostic Target just as it was configured
diagSetTarget("DUT");
}
on key 's'
{
//Setting request size to 3 bytes
//I asigned the size to a variable to be able to read which value it had after resizing if but
//everytime I got 0xFF9E or something like that the case is it seems the diagResize is not working
diagResize(Parameter_Req,0x3);
//Setting bytes on the request to creat 22 05 70 (read by identifier)
Parameter_Req.SetPrimitiveByte(0,0x22);
Parameter_Req.SetPrimitiveByte(1,0x05);
Parameter_Req.SetPrimitiveByte(2,0x70);
//Send Request
diagSendRequest(Parameter_Req);
}
But the request is never sent, nothing new is seen on the Trace window. Does anybody know what I am doing wrong? I tried this with a Diagnostic Request that is declared on the Diagnostic Description and it works the request is sent, so I know my diagnostic configuration is OK. Also, no error is reported by CANoe
Thanks for your help
Edit: I also tried this other way
variables
{
byte ReadDID0570[3];
}
on preStart
{
//Sets Diganostic Target just as it was configured
diagSetTarget("DUT");
}
on key 's'
{
//Set bytes and Send Read Request
ReadDID0570[0] = 0x22;
ReadDID0570[1] = 0x05;
ReadDID0570[2] = 0x70;
//Send request
DiagSendRequestPDU(ReadDID0570, elCount(ReadDID0570));
}
But the result the same absolutely nothing happens.
Edit After the suggestion of M. Spiller
variables
{
diagRequest * Parameter_Req;
}
on preStart
{
//Sets Diganostic Target just as it was configured
diagSetTarget("DUT");
}
on key 's'
{
//Resize the request to three bytes
diagResize(Parameter_Req,0x3);
//Set bytes
Parameter_Req.SetPrimitiveByte(0,0x22);
Parameter_Req.SetPrimitiveByte(1,0x05);
Parameter_Req.SetPrimitiveByte(2,0x70);
//Send Request
diagSendRequest(Parameter_Req);
}
This worked! The request is sent, although is not showed in the Trace window, I know it was sent because the response could be seen on Trace. Now my only question is how can I use diagGetLastResponse(Parameter_res); and on diagResponse Parameter_res using this same method to declare the response?
diagResponse * Parameter_Res;
Because those functions receive the name of the request/response declared on the Diagnostic Description, but using this method the type of request is * so how do I use it?

You have used diagGetLastResponse(Parameter_res) to save the response to the Parameter_res variable. Since this is a variable declared with *, you won't have access to the parameters as specified in your Diagnostic Description.
You can make use of the function diagInterpretRespAs to convert this response variable to a suitable class according to your description file. After this, you can use diagGetParameter to get the parameter with the resolution and offset considered.
Otherwise, you can simply use the raw response variable and use diagGetPrimitiveByte to access the bytes in the response.

Related

http.post Sends the 3rd variable empty

The code gets the username and password from the user's inputs. Then it gets the device Mac Address using the 2 functions. I know this part can be simplified, I'm open to recommendations.
I'm 100% sure that $scope.data.macAddr is not empty because I'm able to print it on the console. I was worried about the data type, but I confirmed it that is a string using the "type" of, which returns 'String'.
Update: Also when I inspect the post headers only username and password are sending over.
I don't understand why http.post sends an empty/ not passing it at all to the server.
P.S I know about the MD5 risks. I'm using MD5 just to test my code. Eventually, at the end, I will use HTTPS/SSL with Bcrypt
var link = 'http://app.example.com/api.php';
MacAddress.getMacAddress(function(macAddress){$scope.getMacAddr(macAddress);}, function(fail){console.log(fail);});
$scope.getMacAddr = function(macAddr) {
$scope.macAddr = macAddr;
$scope.data.macAddr = macAddr;
}
$http.post(link, {
username: md5.createHash($scope.data.username),
password: md5.createHash($scope.data.password),
macAddr: $scope.data.macAddr
}).then(function(res) {
console.log(typeof ($scope.data.macAddr));
OK, so you have two asynchronous calls here. One is the call to get the MAC address, and one is the http post. Here is what happens:
At T0: You call getMacAddress(), passing a callback function that will be called, later, when the mac address is available
At T1: You send an HTTP request, passing a callback to then()
At T1000: The mac address is available: the callback passed at step 1 is called, and initializes $scope.data.macAddr
At T150000: the http response is available. The callpack passed at step 2 is called, and prints $scope.data.macAddr.
Send your http request from inside the callback function that you pass at step 1, when the mac address is available.

Why is Gmail returning a UID outside the range specified by UID FETCH command?

When I run a fetch command UID FETCH 170930:170930 BODY[] I get the response 88924 FETCH (UID 170920 FLAGS (\Seen)). I wasn't expecting to retrieve a message with a UID out of the range specified. Is this normal IMAP behaviour? The 170930 UID came from watching the folder with an IdleManager only moments earlier, so I have no reason to believe that a message with that UID doesn't exist on the server.
The fetch request I've posted here is a guess based on the Java code I'm using to execute it. At the very least it should still be requesting only messages within that range:
Argument args = new Argument();
args.writeString(Long.toString(start) + ":" + Long.toString(end));
args.writeString("BODY[]");
Response[] r = protocol.command("UID FETCH", args);
Response response = r[r.length - 1];
An IMAP server is required to send you FETCH responses in certain cases. Sometimes the server is required to wait with responses, but it's never required not to send you any.
If you send a command that requires two response, and someone else does something that requires one response to you, then you get three responses. That something might be to change the flag on a message (requires FETCH ... FLAGS ... to you, although there's no promptness requirement) or send you some mail (requires EXISTS to you).

What happens to a ZeroMQ multipart message when send fails before the final part?

I'm intending to use multi-part messages in ZeroMQ, but I need to know what happens to the initially enqueued message parts when I get a send error before the last message part is sent.
For example, lets say I have a PUSH socket and I am sending a two part message because I am collecting the header and body from different sources. What happens if the header sends fine, but there is an error sending the body? Does the header remain in the socket's outbound queue until I attempt to send another message, or does the header get dropped due to the error in the body send?
Perhaps some code will make the question more precise:
int header[] = {1, 2, 3}; // <- Header From Source 1
int body[] = {4, 5, 6, 7, 8, 9}; // <- Body From Source 2
void *ctx = zmq_ctx_new();
void *push = zmq_socket(ctx, ZMQ_PUSH);
zmq_connect(push, "tcp://localhost:7890");
int headerSent = 0;
int bodySent = 0;
headerSent = zmq_send(push, &header[0], sizeof(header), ZMQ_SNDMORE);
if (-1 != headerSent)
{
bodySent = zmq_send(push, &body[0], sizeof(body), 0);
// What if ^-- this fails?
}
// Do some other processing to prepare a new header and body here...
headerSent = zmq_send(push, &header[0], sizeof(header), ZMQ_SNDMORE);
if (-1 != headerSent)
{
bodySent = zmq_send(push, &body[0], sizeof(body), 0);
}
Is it possible for me to have a message with two headers here, or does ZeroMQ discard the initial message parts that were submitted with the ZMQ_SNDMORE flag when a subsequent send fails due to (e.g.) interruption from a signal? I'm hoping that is the case because the documentation on zmq_send promises that all message parts will be delivered, or none of them will be delivered. However, I'm not sure how the library decides which message parts are from the same message. Does it consider two message parts to be from the same message if a send error occurs in between them?
ZeroMQ Guide:
When you send a multipart message, the first part (and all following parts) are only actually sent on the wire when you send
the final part.
You will receive all parts of a message, or none at all.
What you could always do is send single part messages and assemble them and manage failure on the receiving end
Recent update: Pieter Hintjens: The End of ZeroMQ Multipart
I don't know exactly what will happen, however logic dictates one of 3 outcomes:
The 2nd frame, which failed, will have successfully processed the 0 in the multipart parameter instead of ZMQ_SNDMORE. The first message will be dropped, and the 2nd message will start anew.
The 2nd frame, which failed, will not have successfully processed the 0 in the multipart parameter instead of ZMQ_SNDMORE. The first message will still be open, your 2nd "header" will be frame 2, your 2nd "body" will be frame 3, and the message will just send with 3 frames instead of 2, erroneously
ZMQ will have its pants around its ankles, and be in some error state which will respond in unexpected ways.
My expectation is that the 2nd possibility is what will happen, if the call fails that it should produce zero side effects so it will be as if it never happened. This is supported by the info on the man page talking about the several error types that you might encounter. In particular it looks like it should be a very rare/exceptional situation where the first part of a multipart message would be accepted by the 2nd would not.

How to use the binary push notifications format by C?

I use the The Push Notification Binary Interface cmd=2
This is format :
Q1: Can I send some device_id in one frame? For example:
item id = 1 , device_tocken #1
item id = 1 , device_tocken #2
item id = 1 , device_tocken #3
item id = 2 , message
item id = 3 ...
and etc
Q2: How I can receive the response error ?
The documentation said: If you send a notification that is accepted by APNs, nothing is returned.
If I make SSL_read after SSL_write and package was accepted by APNs, the program is waiting in SSL_read command.
r = SSL_write(ssl, out_buffer, size);
int len = SSL_read(ssl, in_buff, 6);
If I read from ssl channel into single thread - I have segmentation fault.
Q3: Do You know the link to example of use this protocol?
It's not clear from the documentation, but I don't think you can send multiple device tokens in the same frame, simply because if you get an error response of an invalid device token, you won't be able to know which device token it refers to. If, on the other hand, your frame contains a single device token and a single message identifier, then an error response containing that message identifier will tell you exactly which message caused the error.
You should use a non-blocking read for attempting to read the error response. I don't know how you write that in C, but there must be a way to specify some timeout or to call a read method that specifies a timeout. If there is nothing to read, the method will return after the timeout is elapsed.
The APNS docs contain samples for sending notifications in the older formats (0 and 1). I suggest you use format 1 (which supports error responses), since I don't see any advantage of using the newer format 2.

Writing a GSM modem driver?

I've been working on an application which uses a GSM modem for one of two things; check its status using the built in HTTP stack by sending a GET request to the server, or sending data to the server (using UDP). I have tried several different methods to keep this as reliable as possible, and I'm finally ready to ask for help.
My application is written for the SIMCOM908 module and the PIC18 platform (I'm using a PIC18 Explorer for development).
So the problem is sometimes the modem is busy doing something, and misses a command. As a human, I would see that and just resend the command. Adding a facility for my MCU to timeout and resend isn't an issue.
What is an issue is that the modem sends unsolicited responses after different events. When the modem changes registration status (with the cell tower) it would respond with +CGREG: 1, ... or when the GPS is ready GPS Ready. These responses can happen at any time, including in the middle of a command (like creating an IP connection).
This is a problem, because I haven't thought of a way to deal with this. My application needs to send a command (to connect to the server for example, AT+CIPSTART="UDP","example.com",5000) This command will response with 'OK', and then when the command has finished 'CONNECT OK'. However, I need to be able to react to the many other possible responses, and I haven't figured out a way of doing this. What do I need to do with my code to; wait for a response from the modem, check the response, perform an action based on that response?
I am code limited (being an 8-bit microcontroller!) and would like the keep repetition to a minimum. How can I write a response function that will take a response from the GSM module (solicited or now) and then let the rest of my program know what is happening?
Ideally, I'd like to do something with those responses. Like keep an internal state (when I hear GPS Ready, I know I can power the GPS etc.
Maybe there are some things I should think about, or maybe there's an open source project that already solves this problem?
Here's what I have so far:
/* Command responses */
enum {
// Common
OK = 0,
ERROR,
TIMEOUT,
OTHER,
// CGREG
NOT_REGISTERED,
// CGATT
NOT_ATTACHED,
// Network Status
NO_NETWORK,
// GPRS status
NO_ADDRESS,
// HTTP ACTION
NETWORK_ERROR,
// IP Stack State
IP_INITIAL,
IP_STATUS,
IP_CONFIG,
UDP_CLOSING,
UDP_CLOSED,
UDP_CONNECTING
} gsmResponse;
int gsm_sendCommand(const char * cmd) {
unsigned long timeout = timer_getCurrentTime() + 5000;
uart_clearb(GSM_UART); // Clear the input buffer
uart_puts(GSM_UART, cmd); // Send the command to the module
while (strstr(bf2, "\r") == NULL) { // Keep waiting for a response from the module
if (timeout < timer_getCurrentTime()) { // Check we haven't timed out yet
printf("Command timed out: %s\r\n", cmd);
return TIMEOUT;
}
}
timer_delay(100); // Let the rest of the response be received.
return OK;
}
int gsm_simpleCommand(const char * cmd) {
if (gsm_sendCommand(cmd) == TIMEOUT)
return TIMEOUT;
// Getting an ERROR response is quick, so if there is a response, this will be there
if (strstr(bf2, "ERROR") != NULL)
return ERROR;
// Sometimes the OK (meaning the command ran) can take a while
// As long as there wasn't an error, we can wait for the OK
while (strstr(bf2, "OK") == NULL);
return OK;
}
A simple command is any AT command that is specifically looking for OK or ERROR in response. Something like AT. However, I also use it for more advanced commands like AT+CPIN? because it means I will have captured the whole response, and can further search for the +CPIN: READY. However, none of this actually response to the unsolicited responses. In fact, the gsm_sendCommand() function will return early when the unsolicited response is received.
What a good way to manage complex, occasionally unsolicited, status messages like this? Please take note that this application is written in C, and runs on an 8bit microcontroller!
Having to handle both unsolicited messages as well as responses to requests in the same data stream is difficult since you will need to demultiplex the incoming stream and dispatch the results to the appropriate handler. It's a bit like an interrupt handler in that you have to drop what you were doing and handle this other bit of information which you were not necessarily expecting.
Some modules have a secondary serial port which can also be used for messages. If this is possible you could have unsolicited messages only appear on a single serial port while the main port is for your AT commands. This may not be possible, and some GSM modules will not support the complete command set on a secondary port.
Perhaps a better approach is to just disable unsolicited messages. Most commands all the state to be requested. eg While waiting for registration, instead of waiting for an unsolicited registration message to appear, simply poll the module for the current registration state. This allows you to always be in control, and you only have to handle the responses for the command just sent. If you're waiting for multiple events you can poll in a loop for each item in turn. This will generally make the code simpler as you only have to handle a single response at a time. The downside is that your response times are limited by your polling rate.
If you're set on continuing with the unsolicited message approach, I'd suggest implementing a small queue for unsolicited messages. While waiting for responses to a command, if the response does not match the command, just push the response on a queue. Then, when you've either received a response to your AT command or timed out you can process the unsolicited message queue afterwards.

Resources