【ChatGPT】PythonでのUBX変換(パース)の会話

●下記 Q: をクリックするとChatGPTの回答が見れます。

Q: Pyubxの機能

Q: 機能不足してるから使えない

Q: 既に自分で作ってある

Q: Relposnedが重要

Q: 6個

Q: ノウハウだからウェブに出してない

Q: 趣味

Q: f9pからx20 へ移行検討中

Q: 25hzが肝

Q: 未だ仕様書類発表になってない

Q: Ntripからのrtcm3のレートは遅くて良いのか心配

Q: 自前の基準局作ってダイレクトに無線でrtcm3をbaseへ入れることも検討しないといけないかも

Q: sまったf9pで基準局作る

Q: 基準局からのの無線方式がわからない

Q: 5gを使えるか

Q: Ntripサーバも自前

Q: サーバーのシステムをwindows にするかLinuxラズパイにするか

Q: 話題を変えてUSB経由でUber
ログするにはc#とpythonだが 速度大丈夫か心配

Q: pythonでラズパイでusb経由SDカードログ 速度間に合うか心配

Q: パースって意味

Q: パースは後でいいからバイナリログで行く

Q: ラズパイは何が良いか

Q: ラズパイ displayをスマホで出来るか

Q: ssh接続わからない

Q: sshでwin10pcのコンソールアプリをスマホから操作したい

Q: python自動起動

Q: python exe化したこと無い

Q: データ量がubx以外にIMUとデジタルアンプから100Hzのデータがあるので、110kbpsのデータがあるあのでpython でバイナリーログ出来るか心配

Q: 220kbps

Q: とりあえずWINDOWSのPython でのサンプルプログラム

Q: ログファイル名をタイムスタンプ

Q: パスにC\UPload\に保存

Q: エラー出たmodule ‘serial’ has no attribute ‘Serial’
File “C:\Users\dj171\PycharmProjects\STA25_binLog.py”, line 25, in reader_thread
with serial.Serial(PORT, BAUDRATE, timeout=0) as ser:
^^^^^^^^^^^^^
AttributeError: module ‘serial’ has no attribute ‘Serial’

Q: ファイル名は問題ないから pip install serialとやったのが原因か

Q: C#  絶対値

Q: Python PCでバイナリログした結果 C#と同じだった、RASPY ZEROW2ではどうなるか

Q: PYTHONのPCプログラムはスレッド処理してある結果

Q: RASPY ZEROW2のSD IFの速度

Q: SDIOをつかっているのか

Q: SPIだったらそんなに速度でないはず

Q: SDカードモードってSDIO インターフェースではないのか

Q: SDIOの制御は、LINUXがやっているのか

Q: ラズパイは、IOTでは、SOCの制御では遅くて使えないので使ってこなかった

Q: USB経由SDログという機能が、IOTマイコンが不得意でラズパイが得意という矛盾がある

Q: 以下の記事をパワポにまとめる
USB経由SDログという機能が、IOTマイコンが不得意でラズパイが得意という矛盾がある

Q: USBホスト機能をもてるCPU能力

Q: USBホスト可能なマイコン一覧

Q: Teensy4.1 CPU

Q: ラズパイ CPU ベンチマーク とタブレット ATOM8550のベンチマーク

Q: ラズパイ4B と ZERO 2W

Q: ベンチマークで 5 4  ZERO2W  ATOMZ8550

Q: pi5 とcorei5 M3230

Q: raspi5とPCどちら

Q: python バイナリログプログラムを関数にまとめる

Q: import time はpip で

Q: ログの停止をq キーにする

Q: エラーで起動しない

