aux platform
This commit is contained in:
106
extract/aux.go
106
extract/aux.go
@@ -4,9 +4,12 @@ import (
|
||||
"bufio"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -103,6 +106,11 @@ func (afh AuxFrameHead) CheckFrmHead() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type Record struct {
|
||||
index int
|
||||
frmHead *AuxFrameHead
|
||||
}
|
||||
|
||||
// 从传输帧文件中分离辅助数据,分别存储到辅助数据文件 _AUX.dat 和图像数据文件 _IMG_{波谱}.dat 中
|
||||
func (p *Extractor) SeprateAuxAndImgData(sDataFile string) error {
|
||||
// 打开传输帧文件 - 一次读入内存
|
||||
@@ -114,42 +122,124 @@ func (p *Extractor) SeprateAuxAndImgData(sDataFile string) error {
|
||||
|
||||
log.Info("seprate aux and img data from", sDataFile)
|
||||
|
||||
// 数据质量分析
|
||||
fimg, _ := os.Create("demo/temp/aux_img.txt")
|
||||
defer fimg.Close()
|
||||
fimg.WriteString("字节数 帧头流水号 文件号 帧头时间 中心辅助数据前4字节(行33-36)\n")
|
||||
var qmap []*Record
|
||||
for i := 0; i < len(sData); {
|
||||
// 解析帧
|
||||
if i+24 > len(sData) {
|
||||
log.Info("length of frame head is not engough for frame head")
|
||||
break
|
||||
}
|
||||
|
||||
if sData[i] == 0xD1 && sData[i+1] == 0x5B && sData[i+2] == 0xD1 && sData[i+3] == 0x5B {
|
||||
log.Debug("find package head: 0xD15BD15B")
|
||||
} else {
|
||||
i++
|
||||
// log.Println(i,"not find package head: 0xD15BD15B, skip 1 byte")
|
||||
continue
|
||||
}
|
||||
|
||||
afh := &AuxFrameHead{}
|
||||
afh.Decode(sData[i : i+24])
|
||||
|
||||
if !afh.IsValidFrmHead {
|
||||
log.Info("invalid frame head of original raw data", afh.FrmHead, "i =", i)
|
||||
i += 1
|
||||
} else {
|
||||
r := &Record{index: i, frmHead: afh}
|
||||
qmap = append(qmap, r)
|
||||
i += 24
|
||||
|
||||
// fmt.Println("sn:", afh.SerialNo, "time:", afh.TimeSec)
|
||||
// fmt.Println(time.Unix(int64(afh.TimeSec+uint32(ReferenceTime2000)), 0).String())
|
||||
|
||||
utcTime := binary.BigEndian.Uint32(sData[i+32 : i+36])
|
||||
// fmt.Println("utc time of platform aux:", utcTime)
|
||||
// fmt.Println(time.Unix(int64(utcTime), 0).String())
|
||||
|
||||
// fmt.Println("waveway:", sData[i+36])
|
||||
t := time.Unix(int64(afh.TimeSec+uint32(ReferenceTime2000)), 0)
|
||||
tAux := time.Unix(int64(utcTime), 0)
|
||||
fimg.WriteString(fmt.Sprintf("%d %d %d %s %s\n",
|
||||
i,
|
||||
afh.SerialNo,
|
||||
afh.FileNo,
|
||||
t.String(),
|
||||
tAux.String(),
|
||||
))
|
||||
|
||||
// if len(qmap) > 32 {
|
||||
// break
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(qmap, func(i, j int) bool {
|
||||
return qmap[i].index < qmap[j].index
|
||||
})
|
||||
|
||||
// lastPosOfPkg := 0
|
||||
// lastLenOfPkg := 0
|
||||
// for i, v := range qmap {
|
||||
// pkgLen := v.index - lastPosOfPkg
|
||||
|
||||
// if v.index == 4112 {
|
||||
// fmt.Println("index 4112's frm no", i+1)
|
||||
// fmt.Println("last frm:", qmap[i-1].index)
|
||||
// fmt.Println("next frm:", qmap[i+1].index)
|
||||
// }
|
||||
|
||||
// if pkgLen != 23872 {
|
||||
// log.Info("index:", v.index, "lastLenOfPkg:", lastLenOfPkg, "package length:", pkgLen)
|
||||
// }
|
||||
|
||||
// lastLenOfPkg = pkgLen
|
||||
// lastPosOfPkg = v.index
|
||||
// }
|
||||
|
||||
return nil
|
||||
|
||||
name := filepath.Base(sDataFile)
|
||||
name = strings.TrimRight(name, filepath.Ext(name))
|
||||
outputDir := p.params.OutputPath
|
||||
|
||||
aux0 := filepath.Dir(sDataFile) + "/" + name + "_AUX0.dat"
|
||||
aux0 := outputDir + "/" + name + "_EB.AUX"
|
||||
os.Remove(aux0)
|
||||
faux0, _ := os.OpenFile(aux0, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
|
||||
waux0 := bufio.NewWriter(faux0)
|
||||
defer waux0.Flush()
|
||||
defer faux0.Close()
|
||||
|
||||
aux1 := filepath.Dir(sDataFile) + "/" + name + "_AUX1.dat"
|
||||
aux1 := outputDir + "/" + name + "_PLAT.AUX"
|
||||
os.Remove(aux1)
|
||||
faux1, _ := os.OpenFile(aux1, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
|
||||
waux1 := bufio.NewWriter(faux1)
|
||||
defer waux1.Flush()
|
||||
defer faux1.Close()
|
||||
|
||||
pan := filepath.Dir(sDataFile) + "/" + name + "_IMG_PAN.RAW"
|
||||
pan := outputDir + "/" + name + "_IMG_PAN.RAW"
|
||||
os.Remove(pan)
|
||||
fpan, _ := os.OpenFile(pan, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
|
||||
wpan := bufio.NewWriter(fpan)
|
||||
defer wpan.Flush()
|
||||
defer fpan.Close()
|
||||
panEnviHdr := EnviHdr{}
|
||||
wpanHdr, _ := NewBSQWriter(filepath.Dir(sDataFile)+"/"+name+"_IMG_PAN.HDR", &panEnviHdr)
|
||||
wpanHdr, _ := NewBSQWriter(outputDir+"/"+name+"_IMG_PAN.HDR", &panEnviHdr)
|
||||
defer wpanHdr.Close()
|
||||
|
||||
// 先按单波段存储,再按波段组合存储为 BSQ 格式的 MSS
|
||||
mss := filepath.Dir(sDataFile) + "/" + name + "_IMG_MSS.RAW"
|
||||
mss := outputDir + "/" + name + "_IMG_MSS.RAW"
|
||||
os.Remove(mss)
|
||||
fmss, _ := os.OpenFile(mss, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777)
|
||||
wmss := bufio.NewWriter(fmss)
|
||||
defer wmss.Flush()
|
||||
defer fmss.Close()
|
||||
mssEnviHdr := EnviHdr{}
|
||||
wmssHdr, _ := NewBSQWriter(filepath.Dir(sDataFile)+"/"+name+"_IMG_MSS.HDR", &mssEnviHdr)
|
||||
wmssHdr, _ := NewBSQWriter(outputDir+"/"+name+"_IMG_MSS.HDR", &mssEnviHdr)
|
||||
defer wmssHdr.Close()
|
||||
|
||||
var afh AuxFrameHead
|
||||
@@ -165,6 +255,7 @@ func (p *Extractor) SeprateAuxAndImgData(sDataFile string) error {
|
||||
log.Debug("find package head: 0xD15BD15B")
|
||||
} else {
|
||||
i++
|
||||
// log.Println("not find package head: 0xD15BD15B, skip 1 byte")
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -178,7 +269,8 @@ func (p *Extractor) SeprateAuxAndImgData(sDataFile string) error {
|
||||
|
||||
if !afh.IsValidFrmHead {
|
||||
log.Info("invalid frame head of original raw data")
|
||||
break
|
||||
i += 1
|
||||
continue
|
||||
}
|
||||
|
||||
// 目前只支持线阵模式
|
||||
|
||||
Reference in New Issue
Block a user