Skip to content

Commit cfb2bd3

Browse files
committed
more work on decoding #5 DCP messages. now if character 37 is not blank
render message as-is (binary) otherwise do the normal substitutions.
1 parent 16b0278 commit cfb2bd3

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

opendcs-acquisition/INSTALL.md

+8
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ eventually it gets posted:
206206
207207
```
208208

209+
## Data Encoding
210+
211+
* based on python string method: .decode('unicode-escape') expands all the \077 octal characters to ASCII equivalents.
212+
* replace \r and \n with line-feed and carriage-return respectively.
213+
* trip trailing spaces on each line.
214+
* ignore \f (formfeed) and \t (tab) and any other escape codes.
215+
* not sure what happens with \\ I think nothing.
216+
209217

210218
## Maintenance Activities
211219

opendcs-acquisition/config/sr3/plugins/dcpflow.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def gather(self):
360360
hh=raw_line[13:15]
361361
mm=raw_line[15:17]
362362
rnd="%05d" % random.randint(1,10000)
363+
is_plaintext= (raw_line[37] == ' ')
363364

364365
subdir=os.path.join( self.o.variableExpansion(self.o.directory), \
365366
f"{RxTime.year}{RxTime.month:02d}{RxTime.day:02d}", f"{self.o.source}", \
@@ -368,16 +369,19 @@ def gather(self):
368369
os.makedirs( subdir )
369370

370371
BulletinFile=os.path.join( subdir, f"{Ahl}_{dd}{hh}{mm}_{rnd}" )
371-
bf=open(BulletinFile,'w')
372+
bf=open(BulletinFile,'wb')
372373
#logger.info( f"writing: {BulletinFile}" )
373-
bf.write( f"{Ahl.replace('_',' ')} {dd}{hh}{mm}\r\r\n" )
374+
bf.write( f"{Ahl.replace('_',' ')} {dd}{hh}{mm}\r\r\n".encode('latin1') )
374375
except Exception as ex:
375376
logger.error( "problem reading ob", exc_info=True )
376377
continue
377-
for l in raw_line.split('\\n'):
378-
#l=l.replace('\\r','').replace('\\\\','\\').strip()+'\r\n'
379-
l=l.replace('\\r','').strip()+'\r\n'
380-
bf.write(l)
378+
379+
if is_plaintext:
380+
for l in raw_line.split('\\n'):
381+
l=l.replace('\\r','\r').strip()+'\n'
382+
bf.write(l.encode('latin1'))
383+
else:
384+
bf.write(byte_line)
381385

382386
if bf:
383387
bf.close()

0 commit comments

Comments
 (0)