diff --git a/cosmicpi-arduino.ino b/cosmicpi-arduino.ino index a7439b4..a327e92 100644 --- a/cosmicpi-arduino.ino +++ b/cosmicpi-arduino.ino @@ -27,44 +27,35 @@ // All fields in all output strings conform to the json standard // Here is the list of all records where 'f' denotes float and 'i' denotes integer ... -// {'HTU':{'Tmh':f,'Hum':f}} -// HTU21DF record containing Tmh:temperature in C Hum:humidity percent +// {'temperature':{'temperature':f,'humidity':f}} +// HTU21DF record // -// {'BMP':{'Tmb':f,'Prs':f,'Alb':f}} -// BMP085 record containing Tmb:temperature Prs:pressure Alb:Barrometric altitude +// {'barometer':{'temperature':f,'pressure':f,'altitude':f}} +// BMP085 record // -// {'VIB':{'Vax':i,'Vcn':i}} -// Vibration record containing Vax:3 bit xyz direction mask Vcn:vibration count -// This record is always immediatly followed by 3 more records, TIM, ACL, and MAG +// {'vibration':{'direction':i,'count':i}} +// Vibration record containing "direction":3 bit xyz direction mask "count":vibration count +// This record is always immediatly followed by 3 more records, "timing", "accelerometer", and "magnetometer" // -// {'MAG':{'Mgx':f,'Mgy':f,'Mgz':f}} -// LSM303DLH magnatometer record containing Mgx:the x field strength Mgy:the y field Mgz:ther z field +// {'magnetometer':{'x':f,'y':f,'x':f}} +// LSM303DLH magnetometer record containing "x":the x field strength "y":the y field "z":the z field // -// {'MOG':{'Mox':f,'Moy':f,'Moz':f}} -// LSM303DLH magnatometer record containing Mox:x orientation Moy:y orientation Moz:z orientation -// This record is optional, by default its turned off (it can always be calculated later - Python) +// {'accelerometer':{'x':f,'y':f,'z':f}} +// LSM303DLH accelerometer record +// If this record immediately follows a "vibration" record the fields were hardware latched when the g threshold was exceeded // -// {'ACL':{'Acx':f,'Acy':f,'Acz':f}} -// LSM303DLH acclerometer record containing Acx:the x acceleration Acy:the y acceleration Acz:the z acceleration -// If this record immediatly follows a VIB record the fields were hardware latched when the g threshold was exceeded +// {'location':{'latitude':f,'longitude':f,'altitude':f}} +// GPS location record containing "latitude":latitude in degrees "longitude":longitude in degrees "altitude":altitude in meters // -// {'AOL':{'Aox':f,'Aoy':f,'Aoz':f}} -// LSM303DLH accelerometer record containing Aox:x orientation Aoy:y orientation Aoz:z orientation -// This record is optional, by default its turned off (it can always be calculated later - Python) +// {'timing':{'uptime':i,'counter_frequency':i,'time_string':i}} +// Time record containing "uptime":up time seconds "counter_frequency":counter frequency "time_string":time string // -// {'LOC':{'Lat':f,'Lon':f,'Alt':f}} -// GPS location record containing Lat:latitude in degrees Lon:longitude in degrees Alt:altitude in meters +// {'status':{'queue_size':i,'missed_events':i,'buffer_error':i,'temp_status':i,'baro_status':i,'accel_status':i,'mag_status':i, 'gps_status':i}} +// Status record // -// {'TIM':{'Upt':i,'Frq':i,'Sec':i}} -// Time record containing Upt:up time seconds Frq:counter frequency Sec:time string -// -// {'STS':{'Qsz':i,'Mis':i,'Ter':i,'Htu':i,'Bmp':i,'Acl':i,'Mag':i, 'Gps':i}} -// Status record containing Qsz:events on queue Mis:missed events Ter:buffer error -// Htu:status Bmp:status Acl:status Mag:status Gps:ststus -// -// {'EVT':{'Evt':i,'Frq':i,'Tks':i,'Etm':f,'Adc':[[i,i,i,i,i,i,i,i][i,i,i,i,i,i,i,i]]}} -// Event record containing Evt:event number in second Frq:timer frequency Tks:ticks since last event in second -// Etm:event time stamp to 100ns Adc:[[Channel 0 values][Channel 1 values]] +// {'event':{'event_number':i,'timer_frequency':i,'ticks':i,'timestamp':f,'adc':[[i,i,i,i,i,i,i,i][i,i,i,i,i,i,i,i]]}} +// Event record containing "event_number":event number in second "ticks":ticks since last event in seconds +// "timestamp":event time stamp to 100ns adc:[[Channel 0 values][Channel 1 values]] // N.B. These records pass the data to a python monitor over the serial line. Python has awsome string handling and looks them up in // associative arrays to build records of any arbitary format you want. So this is only the start of the story of record processing. @@ -796,7 +787,7 @@ void PushHtu(int flg) { // If flg is true always push if ((flg) || ((htu_ok) && ((ppcnt % humtmp_display_rate) == 0))) { temph = htu.readTemperature(); humid = htu.readHumidity(); - sprintf(txt,"{'HTU':{'Tmh':%5.3f,'Hum':%4.1f}}\n",temph,humid); + sprintf(txt,"{'temperature':{'temperature':%5.3f,'humidity':%4.1f}}\n",temph,humid); PushTxt(txt); } } @@ -817,7 +808,7 @@ void PushBmp(int flg) { // If flg is true always push bmp.getTemperature(&tempb); altib = bmp.pressureToAltitude((float) SENSORS_PRESSURE_SEALEVELHPA, presr,tempb); - sprintf(txt,"{'BMP':{'Tmb':%5.3f,'Prs':%5.3f,'Alb':%4.1f}}\n",tempb,presr,altib); + sprintf(txt,"{'barometer':{'temperature':%5.3f,'pressure':%5.3f,'altitude':%4.1f}}\n",tempb,presr,altib); PushTxt(txt); } } @@ -838,7 +829,7 @@ uint32_t old_icount = 0; PushTim(1); // Push these first, and then vib PushAcl(1); // This is the real latched value PushMag(1); - sprintf(txt,"{'VIB':{'Vax':%d,'Vcn':%d}}\n",accl_flag,accl_icount); + sprintf(txt,"{'vibration':{'direction':%d,'count':%d}}\n",accl_flag,accl_icount); PushTxt(txt); } } @@ -855,19 +846,11 @@ void PushMag(int flg) { // Push the mago stuff // Micro Tesla - sprintf(txt,"{'MAG':{'Mgx':%f,'Mgy':%f,'Mgz':%f}}\n", + sprintf(txt,"{'magnetometer':{'x':%f,'y':%f,'z':%f}}\n", mag_event.magnetic.x, mag_event.magnetic.y, mag_event.magnetic.z); PushTxt(txt); - - // Orientation (Easy to calculate later in Python - dont waste resources) -#ifdef ORIENTATION - if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &xyz)) { - sprintf(txt,"{'MOG':{'Mox':%f,'Moy':%f,'Moz':%f}}\n",xyz.x,xyz.y,xyz.z); - PushTxt(txt); - } -#endif } } @@ -882,19 +865,11 @@ void PushAcl(int flg) { // Push the accelerometer and compass stuff // Meters per second squared - sprintf(txt,"{'ACL':{'Acx':%f,'Acy':%f,'Acz':%f}}\n", + sprintf(txt,"{'accelerometer':{'x':%f,'y':%f,'z':%f}}\n", acl_event.acceleration.x, acl_event.acceleration.y, acl_event.acceleration.z); PushTxt(txt); - - // Orientation (Easy to calculate later in Python - dont waste resources) -#ifdef ORIENTATION - if (dof.accelGetOrientation(&acl_event, &xyz)) { - sprintf(txt,"{'AOL':{'Aox':%f,'Aoy':%f,'Aoz':%f}}\n",xyz.x,xyz.y,xyz.z); - PushTxt(txt); - } -#endif } } @@ -903,7 +878,7 @@ void PushAcl(int flg) { // Push the accelerometer and compass stuff void PushLoc(int flg) { if ((flg) || ((ppcnt % latlon_display_rate) == 0)) { - sprintf(txt,"{'LOC':{'Lat':%f,'Lon':%f,'Alt':%f}}\n",latitude,longitude,altitude); + sprintf(txt,"{'location':{'latitude':%f,'longitude':%f,'altitude':%f}}\n",latitude,longitude,altitude); PushTxt(txt); } } @@ -913,7 +888,7 @@ void PushLoc(int flg) { void PushTim(int flg) { if ((flg) || ((ppcnt % frqutc_display_rate) == 0)) { - sprintf(txt,"{'TIM':{'Upt':%4d,'Frq':%7d,'Sec':%s}}\n",ppcnt,rega0,rdtm); + sprintf(txt,"{'timing':{'uptime':%4d,'counter_frequency':%7d,'time_string':%s}}\n",ppcnt,rega0,rdtm); PushTxt(txt); } } @@ -924,7 +899,7 @@ void PushSts(int flg, int qsize, int missed) { uint8_t res; if ((flg) || ((ppcnt % status_display_rate) == 0)) { - sprintf(txt,"{'STS':{'Qsz':%2d,'Mis':%2d,'Ter':%d,'Htu':%d,'Bmp':%d,'Acl':%d,'Mag':%d,'Gps':%d}}\n", + sprintf(txt,"{'status':{'queue_size':%2d,'missed_events':%2d,'buffer_error':%d,'temp_status':%d,'baro_status':%d,'accel_status':%d,'mag_status':%d,'gps_status':%d}}\n", qsize,missed,terr,htu_ok,bmp_ok,acl_ok,mag_ok,gps_ok); PushTxt(txt); terr = 0; @@ -970,8 +945,8 @@ void PushEvq(int flg, int *qsize, int *missed) { // Build string and push it out to the print buffer sprintf(txt, - "{'EVT':{'Evt':%1d,'Frq':%8d,'Tks':%8d,'Etm':%s%s," - "'Adc':[[%d,%d,%d,%d,%d,%d,%d,%d],[%d,%d,%d,%d,%d,%d,%d,%d]]}}\n", + "{'event':{'event_number':%1d,'timer_frequency':%8d,'ticks':%8d,'timestamp':%s%s," + "'adc':[[%d,%d,%d,%d,%d,%d,%d,%d],[%d,%d,%d,%d,%d,%d,%d,%d]]}}\n", eb.Count, eb.Frequency, eb.Ticks, eb.DateTime, index(stx,'.'), eb.Ch0[0],eb.Ch0[1],eb.Ch0[2],eb.Ch0[3],eb.Ch0[4],eb.Ch0[5],eb.Ch0[6],eb.Ch0[7], eb.Ch1[0],eb.Ch1[1],eb.Ch1[2],eb.Ch1[3],eb.Ch1[4],eb.Ch1[5],eb.Ch1[6],eb.Ch1[7]);