Custom Protocol is ...
 
Notifications
Clear all

Custom Protocol is not working

10 Posts
2 Users
1 Reactions
3,332 Views
(@kamil01)
Active Member
Joined: 4 years ago
Posts: 12
Topic starter  

Hello
I have a problem with Simhub. After uploading the program, the Custom Protocol option does not work.

Spoiler
SHCustomProtocol

#ifndef _SHCUSTOMPROTOCOL_H_
#define _SHCUSTOMPROTOCOL_H_

#include <Arduino.h>

class SHCustomProtocol {
private:

public:

//int checkeng;
int mglaprawa;
int mglalewa;
int drogowe;
int prawy;
int lewy;
int podswietlenie;
int reczny;
int cisnieniehamulcow;
int retarder;
int wskazowki;
int akumulator;
int olej;
int abss;
int awaryjne;

// int checkengPin = 2;
int mglaprawaPin = 4;
int mglalewaPin = 7;
int awaryjnePin = 8;
int drogowePin = 10;
int prawyPin = 11;
int lewyPin = 12;
int podswietleniePin = A0;
int recznyPin = A1;
int cisnieniehamulcowPin = A2;
int retarderPin = A3;
int wskazowkiPin = A4;
int akumulatorPin = A5;
int olejPin = A6;
int abssPin = A7;

// Called when starting the arduino (setup method in main sketch)
void setup()
{

// pinMode(checkengPin,OUTPUT);
pinMode(mglaprawaPin,OUTPUT);
pinMode(mglalewaPin,OUTPUT);
pinMode(drogowePin,OUTPUT);
pinMode(prawyPin,OUTPUT);
pinMode(lewyPin,OUTPUT);
pinMode(podswietleniePin,OUTPUT);
pinMode(recznyPin,OUTPUT);
pinMode(cisnieniehamulcowPin,OUTPUT);
pinMode(retarderPin,OUTPUT);
pinMode(wskazowkiPin,OUTPUT);
pinMode(akumulatorPin,OUTPUT);
pinMode(olejPin,OUTPUT);
pinMode(abssPin,OUTPUT);
pinMode(awaryjnePin,OUTPUT);

// digitalWrite(checkengPin,LOW);
digitalWrite(mglaprawaPin,LOW);
digitalWrite(mglalewaPin,LOW);
digitalWrite(drogowePin,LOW);
digitalWrite(prawyPin,LOW);
digitalWrite(lewyPin,LOW);
digitalWrite(podswietleniePin,LOW);
digitalWrite(recznyPin,LOW);
digitalWrite(cisnieniehamulcowPin,LOW);
digitalWrite(retarderPin,LOW);
digitalWrite(wskazowkiPin,LOW);
digitalWrite(akumulatorPin,LOW);
digitalWrite(olejPin,LOW);
digitalWrite(abssPin,LOW);
digitalWrite(awaryjnePin,LOW);

}

void read()

{

// int checkeng = FlowSerialReadStringUntil(';').toInt();
int mglaprawa = FlowSerialReadStringUntil(';').toInt();
int mglalewa = FlowSerialReadStringUntil(';').toInt();
int drogowe = FlowSerialReadStringUntil(';').toInt();
int prawy = FlowSerialReadStringUntil('\n').toInt();
int lewy = FlowSerialReadStringUntil(';').toInt();
int podswietlenie = FlowSerialReadStringUntil(';').toInt();
int reczny = FlowSerialReadStringUntil(';').toInt();
int cisnieniehamulcow = FlowSerialReadStringUntil(';').toInt();
int retarder = FlowSerialReadStringUntil(';').toInt();
int wskazowki = FlowSerialReadStringUntil(';').toInt();
int akumulator = FlowSerialReadStringUntil(';').toInt();
int olej = FlowSerialReadStringUntil(';').toInt();
int abss = FlowSerialReadStringUntil('\n').toInt();
/*
if(checkeng == 1){
digitalWrite(checkengPin,HIGH);
}

else
{
digitalWrite(checkengPin,LOW);
}
*/
if(mglaprawa == 1){
digitalWrite(mglaprawaPin,HIGH);
}

else
{
digitalWrite(mglaprawaPin,LOW);
}

if(mglalewa == 1){
digitalWrite(mglalewaPin,HIGH);
}

else
{
digitalWrite(mglalewaPin,LOW);
}

if(drogowe == 1){
digitalWrite(drogowePin,HIGH);
}

else
{
digitalWrite(drogowePin,LOW);
}

if(lewy == 1 && prawy == 0){
digitalWrite(lewyPin,HIGH);
digitalWrite(prawyPin,LOW);
}

else if (lewy == 0 && prawy == 1)
{
digitalWrite(lewyPin,LOW);
digitalWrite(prawyPin,HIGH);
}
else if (lewy == 1 && prawy == 1)
{
digitalWrite(lewyPin,HIGH);
digitalWrite(prawyPin,HIGH);
digitalWrite(awaryjnePin,HIGH);
}

else
{
digitalWrite(prawyPin,LOW);
digitalWrite(lewyPin,LOW);
digitalWrite(awaryjnePin,LOW);
}

if(podswietlenie == 1){
digitalWrite(podswietleniePin,HIGH);
}

else
{
digitalWrite(podswietleniePin,LOW);
}

if(reczny == 1){
digitalWrite(recznyPin,HIGH);
}

else
{
digitalWrite(recznyPin,LOW);
}

if(cisnieniehamulcow == 1){
digitalWrite(cisnieniehamulcowPin,HIGH);
}

else
{
digitalWrite(cisnieniehamulcowPin,LOW);
}

if(retarder == 1){
digitalWrite(retarderPin,LOW);
}

else
{
digitalWrite(retarderPin,HIGH);
}

if(wskazowki == 1){
digitalWrite(wskazowkiPin,HIGH);
}

else
{
digitalWrite(wskazowkiPin,LOW);
}

if(akumulator == 1){
digitalWrite(akumulatorPin,HIGH);
}

else
{
digitalWrite(akumulatorPin,LOW);
}

if(olej == 1){
digitalWrite(olejPin,HIGH);
}

else
{
digitalWrite(olejPin,LOW);
}

if(abss == 1){
digitalWrite(abssPin,HIGH);
}

else
{
digitalWrite(abssPin,LOW);
}

}

void loop() {
}

void idle() {
}
};