Q: PS C:\Users\dj171\PycharmProjects> c:; cd ‘c:\Users\dj171\PycharmProjects’; & ‘c:\Users\dj171\AppData\Local\Programs\Python\Python311\python.exe’ ‘c:\Users\dj171\.vscode\extensions\ms-python.debugpy-2025.6.0-win32-x64\bundled\libs\debugpy\launcher’ ‘65020’ ‘–‘ ‘c:\Users\dj171\PycharmProjects\STA25_binLog_rev01.py’
PS C:\Users\dj171\PycharmProjects> c:; cd ‘c:\Users\dj171\PycharmProjects’; & ‘c:\Users\dj171\AppData\Local\Programs\Python\Python311\python.exe’ ‘c:\Users\dj171\.vscode\extensions\ms-python.debugpy-2025.6.0-win32-x64\bundled\libs\debugpy\launcher’ ‘65033’ ‘–‘ ‘c:\Users\dj171\PycharmProjects\STA25_binLog_rev01.py’
\x5clibs\x5cdebugpy\x5clauncher’ ‘65033’ ‘–‘ ‘c:\x5cUsers\x5cdj171\x5cPycharmProjects\x5cSTA25_binLog_rev01.py’ ;99a4965d-be9e-41f1-af8a-124bdc160018PS C:\Users\dj171\PycharmProjects>

Q: qキーのスレッドではない方法にしたい

Q: 受信 ログはスレッドで、 qキーはループ内で

Q: main関数とログ関数わける

Q: ログ完了したら、ログ経過時間とログファイル名とサイズを表示

Q: COM21 921600 UPload と変更

Q: Python threadの原理わからない

Q: t = threading.Thread(target=my_task) 意味

Q: C#のスレッドよりシンプル

Q: C#の関数をPython変換
static string PVTcnv(byte[] d, ref pvt p)
{
string pvts = “”;
//PVT header[0-6]
//0:itow[6-9]
p.itow = (uint)Toint32(d[9], d[8], d[7], d[6]);
pvts = p.itow.ToString();
//Serial.printf(“PVTcnv:itow=%d\n\r”,pvt[0]);
//1:year[10-12]
p.year = (ushort)(d[10] + d[11] * 256);
pvts = pvts + “,” + p.year.ToString();
//2:month[12]
p.month = d[12];
pvts = pvts + “,” + p.month.ToString();
//3:day[13]
p.day = d[13];
pvts = pvts + “,” + p.day.ToString();
//4:hour[14]
p.hour = d[14];
pvts = pvts + “,” + p.hour.ToString();
//Serial.printf(“PVTcnv:hour=%d\n\r”,pvt[4]);
//5:min[15]
p.min = d[15];
pvts = pvts + “,” + p.min.ToString();
//Serial.printf(“PVTcnv:min=%d\n\r”,pvt[5]);
//6:sec[16]
p.sec = d[16];
pvts = pvts + “,” + p.sec.ToString();
//Serial.printf(“PVTcnv:sec=%d\n\r”,pvt[6]);
//7:valid[17]
p.valid = d[17];
pvts = pvts + “,” + p.valid.ToString();
//8:tAcc[18-21]
p.tacc = (uint)Toint32(d[21], d[20], d[19], d[18]);
pvts = pvts + “,” + p.tacc.ToString();
//9:nano[22-25]
p.nano = Toint32(d[25], d[24], d[23], d[22]);
pvts = pvts + “,” + p.nano.ToString();
//9:nano[22-25]
//10:fixType[26]
p.fixtype = d[26];
pvts = pvts + “,” + p.fixtype.ToString();
//11:flags[27] This is Fix status 131
p.flags = d[27];
pvts = pvts + “,” + p.flags.ToString();
//12:flags2[28]
p.flags2 = d[28];
pvts = pvts + “,” + p.flags2.ToString();
//13:numSV[29]
p.numsv = d[29];
pvts = pvts + “,” + p.numsv.ToString();
//14:lon[30-33]
p.lon = Toint32(d[33], d[32], d[31], d[30]);
pvts = pvts + “,” + p.lon.ToString();
//15:lat[34-37]
p.lat = Toint32(d[37], d[36], d[35], d[34]);
pvts = pvts + “,” + p.lat.ToString();
//16:height[38-41]
p.height = Toint32(d[41], d[40], d[39], d[38]);
pvts = pvts + “,” + p.height.ToString();
//17:hMSL[42-45]
p.hmsl = Toint32(d[45], d[44], d[43], d[42]);
pvts = pvts + “,” + p.hmsl.ToString();
//18:hAcc[46-49]
p.hacc = (uint)Toint32(d[49], d[48], d[47], d[46]);
if (p.hacc > 1000)
{
p.hacc = 0;
}
pvts = pvts + “,” + p.hacc.ToString();
//19:vAcc[50-53]
p.vacc = (uint)Toint32(d[53], d[52], d[51], d[50]);
pvts = pvts + “,” + p.vacc.ToString();
//20:velN[54-57]
p.veln = Toint32(d[57], d[56], d[55], d[54]);
pvts = pvts + “,” + p.veln.ToString();
//21:velE[58-61]
p.vele = Toint32(d[61], d[60], d[59], d[58]);
pvts = pvts + “,” + p.vele.ToString();
//22:velD[62-65]
p.veld = Toint32(d[65], d[64], d[63], d[62]);
pvts = pvts + “,” + p.veld.ToString();
//23:gSpeed[66-69]
p.gspeed = Toint32(d[69], d[68], d[67], d[66]);
pvts = pvts + “,” + p.gspeed.ToString();
//24:headMot[70-73]
p.headmot = Toint32(d[73], d[72], d[71], d[70]);
pvts = pvts + “,” + p.headmot.ToString();
//25:sAcc[74-77]
p.sacc = (uint)Toint32(d[77], d[76], d[75], d[74]);
pvts = pvts + “,” + p.sacc.ToString();
//26:headAcc[78-81]
p.headacc = (uint)Toint32(d[81], d[80], d[79], d[78]);
pvts = pvts + “,” + p.headacc.ToString();
//27:pDOP[82-83]
p.pdop = (ushort)(d[82] + d[83] * 256);
pvts = pvts + “,” + p.pdop.ToString();
//28:flags3[84]
p.flags3 = d[84];
pvts = pvts + “,” + p.flags3.ToString();
//29:reserved1[85]
p.resrv0 = d[85];
pvts = pvts + “,” + p.resrv0.ToString();
//30:headVeh[86-89]
p.headveh = Toint32(d[89], d[88], d[87], d[86]);
pvts = pvts + “,” + p.headveh.ToString();
//31:magDec[90-91]
p.magdec = (short)(d[90] + d[91] * 256);
pvts = pvts + “,” + p.magdec.ToString();
//32:magAcc[92-93]
p.magacc = (ushort)(d[92] + d[93] * 256);
pvts = pvts + “,” + p.magacc.ToString();
return pvts;
}//PVTcnv() end

