-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix first notification not showing (#77)
The first notification data received will only be ignored if the message is from more than 3 seconds in the past
- Loading branch information
Showing
7 changed files
with
159 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,72 @@ | ||
package frc.robot; | ||
package frc.robot.util; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import edu.wpi.first.networktables.NetworkTableInstance; | ||
import edu.wpi.first.networktables.PubSubOption; | ||
import edu.wpi.first.networktables.StringPublisher; | ||
import edu.wpi.first.networktables.StringTopic; | ||
|
||
public final class Elastic { | ||
private static final StringTopic topic = NetworkTableInstance.getDefault() | ||
.getStringTopic("/Elastic/robotnotifications"); | ||
private static final StringPublisher publisher = topic.publish(PubSubOption.sendAll(true)); | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
private static final StringTopic topic = | ||
NetworkTableInstance.getDefault().getStringTopic("/Elastic/RobotNotifications"); | ||
private static final StringPublisher publisher = | ||
topic.publish(PubSubOption.sendAll(true), PubSubOption.keepDuplicates(true)); | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public static void sendAlert(ElasticNotification alert) { | ||
try { | ||
publisher.set(objectMapper.writeValueAsString(alert)); | ||
} catch (JsonProcessingException e) { | ||
e.printStackTrace(); | ||
} | ||
public static void sendAlert(ElasticNotification alert) { | ||
try { | ||
publisher.set(objectMapper.writeValueAsString(alert)); | ||
} catch (JsonProcessingException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static class ElasticNotification { | ||
@JsonProperty("level") | ||
private NotificationLevel level; | ||
|
||
public static class ElasticNotification { | ||
@JsonProperty("level") | ||
private NotificationLevel level; | ||
@JsonProperty("title") | ||
private String title; | ||
@JsonProperty("description") | ||
private String description; | ||
@JsonProperty("title") | ||
private String title; | ||
|
||
public ElasticNotification(NotificationLevel level, String title, String description) { | ||
this.level = level; | ||
this.title = title; | ||
this.description = description; | ||
} | ||
@JsonProperty("description") | ||
private String description; | ||
|
||
public void setLevel(NotificationLevel level) { | ||
this.level = level; | ||
} | ||
public ElasticNotification(NotificationLevel level, String title, String description) { | ||
this.level = level; | ||
this.title = title; | ||
this.description = description; | ||
} | ||
|
||
public void setLevel(NotificationLevel level) { | ||
this.level = level; | ||
} | ||
|
||
public NotificationLevel getLevel() { | ||
return level; | ||
} | ||
public NotificationLevel getLevel() { | ||
return level; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public enum NotificationLevel { | ||
INFO, | ||
WARNING, | ||
ERROR | ||
} | ||
public enum NotificationLevel { | ||
INFO, | ||
WARNING, | ||
ERROR | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters