/** * Set the voltages to display. * v1 - main processor voltage * v2 - display processor voltage * v3 - LED display voltage */ void DisplayModule::SetVoltages(float v1, float v2, float v3) { Wire.beginTransmission(display_address); Wire.write(SET_VOLTAGES); delay(1); SendValue(&v1, sizeof(float)); SendValue(&v2, sizeof(float)); SendValue(&v3, sizeof(float)); Wire.endTransmission(); }
tResult FunctionDriver::OnPinEvent(IPin *source, tInt nEventCode, tInt nParam1, tInt nParam2, IMediaSample *mediaSample) { if (nEventCode != IPinEventSink::PE_MediaSampleReceived) { RETURN_NOERROR; } if (source == &distanceOverallPin) { { __adtf_sample_read_lock_mediadescription(descriptionSignal, mediaSample, inputCoder); inputCoder->Get("f32Value", (tVoid *) &distanceOverall); distanceOverall = distanceOverall * 100; } } else { RETURN_ERROR(ERR_NOT_SUPPORTED); } tFloat32 x = wayLengthFunction.CalculateX(distanceOverall); tFloat32 y = CalculateSinus(0, x); double d = 1; tFloat32 m = CalculateSinus(0, x + d) - CalculateSinus(0, x - d); tFloat32 m_arc = atan(m) * (180 / M_PI); tFloat32 y1 = CalculateSinus(3, x); tFloat32 m1 = CalculateSinus(3, x + d) - CalculateSinus(3, x - d); tFloat32 m1_arc = atan(m1) * (180 / M_PI); tFloat32 steeringAngle = 90 - (m_arc - m1_arc); logger.StartLog(); logger.Log(cString::Format("Distance Overall: %f", distanceOverall).GetPtr()); logger.Log(cString::Format("x: %f", x).GetPtr()); logger.Log(cString::Format("m: %f", m).GetPtr()); logger.Log(cString::Format("y: %f", y).GetPtr()); logger.Log(cString::Format("m1: %f", m1).GetPtr()); logger.Log(cString::Format("y1: %f", y1).GetPtr()); logger.Log(cString::Format("Steering Angle: %f", steeringAngle).GetPtr()); logger.Log("----"); logger.EndLog(); SendValue(mediaSample, speedPin, speed); SendValue(mediaSample, steeringAnglePin, steeringAngle); RETURN_NOERROR; }
void MarkerEvaluator::calcData() { tInt16 data; short int num_list[NUM_ROADSIGNS] = {0}; //increase all roadsign by 1 for (int i = 0; i < RANGE_DATASET; i++) { data = signBuffer.front(); signBuffer.pop_front(); num_list[getListIndexOfSign(data)]++; } int tmp = 0, tmpIndex = 0; //get the max value for (int i = 0; i < NUM_ROADSIGNS; i++) { if (num_list[i] > tmp) { tmp = num_list[i]; tmpIndex = i; } } logger.Log(cString::Format("Sign detected: %d", tmpIndex).GetPtr()); SendEnum(markerOutput, tmpIndex); // TODO reset no-overtaking only on specific signs tBool isNoOvertaking = tRoadSign::NO_OVERTAKING == tmpIndex; SendValue(noOvertakingOutput, isNoOvertaking); }
void StepManiaLanServer::ParseData(PacketFunctions& Packet, const unsigned int clientNum) { int command = Packet.Read1(); switch (command) { case NSCPing: // No Operation SendValue(NSServerOffset + NSCPingR, clientNum); break; case NSCPingR: // No Operation response break; case NSCHello: // Hello Hello(Packet, clientNum); break; case NSCGSR: // Start Request Client[clientNum]->StartRequest(Packet); CheckReady(); //This is what ACTUALLY starts the games break; case NSCGON: // GameOver GameOver(Packet, clientNum); break; case NSCGSU: // StatsUpdate Client[clientNum]->UpdateStats(Packet); if (!Client[clientNum]->lowerJudge) CheckLowerJudge(clientNum); break; case NSCSU: // Style Update Client[clientNum]->StyleUpdate(Packet); SendUserList(); break; case NSCCM: // Chat message AnalizeChat(Packet, clientNum); break; case NSCRSG: SelectSong(Packet, clientNum); break; case NSCSMS: ScreenNetMusicSelectStatus(Packet, clientNum); break; case NSCUPOpts: Client[clientNum]->Player[0].options = Packet.ReadNT(); Client[clientNum]->Player[1].options = Packet.ReadNT(); break; default: break; } }
void DisplayModule::SetTemperature(short temperature) { Debug(" SET_TEMP: "); DebugLn(temperature); Wire.beginTransmission(display_address); Wire.write(SET_TEMP); delay(1); SendValue(&temperature, sizeof(short)); byte et = Wire.endTransmission(); }
void DisplayModule::SetBrightness(int brightness) { Debug(" SET_BRIGHTNESS: "); DebugLn(brightness); Wire.beginTransmission(display_address); Wire.write(SET_BRIGHTNESS); delay(1); SendValue(&brightness, sizeof(int)); byte et = Wire.endTransmission(); }
void DisplayModule::SetPressure(long pressure) { Debug(" SET_PRESSURE: "); DebugLn(pressure); Wire.beginTransmission(display_address); Wire.write(SET_PRESSURE); delay(1); SendValue(&pressure, sizeof(long)); byte et = Wire.endTransmission(); }
void DisplayModule::SetTime(uint32_t time) { Wire.beginTransmission(display_address); // Send the command Wire.write(SET_TIME); delay(1); Debug("SetTime : sending ("); Serial.print(SET_TIME, HEX); Serial.print(") "); DebugLn(time, HEX); SendValue(&time, sizeof(uint32_t)); byte et = Wire.endTransmission(); Debug("endTransmission returns "); DebugLn(et); }
static char *file_export(DBG_Struct *dbg, char *id, char *socket) { static char *filename; char *str; json_object *obj; NETFILE *fp; ValueStruct *ret, *value; ValueStruct *retval; ret = monblob_export(dbg, id); obj = json_object_new_object(); if (!ret) { fprintf(stderr, "[%s] is not registered\n", id); json_object_object_add(obj, "status", json_object_new_int(404)); retval = NULL; } else { value = GetItemLongName(ret, "file_data"); retval = unescape_bytea(dbg, value); char *id; id = ValueToString(GetItemLongName(ret, "id"), dbg->coding); json_object_object_add(obj, "id", json_object_new_string(id)); filename = ValueToString(GetItemLongName(ret, "filename"), dbg->coding); json_object_object_add(obj, "filename", json_object_new_string(filename)); char *content_type; content_type = ValueToString(GetItemLongName(ret, "content_type"), dbg->coding); if (content_type == NULL || strlen(content_type) == 0) { json_object_object_add( obj, "content-type", json_object_new_string("application/octet-stream")); } else { json_object_object_add(obj, "content-type", json_object_new_string(content_type)); } json_object_object_add(obj, "status", json_object_new_int(200)); } str = (char *)json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PLAIN); fp = ConnectBlobAPI(socket); SendString(fp, str); SendValue(fp, retval); FreeValueStruct(retval); Flush(fp); DisconnectBlobAPI(fp); FreeValueStruct(ret); return filename; }
void StateControllerNew::SendCurrentState() { if (tControllerMode::Jury == controllerMode) { __synchronized_obj(transmitLock); tManeuver::ManeuverEnum maneuver = tManeuver::M_UNKNOWN; if (tCarState::Ready == carState || tCarState::Running == carState) { cString currentManeuverString = sectorList[sectionListIndex].maneuverList[maneuverListIndex].action; maneuver = ConvertManeuver(currentManeuverString); } logger.Log(cString::Format("Jury: CarState: %s, Maneuver: %s", tCarState::ToString(carState).c_str(), tManeuver::ToString(maneuver).c_str()).GetPtr()); SendEnum(carStateOutput, static_cast<tInt>(carState)); SendEnum(maneuverOutput, static_cast<tInt>(maneuver)); stateCar stateCar = Convert(carState); tInt16 maneuverId = tInt16(currentManeuverID); SendValue(driveStructOutput, stateCar, maneuverId); } }
void StepManiaLanServer::CheckReady() { bool canStart = true; unsigned int x; //Only check clients that are starting (after ScreenNetMusicSelect before InGame). for (x = 0; (x < Client.size()) && canStart; ++x) { if (Client[x]->isStarting && !Client[x]->GotStartRequest) canStart = false; //Start for courses if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong && Client[x]->GotStartRequest) canStart = true; } if (canStart) { //(Test this) //For whatever reason we need to pause in a way //that will not use a lot of CPU. //When you try playing the music as soon as it's loaded //it will not always play ... immediately usleep ( 2000000 ); //The next three loops are seperate because we want to minimize what is done //during the actual loop that starts the clients. This is in an atempt //to start all the clients as close together as possible. for (x = 0; x < Client.size(); ++x) { if (Client[x]->isStarting) { Client[x]->clientSocket.blocking = true; Client[x]->GotStartRequest = false; } //For Start for courses if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong && Client[x]->GotStartRequest) { Client[x]->clientSocket.blocking = true; Client[x]->GotStartRequest = false; } } //Start clients waiting for a start between ScreenNetMusicSelect and the game. for (x = 0; x < Client.size(); ++x) { if (Client[x]->isStarting) SendValue(NSCGSR + NSServerOffset, x); //For Start for courses if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong) SendValue(NSCGSR + NSServerOffset, x); } for (x = 0; x < Client.size(); ++x) { if (Client[x]->isStarting) { if (Client[x]->startPosition == 1) { Client[x]->isStarting = false; Client[x]->InGame = true; Client[x]->lowerJudge = false; //After we start the clients, clear each client's hasSong. Client[x]->hasSong = false; } Client[x]->clientSocket.blocking = false; } //For Start for courses if (!Client[x]->inNetMusicSelect && !Client[x]->hasSong) { if (Client[x]->startPosition == 1) { Client[x]->isStarting = false; Client[x]->InGame = true; Client[x]->lowerJudge = false; //After we start the clients, clear each client's hasSong. Client[x]->hasSong = false; } Client[x]->clientSocket.blocking = false; } } } }
tResult MarkerEvaluator::OnPinEvent(IPin *sourcePin, tInt eventCode, tInt nParam1, tInt nParam2, IMediaSample *mediaSample) { if (eventCode != IPinEventSink::PE_MediaSampleReceived) { RETURN_NOERROR; } RETURN_IF_POINTER_NULL(mediaSample); logger.StartLog(); if (sourcePin == &roadSignInput) { struct timeval tv; gettimeofday(&tv, NULL); unsigned long long msnew = (unsigned long long) (tv.tv_sec) * 1000 + (unsigned long long) (tv.tv_usec) / 1000; if (lastUpdate + 3000 < msnew) { signBuffer.clear(); } lastUpdate = msnew; tInt16 signId = 0; tFloat32 signSize = 0; { __adtf_sample_read_lock_mediadescription(roadSignDescription, mediaSample, pCoderInput); pCoderInput->Get("i16Identifier", (tVoid *) &signId); pCoderInput->Get("f32Imagesize", (tVoid *) &signSize); } signBuffer.push_back(signId); if (signBuffer.size() > RANGE_DATASET) { calcData(); } } else if (sourcePin == &getReadyInput) { tReadyModule::ReadyModuleEnum module; { __adtf_sample_read_lock_mediadescription(enumDescription, mediaSample, pCoder); pCoder->Get("tEnumValue", (tVoid *) &module); } if (tReadyModule::MarkerEvaluator == module) { logger.Log("Resetting.", false); signBuffer.clear(); SendEnum(markerOutput, static_cast<tInt>(tRoadSign::NO_MATCH)); SendValue(noOvertakingOutput, false); SendEnum(readyOutput, static_cast<tInt>(tReadyModule::MarkerEvaluator)); } } logger.EndLog(); RETURN_NOERROR; }