/*@!Encoding:1252*/
includes
{
  #include "SimCar.cin"
}

variables
{
  msTimer sendTimer;
  int counterSeconds = 0;
}

/****************************************************************/
// SimCar includes the SimCar.cin in which the behaviour
// is implemented. This CAPL programm configures the behaviour
// of the included CAPL programm.
/****************************************************************/
void VehicleSetup()
{
  char stationId[4] = {0, 0, 0, 4};
  char event[13] = {'0','0','0','0','0','0','0','1','0','0','0','0','0'};
  int j = 0;
  
  strncpy(gGps.name, ".\\TRACKS\\GPS_Log_EmergencyBrakeLight.log", elcount(gGps.name)) ; // direction of car
  
  // Start Pos
  gVehicle.latitude = 42.442381;
  gVehicle.longitude = -83.434461;
  gVehicle.heading = 25.69;
  
  // HardBraking flag
  memcpy(gVehicle.event, event, elcount(event));
  
  gVehicle.mobileOrStationaryFlag = 128; // 0 = RSU, 128 = Vehicle

  counterSeconds = 0;
  setTimer(sendTimer, 100);
  
  memcpy(gVehicle.stationId, stationId, elcount(stationId));
}

on timer sendTimer
{
  counterSeconds++;
  
  if(counterSeconds == 422)
  {
    API_StartReadingPositions(gGps.handle); // activate GPS position
    
    C2xEnableMsg("BasicSafetyMessage");
  }
   
  if(counterSeconds == 593)
  {
    API_StopReadingPositions(gGps.handle); // deactivate GPS position
    API_GPS_FileReset(gGps.handle);
    UpdatePosition();
    
    C2xDisableMsg("BasicSafetyMessage");
  }
  else
  {
    setTimer(sendTimer, 100);
  }
}