Skip to content

Commit 2b54dcf

Browse files
authored
Fix inconsitencies with openinverter_can_tool can mapping (#7)
* Don't try to erroneously setNoDelay on the WebServer During setup() the code attempts to disable the Nagle algorithm on a non-existent client socket which causes an ugly error in the system log: [ 432][E][WiFiClient.cpp:320] setSocketOption(): fail on -1, errno: 9, "Bad file number" Remove this code. If setNoDelay() needs to be set then this needs to be done on a per-connection basis. * Fix can mapping with negative gains and offsets When reading can mappings the 24-bit gain value was being misinterpreted. Fix this by sign-extending the 24-bit value into a regular int32_t. When creating a can mapping the offset field was being corrupted. Correctly mask off the gain before ORing the shifted offset value. Tests: - Add can mappings with max positive and negative values for gain and offset. - Verify list displays the expected map - Verify with OIC that the map is as expected - Load a complex can map with a mix of big and little endian mappings with OIC and verify the display matches
1 parent 8914cd0 commit 2b54dcf

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

esp32-web-interface.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,6 @@ void setup(void){
738738
});
739739

740740
server.begin();
741-
server.client().setNoDelay(1);
742741

743742
MDNS.addService("http", "tcp", 80);
744743
}

src/oi_can.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,9 @@ void SendCanMapping(WiFiClient client) {
439439
case GAINOFS:
440440
if (twai_receive(&rxframe, pdMS_TO_TICKS(10)) == ESP_OK) {
441441
if (rxframe.data[0] != SDO_ABORT) {
442-
float gain = (*(int32_t*)&rxframe.data[4]) & 0xFFFFFF;
443-
gain /= 1000;
442+
int32_t gainFixedPoint = ((*(uint32_t*)&rxframe.data[4]) & 0xFFFFFF) << (32-24);
443+
gainFixedPoint >>= (32-24);
444+
float gain = gainFixedPoint / 1000.0f;
444445
int offset = (int8_t)rxframe.data[7];
445446
DBG_OUTPUT_PORT.printf("can %s %d %d %d %d %f %d\r\n", rx ? "rx" : "tx", paramid, cobid, pos, len, gain, offset);
446447
JsonDocument subdoc;
@@ -497,7 +498,7 @@ SetResult AddCanMapping(String json) {
497498
setValueSdo(index, 1, doc["paramid"].as<uint32_t>() | (doc["position"].as<uint32_t>() << 16) | (doc["length"].as<int32_t>() << 24)); //data item, position and length
498499
if (rxframe.data[0] != SDO_ABORT && twai_receive(&rxframe, pdMS_TO_TICKS(10)) == ESP_OK) {
499500
DBG_OUTPUT_PORT.println("Sent position and length");
500-
setValueSdo(index, 2, (uint32_t)((int32_t)(doc["gain"].as<double>() * 1000) | doc["offset"].as<int32_t>() << 24)); //gain and offset
501+
setValueSdo(index, 2, (uint32_t)((int32_t)(doc["gain"].as<double>() * 1000) & 0xFFFFFF) | doc["offset"].as<int32_t>() << 24); //gain and offset
501502

502503
if (rxframe.data[0] != SDO_ABORT && twai_receive(&rxframe, pdMS_TO_TICKS(10)) == ESP_OK) {
503504
if (rxframe.data[0] != SDO_ABORT){

0 commit comments

Comments
 (0)