How to get can channel id using char name?
For example. my CANoe first can channel is 1, and it's name is "BCAN", is there a capl function that can get 1 from "BCAN"?
Related
I am building a gRPC function (called myFunc) that takes the equivalent of the following JSON data as its argument:
{
"id": "ABCD4435010",
"otherId": "WXYZ4435010",
"duration": 30
}
As part of this exercise, I need to design the protobuf message. It looks like this:
1: // MyFunc does something I guess.
2: rpc MyFunc(MyFuncRequest) returns (MyFuncResponse) {
3: option (google.api.http) = {
4: post: "/my.path.to.endpoint/MyFunc"
5: body: "*"
6: };
7: }
8:
9: // MyFuncRequest is the request object for MyFunc.
10: message MyFuncRequest {
11: // id is something.
12: string id = 1;
13: // otherId is something.
14: string otherId = 2;
15: // duration is something.
16: string duration = 3;
17: }
When I try to generate the golang files from this, I get the following errors:
myFile.proto:14:3:Field name "otherId" must be lower_snake_case.
myFile.proto:16:3:Field "duration" must be a google.protobuf.Duration.
2 problems with these errors:
If I change otherId to other_id it will no longer match the key name in the JSON.
If I change duration field's type to google.protobuf.Duration it will no longer match the type of data from the JSON. So that marshalling/unmarshalling will fail.
How can I work around these error messages and get my protocol buffers to compile?
follow the grpc quick start guide for Go in there website(protoc version 3) grpc.io/docs/languages/go/quickstart
By updating their hello world example as saying here change that HelloRequest as follow and regenerate grpc code following this command.
message HelloRequest {
// id is something.
string id = 1;
// otherId is something.
string otherId = 2;
// duration is something.
string duration = 3;
}
regenerate command
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
helloworld/helloworld.proto
It will create grpc request with your fields without an error.
I assume you're getting OtherId and you want otherId.
It may be easiest to create a new type and map this to|from the proto-generated types. This gives you the desired mapping without having to do any 'acrobatics' to keep protoc happy and get the JSON you want.
I'm surprised, it detects and forces duration. You want this to be a number rather than a string. Have you tried using e.g. uint32 in your message definition instead of string (which it isn't)?
Specifying the JSON name for protobuf extension is this an answer to your question?
message TestMessage {
string other_id = 2 [json_name="otherId"];
}
google.protobuf.Duration should a string in json. Read comment here
Its possible to book appointments in my app and I get the queue line value from this code to display for the users in the app:
Text = $"Spot {_Class.Slots.WaitList}";
What im trying to get here is to show the queue that person has. The issue is that the value im getting from that line is the value that says how many people there are in the line. So if a person books an appointment the value has to increase from e.g 2 to 3.
EDIT:
The value im getting from this code I get from the database:
Text = $"Spot {_Class.Slots.WaitList}";
The value is 1 (just an example) but i need the value to be +1 every time.
I tried to do this:
Text = $"Spot {_Class.Slots.WaitList + "1"}";
But it added 10 instead of 1.
What's the type of WaitList field/property?
I don't see a reason why this wouldn't work:
Text = $"Spot {_Class.Slots.WaitList + 1}";
I have an API which takes multiple IDs as a parameter:
http://pqa-volpqa.unknown.com:8080/items/batch/?Ids=00000017072571,00000017072588,00000017072595,00000019786230,00000019987460,00000019988238,00000019988283,00000019990170,00000020015206,00000020015213
Now these IDs are mention in a CSV file like below:
00000017072571
00000017072588
00000017072595
00000019786230
~~
~~
~~
00000020015213
How can I implement this?
If they are as a single string in CSV file you can just use __StringFromFile() or __FileToString() function to read them directly into request parameter
If they are each one a separate line it is still possible with __groovy() function like:
${__groovy(def line = new File('/path/to/your/file.csv').getText().replaceAll(System.getProperty('line.separator')\,'\,'),)}
See Apache JMeter Functions - An Introduction to learn more about JMeter Functions concept.
You can add a Loop controller with Loop count = number of IDs you want to add. Then add a Counter inside the loop controller with the below configurations:
Start: 1
Increment: 1
Reference Name: Counter
Check the boxes for Track counter independently for each user and Reset counter on each thread group iteration
Add a CSV Data Set Config after the counter with the below configurations:
Filename : The full name to your file // if the csv file is not in the same folder with your jmx file you should enter the full path to your CSV file.
Variable Names : id
Finally, add a BeanShell Sampler after the csv data set config with the below code in the code area:
String id = vars.get("id");
int Counter = Integer.parseInt(vars.get("Counter"));
if (Counter == 1){
vars.put("IDs", id);
}
else{
vars.put("IDs", vars.get("IDs") + "," + id);
}
All of the above should be before your API, now you can use your API as below:
http://pqa-volpqa.unknown.com:8080/items/batch/?Ids=${IDs}
In 1st Thread group, in bean-shell Post processor I have added following code to set Jmeter Property with name "id":
int abc=10
int start=${abc}+1;
${__setProperty("id",start)};
print(props.get("id"));
In Second thread group, I am trying to access the value of "id" in beanshell using:
int pq=${__P("id",1)};
Now, The value of 'pq' should be 11 but it takes default value which is '1'.
When I check in Debug PostProcessor, the value of id is string 'start' and not 11. I am not sure what changes are required. One more interesting thing I noticed is: in console it prints 11 for "print(props.get("id"))" where as in jmeter property it stores the string value 'start'.
Any help is appreciated.
First of all, usual notice, don't inline variables and function calls into scripting-based test elements as they may misbehave.
So you should amend your code like:
First Thread Group:
int abc=10
int start=abc+1
props.put('id', start)
Second Thread Group
int pq = props.get('id')
log.info('Property value: ' + pq)
NB: The above code assumes using of JSR223 Test Elements and Groovy language
I have to make the code portable to work on 2 different devices where the length of the OID is just different by 1 byte. Therefore I am reusing the same struct to send the OIDs.
For device #1 I have
MIB[0]=0x2b
MIB[1]=0x06
MIB[2]=0x01
MIB[3]=0x02
MIB[4]=0x01
MIB[5]=0x02
MIB[6]=0x02
MIB[7]=0x01
MIB[8]=0x08
MIB[9]=0xA0
MIB[10]=0x00
For device #2 I have
MIB[0]=0x2b
MIB[1]=0x06
MIB[2]=0x01
MIB[3]=0x02
MIB[4]=0x01
MIB[5]=0x02
MIB[6]=0x02
MIB[7]=0x01
MIB[8]=0x08
MIB[9]=0x01
MIB[10]=???
How do I assign MIB[10] to be NULL, so that the OID that is sent will be 1.3.6.1.2.1.8.1 instead of 1.3.6.1.2.1.8.1.0 by sending MIB[10] = 0x00?
There is no representation for end-of-OID in the data; the length is encoded in the ASN.1 field used to transfer the OID, and this field needs to be replicated along with the OID (especially as you are using the serialized form anyway).