is there a way to modify the CANoe Rx Messages before Receiving on the Bus? - can-bus

I'm Receiving CAN Message from my Controller(Suppose Message ID= 0x100 signals S1,S2),
But I want to change the signals of Canoe Rx message before Receiving it on the Bus.

basically if you want to change something in a CAN frame you can do something like this in capl.
Example:
Framename: TEMP
Signal you want to change: S1, S2
on message TEMP /* or "on message 0x100" in your case */
{
/* if you have a dbc or arxml assigned to the canoe project you can directly
* use frame names and signal names to manipulate the data.
* if not you need to use it's ID and write over the bytes on it.
*/
this.S1 = whatever_value;
this.S2 = whatever_value;
output(this);
}
If you don't have a DBC/ARXML file added to the project, but i highly recommend to do so. The only thing you need to change in the above code that you have to specify which bytes you overwrite.
You change this:
this.S1 = whatever_value;
this.S2 = whatever_value;
To this:
this.byte(0) = whatever_value;
this.byte(1) = whatever_value;
But you need to know which bytes you need to overwrite.

If you cannot modify the message before being sent by the Controller, your only option to modify your message is a HIL (Hardware In the Loop), which you position between the sender (Controller) and CANoe VNs on the bus.
They are called CANStress modules for instance, if you wish to stick to Vector products.
They will sniff the messages on your bus, and at the defined trigger (by you) will overwrite the Physical Layer with whatever you wish, successfully altering or fault-injecting the bus.
Be aware, that modifying the signals means you have to know their mapping, also how to recalculate the CRC tag and modify that also, otherwise the CANoe VN will not accept your message, and will report Rx_Err CRC Check.

Related

Send ethernet/udp packet via CAPL

How to send ethernet packets or UDP packets via CAPL? I know there is an ethernet IG block but I wanted to know if we can send it via capl script just like a CAN messagee is sent via CaPL
Function ethernetPacket <packet var>; can be used to create an Ethernet send object. The object data can be manipulated by selectors associated with this object. More information about these selectors can be found in Help at the following path:
CAPL Functions » Ethernet » ethernetPacket
Here an example on how to send a Ethernet Packet via CAPL
ethernetPacket txPacket;
int i;
txPacket.msgChannel = 1;
txPacket.hwChannel = 2;
txPacket.source = EthGetMacAddressAsNumber( "20:00:00:00:00:01" );
txPacket.destination = EthGetMacAddressAsNumber( "FF:FF:FF:FF:FF:FF" );
txPacket.Length = 100;
txPacket.type = 0xF123;
for( i = 0; i < txPacket.Length; i++ )
{
txPacket.Byte(i) = i & 0xFF;
}
output( txPacket );
You may indeed send ethernet packets through CAPL.
With option .Ethernet several APIs are provided for receiving and transmitting Ethernet frames.
The CAPL Function guide.
For instance, the function ethernetPacket is used to create an Ethernet send object. Unfortunately, I've never done it myself, so I don't have a snippet to demostrate this, yet I urge you to refer to the CANoe/CANalyzer guide under section CAPL Functions > Ethernet CAPL Functions. Interrupt-like procedures are also provided for Ethernet communication, e.g. on ethernetPacket. In addition, you might want to put some more effort in the research, next time...
I know nothing of UDP, yet for sake of completeness CAPL provides APIs for TCP/IP, FlexRay, RS232 (serial), and standards like J1939, K-Line.

STM32F4xx CAN Filter Configuration