Q: PVTcnvの呼び出し方

Q: 以下のC#もPython変換
static string RELPOScnv(byte[] d, ref relp r)
{
//RELPOS header[0-5]
string relps = “”;
//Debug.Print(“{RELPOScnv]:d[0][1][2][3]” + d[0].ToString(“X”) + d[1].ToString(“X”) + d[2].ToString(“X”) + d[3].ToString(“X”));
int s = 0;
//0:ver[6]
r.version = d[s + 6];
relps = relps + “,” + r.version.ToString();
//1:reserved1[7]
r.reserved1 = d[s + 7];
relps = relps + “,” + r.reserved1.ToString();
//2:refStationId[8-9]
r.refstationid = d[s + 8];
relps = relps + “,” + r.refstationid.ToString();
//3:itow[10-13]
//Debug.Print(“{RELPOScnv ITOW]:d[10][11][12][13]” + d[10].ToString(“X”) + d[11].ToString(“X”) + d[12].ToString(“X”) + d[13].ToString(“X”));
r.itow = (uint)Toint32(d[s + 13], d[s + 12], d[s + 11], d[s + 10]);
relps = relps + “,” + r.itow.ToString();
//Serial.printf(“RELPOScnv:itow=%d\n\r”,relpos[3]);
//4:relposN[14-17]
r.relposn = Toint32(d[s + 17], d[s + 16], d[s + 15], d[s + 14]);
relps = relps + “,” + r.relposn.ToString();
//5:relposE[18-21]
r.relpose = Toint32(d[s + 21], d[s + 20], d[s + 19], d[s + 18]);
relps = relps + “,” + r.relpose.ToString();
//6:relposD[22-25]
r.relposd = Toint32(d[s + 25], d[s + 24], d[s + 23], d[s + 22]);
relps = relps + “,” + r.relposd.ToString();
//7:relposLength[26-29]
r.relposlength = Toint32(d[s + 29], d[s + 28], d[s + 27], d[s + 26]);
relps = relps + “,” + r.relposlength.ToString();
//Serial.printf(“RELPOScnv:Lenghth=relpos[7]=%d\n\r”,relpos[7]);
//8:relposHeading[30-33]
r.relposheading = Toint32(d[s + 33], d[s + 32], d[s + 31], d[s + 30]);
relps = relps + “,” + r.relposheading.ToString();
//Serial.printf(“relposHeading[8]=%d,[33]%x,[32]%x,[31]%x,[30]%x,\n\r”,relpos[8],d[33],d[32],d[31],d[30]);
//9:reserved2[34]
r.reserved2 = Toint32(d[s + 37], d[s + 36], d[s + 35], d[s + 34]);
relps = relps + “,” + r.reserved2.ToString();
//10:relposHPN[35]
r.relposhpn = (sbyte)((d[s + 38] & 127) – (d[s + 38] & 128));
relps = relps + “,” + r.relposhpn.ToString();
//Serial.printf(“HPN=%d,d[38]=%x,d[39]=%x,d[40]=%x,d[41]=%x,&127=%dx,&128=%d\n\r”,relpos[10],d[38],d[39],d[40],d[41],d[38] && 127,d[38] && 128);
//11:relposHPE[36]
r.relposhpe = (sbyte)((d[s + 39] & 127) – (d[s + 39] & 128));
relps = relps + “,” + r.relposhpe.ToString();
//12:relposHPD[37]
r.relposhpd = (sbyte)((d[s + 40] & 127) – (d[s + 40] & 128));
relps = relps + “,” + r.relposhpd.ToString();
//13:relposHPLength[38]
r.relposhplength = (sbyte)((d[s + 41] & 127) – (d[s + 41] & 128));
relps = relps + “,” + r.relposhplength.ToString();
//14:accN[38-41]
r.accn = (uint)Toint32(d[s + 41], d[s + 40], d[s + 39], d[s + 38]);
relps = relps + “,” + r.accn.ToString();
//15:accE[42-45]
r.acce = (uint)Toint32(d[s + 45], d[s + 44], d[s + 43], d[s + 42]);
relps = relps + “,” + r.acce.ToString();
//16:accD[46-49]
r.accd = (uint)Toint32(d[s + 49], d[s + 48], d[s + 47], d[s + 46]);
relps = relps + “,” + r.accd.ToString();
//17:accLength[50-53]
r.acclength = (uint)Toint32(d[s + 53], d[s + 52], d[s + 51], d[s + 50]);
relps = relps + “,” + r.acclength.ToString();
//18:accHeading[54-57]
r.accheading = (uint)Toint32(d[s + 57], d[s + 56], d[s + 55], d[s + 54]);
relps = relps + “,” + r.accheading.ToString();
//19:reserved[57-60]
r.reserved3 = (uint)Toint32(d[s + 61], d[s + 60], d[s + 59], d[s + 58]);
relps = relps + “,” + r.reserved3.ToString();
//20:flags[60-63]
r.flags = (uint)Toint32(d[s + 65], d[s + 64], d[s + 63], d[s + 62]);
relps = relps + “,” + r.flags.ToString();
return relps;
}