#endif

 

When enabled, not typing NOTHING in custom protocol. The game can turn on the lights when I click the right turn signal.

 

Nothing changes when I complete the custom Protocol. As if the program itself decides what to turn on. I am asking for help or to check this option, because I already lack the strength to do so. I thought and tried everything for 10 hours.

 

Spoiler
Custom Protocol
if([DataCorePlugin.GameRawData.Lights.Beacon], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Lights.LowBeams], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Lights.HighBeams], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Lights.BlinkerRightOn], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Lights.BlinkerLeftOn], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Lights.LightsDashboardOn], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Drivetrain.ParkingBrake], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Axilliary.AirPressureWarning], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Lights.BrakeLight], '1', '0')
 + ';' +
if([GameRawData.Drivetrain.ElectricEnabled], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Axilliary.BatteryVoltageWarning], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Axilliary.OilPressureWarning], '1', '0')
 + ';' +
if([DataCorePlugin.GameRawData.Drivetrain.CruiseControl], '1', '0')


   
Quote
(@admin5435)
Prominent Member Admin
Joined: 7 years ago
Posts: 732
 

Hi ! 

If I count correctly the Arduino code and the formula does not match,

I see 13 integer being sent(in the formula), but 14 integers being read(on Arduino side). Since it doesn't match it will cause issues (timeouts, disconnects, bad sync ...)

Nicolas


   
ReplyQuote
(@admin5435)
Prominent Member Admin
Joined: 7 years ago
Posts: 732
 

There is also an error on 

