what is Program /46-0106 Error in node Veh1 on channel WLAN 1 in C2X IL CAPL function C2xGetTokenInt: Protocol "EU_ApplMsg::DENM" not found - vector

I'm trying to write a counter which is sending a msg+CTR but when I'm running the program it's saying this type of error "Program / Model 46-0106 Error in node Veh1 on channel WLAN 1 in C2X IL CAPL function C2xGetTokenInt: Protocol "EU_ApplMsg::DENM" not found"
Please can anybody tell me what that error mean and how to fix it?
void OnC2xPacket( long channel, long dir, long radioChannel, long signalStrength, long signalQuality, long packet )
{
byte aRx_stationID;
aRx_stationID = C2xGetTokenInt(packet, "DENM", "header.stationID");
if(aRx_stationID == 222)
{
#Veh1::sVarRxDenmCounter = C2xGetTokenInt(packet, "DENM", "denm.situation.eventType.causeCode");
if(#Veh1::sVarRxDenmCounter != gRxPacketCounterNew && gRxPacketCounterInit != 1)
{
#Veh1::sVarLostPacketNumber++;
#Veh1::sVarRecieveDataAge = 0;
}
else
{
#Veh1::sVarRecieveDataAge =1;
}
gRxPacketCounterNew = ((#Veh1::sVarRxDenmCounter+1)%256);
gRxPacketCounterInit = 0;
if(#Veh1::sVarLostPacketNumber > 1000)
{
#Veh1::sVarLostPacketNumber =0;
}
}
}
I used in the capl code the CAM and DENM messages to send Tx and receive Rx and in the capl code I don't have an error found but maybe there is an infinite loop or somebody else has a piece of knowledge about that issue.

Related

Simple zeek script

I am totally new to zeek scripting, and I am trying to to a very basic DNS tunnel detector.
Here is my code so far :
export {
const conn_packets_limit = 10;
const conn_time_limit = 30secs;
}
event dns_message(c: connection, is_orig: bool, msg: dns_msg, len: count) {
if (c$duration > conn_time_limit) {
print fmt("Long DNS connexion for %s by %s/%s",c$id$resp_h,c$id$resp_h,c$id$orig_p);
}
}
When i try to run it with zeek -C -r ../capture.pcap ../zeek_scripts/dns/dns.zeek I get the following error : error in ./../zeek_scripts/dns/dns.zeek, line 11: syntax error, at or near "}"
I do not know what I am doing wrong with the print line, could you help me ?
Thank you !

printf alternative when using "define _GNU_SOURCE"

After reading https://www.quora.com/How-can-I-bypass-the-OS-buffering-during-I-O-in-Linux I want to try to access data on the serial port with the O_DIRECT option, but the only way I can seem to do that is by adding the GNU_SOURCE define but when I tried to execute the program, nothing at all is printed on the screen.
If I remove "#define _GNU_SOURCE" and compile, then the system gives me an error on O_DIRECT.
If I remove the define and the O_DIRECT flag, then incorrect (possibly outdated) data is always read, but the data is printed on the screen.
I still want to use the O_DIRECT flag and be able to see the data, so I feel I need an alternative command to printf and friends, but I don't know how to continue.
I attached the code below:
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include <termios.h>
#define TIMEOUT 5
int main(){
char inb[3]; //our byte buffer
int nread=0; //number bytes read from port
int n; //counter
int iosz=128; //Lets get 128 bytes
int fd=open("/dev/ttyS0", O_NOCTTY | O_RDONLY | O_SYNC | O_DIRECT); //Open port
tcflush(fd,TCIOFLUSH);
for(n=0;n<iosz;n++){
int s=time(NULL); //Start timer for 5 seconds
while (time(NULL)-s < TIMEOUT && nread < 1){
inb[0]='A'; //Fill buffer with bad data
inb[1]='B';
inb[2]='C';
nread=read(fd,(char*)inb,1); //Read ONE byte
tcflush(fd,TCIOFLUSH);
if (nread < 0 || time(NULL)-s >= TIMEOUT){
close(fd); //Exit if read error or timeout
return -1;
}
}
printf("%x:%d ",inb[0] & 0xFF,nread); //Print byte as we receive it
}
close(fd); //program ends so close and exit
printf("\n"); //Print byte as we receive it
return 0;
}
First off, I'm no expert on this topic, just curious about it, so take this answer with a pinch of salt.
I don't know if what you're trying to do here (if I'm not looking at it the wrong way it seems to be to bypass the kernel and read directly from the port to userspace) was ever a possibility (you can find some examples, like this one but I could not find anything properly documented) but with recent kernels you should be getting an error running your code, but you're not catching it.
If you add these lines after declaring your port:
...
int fd=open("/dev/ttyS0", O_NOCTTY | O_RDONLY | O_SYNC | O_DIRECT );
if (fd == -1) {
fprintf(stderr, "Error %d opening SERIALPORT : %s\n", errno, strerror(errno));
return 1;
}
tcflush(fd,TCIOFLUSH);
....
When you try to run you'll get: Error 22 opening SERIALPORT : Invalid argument
In my humble and limited understanding, you should be able to get the same effect changing the settings on termios to raw, something like this should do:
struct termios t;
tcgetattr(fd, &t); /* get current port state */
cfmakeraw(&t); /* set port state to raw */
tcsetattr(fd, TCSAFLUSH, &t); /* set updated port state */
There are many good sources for termios, but the only place I could find taht also refers to O_DIRECT (for files) is this one.

Arduino with servo and RTC

I am making a project that involves a RTC and a servo motor so that it only turns on at a certain time. A snippet from the loop is:
void loop() {
DateTime now = rtc.now();
if (DateTime == 19:10) {
//Some stuff
} else {
return();
}
}
and my error is:
Arduino: 1.6.8 (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\User\Documents\Arduino\Servo_motor\Servo_motor.ino: In function 'void loop()':
Servo_motor:36: error: expected primary-expression before '==' token
if (DateTime == 19:10) {
^
Servo_motor:36: error: expected ')' before ':' token
if (DateTime == 19:10) {
^
Servo_motor:45: error: expected primary-expression before '}' token
}
^
Servo_motor:45: error: return-statement with a value, in function returning 'void' [-fpermissive]
Servo_motor:45: error: expected ';' before '}' token
Multiple libraries were found for "RTClib.h"
Used: C:\Program Files (x86)\Arduino\libraries\RTClib
Not used: C:\Users\User\Documents\Arduino\libraries\arduino_786051
exit status 1
expected primary-expression before '==' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I am really confused. Can someone please help?
I'm going to assume you're using the Adafruit RTClib located here, as this is likely the one accessible from the IDE, or that a tutorial will use. It's also a fork of the other available RTClib, so this answer is likely to pertain to both.
If you check RTClib.h, you will find the publicly available methods for DateTime and all the RTC classes. If you do so, you'll notice that there is no operator== method, and in general this means that you can't use that as a form of comparison.
In order to do what you want, you need to use DateTime.minute() and DateTime.hour() and compare them separately. In your loop block it would look as follows:
void loop() {
DateTime now = rtc.now();
if (now.hour() == 19 && now.minute() == 10) {
//Some stuff
} else {
return;
}
}
However, this has the possibility of running the code in question quite a few times, as this check will succeed every time the loop runs during the minute following the RTC ticking over to 19:10.
It seems you're comparing the the type with a constant (time without quotes).
Dont you mean something like this?
if (now == "19:10") {

qt read data from serial port just after open by another program

I'm using Qt version 5.5.1 from windows 8.1.
When I run qtserialport terminal example,
program connects to port successfully, but does not receive any data.
But when I close this program and open Hercules_3-2-6 Application (rs232 terminal software), that application read data,
and after close Hercules_3-2-6 application and open terminal example again, this program works and reads data until restarting computer.
I repeat this process many times.
But terminal project does not receive any data after restarting system until port opens one time by Hercules_3-2-6 Application.
Specification of port:
Name: COM3,
Baud Rate: 9600,
Data bits: 8,
Parity: None,
Stop bits: 1,
Flow control: None
void MainWindow::openSerialPort()
{
SettingsDialog::Settings p = settings->settings();
serial->setPortName(p.name);
serial->setBaudRate(p.baudRate);
serial->setDataBits(p.dataBits);
serial->setParity(p.parity);
serial->setStopBits(p.stopBits);
serial->setFlowControl(p.flowControl);
if (serial->open(QIODevice::ReadWrite)) {
console->setEnabled(true);
console->setLocalEchoEnabled(p.localEchoEnabled);
ui->actionConnect->setEnabled(false);
ui->actionDisconnect->setEnabled(true);
ui->actionConfigure->setEnabled(false);
showStatusMessage(tr("Connected to %1 : %2, %3, %4, %5, %6")
.arg(p.name).arg(p.stringBaudRate).arg(p.stringDataBits)
.arg(p.stringParity).arg(p.stringStopBits).arg(p.stringFlowControl));
} else {
QMessageBox::critical(this, tr("Error"), serial->errorString());
showStatusMessage(tr("Open error"));
}
}
void MainWindow::readData()
{
QByteArray data = serial->readAll();
console->putData(data);
}
Simply you must configure serial port after that you have open it. If you open the port after these instruction:
serial->setBaudRate(p.baudRate);
serial->setDataBits(p.dataBits);
serial->setParity(p.parity);
serial->setStopBits(p.stopBits);
serial->setFlowControl(p.flowControl);
they was ignored. Your second program configure right the serial port for you and the configuration remain when you start your program.
Try this:
void MainWindow::openSerialPort()
{
SettingsDialog::Settings p = settings->settings();
serial->setPortName(p.name);
if (serial->open(QIODevice::ReadWrite)) {
serial->setBaudRate(p.baudRate);
serial->setDataBits(p.dataBits);
serial->setParity(p.parity);
serial->setStopBits(p.stopBits);
serial->setFlowControl(p.flowControl);
console->setEnabled(true);
console->setLocalEchoEnabled(p.localEchoEnabled);
ui->actionConnect->setEnabled(false);
ui->actionDisconnect->setEnabled(true);
ui->actionConfigure->setEnabled(false);
showStatusMessage(tr("Connected to %1 : %2, %3, %4, %5, %6")
.arg(p.name).arg(p.stringBaudRate).arg(p.stringDataBits)
.arg(p.stringParity).arg(p.stringStopBits).arg(p.stringFlowControl));
} else {
QMessageBox::critical(this, tr("Error"), serial->errorString());
showStatusMessage(tr("Open error"));
}
}
void MainWindow::readData()
{
QByteArray data = serial->readAll();
console->putData(data);
}
You must pay attention when configuring a serial port, any option can return true or false; best practice want to check and manage every error that can be returned.

iOS UDP broadcast vs. PHP UDP broadcast

I'm trying to send data via UDP to the network. I've got some PHP code running on my local machine which works:
#!/usr/bin/php -q
<?php
$socket = stream_socket_client('udp://225.0.0.0:50000');
for($i=0;$i<strlen($argv[1]);$i++) $b.="\0\0\0".$argv[1][$i];
fwrite($socket,$b,strlen($argv[1])*4);
fclose($socket);
?>
Gives me the output in tcpdump:
18:53:24.504447 IP 10.0.1.2.52919 > 225.0.0.0.50000: UDP, length 36
I'm trying to get to the same result on a remote iOS with the following code:
- (void)broadcast:(NSString *)dx {
NSData* data=[dx dataUsingEncoding:NSUTF8StringEncoding];
NSLog(#"Broadcasting data: %#", dx);
int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
struct sockaddr_in addr4client;
memset(&addr4client, 0, sizeof(addr4client));
addr4client.sin_len = sizeof(addr4client);
addr4client.sin_family = AF_INET;
addr4client.sin_port = htons(PORT);
addr4client.sin_addr.s_addr = htonl(INADDR_BROADCAST);
int yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (void *)&yes, sizeof(yes)) == -1) {
NSLog([NSString stringWithFormat:#"Failure to set broadcast! : %d", errno]);
}
char *toSend = (char *)[data bytes];
if (sendto(fd, toSend, [data length], 0, (struct sockaddr *)&addr4client, sizeof(addr4client)) == -1) {
NSLog([NSString stringWithFormat:#"Failure to send! : %d", errno]);
}
close(fd);
}
Which gives me the following output in tcpdump:
19:01:22.776192 IP 10.0.1.4.60643 > broadcasthost.50000: UDP, length 9
Looks basically OK, but doesn't arrive in Quartz Composer for some reason, I guess there should be the IP address or something instead of 'broadcasthost'.
Any idea?
The problem was not in the implementation of the broadcaster, but the format of the string. To work with Quartz Composer, every character needs to be preceded by a backslash-zero combination: "\0\0\0", so "abc" has to be formatted and sent as "\0\0\0a\0\0\0b\0\0\0c".
See also Celso Martinho's blog article: Leopard’s Quartz Composer and Network events.
I suggest using AsyncSocket ( google it, its on googlecode ), very well tested objective-c code that runs on iOS.
That way you can send data really easy using a NSData object. AsyncSocket manages the hard part for you.
If that isn't an option for you you should use CFSocket. What you are doing is implementing code that has been written for you already, CFSocket.

Resources