issue_9 #14

Merged
huang merged 11 commits from issue_9 into main 2025-09-25 00:16:50 +08:00
Showing only changes of commit f764ad8962 - Show all commits

View File

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