int prawy = FlowSerialReadStringUntil('\n').toInt();

It should be 

int prawy = FlowSerialReadStringUntil(';').toInt();


   
ReplyQuote
(@kamil01)
Active Member
Joined: 4 years ago
Posts: 12
Topic starter  

@admin5435 Yes, I know it, I dug in a bug case, but even after correcting it, it still doesn't work.
My point is that the custom protocol may not exist, and the LEDs right as they want when added on the same.


   
ReplyQuote
(@kamil01)
Active Member
Joined: 4 years ago
Posts: 12
Topic starter  
Spoiler

#ifndef _SHCUSTOMPROTOCOL_H_
#define _SHCUSTOMPROTOCOL_H_

#include <Arduino.h>

class SHCustomProtocol {
private:

public:

int mglaprawa;
int mglalewa;
int drogowe;
int prawy;
int lewy;
int podswietlenie;
int reczny;
int cisnieniehamulcow;
int retarder;
int wskazowki;
int akumulator;
int olej;
int abss;
int awaryjne;

int mglaprawaPin = 4;
int mglalewaPin = 7;
int awaryjnePin = 8;
int drogowePin = 10;
int prawyPin = 11;
int lewyPin = 12;
int podswietleniePin = A0;
int recznyPin = A1;
int cisnieniehamulcowPin = A2;
int retarderPin = A3;
int wskazowkiPin = A4;
int akumulatorPin = A5;
int olejPin = A6;
int abssPin = A7;

// Called when starting the arduino (setup method in main sketch)
void setup() 
{

pinMode(mglaprawaPin,OUTPUT);
pinMode(mglalewaPin,OUTPUT);
pinMode(drogowePin,OUTPUT);
pinMode(prawyPin,OUTPUT);
pinMode(lewyPin,OUTPUT);
pinMode(podswietleniePin,OUTPUT);
pinMode(recznyPin,OUTPUT);
pinMode(cisnieniehamulcowPin,OUTPUT);
pinMode(retarderPin,OUTPUT);
pinMode(wskazowkiPin,OUTPUT);
pinMode(akumulatorPin,OUTPUT);
pinMode(olejPin,OUTPUT);
pinMode(abssPin,OUTPUT);
pinMode(awaryjnePin,OUTPUT);

digitalWrite(mglaprawaPin,LOW);
digitalWrite(mglalewaPin,LOW);
digitalWrite(drogowePin,LOW);
digitalWrite(prawyPin,LOW);
digitalWrite(lewyPin,LOW);
digitalWrite(podswietleniePin,LOW);
digitalWrite(recznyPin,LOW);
digitalWrite(cisnieniehamulcowPin,LOW);
digitalWrite(retarderPin,LOW);
digitalWrite(wskazowkiPin,LOW);
digitalWrite(akumulatorPin,LOW);
digitalWrite(olejPin,LOW);
digitalWrite(abssPin,LOW);
digitalWrite(awaryjnePin,LOW);

}

void read()

{

int mglaprawa = FlowSerialReadStringUntil(';').toInt();
int mglalewa = FlowSerialReadStringUntil(';').toInt();
int drogowe = FlowSerialReadStringUntil(';').toInt();
int prawy = FlowSerialReadStringUntil(';').toInt();
int lewy = FlowSerialReadStringUntil(';').toInt();
int podswietlenie = FlowSerialReadStringUntil(';').toInt();
int reczny = FlowSerialReadStringUntil(';').toInt();
int cisnieniehamulcow = FlowSerialReadStringUntil(';').toInt();
int retarder = FlowSerialReadStringUntil(';').toInt();
int wskazowki = FlowSerialReadStringUntil(';').toInt();
int akumulator = FlowSerialReadStringUntil(';').toInt();
int olej = FlowSerialReadStringUntil(';').toInt();
int abss = FlowSerialReadStringUntil('\n').toInt();

if(mglaprawa == 1){
digitalWrite(mglaprawaPin,HIGH);
}

else
{
digitalWrite(mglaprawaPin,LOW);
}

if(mglalewa == 1){
digitalWrite(mglalewaPin,HIGH);
}

else
{
digitalWrite(mglalewaPin,LOW);
}

if(drogowe == 1){
digitalWrite(drogowePin,HIGH);
}

else
{
digitalWrite(drogowePin,LOW);
}

if(lewy == 1 && prawy == 0){
digitalWrite(lewyPin,HIGH);
digitalWrite(prawyPin,LOW);
}

else if (lewy == 0 && prawy == 1)
{
digitalWrite(lewyPin,LOW);
digitalWrite(prawyPin,HIGH);
}
else if (lewy == 1 && prawy == 1)
{
digitalWrite(lewyPin,HIGH);
digitalWrite(prawyPin,HIGH);
digitalWrite(awaryjnePin,HIGH);
}

else
{
digitalWrite(prawyPin,LOW);
digitalWrite(lewyPin,LOW);
digitalWrite(awaryjnePin,LOW);
}

if(podswietlenie == 1){
digitalWrite(podswietleniePin,HIGH);
}

else
{
digitalWrite(podswietleniePin,LOW);
}

if(reczny == 1){
digitalWrite(recznyPin,HIGH);
}

else
{
digitalWrite(recznyPin,LOW);
}

if(cisnieniehamulcow == 1){
digitalWrite(cisnieniehamulcowPin,HIGH);
}

else
{
digitalWrite(cisnieniehamulcowPin,LOW);
}

if(retarder == 1){
digitalWrite(retarderPin,LOW);
}

else
{
digitalWrite(retarderPin,HIGH);
}

if(wskazowki == 1){
digitalWrite(wskazowkiPin,HIGH);
}

else
{
digitalWrite(wskazowkiPin,LOW);
}

if(akumulator == 1){
digitalWrite(akumulatorPin,HIGH);
}

else
{
digitalWrite(akumulatorPin,LOW);
}

if(olej == 1){
digitalWrite(olejPin,HIGH);
}

else
{
digitalWrite(olejPin,LOW);
}

if(abss == 1){
digitalWrite(abssPin,HIGH);
}

else
{
digitalWrite(abssPin,LOW);
}

}

void loop() {
}

void idle() {
}
};