Q: C#の関数をPython 変換
static void ubxtocsv467(int n, string f,int tn)//ubx 個別ファイル csv変換 tn:serialNo 4,6,7
{
FileStream fs = new FileStream(@f, FileMode.Open, FileAccess.Read);
//UDPでは、RTKファイルは 3-19-12-2.bin_BTUBX.csv BNOファイルは 3-19-12-2.bin_BTBNO.csv
string fc = f + “_BTUBX_”+tn.ToString()+”.csv”;

int fileSize = (int)fs.Length; // ファイルのサイズ
byte[] buf;
byte[] bufs=new byte[172];//sorted buf
byte[] pvtb = new byte[100];
byte[] relpb = new byte[72];
byte[] bnob = new byte[172];
//int[] itowEarry=new int[100000];
int startn = 0;
int startn_1 = 0;
buf = new byte[fileSize]; // データ格納用配列
int index0 = 0;
int index_1 = 0;
int index_error = 0;
int indexok = 0;
int readSize = 0; // Readメソッドで読み込んだバイト数
int remain = fileSize; // 読み込むべき残りのバイト数
int bufPos = 0; // データ格納用配列内の追加位置
int k = 0;
long[] itowarry;
string[] indexerr = new string[1000];
string bnodata = “”;
string bnodata_1 = “”;
string bnodataw = “”;
int bnoitow = 0;//タイマー積算bnitow
int itownow = 0;//RTKのitow
int itownow_1 = 0;//1個前のitownow
int itownowsa = 0;//itownowの先頭
int bnitowH = 0;//補正済みbnitow
long itow1 = 0;
double lat_lon = 0;
double lat_lon_1 = 0;
int straightin = 0;
int straightn = 0;
int straightin_1 = 0;
int itowErr, totaln;
//itow1 = 0;
int headstart = 0;
int headend = 0;
int headmot1 = 0;
itowErr = 0;
totaln = 0;
//
string headUBX;
headUBX = “No,iTOW,year,month,day,hour,min,sec,valid,tAcc,nano,fixtype,flags,”;
headUBX = headUBX + “flags2,numSV,lon,lat,height,hMSL,hAcc,vAcc,velN,velE,velD,gSpeed,headMot,sAcc,”;
headUBX = headUBX + “headAcc,pDOP,flags3,reserved1,headVeh,magDec,magAcc,na,”;
headUBX = headUBX + “version,reserved2,refStationId,iTOWR,relPosN,relPosE,relPosD,relPosLength,”;
headUBX = headUBX + “relPosHeading,relPosHPN,relPosHPE,relPosHPD,relPosHPLength,accN,accE,accD,”;
headUBX = headUBX + “accLength,accHeading,reserverd4,flagsR,a”;

//fix error itowerror
f131 = 0;
f673 = 0;
itow_1 = 0;
itowloss = 0;
//int itowper = 0;
// fixper = 0;
while (remain > 0)
{

// 172Bytesずつbuf[]に読み込む
readSize = fs.Read(buf, bufPos, Math.Min(172, remain));
bufPos += readSize;
remain -= readSize;
k++;//172byte単位でカウントアップ
}
itowarry = new long[k];
int dsize = fileSize;
int[] stArry4 = new int[18000];//30min
int[] stArry6 = new int[18000];//30min
int[] stArry7 = new int[18000];//30min
int stcnt4 = 0;
int stcnt6 = 0;
int stcnt7 = 0;
//rev800_4用のデータは、1ファイルに全て混在しているので、毎回頭出し必要なので、PVTヘッダー番号配列を作成
for (int ii=0;ii<dsize; ii++)
{
if (buf[ii]==0xB5 && buf[ii+1]==0X62 && buf[ii+2]==0x01 && buf[ii+3]==0x07)
{
if (buf[ii + 4] ==0x04)
{
stArry4[stcnt4] = ii;
stcnt4++;
}
if (buf[ii + 4] == 0x06)
{
stArry6[stcnt6] = ii;
stcnt6++;
}
if (buf[ii + 4] == 0x07)
{
stArry7[stcnt7] = ii;
stcnt7++;
}

}
}

//UDPでは、RTKファイルは 3-19-12-2.bin_BTUBX.csv BNOファイルは 3-19-12-2.bin_BTBNO.csv
System.IO.StreamWriter sw = new System.IO.StreamWriter(@fc, false);//swはrtk BTUX用

sw.WriteLine(headUBX);

//buf からUBX 抽出
// startn = i * 172;
if (tn == 4)
{
k= stcnt4;
}
if (tn == 6)
{
k= stcnt6;
}
if (tn == 7)
{
k = stcnt7;
}
//k = stcnt4 + stcnt6 + stcnt4-3;
for (int i = 0; i < k – 1; i++)//172byte単位で読む
{
if (tn == 4)
{
startn = stArry4[i];

}
if (tn == 6)
{
startn = stArry6[i];

}
if (tn == 7)
{
startn = stArry7[i];

}

//Console.Write(i.ToString() + “,” + string.Format(“{0:X2}”, buf[i*172])+”,:,”);

//TextBox1.Textの内容を書き込む
//PVT取り出し

//PVT RELPOSNED trans
if (buf[0 + startn] == 0xB5 && buf[1 + startn] == 0x62 && buf[2 + startn] == 0x01 && buf[3 + startn] == 0x07 && buf[4+startn]==tn)
{
//===========UBX translate================================
for (int j = 0; j < 100; j++)//bufからpvtbへ格納
{
pvtb[j] = buf[j + startn];
}
for (int j = 0; j < 72; j++)//bufからrelpbへ格納 { relpb[j] = buf[j + startn + 100]; } itow1 = pvtd.itow;//1個前のitow記録 headmot1 = pvtd.headmot; string ubx0 = PVTcnv(pvtb, ref pvtd); string ubx1 = RELPOScnv(relpb, ref relpd); string istr = i.ToString(); sw.WriteLine(istr + “,” + ubx0 + “,” + ubx1); //Console.WriteLine(istr + “,” + ubx0 + “,” + ubx1); //Console.WriteLine(ubx1); //———-itowエラーカウント—————— itowarry[i] = pvtd.itow; //if (i > 0 && i % 2 == 0)
//{
if (Math.Abs(itowarry[i] – itow1)>135 || Math.Abs(itowarry[i] – itow1)< 115 )//itow loss検出 125msec±5msec { itowErr++; //Console.WriteLine(“>>>>itowErr=” + itowErr + “[” + itowarry[i] + “-” + itow1);

}

//}
//Fix率
if (pvtd.flags == 131)
{
f131++;
}
else
{
f673++;
}

totaln++;

}
else//ubx順序がバラバラの場合はソートする
{
int nc, ns;//counter
int pvtstartN = 0;//pvtstart No
int relpstartN = 0;//relpos start No
for (nc = 0; nc < 172; nc++)//開始位置検索
{
if (buf[nc%172 + startn] == 0xB5 && buf[(nc+ 1)%172 + startn] == 0x62 && buf[(nc + 2)%172 + startn] == 0x01 && buf[(nc + 3)%172 + startn] == 0x07)
{
pvtstartN = nc;
Console.WriteLine(“epochNo=” + i + “pvtstartN=” + pvtstartN);
}
if (buf[nc%172 + startn] == 0xB5 && buf[(nc + 1)%172 + startn] == 0x62 && buf[(nc + 2)%172 + startn] == 0x01 && buf[(nc + 3)%172 + startn] == 0x3c)
{
relpstartN = nc;
Console.WriteLine(“epochNo=” + i + “relpstartN=” + relpstartN);
}

}
//SORT

for (ns = 0; ns < 172 – pvtstartN; ns++)
{
bufs[ns] = buf[ns + pvtstartN+startn];
//Console.WriteLine(“bufs[” + ns + “]=” + bufs[ns].ToString(“X”) + “buf[” + (ns+pvtstartN+startn) + “]=” + buf[ns+pvtstartN+startn].ToString(“X”));
}
//前半分
int nokori = 172 – pvtstartN;
for (ns = 0; ns < pvtstartN; ns++)
{
bufs[ns +nokori] = buf[ns+startn];
//Console.WriteLine(“bufs[” + (ns+nokori) + “]=” + bufs[ns + pvtstartN].ToString(“X”) + “buf[” + (ns+startn) + “]=” + buf[ns+startn].ToString(“X”));
}
//chkeck
for (ns = 0; ns < 172; ns++)
{
//Console.Write( bufs[ns].ToString(“X”));
}
Console.WriteLine();
//===========UBX 分離================================
for (int j = 0; j < 100; j++)//bufからpvtbへ格納
{
pvtb[j] = bufs[j];
Console.Write(pvtb[j].ToString(“X”));
}
Console.WriteLine();
for (int j = 0; j < 72; j++)//bufからrelpbへ格納
{
relpb[j] = bufs[j + 100];
Console.Write(relpb[j].ToString(“X”));
}
//================UBX変換===============================
string ubx0 = PVTcnv(pvtb, ref pvtd);
string ubx1 = RELPOScnv(relpb, ref relpd);
string istr = tn.ToString();
sw.WriteLine(istr + “,” + ubx0 + “,” + ubx1);

}
}//ubx for END
double itowper = (double)itowErr / k*100;
double flagper=(double)f673 / k*100;
Console.WriteLine(“********************RX”+tn+”:itowERR=” + itowErr.ToString() + “/” + k.ToString()+”<“+itowper.ToString(“F2”) + “%>,f131 =” + f131.ToString() + “,f673=” + f673.ToString()+”<“+flagper.ToString(“F2″)+”%>****************”);
//for(int ii = 0; ii < itowErr; ii++)
//{
// Console.WriteLine(“itowEarry[” + ii + “]=” + itowEarry[ii]);
//}
}//ubxtocsv END

