int setOrder(matrix *mat) { char param[BUFSIZE + 1]; int order; if (!getNextParam(param)) return 0; /* Parameter auslesen */ if ((order = atol(param)) < 1) return 0; freeMat(mat); mat = allocMat(order, order); /* Neue Matrix mit eingegebenen Rang erstellen */ return 1; }
int setBValues(matrix *mat) { int i; char param[BUFSIZE + 1]; double value; for (i = 0; i < (int)(mat->col); i++) { if (!getNextParam(param)) return 0; /* Für jeden der n Werte einen Parameter einlesen */ value = atof(param); mat->vec[i] = value; } return 1; }
/* * Periodic updates of parameters to ichip RAM. * Also query for changed parameters of the config page. */ void ICHIPWIFI::handleTick() { MotorController* motorController = DeviceManager::getInstance()->getMotorController(); Throttle *accelerator = DeviceManager::getInstance()->getAccelerator(); Throttle *brake = DeviceManager::getInstance()->getBrake(); tickCounter++; // make small slices so the main loop is not blocked for too long if (tickCounter == 1) { if (motorController) { setParam("timeRunning", getTimeRunning()); setParam("torqueRequested", motorController->getTorqueRequested() / 10.0f, 1); setParam("torqueActual", motorController->getTorqueActual() / 10.0f, 1); } if (accelerator) setParam("throttle", accelerator->getLevel() / 10.0f, 1); if (brake) setParam("brake", brake->getLevel() / 10.0f, 1); else setParam("brake", "n/a"); } else if (tickCounter == 2) { if (motorController) { setParam("speedRequested", motorController->getSpeedRequested()); setParam("speedActual", motorController->getSpeedActual()); setParam("dcVoltage", motorController->getDcVoltage() / 10.0f, 1); setParam("dcCurrent", motorController->getDcCurrent() / 10.0f, 1); } } else if (tickCounter == 3) { if (motorController) { setParam("acCurrent", motorController->getAcCurrent() / 10.0f, 1); setParam("bitfield1", motorController->getStatusBitfield1()); setParam("bitfield2", motorController->getStatusBitfield2()); setParam("bitfield3", motorController->getStatusBitfield3()); setParam("bitfield4", motorController->getStatusBitfield4()); } } else if (tickCounter == 4) { if (motorController) { setParam("running", (motorController->isRunning() ? "true" : "false")); setParam("faulted", (motorController->isFaulted() ? "true" : "false")); setParam("warning", (motorController->isWarning() ? "true" : "false")); setParam("gear", (uint16_t) motorController->getGearSwitch()); } } else if (tickCounter > 4) { if (motorController) { setParam("tempMotor", motorController->getTemperatureMotor() / 10.0f, 1); setParam("tempInverter", motorController->getTemperatureInverter() / 10.0f, 1); setParam("tempSystem", motorController->getTemperatureSystem() / 10.0f, 1); setParam("mechPower", motorController->getMechanicalPower() / 10.0f, 1); tickCounter = 0; } getNextParam(); // wait "loadParams" cycles of tickCounter > 4 before sending config parameters // sending them too early after a soft-reset of ichip results in lost data. if (loadParams > 0) { if (loadParams == 1) loadParameters(); loadParams--; } } }
/* * Process the parameter update from ichip we received as a response to AT+iWNXT. * The response usually looks like this : key="value", so the key can be isolated * by looking for the '=' sign and the leading/trailing '"' have to be ignored. */ void ICHIPWIFI::processParameterChange(char *key) { PotThrottleConfiguration *acceleratorConfig = NULL; PotThrottleConfiguration *brakeConfig = NULL; MotorControllerConfiguration *motorConfig = NULL; Throttle *accelerator = DeviceManager::getInstance()->getAccelerator(); Throttle *brake = DeviceManager::getInstance()->getBrake(); MotorController *motorController = DeviceManager::getInstance()->getMotorController(); if (accelerator) acceleratorConfig = (PotThrottleConfiguration *)accelerator->getConfiguration(); if (brake) brakeConfig = (PotThrottleConfiguration *)brake->getConfiguration(); if(motorController) motorConfig = (MotorControllerConfiguration *)motorController->getConfiguration(); char *value = strchr(key, '='); if (value) { value[0] = 0; // replace the '=' sign with a 0 value++; if (value[0] == '"') value++; // if the value starts with a '"', advance one character if (value[strlen(value) - 1] == '"') value[strlen(value) - 1] = 0; // if the value ends with a '"' character, replace it with 0 if (!strcmp(key, "numThrottlePots") && acceleratorConfig) { acceleratorConfig->numberPotMeters = atol(value); accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleSubType") && acceleratorConfig) { acceleratorConfig->throttleSubType = atol(value); accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleMin1") && acceleratorConfig) { acceleratorConfig->minimumLevel1 = atol(value); accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleMin2") && acceleratorConfig) { acceleratorConfig->minimumLevel2 = atol(value); accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleMax1") && acceleratorConfig) { acceleratorConfig->maximumLevel1 = atol(value); accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleMax2") && acceleratorConfig) { acceleratorConfig->maximumLevel2 = atol(value); accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleRegenMax") && acceleratorConfig) { acceleratorConfig->positionRegenMaximum = atol(value) * 10; } else if (!strcmp(key, "throttleRegenMin") && acceleratorConfig) { acceleratorConfig->positionRegenMinimum = atol(value) * 10; accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleFwd") && acceleratorConfig) { acceleratorConfig->positionForwardMotionStart = atol(value) * 10; accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleMap") && acceleratorConfig) { acceleratorConfig->positionHalfPower = atol(value) * 10; accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleMinRegen") && acceleratorConfig) { acceleratorConfig->minimumRegen = atol(value); accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleMaxRegen") && acceleratorConfig) { acceleratorConfig->maximumRegen = atol(value); accelerator->saveConfiguration(); } else if (!strcmp(key, "throttleCreep") && acceleratorConfig) { acceleratorConfig->creep = atol(value); accelerator->saveConfiguration(); } else if (!strcmp(key, "brakeMin") && brakeConfig) { brakeConfig->minimumLevel1 = atol(value); brake->saveConfiguration(); } else if (!strcmp(key, "brakeMax") && brakeConfig) { brakeConfig->maximumLevel1 = atol(value); brake->saveConfiguration(); } else if (!strcmp(key, "brakeMinRegen") && brakeConfig) { brakeConfig->minimumRegen = atol(value); brake->saveConfiguration(); } else if (!strcmp(key, "brakeMaxRegen") && brakeConfig) { brakeConfig->maximumRegen = atol(value); brake->saveConfiguration(); } else if (!strcmp(key, "speedMax") && motorConfig) { motorConfig->speedMax = atol(value); motorController->saveConfiguration(); } else if (!strcmp(key, "torqueMax") && motorConfig) { motorConfig->torqueMax = atol(value) * 10; motorController->saveConfiguration(); } } getNextParam(); // try to get another one immediately }