Garmin Fleet Management Controller  2.19.0
SensorListItem.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * SensorListItem.cpp
5 *
6 * Copyright 2014 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "SensorListItem.h"
12 #include <sstream>
13 
14 #if( FMI_SUPPORT_A617 )
15 
16 //----------------------------------------------------------------------
18 //----------------------------------------------------------------------
20 {
21  numUpdates = 0;
22 }
23 
24 void SensorListItem::readFromStream( std::istream &aStream )
25 {
28 
29  if( !aStream.eof() )
30  {
31  aStream >> config.change_id;
32  aStream.get();
33  }
34  if( !aStream.eof() )
35  {
36  uint8 buffer;
37  aStream >> buffer;
38  config.display_index = buffer;
39  aStream.get();
40  }
41  if( !aStream.eof() )
42  {
43  aStream >> config.icon;
44  aStream.get();
45  }
46  if( !aStream.eof() )
47  {
48  aStream >> numUpdates;
49  aStream.get();
50  }
51  if( numUpdates > 0 )
52  {
53  if( !aStream.eof() )
54  {
55  aStream >> update.change_id;
56  aStream.get();
57  }
58  if( !aStream.eof() )
59  {
60  aStream >> update.unique_id;
61  aStream.get();
62  }
63  if( !aStream.eof() )
64  {
65  uint8 buffer;
66  aStream >> buffer;
67  update.severity = buffer;
68  aStream.get();
69  }
70  if( !aStream.eof() )
71  {
72  int buffer;
73  aStream >> buffer;
74  update.play_sound = buffer;
75  aStream.get();
76  }
77  if( !aStream.eof() )
78  {
79  int buffer;
80  aStream >> buffer;
81  update.record_sensor = buffer;
82  aStream.get();
83  }
84  if( !aStream.eof() )
85  {
86  aStream.getline(update.status, sizeof(update.status), '-');
87  }
88  if( !aStream.eof() )
89  {
90  aStream.getline(update.description, sizeof(update.status), '-');
91  }
92  }
93 
94  if( !aStream.eof() )
95  {
96  aStream >> config.unique_id;
97  aStream.get();
98  }
99  if( !aStream.eof() )
100  {
101  aStream >> config.name;
102  }
103 
104  setConfig( config );
105 
106  //config's unique id has to be set before this happens.
107  if( numUpdates > 0 )
108  {
109  setUpdate( update );
110  }
111 
112  setCurrentName( CString( config.name ) );
113  setId( config.unique_id );
114 
115  //make sure it's not a sensor with junk data
116  if( config.icon < 52428 )
117  {
118  setValid();
119  }
120 }
121 
122 void SensorListItem::writeToStream( std::ofstream &aStream )
123 {
124  std::ostringstream os;
125  os << (uint32)getChangeId();
126  aStream << os.str().c_str();
127  aStream << "-";
128  os.clear();
129  os.str("");
130 
131  os << (uint8)getDisplayIndex();
132  aStream << os.str().c_str();
133  aStream << "-";
134  os.clear();
135  os.str("");
136 
137  os << getIcon();
138  aStream << os.str().c_str();
139  aStream << "-";
140  os.clear();
141  os.str("");
142 
143  os << numUpdates;
144  aStream << os.str().c_str();
145  aStream << "-";
146  os.clear();
147  os.str("");
148 
149  if( numUpdates > 0 )
150  {
151  os << (uint32)mUpdate.change_id;
152  aStream << os.str().c_str();
153  aStream << "-";
154  os.clear();
155  os.str("");
156 
157  os << (uint32)mUpdate.unique_id;
158  aStream << os.str().c_str();
159  aStream << "-";
160  os.clear();
161  os.str("");
162 
163  os << (uint8)mUpdate.severity;
164  aStream << os.str().c_str();
165  aStream << "-";
166  os.clear();
167  os.str("");
168 
169  os << (int)getPlaySound();
170  aStream << os.str().c_str();
171  aStream << "-";
172  os.clear();
173  os.str("");
174 
175  os << (int)getRecordSensor();
176  aStream << os.str().c_str();
177  aStream << "-";
178  os.clear();
179  os.str("");
180 
181  aStream << getStatus();
182  aStream << "-";
183 
184  aStream << getDescription();
185  aStream << "-";
186  }
187 
189 }
190 
191 //----------------------------------------------------------------------
194 //----------------------------------------------------------------------
196 {
197  return numUpdates;
198 }
199 
200 //----------------------------------------------------------------------
203 //----------------------------------------------------------------------
205 {
206  return mConfig.change_id;
207 }
208 
209 //----------------------------------------------------------------------
212 //----------------------------------------------------------------------
214 {
215  return mConfig.unique_id;
216 }
217 
218 //----------------------------------------------------------------------
221 //----------------------------------------------------------------------
223 {
224  return mConfig.icon;
225 }
226 
227 //----------------------------------------------------------------------
230 //----------------------------------------------------------------------
232 {
233  return mConfig.display_index;
234 }
235 
236 //----------------------------------------------------------------------
239 //----------------------------------------------------------------------
240 const char* SensorListItem::getName() const
241 {
242  return &mConfig.name[0];
243 }
244 
245 //----------------------------------------------------------------------
248 //----------------------------------------------------------------------
250 {
251  return mUpdate.severity;
252 }
253 
254 //----------------------------------------------------------------------
257 //----------------------------------------------------------------------
259 {
260  return mUpdate.play_sound;
261 }
262 
263 //----------------------------------------------------------------------
266 //----------------------------------------------------------------------
268 {
269  return mUpdate.record_sensor;
270 }
271 
272 //----------------------------------------------------------------------
275 //----------------------------------------------------------------------
276 const char* SensorListItem::getStatus() const
277 {
278  return &mUpdate.status[0];
279 }
280 
281 //----------------------------------------------------------------------
284 //----------------------------------------------------------------------
286 {
287  return &mUpdate.description[0];
288 }
289 
290 //----------------------------------------------------------------------
293 //----------------------------------------------------------------------
295  (
297  )
298 {
299  mConfig = aConfig;
300 }
301 
302 //----------------------------------------------------------------------
305 //----------------------------------------------------------------------
307  (
309  )
310 {
311  if( getUniqueId() == aUpdate.unique_id )
312  {
313  mUpdate = aUpdate;
314  numUpdates++;
315  }
316 }
317 
318 //----------------------------------------------------------------------
321 //----------------------------------------------------------------------
323  (
325  )
326 {
327  mParent = aParent;
328 }
329 
330 //----------------------------------------------------------------------
333 //----------------------------------------------------------------------
335  (
336  CString aName
337  )
338 {
339  mCurrentName = aName;
340 }
341 //----------------------------------------------------------------------
344 //----------------------------------------------------------------------
346  (
347  uint8 index
348  )
349 {
350  mConfig.display_index = index;
351 }
352 
353 
354 #endif
boolean getPlaySound() const
Get the play sound setting.
uint32 getNumUpdates() const
Get the number of updates submitted.
void setId(const key_type &aId)
Set item&#39;s ID.
Data type for Update Sensor Request Packet ID (0x1406) from server to client.
Definition: fmi.h:2184
boolean getRecordSensor() const
Get the record sensor setting.
fmi_sensor_config_request mConfig
uint32 getChangeId() const
Get the change id.
FileBackedMap< SensorListItem > * mParent
The map that this item belongs to, or NULL if none.
void setValid(BOOL aValid=TRUE)
Set this item as valid.
char description[110]
Definition: fmi.h:2193
void setCurrentName(CString aName)
Set the current name of the sensor.
virtual void writeToStream(std::ofstream &aStream) const
Write a ClientListItem to an output stream.
CString mCurrentName
The last name acknowledged by the client.
void setDisplayIndex(uint8 index)
Set dispolay index in the list.
fmi_sensor_update_request mUpdate
virtual void readFromStream(std::istream &aStream)
Read a ClientListItem from an input stream.
unsigned short int uint16
16-bit unsigned integer
Definition: garmin_types.h:64
uint8 getDisplayIndex() const
Get display index.
virtual void writeToStream(std::ofstream &aStream)
Stores the name associated with a list item that is sent to the client.
const char * getName() const
Get name.
void setUpdate(fmi_sensor_update_request mUpdate)
Set the update.
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
uint32 getUniqueId() const
Get the unique id.
uint8 getSeverity() const
Get the severity.
Data type for Configure Sensor Request Packet ID (0x1402) from server to client.
Definition: fmi.h:2155
const char * getStatus() const
Get the status.
uint16 getIcon() const
Get icon.
void setConfig(fmi_sensor_config_request aConfig)
Set the sensor.
unsigned long int uint32
32-bit unsigned integer
Definition: garmin_types.h:66
void setParent(FileBackedMap< SensorListItem > *aParent)
Set the parent.
const char * getDescription() const
Get the description.
SensorListItem()
Constructor.