Q: import struct は

Q: PVTcnv() をPythonで再現するときに struct をどう使うかも例付きで説明

Q: 前回の回答はクラスで」やってたclass PVT: def __init__(self): self.itow = 0 self.year = 0 self.month = 0 self.day = 0 self.hour = 0 self.min = 0 self.sec = 0 self.valid = 0 self.tacc = 0 self.nano = 0 self.fixtype = 0 self.flags = 0 self.flags2 = 0 self.numsv = 0 self.lon = 0 self.lat = 0 self.height = 0 self.hmsl = 0 self.hacc = 0 self.vacc = 0 self.veln = 0 self.vele = 0 self.veld = 0 self.gspeed = 0 self.headmot = 0 self.sacc = 0 self.headacc = 0 self.pdop = 0 self.flags3 = 0 self.resrv0 = 0 self.headveh = 0 self.magdec = 0 self.magacc = 0

Q: structのフォーマット覚えるのが嫌だからもっと単純化

Q: pvtd.itow, ofs = read(“<I”, pvtb, ofs) 意味わからない

Q: ofsが自動でインクリメントされるのが味噌

Q: ofs理解するだけで全部できるから便利

Q: structの必要性わからない

Q: 確かに楽だわ

Q: PVTcnv不要だからなおさら良い

