Cut bytes of data received as a string in C++ - c++

Hi I am receiving string data bytes from a TCP connection which looks like this :
00500060001157 1158 1159 1160
First I want to print the entire string received and then I want to separate out the data 1157, 1158, 1159 and 1160 from this input data and print them separately. How do I do that?

Related

Reading and Writing from a csv file: want to only extract rows that do not contain zeros

I'm trying to write a program to pull information from a file, but i only want the rows that do not contain 0. I know how to get the file to print to screen but I can't seem to get the desired rows printed with out printing each individual line I want. I've tried putting the information i want into a list and writing it to a new CSV file but it just jumbles everything up into 2 rows instead of the 300+ I'm trying to get. Any help would be appreciated
Months A B C
Feb-49 0 0 0
Jan-50 95 378 3767
Feb-50 67 17 233
Jan-51 0 0 0
Feb-51 0 0 0
#This file has about 400 rows that look something like this

Reading from serial problems with Amazon FreeRTOS

I am attempting to read from the uart2 on an ESP32 DevKitC clone on a task thread.
My code is as follows:
uint8_t data[128];
data[0] = '\0'; //null terminate so we don't print garbage
for( ; ; ) {
//get a chunk of data off the FIFO buffer
const int uart_num = UART_NUM_2;
int length = 0;
IotLogInfo( "preread" );
length = uart_read_bytes(uart_num, data, 10, 1000 / portTICK_RATE_MS); //read 10 bytes or time out after a second.
if(length == -1)
IotLogInfo( "read reported error! -1" );
//did we rx anything?
if(length > 0){
data[length] = '\0'; //null terminate the string
IotLogInfo( "Rx: %i bytes", length );
IotLogInfo( "Rx: %s ", data );
}
else{
IotLogInfo( "rx no data" );
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
For some reason char 2 and 3 of the transmitted string "UVW" are getting messed with, even if the buffer holds more than a single transmission:
122 4911 [_readSerialForM] [INFO ][DEMO][49110] preread
123 5011 [_readSerialForM] [INFO ][DEMO][50110] Rx: 3 bytes
124 5011 [_readSerialForM] [INFO ][DEMO][50110] Rx: U⸮⸮
126 5011 [_readSerialForM] [INFO ][DEMO][50110] preread
127 5111 [_readSerialForM] [INFO ][DEMO][51110] Rx: 3 bytes
128 5111 [_readSerialForM] [INFO ][DEMO][51110] Rx: U⸮⸮
130 5111 [_readSerialForM] [INFO ][DEMO][51110] preread
131 5510 [_readSerialForM] [INFO ][DEMO][55100] Rx: 12 bytes
132 5510 [_readSerialForM] [INFO ][DEMO][55100] Rx: U⸮⸮U⸮⸮U⸮⸮U⸮⸮
134 5510 [_readSerialForM] [INFO ][DEMO][55100] preread
135 5710 [_readSerialForM] [INFO ][DEMO][57100] Rx: 6 bytes
136 5710 [_readSerialForM] [INFO ][DEMO][57100] Rx: U⸮⸮U⸮⸮
138 5710 [_readSerialForM] [INFO ][DEMO][57100] preread
139 5910 [_readSerialForM] [INFO ][DEMO][59100] Rx: 6 bytes
140 5910 [_readSerialForM] [INFO ][DEMO][59100] Rx: U⸮⸮U⸮⸮
"UVW" should be 0x55 x56 x57 but it appears it's being interpreted as "0x55 0xD5 0xFD", what's even weirder is if I send "UUU" to the serial which should be "0x55 0x55 0x55" it arrives as "0x55 0x55 0xF5", which is very weird as byte #2 isn't being malformed when its a repeat of the byte before it.
I have independently verified the transmission with an arduino and it reads perfectly. So I am very confused.
Im sure this is a fairly simple error on my part. However I cannot figure out what it is.
Thank you in advance.
The serial interface must be configured correctly. The settings on both ends
must be the same.
Wikipedia
writes
Many settings are required for serial connections used for asynchronous start-stop communication, to
select speed, number of data bits per character, parity, and number of stop bits per character.
(...)
Often if the settings are entered incorrectly the connection will not be dropped;
however, any data sent will be received on the other end as nonsense.
If the receiver sees a bad bit pattern on the wire it should raise "framing error" or "parity error".
However some errors cannot be detected and often those error states are simply ignored.
Another great source of problems with the serial interface is on the electric side.
The traditional RS232 comes with voltages up to +/-15V. In contrast, micro-controllers prefer classic logic signals (3.3V or 5V).
Mixing up the wires may allow some communication in one direction.
To rule out this complex you should check the signals with a multimeter or, even better, an oscilloscope.

using data not sorted (nearmrg)

I am trying to use nearmrg on my data files and I keep getting the same error:
using data not sorted
As I wanted to break down the problem I used very simple test data instead of my real data and the error message still shows up. Now I have the following:
Master.dta:
Group Date
A 15.01.2012
A 15.02.2012
B 15.01.2012
B 15.02.2012
C 15.01.2012
C 15.02.2012
Using.dta:
Group Date SVarOfInterest1 SVarOfInterest2
A 01.01.2012 1 201
A 15.01.2012 2 202
A 03.02.2012 3 203
A 23.02.2012 4 204
B 03.01.2012 11 211
B 19.01.2012 12 212
B 03.02.2012 13 213
C 20.01.2012 21 221
C 25.01.2012 22 222
C 04.02.2012 23 223
C 03.01.2012 24 224
This is the code:
nearmrg Group using Using.dta, nearvar(Date) genmatch(SourceDate) lower
using data not sorted
r(5);
It appears that Stata thinks that your using data is not sorted. Even if if looks sorted to you, run the sort command on each data file prior to running nearmrg.
tempfile myTemp
<read in Using file>
sort Group
* save temporary file
save "`myTemp'"
<read in master file>
sort Group
nearmrg Group using `myTemp', nearvar(Date) genmatch(SourceDate) lower
As a side note, nearmrg is not part of base Stata. It is helpful if you mention that it is a user written package in your question.

SAS Format Data from "flat" data source

Hope you can help.
Im trying to read flat data from mainframe with my program in SAS with this code:
INFILE DG121 TRUNCOVER
Missover FIRSTOBS=2 ;
INPUT
# 1 LAENGDE IB2.
# 3 TOTANM IB2.
# 5 REXHTYP IB2.
# 7 RMODTAFD PD3.
# 10 RANVDATO PD5.
# 15 RKUNDENR PD6.
# 21 RBRKODE PD2.
# 23 RRAADGIV ÅCHAR1.
# 24 RKUNDKAT ÅCHAR3.
# 27 RMAXOPR PD8.2
# 35 RLOBTIDO PD2.
# 37 RPRODBET ÅCHAR6.
# 43 RMEDIE ÅCHAR5.
# 48 ROPSIG ZD3.
# 69 BRUGER IB4.
I get the Note in my log:
NOTE: Invalid data for RMODTAFD in line 47291 7-9.
NOTE: Invalid data for RANVDATO in line 47291 10-14.
NOTE: Invalid data for RKUNDENR in line 47291 15-20.
NOTE: Invalid data for RBRKODE in line 47291 21-22.
NOTE: Invalid data for RMAXOPR in line 47291 27-34.
NOTE: Invalid data for RLOBTIDO in line 47291 35-36.
NOTE: Invalid data for ROPSIG in line 47291 48-50.
ERROR: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
47291 .ü.......................................................^.......................5\.................
ZONE 0A00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0500FFFFFFFFFFFFFFFFFFFF0FEFFFFFFFFFFFFFFFFF
NUMR 0100FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0F0AFFFFFFFFFFFFFFFFFFFF550FFFFFFFFFFFFFFFFF
101 .......................rrrr{.r{.rr{...........¸...èhÇ..{..}.{ 161
ZONE FFFFFFFFFFFFFFFFFFFFFF0999990990999FFF00001120900058632900429
NUMR FFFFFFFFFFFFFFFFFFFFFF99999C99C999CFFF00691462D00548862C0078C
LAENGDE=161 TOTANM=0 REXHTYP=-1 RMODTAFD=. RANVDATO=. RKUNDENR=. RBRKODE=. RRAADGIV=¤ RKUNDKAT=¤¤¤ RMAXOPR=. RLOBTIDO=.
RPRODBET=¤¤¤¤¤¤ RMEDIE=¤¤¤¤¤ ROPSIG=. BRUGER=-1 _ERROR_=1 _N_=47290
NOTE: EOV macro was not able to obtain an additional extent for library data set SYS15133.T093707.RA000.G46973.R0566335, volume
number 1. System rc = 00000B37; Reason code = 00000004.
ERROR: Write to WORK.WAB.DATA failed. File is full and may be damaged.
My question is.
I know my PD format cannot read char. But can i in some way make sas skip the data it cannot read so i dont get the note:
NOTE: Invalid data for ROPSIG in line 47291 48-50
You can use ?? input format modifier to get rid of error and make sas move on with the processing. Check out Format modifier in the SAS documentation for INPUT statement ->Format Modifiers for Error Reporting.
data input_data;
infile datalines missover;
input age ?? 8.;
datalines;
12
45
32
A
54
Z
66
;;;;
run;
proc print data=input_data;run;
So your code should be like :
INPUT
# 1 LAENGDE ?? IB2.
# 3 TOTANM ?? IB2.
# 5 REXHTYP ?? IB2.
# 7 RMODTAFD ?? PD3.
.
.
.
Also, i wanted to point out that based on your log, the error that is showing up is for space out( B37 is out of space error on Mainframe). Try increasing the allocation size of the library where the dataset is getting created to prevent that error.

rrd graph configurate query

I am updating my RRD file with some counts...
For example:
time: value:
12:00 120
12:05 135
12:10 154
12:20 144
12:25 0
12:30 23
13:35 36
here my RRD is updating as below logic:
((current value)-(previous value))/((current time)-(previous time))
eg. ((135-120))/5 = 15
but my problem is when it comes 0 the reading will be negative:
((0-144))/5
Here " 0 " value comes with system failure only( from where the data is fetched)..It must not display this reading graph.
How can I configure like when 0 comes it will not update the "RRD graph" (skip this reading (0-144/5)) and next time it will take reading like ((23-0)/5) but not (23-144/10)
When specifying the data sources when creating the RRD, you can specify which range of values is acceptable.
DS:data_source:GAUGE:10:1:U will only accept values above 1.
So if you get a 0 during an update, rrd will replace it with unknown and i assume it can find a way to discard it.