I am writing in reference to the information in the reference manual (bxCAN).
I am trying to understand how CAN filter configuration works and need your help to check whether I understand it correctly or not.
Especially the configuration of the filter ID and the filter mask ID.
After I take a look of the stdPeriphLib and the ref. manual, I think that in understand what happens but I´m not sure.
FilterIdHigh/Low:
Is FilterIdHigh/Low the comparative value for CAN Controller after the binary AND with the FilterIdMask?
e.g:
CAN Controller receives a message --> CAN_Rx_
CAN Controller makes a binary AND with the FilterIdMask -->
CAN_Rx_ArbitrationField & FilterIdMask = Result
The CAN Controller compares the Result with the FilterId.
If there is a match CAN Controller puts the CAN_Rx_ message into the assigned FIFO otherwise it will discard the message.
Isn´t it?
Thank´s in advantage.
First received ID is ANDed with Mask to remove bits which are not required and then compared with ID. If they match, then only message is accepted.
if((CAN_RX_ID & CAN_FILTER_MASK) == (CAN_FILTER_ID & CAN_FILTER_MASK))
{
Copy Data in Buffer
}
else
{
Discard the message
}
Note that, only those bits which are set in Mask are compared.
Say, you want to accept only one frame with ID 0x18EBFAB0. In that case, you will set Filter ID as 0x18EBFAB0 and Mask as 0x1FFFFFFF.
When message with any other ID arrives, it will not satisfy required condition and it will be ignored.
If message with ID 0x18EBF9B0 is received,
(0x18EBF9B0 & 0x1FFFFFFF) != (0x18EBFAB0 & 0x1FFFFFFF)
Message will be ignored
If you want to accept any message between ID 0x120 to 0x127.
In that case, set Mask as 0x1F0 and Filter ID as 0x120. With this, Last 4 bits of the ID will be ignored as they are set to 0.
When Message with ID 0x123 is received,
(0x123 & 0x1F0) == (0x120 & 0x1F0)
Message will be accepted.

limitation for NumberOfElements in scatter/gather list

My device driver for a PCIe FPGA is based on 7600.16385.1\src\general\PLX9x5x
Upon ReadFile in the application, PLxEvtIoRead is called:
//
// Initialize this new DmaTransaction.
//
status = WdfDmaTransactionInitializeUsingRequest(
devExt->ReadDmaTransaction,
Request,
PLxEvtProgramReadDma,
WdfDmaDirectionReadFromDevice );
//
// Execute this DmaTransaction.
//
status = WdfDmaTransactionExecute( devExt->ReadDmaTransaction,
WDF_NO_CONTEXT);
....
Upon calling to WdfDmaTransactionExecute, PLxEvtProgramReadDma is called.
BOOLEAN
PLxEvtProgramReadDma(
IN WDFDMATRANSACTION Transaction,
IN WDFDEVICE Device,
IN WDFCONTEXT Context,
IN WDF_DMA_DIRECTION Direction,
IN PSCATTER_GATHER_LIST SgList
)
{
KdPrint ((???SgList->NumberOfElements = %d\n???,SgList->NumberOfElements));
}
The problem:
i want to transfer a large amount of data via this Scatter/Gather list(around 1 GB), but it seems NumberOfElements is limited by something, somehow that the larges transmition is 1MB(255 element in list, each 4k). i changed MaximumTransfecrLength in function below to 500MB:
WDF_DMA_ENABLER_CONFIG_INIT(&dmaConfig,
WdfDmaProfileScatterGatherDuplex,
deviceContext->MaximumTransferLength);
but still i can not transfer more than 1MB.
what is the thing that limits NumberOfElements and how i can solve it?
I needed to change the second parameter in WDF_DMA_ENABLER_CONFIG_INIT function to WdfDmaProfileScatterGather64, and of course we have to make sure that hardware(FPGA or anything in other side of PCIE endpoint) can support 64-bit addressing mode.
I just change my code as below:
WDF_DMA_ENABLER_CONFIG_INIT(&dmaConfig,
WdfDmaProfileScatterGather64,
deviceContext->MaximumTransferLength);

twisted buffer full in tcp connection