Q: 有難う 一歩一歩進めるよ

Q: relposcnvも簡単に
class RELPOS:
def __init__(self):
self.version = 0
self.reserved1 = 0
self.refstationid = 0
self.itow = 0
self.relposn = 0
self.relpose = 0
self.relposd = 0
self.relposlength = 0
self.relposheading = 0
self.reserved2 = 0
self.relposhpn = 0
self.relposhpe = 0
self.relposhpd = 0
self.relposhplength = 0
self.accn = 0
self.acce = 0
self.accd = 0
self.acclength = 0
self.accheading = 0
self.reserved3 = 0
self.flags = 0

def RELPOScnv(d: bytes, r: RELPOS) -> str:
s = 0
relps = “”

r.version = d[s + 6]
relps += f”,{r.version}”

r.reserved1 = d[s + 7]
relps += f”,{r.reserved1}”

r.refstationid = d[s + 8] + (d[s + 9] << 8)
relps += f”,{r.refstationid}”

r.itow = to_int32(d[s + 10], d[s + 11], d[s + 12], d[s + 13])
relps += f”,{r.itow}”

r.relposn = to_int32(d[s + 14], d[s + 15], d[s + 16], d[s + 17])
relps += f”,{r.relposn}”

r.relpose = to_int32(d[s + 18], d[s + 19], d[s + 20], d[s + 21])
relps += f”,{r.relpose}”

