Skip to content

Commit

Permalink
description parsing now working
Browse files Browse the repository at this point in the history
  • Loading branch information
BeSeeTek committed Dec 5, 2019
1 parent 85ed419 commit 3b0ebaf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Inc/freertos_cubemx.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extern "C" {
#include "tim64extender.h"
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 5
#define VERSION_PATCH 6
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

Expand Down
2 changes: 1 addition & 1 deletion Src/MS5837.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ int MS5837::getDescription(DescriptionMessage * Message,DescriptionMessage_DESCR
Message->has_str_Data_01=true;
Message->has_str_Data_02=true;
strncpy(Message->str_Data_01,"Temperature\0",sizeof(Message->str_Data_01));
strncpy(Message->str_Data_01,"Pressure\0",sizeof(Message->str_Data_02));
strncpy(Message->str_Data_02,"Pressure\0",sizeof(Message->str_Data_02));
}
if(DESCRIPTION_TYPE==DescriptionMessage_DESCRIPTION_TYPE_UNIT)
{
Expand Down
48 changes: 38 additions & 10 deletions tools/MET4FOFDataReceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,26 @@ def __str__(self):
#todo override set methode
def setDescription(self,key,value):
self.Description[key]=value
if(self.Description['PHYSICAL_QUANTITY']!=False and
self.Description['UNIT']!=False and
self.Description['RESOLUTION']!=False and
self.Description['MIN_SCALE']!=False and
self.Description['MAX_SCALE']!=False):
self._complete=True

class SensorDescription:
def __init__(self,ID,SensorName):
self.ID=ID
self.SensorName=SensorName
self._complete=False
self.Channels=AliasDict([])
self.ChannelCount=0
self._ChannelsComplte=0

def setChannelParam(self,CHID,key,value):
wasComplete=False
if CHID in self.Channels:
wasComplete=self.Channels[CHID]._complete#read if channel was completed before
self.Channels[CHID].setDescription(key,value)
if(key=='PHYSICAL_QUANTITY'):
self.Channels.add_alias(CHID,value)#make channels callable by their Quantity
Expand All @@ -234,11 +245,26 @@ def setChannelParam(self,CHID,key,value):
self.Channels[CHID]=ChannelDescription(CHID)
self.Channels[CHID].setDescription(key,value)
self.Channels.add_alias(CHID,'Data_'+'{:02d}'.format(CHID))#make channels callable by ther Data_xx name
self.ChannelCount=self.ChannelCount+1
if(wasComplete==False and self.Channels[CHID]._complete):
self._ChannelsComplte=self._ChannelsComplte+1
if( self._ChannelsComplte==self.ChannelCount):
self._complete=True
print("Description completed")

def __getitem__(self, key):
#if key='SpecialKey':
# self.Description['SpecialKey']
return self.Channels[key]

def getDict(self):
RetunDict={'Name':self.SensorName}
for key in self.Channels:
print(self.Channels[key].Description)
RetunDict.update({self.Channels[key]['CHID']:self.Channels[key].Description})
return RetunDict


class Sensor:
StrFieldNames=['str_Data_01','str_Data_02','str_Data_03','str_Data_04','str_Data_05','str_Data_06','str_Data_07','str_Data_08','str_Data_09',
'str_Data_10','str_Data_11','str_Data_12','str_Data_13','str_Data_14','str_Data_15','str_Data_16']
Expand Down Expand Up @@ -313,8 +339,11 @@ def run(self):
#run only if no description packed has been procesed ever
#self.Description.SensorName=message.Sensor_name
print('Found new '+Description.Sensor_name+' sensor with ID:'+str(self.params['ID']))
print(str(Description.Description_Type))
#print(str(Description.Description_Type))
if self.DescriptionsProcessed[Description.Description_Type]==False :

if( self.Description.SensorName=='Name not Set'):
self.Description.SensorName=Description.Sensor_name
#we havent processed thiss message before now do that
if Description.Description_Type in [0,1,2]:#["PHYSICAL_QUANTITY","UNIT","UNCERTAINTY_TYPE"]
#print(Description)
Expand All @@ -324,21 +353,20 @@ def run(self):
for StrField in self.StrFieldNames:
if Description.HasField(StrField):
self.Description.setChannelParam(FieldNumber,self.DescriptionTypNames[Description.Description_Type],Description.__getattribute__(StrField))
print(str(FieldNumber)+' '+Description.__getattribute__(StrField))
#print(str(FieldNumber)+' '+Description.__getattribute__(StrField))
FieldNumber=FieldNumber+1

self.DescriptionsProcessed[Description.Description_Type]=True
print(self.DescriptionsProcessed)
#print(self.DescriptionsProcessed)
if Description.Description_Type in [3,4,5]:#["RESOLUTION","MIN_SCALE","MAX_SCALE"]
self.DescriptionsProcessed[Description.Description_Type]=True
FieldNumber=1
for FloatField in self.FFieldNames:
if Description.HasField(FloatField):
self.Description.setChannelParam(FieldNumber,self.DescriptionTypNames[Description.Description_Type],Description.__getattribute__(StrField))
print(str(FieldNumber)+' '+str(Description.__getattribute__(FloatField)))

self.Description.setChannelParam(FieldNumber,self.DescriptionTypNames[Description.Description_Type],Description.__getattribute__(FloatField))
#print(str(FieldNumber)+' '+str(Description.__getattribute__(FloatField)))
FieldNumber=FieldNumber+1
print(self.DescriptionsProcessed)
#print(self.DescriptionsProcessed)
#string Processing
except Exception:
print (" Sensor id:"+hex(self.params["ID"])+"Exception in user Description parsing:")
Expand All @@ -348,7 +376,7 @@ def run(self):
if self.flags["callbackSet"]:
if(message['Type']=='Data'):
try:
self.callback(message['ProtMsg'])
self.callback(message['ProtMsg'],self.Description)
except Exception:
print (" Sensor id:"+hex(self.params["ID"])+"Exception in user callback:")
print('-'*60)
Expand Down Expand Up @@ -382,7 +410,7 @@ def stop(self):
def join(self, *args, **kwargs):
self.stop()

def DumpDataMPU9250(message):
def DumpDataMPU9250(message,Description):
filename='data/DataDump.log'
if not (os.path.exists(filename)):
dumpfile = open(filename, "a+")
Expand Down Expand Up @@ -418,7 +446,7 @@ def DumpDataMPU9250(message):
# '\n TEMP:',message.Data_10,
# '\n ADC:',message.Data_11,message.Data_12,message.Data_13),

def DumpDataGPSDummySensor(message):
def DumpDataGPSDummySensor(message,Description):
if not (os.path.exists('data/GPSLog.log')):
dumpfile = open('data/GPSLog.log', "a+")
dumpfile.write("id;sample_number;unix_time;unix_time_nsecs;time_uncertainty;GPSCount\n")
Expand Down

0 comments on commit 3b0ebaf

Please sign in to comment.