#endif

 

Now is good?


   
ReplyQuote
(@kamil01)
Active Member
Joined: 4 years ago
Posts: 12
Topic starter  

 

Why are the LEDs working when custom protocol is empty? This way I have no control over the LEDs.

When I add a custom protocol, nothing changes


   
ReplyQuote
(@kamil01)
Active Member
Joined: 4 years ago
Posts: 12
Topic starter  

My setting seems to be: [DataCorePlugin.GameRawData.Lights.LowBeams]
was encoded in arduino, just how?
The whole sketch: https://sharemods.com/372882yokrza/DisplayClientV2.zip.html


   
ReplyQuote
(@admin5435)
Prominent Member Admin
Joined: 7 years ago
Posts: 732
 

I see you were using two arduinos if I'm not wrong. Does it uses the same name ? They could be mixed ?make sure to give it an unique name in sketch setup. Also after changing the formula you need to click on the apply button otherwise the old formula will still be taken into account.

About the code it looks better, but it's just a visual check.


   
ReplyQuote
(@kamil01)
Active Member
Joined: 4 years ago
Posts: 12
Topic starter  

It's better now. I turn on the left turn signal works, turn on the right one does not work. I turn on the cruise control and the right turn signal lights up.

So the pins responsible for oil and cruise control do not fire (the right direction works, but on the cruise control). Strange, because the connection to the arduino was checked 100 times.


   
ReplyQuote
(@kamil01)
Active Member
Joined: 4 years ago
Posts: 12
Topic starter  

Everything was explained. Pins A6 and A7 cannot activate. I switched to D13 and to D3 and now everything works 🙂 Thank you so much for your help!


   
Wotever reacted
ReplyQuote
Share: