issue_9 #14
@@ -8,16 +8,18 @@ import (
|
|||||||
// --- 通用结构体 ---
|
// --- 通用结构体 ---
|
||||||
|
|
||||||
// DeviceInfo 包含了所有事件中通用的设备信息。
|
// DeviceInfo 包含了所有事件中通用的设备信息。
|
||||||
|
// 基于 aiserver.proto v4 (integration)
|
||||||
type DeviceInfo struct {
|
type DeviceInfo struct {
|
||||||
TenantID string `json:"tenantId"`
|
TenantID string `json:"tenantId"`
|
||||||
TenantName string `json:"tenantName"`
|
TenantName string `json:"tenantName"`
|
||||||
ApplicationID string `json:"applicationId"`
|
ApplicationID string `json:"applicationId"`
|
||||||
ApplicationName string `json:"applicationName"`
|
ApplicationName string `json:"applicationName"`
|
||||||
DeviceProfileID string `json:"deviceProfileId"`
|
DeviceProfileID string `json:"deviceProfileId"`
|
||||||
DeviceProfileName string `json:"deviceProfileName"`
|
DeviceProfileName string `json:"deviceProfileName"`
|
||||||
DeviceName string `json:"deviceName"`
|
DeviceName string `json:"deviceName"`
|
||||||
DevEui string `json:"devEui"`
|
DevEui string `json:"devEui"`
|
||||||
Tags map[string]string `json:"tags"`
|
DeviceClassEnabled string `json:"deviceClassEnabled,omitempty"` // Class A, B, or C
|
||||||
|
Tags map[string]string `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Location 包含了地理位置信息。
|
// Location 包含了地理位置信息。
|
||||||
@@ -29,6 +31,30 @@ type Location struct {
|
|||||||
|
|
||||||
// --- 可复用的子结构体 ---
|
// --- 可复用的子结构体 ---
|
||||||
|
|
||||||
|
// UplinkRelayRxInfo 包含了上行中继接收信息。
|
||||||
|
type UplinkRelayRxInfo struct {
|
||||||
|
DevEui string `json:"devEui"`
|
||||||
|
Frequency uint32 `json:"frequency"`
|
||||||
|
Dr uint32 `json:"dr"`
|
||||||
|
Snr int32 `json:"snr"`
|
||||||
|
Rssi int32 `json:"rssi"`
|
||||||
|
WorChannel uint32 `json:"worChannel"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeyEnvelope 包装了一个加密的密钥。
|
||||||
|
// 基于 common.proto
|
||||||
|
type KeyEnvelope struct {
|
||||||
|
KEKLabel string `json:"kekLabel,omitempty"`
|
||||||
|
AESKey string `json:"aesKey,omitempty"` // Base64 编码的加密密钥
|
||||||
|
}
|
||||||
|
|
||||||
|
// JoinServerContext 包含了 Join-Server 上下文。
|
||||||
|
// 基于 common.proto
|
||||||
|
type JoinServerContext struct {
|
||||||
|
SessionKeyID string `json:"sessionKeyId"`
|
||||||
|
AppSKey *KeyEnvelope `json:"appSKey,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// UplinkRxInfo 包含了上行接收信息。
|
// UplinkRxInfo 包含了上行接收信息。
|
||||||
type UplinkRxInfo struct {
|
type UplinkRxInfo struct {
|
||||||
GatewayID string `json:"gatewayId"`
|
GatewayID string `json:"gatewayId"`
|
||||||
@@ -47,7 +73,7 @@ type LoraModulationInfo struct {
|
|||||||
Bandwidth int `json:"bandwidth"`
|
Bandwidth int `json:"bandwidth"`
|
||||||
SpreadingFactor int `json:"spreadingFactor"`
|
SpreadingFactor int `json:"spreadingFactor"`
|
||||||
CodeRate string `json:"codeRate"`
|
CodeRate string `json:"codeRate"`
|
||||||
Polarization bool `json:"polarizationInvert,omitempty"` // omitempty 因为只在下行中出现
|
Polarization bool `json:"polarizationInvert,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modulation 包含了具体的调制信息。
|
// Modulation 包含了具体的调制信息。
|
||||||
@@ -73,7 +99,7 @@ type ResolvedLocation struct {
|
|||||||
Latitude float64 `json:"latitude"`
|
Latitude float64 `json:"latitude"`
|
||||||
Longitude float64 `json:"longitude"`
|
Longitude float64 `json:"longitude"`
|
||||||
Altitude float64 `json:"altitude"`
|
Altitude float64 `json:"altitude"`
|
||||||
Source string `json:"source"` // e.g. "GEO_RESOLVER_TDOA"
|
Source string `json:"source"`
|
||||||
Accuracy int `json:"accuracy"`
|
Accuracy int `json:"accuracy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,27 +107,33 @@ type ResolvedLocation struct {
|
|||||||
|
|
||||||
// UpEvent 对应 ChirpStack 的 "up" 事件。
|
// UpEvent 对应 ChirpStack 的 "up" 事件。
|
||||||
type UpEvent struct {
|
type UpEvent struct {
|
||||||
DeduplicationID string `json:"deduplicationId"`
|
DeduplicationID string `json:"deduplicationId"`
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
||||||
DevAddr string `json:"devAddr"`
|
DevAddr string `json:"devAddr"`
|
||||||
ADR bool `json:"adr"`
|
ADR bool `json:"adr"`
|
||||||
DR int `json:"dr"`
|
DR int `json:"dr"`
|
||||||
FCnt uint32 `json:"fCnt"`
|
FCnt uint32 `json:"fCnt"`
|
||||||
FPort uint8 `json:"fPort"`
|
FPort uint8 `json:"fPort"`
|
||||||
Confirmed bool `json:"confirmed"`
|
Confirmed bool `json:"confirmed"`
|
||||||
Data string `json:"data"` // Base64 编码的原始数据
|
Data string `json:"data"`
|
||||||
Object json.RawMessage `json:"object"` // Codec 解码后的 JSON 对象
|
Object json.RawMessage `json:"object"`
|
||||||
RxInfo []UplinkRxInfo `json:"rxInfo"`
|
RxInfo []UplinkRxInfo `json:"rxInfo"`
|
||||||
TxInfo UplinkTxInfo `json:"txInfo"`
|
TxInfo UplinkTxInfo `json:"txInfo"`
|
||||||
|
RelayRxInfo *UplinkRelayRxInfo `json:"relayRxInfo,omitempty"`
|
||||||
|
JoinServerContext *JoinServerContext `json:"joinServerContext,omitempty"`
|
||||||
|
RegionConfigID string `json:"regionConfigId,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// JoinEvent 对应 ChirpStack 的 "join" 事件。
|
// JoinEvent 对应 ChirpStack 的 "join" 事件。
|
||||||
type JoinEvent struct {
|
type JoinEvent struct {
|
||||||
DeduplicationID string `json:"deduplicationId"`
|
DeduplicationID string `json:"deduplicationId"`
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
||||||
DevAddr string `json:"devAddr"`
|
DevAddr string `json:"devAddr"`
|
||||||
|
RelayRxInfo *UplinkRelayRxInfo `json:"relayRxInfo,omitempty"`
|
||||||
|
JoinServerContext *JoinServerContext `json:"joinServerContext,omitempty"`
|
||||||
|
RegionConfigID string `json:"regionConfigId,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AckEvent 对应 ChirpStack 的 "ack" 事件。
|
// AckEvent 对应 ChirpStack 的 "ack" 事件。
|
||||||
@@ -111,18 +143,18 @@ type AckEvent struct {
|
|||||||
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
||||||
Acknowledged bool `json:"acknowledged"`
|
Acknowledged bool `json:"acknowledged"`
|
||||||
FCntDown uint32 `json:"fCntDown"`
|
FCntDown uint32 `json:"fCntDown"`
|
||||||
QueueItemID string `json:"queueItemId"` // 关键字段,用于关联下行指令
|
QueueItemID string `json:"queueItemId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TxAckEvent 对应 ChirpStack 的 "txack" 事件。
|
// TxAckEvent 对应 ChirpStack 的 "txack" 事件。
|
||||||
type TxAckEvent struct {
|
type TxAckEvent struct {
|
||||||
DeduplicationID string `json:"deduplicationId"`
|
DownlinkID uint32 `json:"downlinkId"` // 修改: 替换 DeduplicationID
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
||||||
FCntDown uint32 `json:"fCntDown"`
|
FCntDown uint32 `json:"fCntDown"`
|
||||||
GatewayID string `json:"gatewayId"`
|
GatewayID string `json:"gatewayId"`
|
||||||
QueueItemID string `json:"queueItemId"` // 关键字段,用于关联下行指令
|
QueueItemID string `json:"queueItemId"`
|
||||||
TxInfo DownlinkTxInfo `json:"txInfo"`
|
TxInfo DownlinkTxInfo `json:"txInfo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusEvent 对应 ChirpStack 的 "status" 事件。
|
// StatusEvent 对应 ChirpStack 的 "status" 事件。
|
||||||
@@ -130,9 +162,9 @@ type StatusEvent struct {
|
|||||||
DeduplicationID string `json:"deduplicationId"`
|
DeduplicationID string `json:"deduplicationId"`
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
||||||
Margin int `json:"margin"` // 信号余量,可以近似看作 SNR
|
Margin int `json:"margin"`
|
||||||
ExternalPower bool `json:"externalPowerSource"`
|
ExternalPower bool `json:"externalPowerSource"`
|
||||||
BatteryLevel float32 `json:"batteryLevel"` // 电池电量百分比
|
BatteryLevel float32 `json:"batteryLevel"`
|
||||||
BatteryLevelUnavailable bool `json:"batteryLevelUnavailable"`
|
BatteryLevelUnavailable bool `json:"batteryLevelUnavailable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,8 +173,8 @@ type LogEvent struct {
|
|||||||
DeduplicationID string `json:"deduplicationId"`
|
DeduplicationID string `json:"deduplicationId"`
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
||||||
Level string `json:"level"` // 日志级别, e.g., "INFO", "WARNING", "ERROR"
|
Level string `json:"level"`
|
||||||
Code string `json:"code"` // 日志代码, e.g., "UPLINK_F_CNT_RETRANSMISSION"
|
Code string `json:"code"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Context map[string]string `json:"context"`
|
Context map[string]string `json:"context"`
|
||||||
}
|
}
|
||||||
@@ -161,5 +193,6 @@ type IntegrationEvent struct {
|
|||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
DeviceInfo DeviceInfo `json:"deviceInfo"`
|
||||||
IntegrationName string `json:"integrationName"`
|
IntegrationName string `json:"integrationName"`
|
||||||
|
EventType string `json:"eventType,omitempty"`
|
||||||
Object json.RawMessage `json:"object"`
|
Object json.RawMessage `json:"object"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user