r.relposd = to_int32(d[s + 22], d[s + 23], d[s + 24], d[s + 25])
relps += f”,{r.relposd}”

r.relposlength = to_int32(d[s + 26], d[s + 27], d[s + 28], d[s + 29])
relps += f”,{r.relposlength}”

r.relposheading = to_int32(d[s + 30], d[s + 31], d[s + 32], d[s + 33])
relps += f”,{r.relposheading}”

r.reserved2 = to_int32(d[s + 34], d[s + 35], d[s + 36], d[s + 37])
relps += f”,{r.reserved2}”

r.relposhpn = (d[s + 38] & 0x7F) – (d[s + 38] & 0x80)
relps += f”,{r.relposhpn}”

r.relposhpe = (d[s + 39] & 0x7F) – (d[s + 39] & 0x80)
relps += f”,{r.relposhpe}”

r.relposhpd = (d[s + 40] & 0x7F) – (d[s + 40] & 0x80)
relps += f”,{r.relposhpd}”

r.relposhplength = (d[s + 41] & 0x7F) – (d[s + 41] & 0x80)
relps += f”,{r.relposhplength}”

r.accn = int.from_bytes(d[s + 42:s + 46], byteorder=’little’, signed=False)
relps += f”,{r.accn}”

r.acce = int.from_bytes(d[s + 46:s + 50], byteorder=’little’, signed=False)
relps += f”,{r.acce}”

