1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                ICCONFIG.H                                 */
4 /*                                                                           */
5 /* (C) 1995-97  Ullrich von Bassewitz                                        */
6 /*              Wacholderweg 14                                              */
7 /*              D-70597 Stuttgart                                            */
8 /* EMail:       uz@ibb.schwaben.com                                          */
9 /*                                                                           */
10 /*****************************************************************************/
11 
12 
13 
14 // $Id$
15 //
16 // $Log$
17 //
18 //
19 
20 
21 
22 #ifndef _ICCONFIG_H
23 #define _ICCONFIG_H
24 
25 
26 
27 #include <string.h>
28 
29 #include "coll.h"
30 
31 #include "icver.h"
32 #include "istecmsg.h"
33 
34 
35 
36 /*****************************************************************************/
37 /*                                 Constants                                 */
38 /*****************************************************************************/
39 
40 
41 
42 // Possible values for IstecBaseConfig.Connection
43 const unsigned coPointToMulti           = 0;
44 const unsigned coPointToPoint           = 1;
45 const unsigned coMax                    = 1;
46 
47 // Possible values for IstecBaseConfig.Protocol
48 const unsigned pr1TR6                   = 0;
49 const unsigned prDSS1                   = 1;
50 const unsigned prMax                    = 1;
51 
52 // Possible values for IstecBaseConfig.DialCaps
53 const unsigned dcKeine                  = 0;
54 const unsigned dcInland                 = 1;
55 const unsigned dcOrt                    = 2;
56 const unsigned dcHalbamt                = 3;
57 const unsigned dcNichtamt               = 4;
58 const unsigned dcMax                    = 4;
59 
60 // Possible values for IstecBaseConfig.Service
61 const unsigned svFernsprechen           = 0;
62 const unsigned svFaxG3                  = 1;
63 const unsigned svDatenModem             = 2;
64 const unsigned svDatexJModem            = 3;
65 const unsigned svAnrufbeantworter       = 4;
66 const unsigned svKombi                  = 5;
67 
68 // Flags for the internal and external knock bitsets
69 const unsigned knInt21                  = 0x0001;
70 const unsigned knInt22                  = 0x0002;
71 const unsigned knInt23                  = 0x0004;
72 const unsigned knInt24                  = 0x0008;
73 const unsigned knInt25                  = 0x0010;
74 const unsigned knInt26                  = 0x0020;
75 const unsigned knInt27                  = 0x0040;
76 const unsigned knInt28                  = 0x0080;
77 const unsigned knMSN0                   = 0x0001;
78 const unsigned knMSN1                   = 0x0002;
79 const unsigned knMSN2                   = 0x0004;
80 const unsigned knMSN3                   = 0x0008;
81 const unsigned knMSN4                   = 0x0010;
82 const unsigned knMSN5                   = 0x0020;
83 const unsigned knMSN6                   = 0x0040;
84 const unsigned knMSN7                   = 0x0080;
85 const unsigned knMSN8                   = 0x0100;
86 const unsigned knMSN9                   = 0x0200;
87 const unsigned knTFE1                   = 0x0400;
88 const unsigned knTFE2                   = 0x0800;
89 const unsigned knTFE3                   = 0x1000;
90 const unsigned knTFE4                   = 0x2000;
91 
92 // Signaling
93 const unsigned siStandard               = 0;
94 const unsigned siSignal1                = 1;
95 const unsigned siSignal2                = 2;
96 const unsigned siSignal3                = 3;
97 const unsigned siNone                   = 4;
98 
99 // Reroute conditions
100 const unsigned rcNone                   = 0;
101 const unsigned rcUnconditional          = 1;
102 const unsigned rcBusy                   = 2;
103 const unsigned rcDelayed                = 3;
104 
105 // Count of MSN's
106 const unsigned bcMSNCount               = 10;
107 
108 // Maximum count of devices
109 const unsigned IstecDevCount            = 64;
110 
111 // Short number count (default)
112 const unsigned ShortNumberCount         = 60;
113 
114 // Number of first and last usable device
115 const unsigned FirstDev                 = 21;
116 const unsigned LastDev                  = 28;
117 
118 // Raw sizes of the transmission data buffers. The actual space occupied from
119 // the date maybe less, depending on the istec firmware version.
120 const unsigned BaseConfigSize           = 116;
121 const unsigned DevConfigSize            = 26;
122 const unsigned ChargeSize               = 128;
123 
124 
125 
126 /*****************************************************************************/
127 /*                           class IstecBaseConfig                           */
128 /*****************************************************************************/
129 
130 
131 
132 // Basic ISTEC configuration struct
133 class IstecBaseConfig: public Streamable {
134 
135 public:
136     unsigned char       Connection;
137     unsigned char       DevCount;
138     unsigned char       Protocol;
139     unsigned char       VersionHigh;
140     unsigned char       VersionLow;
141     unsigned char       TFEAssignment;
142 
143     unsigned char       MSN [bcMSNCount] [5];   // MSN in BCD
144 
145     unsigned char       Music;                  // 0 == off, 1 == on
146     unsigned char       IntS0;
147     unsigned char       ExtS0;
148 
149     unsigned char       QueryLoc1;
150     unsigned char       QueryLoc2;
151     unsigned char       Number1 [11];           // Number 1, pascal style
152     unsigned char       Number2 [11];           // Number 2, pascal style
153 
154     unsigned char       MSNGroups [10];
155 
156 //  ----------------------------------------    // 1.93 and up
157     unsigned char       MusicPort;
158     u16                 CountryCode;
159     unsigned char       TFELoc [4];             // TFE Location (bitmap)
160 
161 //  ----------------------------------------    // 2.00 and up
162 
163     unsigned char       AlarmTone;              // Unused according to E. docs
164     unsigned char       Signaling [bcMSNCount];
165     unsigned char       Reserved [5];
166 
167 
168     IstecBaseConfig ();
169     // Constructor
170 
171     IstecBaseConfig (StreamableInit);
172     // Build constructor
173 
174     virtual void Load (Stream& S);
175     // Load the object from a stream
176 
177     virtual void Store (Stream& S) const;
178     // Store the object into a stream
179 
180     virtual u16 StreamableID () const;
181     // Return the stream ID
182 
183     static Streamable* Build ();
184     // Return a new instance
185 
186     unsigned char* Pack (unsigned char* Buf) const;
187     // Pack the data of struct IstecBaseConfig into an array ready for
188     // transmission. The function returns Buf.
189 
190     IstecBaseConfig& Unpack (const unsigned char* Buf);
191     IstecBaseConfig& Unpack (const IstecMsg& Msg);
192     // Unpack an array of char that contains data for an IstecBaseConfig struct.
193     // The function returns *this and corrects invalid raw values.
194 
195     friend int operator == (const IstecBaseConfig&, const IstecBaseConfig&);
196     friend int operator != (const IstecBaseConfig&, const IstecBaseConfig&);
197     // Compare two structs
198 
199     double GetFirmwareVersion () const;
200     // Return the firmware version from this base configuration
201 
202     unsigned IstecID () const;
203     // Return the type of the istec, determined by the parameters of the base
204     // configuration. The return value is 0 if the istec type could not be
205     // identified, 1008 for an istec 1008 etc.
206 
207 };
208 
209 
210 
IstecBaseConfig(StreamableInit)211 inline IstecBaseConfig::IstecBaseConfig (StreamableInit)
212 // Build constructor
213 {
214 }
215 
216 
217 
GetFirmwareVersion()218 inline double IstecBaseConfig::GetFirmwareVersion () const
219 // Return the firmware version from this base configuration
220 {
221     return double (VersionHigh) + double (VersionLow) / 100;
222 }
223 
224 
225 
226 /*****************************************************************************/
227 /*                           class IstecDevConfig                            */
228 /*****************************************************************************/
229 
230 
231 
232 // Configuration of the devices device
233 class IstecDevConfig: public Streamable {
234 
235 public:
236     unsigned char       DevNum;
237     unsigned char       DialCaps;
238     unsigned char       Service;
239     unsigned char       Reroute;
240     unsigned char       ChargePulse;
241     unsigned char       PIN [2];
242     String              ExtNum;
243 
244 //  ---------------------------------   // 1.93 and up
245     unsigned char       TerminalMode;
246 
247 //  ---------------------------------   // 1.94 and up
248     unsigned char       InternalKnock;
249     unsigned char       Fill1;
250     u16                 ExternalKnock;
251 
252 //  ---------------------------------   // 1.95 and up
253 
254     unsigned char       ExtNumLen;      // Length of external number
255 
256 //  ---------------------------------   // 2.00 and up
257 
258     unsigned char       RerouteIfBusy;
259     unsigned char       RerouteDelayed;
260     unsigned char       RingsUntilReroute;
261 
262 
263     IstecDevConfig (unsigned char aDevNum);
264     // Create an IstecDevConfig
265 
266     IstecDevConfig (StreamableInit);
267     // Build constructor
268 
269     virtual void Load (Stream& S);
270     // Load the object from a stream
271 
272     virtual void Store (Stream& S) const;
273     // Store the object into a stream
274 
275     virtual u16 StreamableID () const;
276     // Return the stream ID
277 
278     static Streamable* Build ();
279     // Return a new instance
280 
281     String GetPIN () const;
282     // Get the PIN as a string
283 
284     void SetPIN (const String& aPIN);
285     // Set the PIN from a string
286 
287     void SetReroute (const String& Phone, unsigned Cond = rcUnconditional);
288     // Set the reroute according to Phone and Cond. If Cond is the default
289     // (rcUnconditional) and Phone is empty, Cond is corrected to rcNone
290     // (this simplifies handling of reroutes).
291 
292     String GetReroute () const;
293     // Get the reroute number
294 
295     unsigned GetRerouteCondition () const;
296     // Get the current setting for the reroute condition
297 
298     unsigned GetRerouteRings () const;
299     // Get the "rings until reroute" value
300 
301     void SetRerouteRings (unsigned Rings);
302     // Set the "rings until reroute" value
303 
304     unsigned char* Pack (unsigned char* Buf,
305                          double aFirmwareVersion = FirmwareVersion) const;
306     // Pack the data of struct IstecDevConfig into an array ready for
307     // transmission. The function returns Buf.
308 
309     IstecDevConfig& Unpack (const unsigned char* Buf,
310                             double aFirmware = FirmwareVersion);
311     IstecDevConfig& Unpack (const IstecMsg& Msg, double aFirmware = FirmwareVersion);
312     // Unpack an array of char that contains data for a IstecDevConfig struct.
313     // The function returns this.
314 
315     friend int operator == (const IstecDevConfig&, const IstecDevConfig&);
316     friend int operator != (const IstecDevConfig&, const IstecDevConfig&);
317     // Compare two structs
318 
319     int GetIntKnock (unsigned Bit) const;
320     // Return true if the internal knock bit is set
321 
322     int GetExtKnock (unsigned Bit) const;
323     // Return true if the external knock bit is set
324 
325     void SetIntKnock (unsigned Bit);
326     // Set the interal knock to true
327 
328     void SetExtKnock (unsigned Bit);
329     // Set the external knock to true
330 
331     void ClrIntKnock (unsigned Bit);
332     // Set the interal knock to false
333 
334     void ClrExtKnock (unsigned Bit);
335     // Set the external knock to false
336 
337 };
338 
339 
340 
IstecDevConfig(StreamableInit)341 inline IstecDevConfig::IstecDevConfig (StreamableInit):
342     ExtNum (Empty)
343 // Build constructor
344 {
345 }
346 
347 
348 
GetIntKnock(unsigned Bit)349 inline int IstecDevConfig::GetIntKnock (unsigned Bit) const
350 // Return true if the internal knock bit is set
351 {
352     return (InternalKnock & Bit) != 0;
353 }
354 
355 
356 
GetExtKnock(unsigned Bit)357 inline int IstecDevConfig::GetExtKnock (unsigned Bit) const
358 // Return true if the external knock bit is set
359 {
360     return (ExternalKnock & Bit) != 0;
361 }
362 
363 
364 
SetIntKnock(unsigned Bit)365 inline void IstecDevConfig::SetIntKnock (unsigned Bit)
366 // Set the interal knock to true
367 {
368     InternalKnock |= Bit;
369 }
370 
371 
372 
SetExtKnock(unsigned Bit)373 inline void IstecDevConfig::SetExtKnock (unsigned Bit)
374 // Set the external knock to true
375 {
376     ExternalKnock |= Bit;
377 }
378 
379 
380 
ClrIntKnock(unsigned Bit)381 inline void IstecDevConfig::ClrIntKnock (unsigned Bit)
382 // Set the interal knock to false
383 {
384     InternalKnock &= ~Bit;
385 }
386 
387 
388 
ClrExtKnock(unsigned Bit)389 inline void IstecDevConfig::ClrExtKnock (unsigned Bit)
390 // Set the external knock to false
391 {
392     ExternalKnock &= ~Bit;
393 }
394 
395 
396 
397 /*****************************************************************************/
398 /*                            class IstecDevColl                             */
399 /*****************************************************************************/
400 
401 
402 
403 class IstecDevColl: public SortedCollection<IstecDevConfig, unsigned char> {
404 
405 protected:
406     virtual int Compare (const unsigned char* Key1, const unsigned char* Key2);
407     virtual const unsigned char* KeyOf (const IstecDevConfig* Item);
408     // Helpers for managing sort order
409 
410 
411 public:
412     IstecDevColl ();
413     // Create a IstecDevColl
414 
415     IstecDevColl (StreamableInit);
416     // Build constructor
417 
418     virtual u16 StreamableID () const;
419     // Return the stream ID
420 
421     static Streamable* Build ();
422     // Return a new instance
423 
424     IstecDevConfig& NewDev (unsigned char Dev);
425     // Create and insert a new device with the given number
426 };
427 
428 
429 
430 /*****************************************************************************/
431 /*                             class IstecConfig                             */
432 /*****************************************************************************/
433 
434 
435 
436 class IstecConfig: public Streamable {
437 
438 private:
439     IstecConfig (StreamableInit);
440     // Build constructor
441 
442 
443 public:
444     IstecBaseConfig     BaseConfig;
445     IstecDevColl        DevColl;
446 
447 
448     IstecConfig ();
449     // Create an IstecConfig object
450 
451     virtual void Load (Stream& S);
452     // Load the object from a stream
453 
454     virtual void Store (Stream& S) const;
455     // Store the object into a stream
456 
457     virtual u16 StreamableID () const;
458     // Return the stream ID
459 
460     static Streamable* Build ();
461     // Return a new instance
462 
463     IstecDevConfig& GetDevConfig (unsigned char Dev);
464     // Get the config for the specified device. If the entry does not exist,
465     // it is created.
466 
467     const IstecDevConfig& GetDevConfig (unsigned char Dev) const;
468     // Get the config for the specified device. If the entry does not exist,
469     // FAIL is called.
470 
471     unsigned GetDevCount () const;
472     // Return the device count
473 
474     void UnpackDevConfig (const IstecMsg& Msg, double aFirmware = FirmwareVersion);
475     // Unpack a device config from an istec message
476 
477     void UnpackBaseConfig (const IstecMsg& Msg);
478     // Unpack the base configuration from an istec message
479 
480     void PackDevConfig (unsigned char Dev, unsigned char* Buf,
481                         double aFirmware = FirmwareVersion) const;
482     // Pack a device config
483 
484     void PackBaseConfig (unsigned char* Buf) const;
485     // Pack the base configuration
486 
487     double GetFirmwareVersion () const;
488     // Return the firmware version from the base config
489 
490     unsigned IstecID () const;
491     // Return the type of the istec, determined by the parameters of the base
492     // configuration. The return value is 0 if the istec type could not be
493     // identified, 1008 for an istec 1008 etc.
494 
495     unsigned GetExtS0 () const;
496     // Return the count of external S0 busses
497 
498     unsigned GetIntS0 () const;
499     // Return the count of internal S0 busses
500 
501     unsigned GetProtocol () const;
502     // Return the protocol used by the istec
503 
504     unsigned GetConnection () const;
505     // Get the connection value from the base configuration
506 
507     unsigned GetMusic () const;
508     // Get the music value from the base configuration
509 
510     unsigned GetMusicPort () const;
511     // Get the music port from the base configuration
512 
513     unsigned GetCountryCode () const;
514     // Get the country code from the base configuration
515 
516     unsigned GetTFEAssignment () const;
517     // Get the TFE assignment from the base configuration
518 
519     String GetNumber1 () const;
520     String GetNumber2 () const;
521     // Get the numbers from the base configuration
522 
523     void SetNumber1 (const String& Num);
524     void SetNumber2 (const String& Num);
525     // Set the number in the base configuration
526 
527 };
528 
529 
530 
GetDevCount()531 inline unsigned IstecConfig::GetDevCount () const
532 {
533     return BaseConfig.DevCount;
534 }
535 
536 
537 
GetFirmwareVersion()538 inline double IstecConfig::GetFirmwareVersion () const
539 // Return the firmware version from the base config
540 {
541     return BaseConfig.GetFirmwareVersion ();
542 }
543 
544 
545 
IstecID()546 inline unsigned IstecConfig::IstecID () const
547 // Return the type of the istec, determined by the parameters of the base
548 // configuration. The return value is 0 if the istec type could not be
549 // identified, 1008 for an istec 1008 etc.
550 {
551     return BaseConfig.IstecID ();
552 }
553 
554 
555 
GetExtS0()556 inline unsigned IstecConfig::GetExtS0 () const
557 // Return the count of external S0 busses
558 {
559     return BaseConfig.ExtS0;
560 }
561 
562 
563 
GetIntS0()564 inline unsigned IstecConfig::GetIntS0 () const
565 // Return the count of internal S0 busses
566 {
567     return BaseConfig.IntS0;
568 }
569 
570 
571 
GetProtocol()572 inline unsigned IstecConfig::GetProtocol () const
573 // Return the protocol used by the istec
574 {
575     return BaseConfig.Protocol;
576 }
577 
578 
579 
GetConnection()580 inline unsigned IstecConfig::GetConnection () const
581 // Get the connection value from the base configuration
582 {
583     return BaseConfig.Connection;
584 }
585 
586 
587 
GetMusic()588 inline unsigned IstecConfig::GetMusic () const
589 // Get the music value from the base configuration
590 {
591     return BaseConfig.Music;
592 }
593 
594 
595 
GetMusicPort()596 inline unsigned IstecConfig::GetMusicPort () const
597 // Get the music port from the base configuration
598 {
599     return BaseConfig.MusicPort;
600 }
601 
602 
603 
GetCountryCode()604 inline unsigned IstecConfig::GetCountryCode () const
605 // Get the country code from the base configuration
606 {
607     return BaseConfig.CountryCode;
608 }
609 
610 
611 
GetTFEAssignment()612 inline unsigned IstecConfig::GetTFEAssignment () const
613 // Get the TFE assignment from the base configuration
614 {
615     return BaseConfig.TFEAssignment;
616 }
617 
618 
619 
620 /*****************************************************************************/
621 /*                             class IstecCharges                            */
622 /*****************************************************************************/
623 
624 
625 
626 class IstecCharges {
627 
628     unsigned Charges [IstecDevCount];
629 
630 public:
631     IstecCharges ();
632     // Constructor - clears the charges on startup
633 
634     void Clear ();
635     // Clear the charges
636 
637     unsigned& operator [] (unsigned Device);
638     // Return a reference to the charges of a specific device
639 
640     const unsigned& operator [] (unsigned Device) const;
641     // Return a reference to the charges of a specific device
642 
643     unsigned char* Pack (unsigned char* Buf) const;
644     // Pack the data of IstecCharges into an array ready for transmission.
645     // The function returns Buf.
646 
647     IstecCharges& Unpack (const unsigned char* Buf);
648     // Unpack an array of char that contains data for an IstecCharges struct.
649     // The function returns this.
650 
651     friend int operator == (const IstecCharges&, const IstecCharges&);
652     friend int operator != (const IstecCharges&, const IstecCharges&);
653     // Compare two structs
654 
655 };
656 
657 
658 
IstecCharges()659 inline IstecCharges::IstecCharges ()
660 // Constructor - clears the charges on startup
661 {
662     Clear ();
663 }
664 
665 
666 
667 /*****************************************************************************/
668 /*                                   Code                                    */
669 /*****************************************************************************/
670 
671 
672 
673 unsigned char* ToBCD (const char* S, unsigned char* T, unsigned TSize, int LowFirst = 1);
674 // Convert the number string in S to a BCD representation in T, filling unused
675 // digits with 'F'. The function returns T. When LowFirst is set, decoding
676 // order is low/high, when LowFirst is zero it's the other way round.
677 
678 char* FromBCD (char* S, const unsigned char* T, unsigned TSize, int LowFirst = 1);
679 // Convert the BCD string in T into an ASCII representation in S. Conversion
680 // stops if an invalid BCD char or TSize is reached. A trailing zero is added
681 // to S. It is assumed that S is big anough to hold the resulting string (S
682 // must be TSize*2+1 chars in size). When LowFirst is set, decoding order
683 // is low/high, when LowFirst is zero it's the other way round.
684 // The function returns S.
685 
686 String FromBCD (const unsigned char* T, unsigned TSize, int LowFirst = 1);
687 // Convert the BCD string in T into an ASCII representation. Conversion
688 // stops if an invalid BCD char or TSize is reached. When LowFirst is set,
689 // decoding order is low/high, when LowFirst is zero it's the other way round.
690 // The resulting string is returned.
691 
692 unsigned char* ToPascal (const char* S, unsigned char* T, unsigned TSize);
693 // Convert the C style string in S to the pascal string in T and return T.
694 
695 char* FromPascal (char* S, const unsigned char* T, unsigned SSize);
696 // Convert the pascal style string in T into a C like string in S and return S.
697 
698 unsigned char InSignal (unsigned char Type);
699 // Convert the given signal type into the internally used representation
700 
701 unsigned char OutSignal (unsigned char Type);
702 // Convert the given signal type into the representation used by the istec
703 
704 unsigned InternalPhone (const String& Phone);
705 // If the given phone number is an internal number, return the code of this
706 // device (1..8). If it is not an internal number, return 0.
707 
708 
709 
710 // End of ICCONFIG.H
711 
712 #endif
713 
714 
715