void handleButtonEventMessage(int messageId, uint64_t data, CanSignal* signals, int signalCount, Listener* listener) { CanSignal* buttonTypeSignal = lookupSignal("button_type", signals, signalCount); CanSignal* buttonStateSignal = lookupSignal("button_state", signals, signalCount); if(buttonTypeSignal == NULL || buttonStateSignal == NULL) { debug("Unable to find button type and state signals"); return; } float rawButtonType = decodeCanSignal(buttonTypeSignal, data); float rawButtonState = decodeCanSignal(buttonStateSignal, data); bool send = true; const char* buttonType = stateHandler(buttonTypeSignal, signals, signalCount, rawButtonType, &send); if(!send || buttonType == NULL) { debug("Unable to find button type corresponding to %f", rawButtonType); return; } const char* buttonState = stateHandler(buttonStateSignal, signals, signalCount, rawButtonState, &send); if(!send || buttonState == NULL) { debug("Unable to find button state corresponding to %f", rawButtonState); return; } sendEventedStringMessage(BUTTON_EVENT_GENERIC_NAME, buttonType, buttonState, listener); }
void handleOccupancyMessage(int messageId, uint64_t data, CanSignal* signals, int signalCount, Listener* listener) { sendOccupancyStatus("driver", data, lookupSignal("driver_occupancy_lower", signals, signalCount), lookupSignal("driver_occupancy_upper", signals, signalCount), signals, signalCount, listener); sendOccupancyStatus("passenger", data, lookupSignal("passenger_occupancy_lower", signals, signalCount), lookupSignal("passenger_occupancy_upper", signals, signalCount), signals, signalCount, listener); }
void handleTirePressureMessage(int messageId, uint64_t data, CanSignal* signals, int signalCount, Listener* listener) { sendTirePressure("front_left", data, lookupSignal("tire_pressure_front_left", signals, signalCount), signals, signalCount, listener); sendTirePressure("front_right", data, lookupSignal("tire_pressure_front_right", signals, signalCount), signals, signalCount, listener); sendTirePressure("rear_right", data, lookupSignal("tire_pressure_rear_right", signals, signalCount), signals, signalCount, listener); sendTirePressure("rear_left", data, lookupSignal("tire_pressure_rear_left", signals, signalCount), signals, signalCount, listener); }
void handleDoorStatusMessage(int messageId, uint64_t data, CanSignal* signals, int signalCount, Listener* listener) { sendDoorStatus("driver", data, lookupSignal("driver_door", signals, signalCount), signals, signalCount, listener); sendDoorStatus("passenger", data, lookupSignal("passenger_door", signals, signalCount), signals, signalCount, listener); sendDoorStatus("rear_right", data, lookupSignal("rear_right_door", signals, signalCount), signals, signalCount, listener); sendDoorStatus("rear_left", data, lookupSignal("rear_left_door", signals, signalCount), signals, signalCount, listener); }
void receiveTranslatedWriteRequest(cJSON* nameObject, cJSON* root) { char* name = nameObject->valuestring; cJSON* value = cJSON_GetObjectItem(root, "value"); // Optional, may be NULL cJSON* event = cJSON_GetObjectItem(root, "event"); CanSignal* signal = lookupSignal(name, getSignals(), getSignalCount(), true); if(signal != NULL) { if(value == NULL) { debug("Write request for %s missing value", name); return; } sendCanSignal(signal, value, getSignals(), getSignalCount()); } else { CanCommand* command = lookupCommand(name, getCommands(), getCommandCount()); if(command != NULL) { command->handler(name, value, event, getSignals(), getSignalCount()); } else { debug("Writing not allowed for signal with name %s", name); } } }
bool handleTurnSignalCommand(const char* name, cJSON* value, cJSON* event, CanSignal* signals, int signalCount) { const char* direction = value->valuestring; CanSignal* signal = NULL; if(!strcmp("left", direction)) { signal = lookupSignal("turn_signal_left", signals, signalCount); } else if(!strcmp("right", direction)) { signal = lookupSignal("turn_signal_right", signals, signalCount); } if(signal != NULL) { return sendCanSignal(signal, cJSON_CreateBool(true), booleanWriter, signals, signalCount, true); } else { debug("Unable to find signal for %s turn signal", direction); } return false; }
float firstReceivedOdometerValue(CanSignal* signals, int signalCount) { if(totalOdometerAtRestart == 0) { CanSignal* odometerSignal = lookupSignal("total_odometer", signals, signalCount); if(odometerSignal != NULL && odometerSignal->received) { totalOdometerAtRestart = odometerSignal->lastValue; } } return totalOdometerAtRestart; }
int sysSignalWait() { int sig; sigMonitorEnter(); while ((sig = lookupSignal()) == -1) { sigMonitorWait(); } sigMonitorExit(); return sig; }
void handleGpsMessage(int messageId, uint64_t data, CanSignal* signals, int signalCount, Listener* listener) { float latitudeDegrees = decodeCanSignal( lookupSignal("latitude_degrees", signals, signalCount), data); float latitudeMinutes = decodeCanSignal( lookupSignal("latitude_minutes", signals, signalCount), data); float latitudeMinuteFraction = decodeCanSignal( lookupSignal("latitude_minute_fraction", signals, signalCount), data); float longitudeDegrees = decodeCanSignal( lookupSignal("longitude_degrees", signals, signalCount), data); float longitudeMinutes = decodeCanSignal( lookupSignal("longitude_minutes", signals, signalCount), data); float longitudeMinuteFraction = decodeCanSignal( lookupSignal("longitude_minute_fraction", signals, signalCount), data); latitudeMinutes = (latitudeMinutes + latitudeMinuteFraction) / 60.0; if(latitudeDegrees < 0) { latitudeMinutes *= -1; } latitudeDegrees += latitudeMinutes; longitudeMinutes = (longitudeMinutes + longitudeMinuteFraction) / 60.0; if(longitudeDegrees < 0) { longitudeMinutes *= -1; } longitudeDegrees += longitudeMinutes; sendNumericalMessage("latitude", latitudeDegrees, listener); sendNumericalMessage("longitude", longitudeDegrees, listener); }
float handleUnsignedSteeringWheelAngle(CanSignal* signal, CanSignal* signals, int signalCount, float value, bool* send) { CanSignal* steeringAngleSign = lookupSignal("steering_wheel_angle_sign", signals, signalCount); if(steeringAngleSign == NULL) { debug("Unable to find stering wheel angle sign signal"); *send = false; } else { if(steeringAngleSign->lastValue == 0) { // left turn value *= -1; } } return value; }