I´m having problems with receiving long data (>1024bytes) in a simple twisted server implementation.
From the beginning, I´m developing an ios App that has to synchronize with a twisted server. I prepare the information to send in JSON format. Then I start to send that data in chuncks (right now in chunck of 256bytes + 4 bytes for the command - Yes, I´m implementing my own protocol). The connection is ok, and I receive those packet´s in my server (in the dataReceived function of my own Protocol subclass).
The ios method: NSInteger writtenBytes =[self.outputStream write:[data bytes] maxLength:[data length]] return the written bytes into the stream. For the first 4 packets the value returned is the expected (260 bytes). If I have more available bytes to send, the next time I call that method it returns 0 (which apple documentation says: "If the receiver is a fixed-length stream and has reached its capacity, 0 is returned.").
So I deduce that the input buffer is full. I don´t know how to free that buffer (I don´t know how to reach that buffer). I don't know where is the limit of that buffer (it seems to me almost ridiculous).
This is a basic test of the server (Just the important things for this question with a basic based in strings protocol)
from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
class IphoneSync(Protocol):
def __init__(self):
self.__buffer = ""
def connectionMade(self):
self.transport.write("0:")
self.factory.clients.append(self)
print "clients are ", self.factory.clients
def connectionLost(self, reason):
self.factory.clients.remove(self)
def dataReceived(self, data):
#print "data is ", data
a = data.split(':')
if len(a) > 1:
command = a[0]
content = a[1]
msg = ""
if command == "iam":
#user&Pass checking
msg = "1"
elif command == "msg":
self.__buffer += data
msg = "1: continue"
elif command == "fin":
#procesaremos todo
#Convertir datos en json
#insertar/actualizar data en sqlite
#devolver respuesta
print "buffer is", self.__buffer
msg = "2: procesing"
print msg
self.transport.write(msg)
#for c in self.factory.clients:
#c.message(msg)
def message(self, message):
self.transport.write(message)
#self.transport.write(message + '\n')
factory = Factory()
factory.protocol = IphoneSync
factory.clients = []
dir(factory)
reactor.listenTCP(8000, factory)
print "Iphone Chat server started"
reactor.run()
I saw the LineReceiver class but i´m not sending lines. The transfered data could be very big (10Mb-50Mb). I´m thinking about the Consumer/Producer model, or RPC Protocols like (AMP, or PB) as a solution but i wanted to work with my own protocol.
If someone knows how to help me, i´ll appreciate very much. Thanks anyway.
The connection is ok, and I receive those packet´s in my server (in the dataReceived function of my own Protocol subclass).
Probably not. TCP is a "stream oriented" protocol. Your application's use of it is not in terms of packets but in terms of a sequence of bytes. There is no guarantee whatsoever that dataReceived will be called with the same string that you passed to outputStream write. If you write "hello, world", dataReceived may be called with "hello, world" - or it may be called twice, first with "hello," and then with " world". Or it may be called 12 times: first "h", then "e", then "l", etc.
And if you call outputStream write twice, once with "hello," and once with " world", then it's entirely possible dataReceived will be called just once with "hello, world". Or perhaps twice, but with "h" and then "ello, world".
So this brand new protocol you're inventing (which I see you mentioned you recognized you were doing, but you didn't explain why this is a good idea or an important part of your application, instead of just a large source of potential bugs and a poor use of time :) has to do something called "framing" in order to let you actually interpret the byte sequence being passed around. This is why there are protocols like AMP.
To actually answer your question, outputStream write returns the number of bytes it was actually able to buffer for sending. You must always check its return value and re-try writing any bytes it wasn't able to send, preferably after waiting for notification that there is more buffer space. Buffer space becomes available after bytes using that space are sent across the network and acknowledged by the receiver. This takes time, as networks are not instantaneous. Notification about buffer space being available comes in many forms, the oldest and most widespread of which (but not necessarily the best in your environment), the select(2) system call.
In addition to Jean-Paul Calderone's answer (ensuring that data are being sent completely from the obj-c side by using select or thread), for protocol part I would suggest using length-prefixed string (AKA Netstring) for simple use case.
Here's an implementation. Whenever something is received, you need to call NSBuffer.write then NSBuffer.extract to get available strings.

Faster reading of inbox in Java

I'd like to get a list of everyone who's ever been included on any message in my inbox. Right now I can use the javax mail API to connect via IMAP and download the messages:
Folder folder = imapSslStore.getFolder("[Gmail]/All Mail");
folder.open(Folder.READ_ONLY);
Message[] messages = folder.getMessages();
for(int i = 0; i < messages.length; i++) {
// This causes the message to be lazily loaded and is slow
String[] from = messages[i].getFrom();
}
The line messages[i].getFrom() is slower than I'd like because is causes the message to be lazily loaded. Is there anything I can do to speed this up? E.g. is there some kind of bulk loading I can do instead of loading the messages one-by-one? Does this load the whole message and is there something I can do to only load the to/from/cc fields or headers instead? Would POP be any faster than IMAP?
You want to add the following before the for loop
FetchProfile fetchProfile = new FetchProfile();
fetchProfile.add(FetchProfile.Item.ENVELOPE);
folder.fetch(messages, fetchProfile);
This will prefetch the "envelope" for all the messages, which includes the from/to/subject/cc fields.
You can use fetch-method in Folder. According Javadocs:
Clients use this method to indicate that the specified items are
needed en-masse for the given message range. Implementations are
expected to retrieve these items for the given message range in a
efficient manner. Note that this method is just a hint to the
implementation to prefetch the desired items.
For fetching FROM appropriate FetchProfile is ENVELOPE. Of course it is still up to implementation and mail server does that really help.

Resources