r.accd = int.from_bytes(d[s + 50:s + 54], byteorder=’little’, signed=False)
relps += f”,{r.accd}”

r.acclength = int.from_bytes(d[s + 54:s + 58], byteorder=’little’, signed=False)
relps += f”,{r.acclength}”

r.accheading = int.from_bytes(d[s + 58:s + 62], byteorder=’little’, signed=False)
relps += f”,{r.accheading}”

r.reserved3 = int.from_bytes(d[s + 62:s + 66], byteorder=’little’, signed=False)
relps += f”,{r.reserved3}”

r.flags = int.from_bytes(d[s + 66:s + 70], byteorder=’little’, signed=False)

Q: df  カラム内全行の値の一定範囲の個数カウント

Q: 前の行と現在行の差をとって、新たなカラムを作る

Q: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
File “C:\Users\dj171\PycharmProjects\STA25_binLog_speedUp_rev03.py”, line 492, in main
itowErr4 = ((df4[“iTOW_diff”] < 120) or (df4[“iTOW_diff”] > 130)).sum()

Q: itowErr4/len(df4)*100,”%” 小数点2桁にしたい

Q: byte 配列の定義

Q: df 定義

Q: スレッド無し シリアル受信 バッファにためこむ

Q: while qキーが入るまでループ回る

Q: ser.write(“a”)  エラー

Q: 5秒待ち

Q: キー入力を読む

Q: キー入力はターミナルで読まない

Q: if msvcrt.kbhit(): # キーが押されたかチェック
key = msvcrt.getch() # 押されたキーを取得(バイト型) 効いてない

Q: python 現在時刻

Q: python ターミナルのログをcsv保存したい

Q: logging

Q: mylog.logどこに保存

Q: stop_flag bool  最初はfalse

Q: closeは

Q: ファイルサイズがゼロになってしまう
def binary_log():
“””ログ処理の本体:スレッド起動と監視”””
global stop_flag
os.makedirs(LOG_DIR, exist_ok=True)
filename = f”log_{datetime.now().strftime(‘%Y%m%d_%H%M%S’)}.bin”
log_path = os.path.join(LOG_DIR, filename)

# 開始時間記録
start_time = time.time()
now = datetime.now()
print(f”[開始] ファイル名: {filename}”)
print(f”[開始] 時刻: {now}”)

# スレッド起動
thread = threading.Thread(target=receiver_thread, args=(log_path, start_time))
thread.start()

print(“[MAIN] ログ中:’q’ を押すと停止します”)
last_print = time.time()

while not stop_flag:
if msvcrt.kbhit():
key = msvcrt.getch().lower()
if key == b’q’:
print(“[MAIN] ‘q’ が押されました。停止します。”)
stop_flag = True

break

if time.time() – last_print >= 1.0:
#print(f”[MAIN] ログ中… {datetime.now().strftime(‘%H:%M:%S’)}”)
last_print = time.time()

time.sleep(0.05)

thread.join()

# 結果の表示
elapsed = time.time() – start_time
size_kb = os.path.getsize(log_path) / 1024
print(f”[完了] ファイル名: {filename}”)
print(f”[完了] 経過時間: {elapsed:.2f} 秒”)
print(f”[完了] ファイルサイズ: {size_kb:.1f} KB”)

Q: 数値文字を整数へ

Q: win10 exploreの検索が不便

Q: everthingでファイルの更新期間を指定

 

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です