Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sielc.socket;
- import com.fasterxml.jackson.annotation.JsonIgnore;
- import java.util.LinkedHashMap;
- import java.util.Map;
- public class MsgValues extends WebSocketMessage {
- public long from;
- public long to;
- public Map<Integer, int[]> values;
- @JsonIgnore
- public int lastIndex;
- public MsgValues(long from, long to, int[][] values, int lastIndex) {
- this.from = from;
- this.to = to;
- this.values = new LinkedHashMap<>(8);
- for (int i = 0; i < 8; i++) {
- this.values.put(i, values[i]);
- }
- this.lastIndex = lastIndex;
- }
- }
- package com.sielc.socket
- import com.fasterxml.jackson.annotation.JsonIgnoreProperties
- import com.fasterxml.jackson.annotation.JsonSubTypes
- import com.fasterxml.jackson.annotation.JsonTypeInfo
- import com.fasterxml.jackson.databind.ObjectMapper
- @JsonIgnoreProperties(ignoreUnknown = true)
- @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "event")
- @JsonSubTypes(
- JsonSubTypes.Type(value = MsgStart::class, name = "start"),
- JsonSubTypes.Type(value = MsgStop::class, name = "stop"),
- JsonSubTypes.Type(value = MsgCancel::class, name = "cancel"),
- JsonSubTypes.Type(value = MsgHello::class, name = "hello"),
- JsonSubTypes.Type(value = MsgStarted::class, name = "started"),
- JsonSubTypes.Type(value = MsgNewMeasurement::class, name = "new measurement"),
- JsonSubTypes.Type(value = MsgValues::class, name = "values"),
- JsonSubTypes.Type(value = MsgCancelledMeasurement::class, name = "cancel measurement"),
- JsonSubTypes.Type(value = MsgFinishedMeasurement::class, name = "finish measurement")
- )
- abstract class WebSocketMessage
- abstract class WebSocketMessageWithChannel(var channel: Int = 0) : WebSocketMessage()
- abstract class WebSocketDynamicMessage : WebSocketMessage() {
- abstract fun createMessage(): String?
- open fun onSuccess() {}
- }
- public class ObjectMapperSingleton {
- companion object {
- @JvmField
- public val get = ObjectMapper()
- }
- }
- package com.sielc.socket
- import com.fasterxml.jackson.annotation.JsonIgnoreProperties
- import com.fasterxml.jackson.annotation.JsonSubTypes
- import com.fasterxml.jackson.annotation.JsonTypeInfo
- class MsgHello : WebSocketMessageWithChannel() {
- val msg: String = "Hello from raspberry!"
- }
- class MsgStart : WebSocketMessage() {
- var id: Int = -1
- var channel: Int = 0
- var duration: Long = 0
- var period: Long = 0
- }
- class MsgStop : WebSocketMessageWithChannel()
- class MsgCancel : WebSocketMessageWithChannel()
- class MsgFinishedMeasurement(channel: Int) : WebSocketMessageWithChannel(channel)
- class MsgCancelledMeasurement(channel: Int) : WebSocketMessageWithChannel(channel)
- class MsgStarted(val id: Int, channel: Int) : WebSocketMessageWithChannel(channel)
- class MsgNewMeasurement(val id: Int,
- channel: Int,
- var time: Long,
- var duration: Long,
- var period: Long) : WebSocketMessageWithChannel(channel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement