System and method for monitoring and controlling energy distribution
40 claims: 4 independent, 36 dependent
- 1Claims of equivalent WO 0198851 A1 WHAT IS CLAIMED IS:1. A system for monitoring and controlling energy distribution from at least one Energy Service Provider, comprising: a publicly accessible distributed network;a network access device that interfaces power monitoring and power curtailment circuitry to said distributed network;and a management device that supports interfaces to said power monitoring and said power curtailment circuitry, said management device located remotely from said network access device, and comprising a control device that interfaces said network access device through said publicly accessible distributed network, wherein said management device controls electrical loads at a remote location based in part on market prices of electricity.
- 19The system of claiml further comprising a plurality of manually activated switches wherein at least one switch is adapted to initiate a connection between said network access device and said management device and at least one switch is adapted to reset said network access device.
- 21A system for monitoring and redistributing energy, comprising:a publicly accessible network;an energy exchange interfaced to said publicly accessible network;an E1-2000 interfaced to power monitoring circuitry, power curtailment circuitry and said publicly accessible network;an on-line Site interfaced to said E1-2000 and said energy exchange through said publicly accessible network, said on-line Site facilitating energy redistribution by monitoring power consumption data through said E1-2000, price data through said energy exchange, and initiating curtailment events through said E1-2000.
- 32A method of monitoring and controlling energy distribution, comprising:monitoring electrical load data from a plurality of distributed locations and electric market supply data through a publicly accessible distributed network;and receiving said data at an on-line Site connected to said publicly accessible distributed network, said on-line Site processing said electrical load and said market supply data and initiating at least one power curtailment request at one of said distributed locations based on said electrical load data and said market supply data.
Independent claims4
1,772 paragraphs in 7 sections, as filed
Description of equivalent WO 0198851 A1
SYSTEM AND METHOD FOR MONITORING AND CONTROLLING ENERGY DISTRIBUTION
MICROFICHE APPENDIX
0003A Microfiche Appendix of the presently preferred source code is attached and comprises two (2) sheets having a total of 168 frames (98 on frame 1 and 70 on frame two). The Microfiche Appendix contains material that is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction of the Microfiche Appendix as it appears in the Patent and Trademark Office patent files or records, but otherwise reserves all copyright rights whatsoever.
BACKGROUND
00051. Technical Field
0006The present invention relates to a system and a method that manages energy use, and in particular, to a system and a method that monitors energy use and energy supplies using either a public or a private distributed network to initiate curtailment requests and disconnect dispensable loads from energy supplies or activate end-user generators.
00072. Description of Related Art
0008New supplies of electricity will be needed as demand for electricity grows. To meet this demand, local and regional utilities are evaluating many different strategies from the building of thermal (steam-generated), water powered, fossil fuel, and nuclear generators to the pooling of unutilized electric capacity. In pooling systems, utilities join together in a grid system to share and distribute unutilized electric capacity through open market allocations. These systems offer great opportunities for economic gain as electric demand can be met without substantial investments in new power plants. However, these systems also have risks. Grid systems can breakdown when demand exceeds supply, which can affect large numbers of end users. To protect against power failures, end-users must also improve end-use efficiency.
0009One means of achieving a sustainable supply of electric power in the future is to use efficient end-use technologies. Energy efficiency programs that focused only on appliances, power plants, and equipment in the past now need to pursue other avenues of technology that increase the availability of energy and improve supply and end-user efficiency. New technologies must be found to meet customer, generator, supplier, network operator, regulator, and environmental policy maker objectives.
0010Another means of achieving a sustainable supply of electric power is to create competitive electric markets driven by demand side bidding. The goal of demand side bidding is to reduce the demand for energy through efficient load utilization and efficient energy distribution.
0011Demand side bidding offsets the need for increased generation through demand reduction. The system treats an offer from an end-user to reduce demand as an offer to sell generated electricity. The energy not consumed by an end-user is considered "generated" as it is available to meet other demand. There can be contractual incentives for end-users to switch dispensable loads off-line during periods of high demand. End-users, for example, might receive payments for "generating" electricity they do not consume. In practice, such a system has not met expectations as it requires an accessible system that integrates open market price exchanges with advanced technology.
BRIEF DESCRIPTION OF THE DRAWINGS
0013FIG. 1 is a block diagram of a first embodiment of the invention. FIG. 2 is a block diagram of an Internet Customer Curtailment Module device of FIG. 1.
0014FIG. 3 is a block diagram of a Command and Control Center of FIG. 1. FIG. 4 is a block diagram of the Command and Control Center of FIG. 1. FIG. 5 is a block diagram of the Command and Control Center of FIG. 1. FIG. 6 is a flow-chart of the Energy1st-2000 of FIG. 2.
0015FIG. 7 is a block diagram of an on-line Site of FIG. 1.
0016FIG. 8 is an exemplary start-page of the on-line Site of FIG. 1.
0017FIG. 9 is an exemplary address dialog-box of FIG. 1. FIG. 10 is an exemplary contact dialog-box of FIG. 1.
0018FIG. 11 is an exemplary load summary dialog-box of FIG. 1.
0019FIG. 12 is an exemplary option dialog-box of FIG. 1.
0020FIG. 13 is an exemplary forecast dialog box of FIG. 1.
0021FIG. 14 is an exemplary communication summary of FIG. 1. FIG. 15 is an exemplary Energy1st-2000 dialog-box of FIG. 1 illustrating a HVAC interface assigned to an exemplary zone and exemplary meter summaries.
0022FIG. 16 is an exemplary log of the exemplary zone of FIG. 15.
0023FIG. 17 is an exemplary Energy1st-2000 dialog box of FIG. 1 assigned to an exemplary zone. FIG. 18 is an exemplary Watermark dialog-box of the exemplary zone of FIG. 17.
0024FIG. 19 is an exemplary application function of FIG. 1.
0025FIG. 20 is an exemplary start-page dialog box of the curtailment system of FIG. 1.
0026FIG. 21 is an exemplary application function of FIG. 20.
0027FIG. 22 is an exemplary message initiation and automated load management function of FIG. 20.
0028FIG. 23 is an exemplary curtailment notification/acknowledgement status summary of FIG. 20.
0029FIG. 24 is an exemplary user-defined graphic of FIG. 1.
0030In the drawings, the same reference numbers through several views designate the same or similar elements.
DETAILED DESCRIPTION
0032The system and method of the present invention overcomes many barriers to a successful demand side bidding program by integrating open market energy price exchanges with advanced communication, database, and curtailment technologies. The system and method of the invention provides complete access to real-time load profiles and load control data and provides end-users, such as end-user customers, and energy supply providers with manual, automatic, and hybrid control of load reduction processes that optimize energy distribution and energy use. Energy supply providers include energy marketers, grid owners, utilities, merchant plant proprietors, cooperatives, and municipalities.
0033FIG. 1 illustrates a block diagram of a preferred embodiment of the invention. The system 2 preferably comprises a network access device such as an Energyl st-2000 ("E1 -2000")<sub>,</sub> 4, a customer or end-user interface 6, an Energy
0034Service Provider ("ESP") interface 8, and a management device 10. The network access device, customer or end-user interface 6, ESP interface 8, and management device 10 are preferably joined together by gateways linked together by a publicly accessible or a privately accessible distributed network. The gateways perform protocol conversions, data translations, data conversions, and message handling.
0035Preferably, an access provider, such as an Internet Service Provider ("ISP") 12, provides network connectivity services to the network access device, the customer or end-user interface 6, the ESP interface 8, and the management device 10. Connectivity can be provided in many ways. One way allows devices to dial up the access provider through a modem. A modem, which is any device that converts data from one form to another, uses landlines or wireless transceivers to access remote devices. Connectivity can also be achieved through dedicated lines such as T1 carriers. T1 carriers are private lines or leased lines unlike the public lines or switched lines used in standard dial-up telephone connections. T1 carriers provide high bandwidths that can transmit large blocks of text and image data. A third means of connectivity uses set-top boxes that uses communication and signal-routing technology to access publicly accessible networks, such as the Internet 16 through coaxial, fiber optic, twisted pair, or other types of cable.
0036A network access device is a controller and its supporting interfaces that coordinates communication and control between power monitoring circuitry, power curtailment circuitry, and a distributed network. A preferred embodiment of a network access device is an E1-2000 4 that links power monitoring circuitry 14, power curtailment circuitry, and a management device 10 through a publicly accessible distributed network such as the Internet 16, for example. An E1-2000 4 accepts structured input; processes it according to a set of prescribed rules, and produces outputs. Some outputs are sent to the management device 10 through the ISP 12.
0037In the preferred embodiment, the E1-2000 4 comprises a processor, a nonvolatile or FLASH memory, two RS-232-C asynchronous serial communication ports, one RS-232-C / RS-485 asynchronous serial communication port, a modem, a Local Area Network ("LAN") device, such as an Ethernet device or LAN that utilizes Carrier Senses with Multiple Access Collision Detection ("CSMA CD") protocol to regulate communication line traffic, three relay controlled ("digital") and two analog voltage channels, an eight channel pulse accumulator device, a push button-switch card with an interface, a visual ("a light") and/or auditory ("piezoelectric transducer") alarm and a 60W/110V power supply.
0038The E1-2000 4 operates under the control of a processor that provides a platform to execute application programs. The non-volatile or Flash memory stores code and data on a temporary ("volatile") and on a permanent ("non-volatile") basis. Unlike some non-volatile memory that is erased and programmed in bytes, the FLASH memory is erased and programmed in blocks and in some preferred embodiments can interface five volt, three volt, and two volt system buses. In one preferred embodiment, the FLASH memory performs reading and programming operations simultaneously.
0039Preferably, two RS-232-C asynchronous serial communication ports provide point-to-point serial communication between peripheral devices. The RS-232-C / RS-485 serial communication port allows multiple meters, pulse accumulators 18, device control and building control systems, counters, and displays to be connected to the same RS-232-C / RS-485 line in parallel. Because each of these devices has its own unique digital address, the RS-232-C / RS-485 port can support up to 254 digital addresses that allows multiple devices to be addressed and transmit on the same communication line. An internal modem and Ethernet device allows the E1-2000 4 to communicate with an access provider such as an ISP 12 or other network nodes at a prescribed programmable frequency of seconds, minutes, weeks, months or other desired time increments. The modem and Ethernet device can communicate to devices dispersed across local or distant areas.
0040Preferably, three relay controlled voltage channels or digital channels and two analog voltage channels interface external devices such as dispensable loads or generators. The three relay controlled and two analog voltage channels can control power generators and/or Heating Ventilation and Air Controllers ("HVAC"), lighting controls, motors, boilers, and cooler loads and/or other facility control systems, for example.
0041The E1-2000 4 acquires data, in part, through one or more external pulse accumulator devices 18 with firmware that gives it independent decision-making ability. The pulse accumulator devices 18 track pulse frequency and aggregate the number of pulses generated by power monitoring circuitry such as a power meter 14 through eight separate electrically isolated channels. In one preferred power monitoring circuit, the frequency of the output pulses is proportional to the instantaneous power tracked by the power monitoring circuit and the aggregate pulse count is proportional to the total watt-hours tracked by the power monitoring circuit 14. In alternative preferred embodiments, the pulse accumulator device 18 is integrated within the E1-2000 4.
0042The push button-switch card 20 partially illustrated in FIG. 2 includes a plurality of manually actuated programmable switches 22. In the preferred embodiment, one programmable switch 22 is programmed to initiate a connection between the E1- 2000 4 and the management device 10 while a second programmable switch 22 is programmed to reset the E1-2000 4. The push-button switch card 20 can also comprise multi-functional switches such as programmable switches 22 that initiate connections between the E1-2000 4 and the management device 10 when actuating a first state and reset the E1-2000 4 when actuating a second state. Another preferred feature of the push button-switch card 20 includes providing a programmable switch 22 that actuates multiple states of the E1-2000 4 according to the time interval the switch is actuated.
0043Preferably, the E1-2000 processor controls the visual and/or the auditory E1- 2000 alarm(s). In the preferred embodiment, when the E1-2000 4 receives a curtailment notification an auditory alarm is actuated for a timed interval that is preferably acknowledged through a push button-switch 22 or deactivated by a lapse of time.
0044As part of the E1-2000 4 installation process, an E1-2000 4 is electrically connected to the end-user's meters 14. Often, end-users utilize one of three types of meters 14. These meters are standard pulse meters, which include time of day kilowatt hour relay meters that can be outfitted with a pulse relay board, pulse meters with internal pulse accumulating circuitry, and smart meters. Standard pulse meters generate output pulses that are proportional to the instantaneous power delivered to a load. A single E1-2000 4 can preferably read up to eight standard pulse meters. Each of the standard meters is connected to the E1-2000 4 through the accumulator device 18 that tracks the frequency of the output pulses and aggregates or counts the meter pulse outputs. The pulse accumulator device 18 comprises a user-defined multiplier circuit that calculates the precise quantity of energy delivered to a load. Because pulse meters with internal pulse accumulating circuitry have RS-232-C ports, these meters are directly connected to the E1-2000 4, bypassing the accumulator device 18. Similarly, smart meters have RS-485 ports that directly connect to the E1 -2000 4. While the E1-2000 4 is capable of interfacing any combination of these meters, its multiple Institute of Electrical and Electronic Engineering ("IEEE") standard interfaces allows the E1-2000 4 to interface many other types of devices or combination of meters and peripheral devices. Moreover, when expansion boards are used, alternative E1-2000 4 embodiments and accumulator devices 18 can interface more than eight standard meters.
0045Preferably, the E1-2000 4 connects to a publicly accessible or a privately accessible distributed network through a modem or a LAN such as an Ethernet device. The Operating System and Application Software are stored in FLASH memory. Preferably, volatile memory such as Random Access Memory ("RAM") stores operating data that is uploaded to the management device 10. However, to compensate for blackouts, brownouts, and power surges, RAM with power supply backup, non-volatile memory such as Electrical Programmable Read-only Memories ("EPROM"), and/or Flash memory is used to store operating data in alternative preferred embodiments to protect and maintain data integrity.
0046Once the E1-2000 4 is properly installed, it initially connects to the management device 10 through a publicly accessible distributed network, such as the Internet 16. All E1 -2000s 4 preferably share a common access provider username and password, which allows each E1 -2000 4 to connect to the distributed network through a common global access account.
0047Upon connectivity, the E1-2000 4 identifies itself and identifies its current Application Software version. If the management device 10, which also supports an on-line Site, determines that the Application Software is outdated, the management device 10 downloads a new version of the Application Software before continuing its initialization routine. The E1-2000 4 uses its remote upgrade capability to seamlessly update Application Software when needed.
0048Preferably, the E1-2000 4 synchronizes its internal clock with the system clock of the management device 10 after it validates its Application Software. Synchronization allows the management device 10 to track load profiles and curtailment events in real-time. The E1-2000 4 then compares the date and time ("timestamp") of its Configuration File with the configuration timestamp stored in management device memory. If the Configuration File attributes differ from the stored attributes, the E1-2000 4 downloads an updated Configuration File that preferably includes the E1-2000 callback frequency, its meter designations, its pulse accumulator device identity, its meter multiplier coefficients, its meter polling frequency, and its Watermark boundaries assigned to each meter the E1- 2000 4 supports. All expired data in memory is then flushed before logging off of the management device 10 and disconnecting from the ISP 12.
0049Once the E1-2000 4 is initialized, preferably the E1-2000 4 connects to the ISP 12 in response to a number of events. The E1-2000 4 connects to the ISP 12 at its scheduled callback intervals, when a Watermark violation occurs, or when initiated by a ring instruction. The scheduled callback intervals establish a standard schedule of connections between the E1 -2000 4 and the management device 10. In this event, the E1-2000 4 automatically connects to the management device 10 at programmed intervals at which time the E1-2000 4 uploads all of its meter and operating data to the management device.
0050A Watermark is a user-defined characteristic, operation, or condition that causes the E1-2000 4 to automatically interface the management device 10 regardless of the E1-2000's 4 callback schedule. Preferably, when a Watermark violation occurs, the E1-2000 4 immediately connects to the management device 10 through the ISP 12. In the preferred embodiment, Watermark violations occur when energy usage is (1) greater than ("HI") a user-defined limit, or (2) less than ("LO") a user-defined limit, or (3) equal to ("EQ") a user-defined limit, or (4) less than a user-defined limit BUT not equal to zero ("LONZ"). Preferably, the E1- 2000 4 compares meter data or peripheral data to its user designated Watermarks each time a meter, accumulator device, or any other device is polled, however, in alternative embodiments the E1-20004 can be programmed to continuously monitor the status of one or more devices and compare the status of these devices with their prescribed Watermarks to detect Watermark violations in real-time.
0051Preferably, all communication between the E1-2000 4 and the management device 10 is initiated by the E1-2000 4. If the E1-2000 modem is called, the E1- 2000 modem will not receive the incoming call. In response to any incoming call, the E1-2000 4 automatically contacts the management device 10 when a communication line is available (the incoming call initiates a "ring instruction"). The E1-2000's 4 call protocol prevents the E1-2000 4 from communicating directly with unauthorized computers or devices and vice versa which protects the E1-2000 4 against external threats and access from unauthorized users such hackers. All communication to the E1-2000 4 is routed through the management device 10 or the LAN. Thus, it is the management device 10 or the LAN that decides whether it is safe to allow a message, a program parameter, a file, or other data to pass to the E1-2000 device 4. Because LAN based E1-2000's 4 exist behind end-user Firewalls, these E1 -2000s 4 are protected by the Firewall security of the end-user's network as well.
0052When the E1-2000 4 connects to an ISP 12 it cycles through a programmed routine. The E1-2000 4 first identifies itself through a unique code, which is a string of characters. The management device 10 compares the code against a stored list of authorized codes. If the code is validated, the management device 10 allows the E1-2000 4 access. The E1-2000 4 then validates its Application Software and synchronizes its internal clock with the system clock of the management device 10. After its clock is synchronized, the E1-2000 4 uploads each of its individual meter or device readings, which are validated by the management device 10 and then stored in a database. If any Watermark violations occurred since the last E1-2000 4 interface, these violations are uploaded, validated, and entered in the database. The E1-2000 4 next downloads its callback connection schedule and then validates its Configuration File. If any curtailment instructions were entered at the on-line Site or sent directly to the management device 10 by the ESP, the E1 -2000 4 downloads curtailment notification instructions before clearing expired or uploaded data, logging off of the management device 10, and disconnecting from the ISP 12.
0053The E1-2000 4 receives a set of instructions from the management device 10 when it is selected by an ESP to curtail energy consumption. These instructions can include defining its callback intervals, actuating a visual and/or audible alarm, and controlling the analog and relay controlled ("digital") voltage channels. Preferably, the management device 10 will instruct the E1-2000 4 to shorten its callback frequency or maintain a continuous connection with the management device 10 which allows end-users and ESPs to receive real-time or near real-time measurements of end-user's energy consumption. During a curtailment period, a visual and/or audible alarm can provide notice to an end-user that an E1-2000 4 is operating under a curtailment notice. If a push-button switch 22 is used to deactivate the alarm, the E1-2000 4 can automatically interface the management device 10 and record the time and frequency the push-button switch 22 was actuated in a database and thus track each time a curtailment notice was acknowledged.
0054Because the analog and relay controlled voltage channels are preferably connected to the end-user's control systems 24, the management device 10 through the E1-2000 4 can directly control user's loads such as air conditioners, lights, pumps, etc., for example, and generators at the ESP's or end-user's direction. The management device 10 can instruct one or multiple analog voltage channels of the E1-2000 4 to produce a range of voltage levels. In the preferred embodiment, two analog voltage channels produce a continuous voltage that range between .95 volts and 2.6 volts. To ensure that the analog voltage channels will interface and control many end-user internal or external control systems, loads, and generators, the E1-2000 4 can be incremented through one hundred different steps within this voltage range. Other low, medium, and high voltage ranges as designated by the IEEE Standards Board (LB 100A - April 23, 1975) are used in alternative preferred embodiments to control low, medium, or high voltage systems.
0055Similarly, the management device 10 can instruct one or more of the relay controlled voltage channels of the E1-2000 4 to generate digital signals of varying pulse widths. In the preferred embodiment, the relay-controlled channels are capable of switching between two voltage states at rates that range between 20 and 90 millisecond intervals. Other pulse width ranges are possible in alternative preferred embodiments. The relays generate digital signals that can interface end-user's controls 24 and allows relatively low power signals to control high- powered devices. Either analog or relay controlled voltage channels can control many combinations of loads, generators, and end-user control systems 24. Their individual or combined use depends on the end-user's facilities and/or the end- user's and ESP's system objectives.
0056Other notable features of the E1 -2000 4 includes (1 ) the ability of the E1 -2000 4 to connect to an access provider such as an ISP 12 through either a LAN or a modem if either device is inoperable; (2) the ability of the E1-2000 4 to connect to an access provider such as a conventional or low-Earth-orbit satellite provider through wireless transceivers; (3) the ability of the E1-2000 4 to access multiple ISP 12 access numbers if one or more of the numbers are in use or are not available; (4) the ability of the E1-2000 4 to access multiple secondary servers supporting the management device 10 if the primary server fails or is inoperable through a LAN or a modem connection; and (5) the E1-2000's 4 use of the LINUX ™ operating system, although other operating systems such as WINDOWS ™, UNIX ™, or operating systems used in SUN ™ workstations or in APPLE™ machines can be used in alternative preferred embodiments.
0057Referring to the drawings, and particularly FIGS. 3 - 5, block diagrams illustrate the structural, sequential, or functional relationships of the Command and Control Center ("CCC") 26 (shown in FIG. 1) that interfaces and supports the management device 10. The CCC 26 comprises end-user records 28, end-user groupings 30, a curtailment decision matrix 32, a curtailment module 34, a curtailment monitor 36, a settlement module 38, notification records 40, load management records 42, and load reduction methods 44. These records and modules reside within a database, memory, or a management system. In the preferred embodiment, the database is a relational database that includes Object Link Embedding ("OLE") that stores information in tables - rows and columns of data and conducts searches by using data in specified rows or columns. The rows of the table represent records (a collection of information about separate items) and the columns represent fields (particular attributes of a record).
0058As shown in FIG. 3, the CCC 26 maintains records describing an end-user's identity 28, notification records 46, load reduction records 48, load-forecast records 50, curtailment istory 52, and E1-2000 4 records 54. The end-user's identity records 28 include the end-user's name and address. The end-users name is simply a field that distinguishes one entity from another. The customer notification records 46 include records of contacts, email, Internet, network, and facsimile addressees. These records are referenced when the management device 10 notifies end-users of market prices, when notifying end-users of curtailment events, or when other trigger action events occur.
0059Preferably, the load reduction records 48 include information on an end-user's displaceable loads, load reduction systems and controls, and generating devices. In the preferred embodiment, a record of load reduction/displacement items includes data that identifies end-user's generators, HVAC units, lighting control units, building control systems used to control other devices, and other items. Preferably, the load reduction records 48 also includes attributes such as (1) the level of kilowatt reduction; (2) the trigger price at which a decision to displace a load, activate a generator, or contact a control system occurs; (3) the number of days, years, and hours within a day a load can be switched off-line, a generator can be activated, or a controller contacted; (4) the notification lead time needed before a curtailment event can occur; and (5) whether the load, generator, or control system is manually or automatically activated or deactivated.
0060Preferably, the load-forecast records 50 provide incremental and aggregate load forecast data over a prescribed period that include data that can be automatically imported into the CCC 26 and is fully compatible with other electronic devices and software such as devices and software that graphically illustrate variables using histograms and plots and/or perform statistical analysis. This feature is useful for anticipating demand peaks and curtailment scheduling. In the preferred embodiment, the load-forecast records 50 include the incremental kilowatt load forecast data over twenty four-hour periods, which are used to calculate end-user baselines for load curtailment performance analysis.
0061The curtailment records 52 preferably include load curtailment information such as the date of the curtailment event, the message(s) sent to the designated end- user contact, the amount of electrical power to be curtailed, the date and time the end-user contact was notified, the start-time and interval of time that the curtailment event will occur, the end-user contact's response to the curtailment notice, load data that allows the end-user or ESP to graph or statistically analyze curtailment performance, and calculated curtailment credits, if applicable.
0062The E1-2000 records 54 preferably include attributes for each E1-2000 4 assigned to end-user facilities. In the preferred embodiment, the E1-2000 records 54 include information that identities whether the E1-2000 4 is in a LAN or in a dial-up mode, the standard communication time interval, the stand-by communication time interval, the meter/pulse channel allocation, the pulse meter or device protocol, the meter multiplier coefficient, the polling time interval, and the Watermark rules, which include an upper and lower data limit validation value.
0063The end-user groupings 30 are records created by the ESP, preferably through the ESP CCC 26. The end-user groupings 30 comprise a collection of records that the ESP forms for load consolidation. The CCC interface allows the ESP to preferably group end-users by group name, available load, zip code or designated areas, notification lead times, or by selected trigger prices 56. The attributes of the ESP selectable groups 58 preferably include the end-users address, the amount of energy committed to curtailment, the notification lead time, the days available for load reduction, the hours available for load reduction, the available load, the trigger prices, and the method of curtailment, whether it be by a manual or an automatic method.
0064The curtailment decision matrix 32 includes Energy Price Exchange data 60 (such as data available from Cinergy or Nymex, for example), generation, Transmission & Distribution ("T&D"), and data that describes the availability of displaceable and curtailable end-user customer loads. The CCC 26 interfaces Energy Price Exchanges to obtain and display indexes of relative prices from selected exchanges or hourly spot market prices or future market prices from selected exchanges. These records provide information that allows end-users to anticipate curtailment events and provide ESPs with lead-times to issue curtailment notices.
0065Preferably, the curtailment decision matrix provides the ESP with end-user- profiling applications. In the preferred embodiment, these applications provide decision support information to the ESP interface 8 that allow ESPs to select end- users based on trigger prices 62, time and day constraints 64, and acquisition and/or cost constraints 66. In the trigger price application 62, the ESP can display and/or issue curtailment notices to end-user groups whose trigger price is less than or equal to hourly spot market prices or to anticipated market prices. Due to generation and T&D constraints, the ESP can display and/or issue curtailment notices to end-user customers based on the their respective curtailable loads and generators for load displacement. This application helps reduce substation and transformer stress caused by excessive time of day demand. The acquisition and cost constraint application 66 reduces the load requirements of an ESP by displaying and/or issuing curtailment notices to end- users based on their committed load reductions and/or their location or the location of a selected feeder line or other selectable components.
0066FIG. 4 illustrates how curtailment events are implemented. The process begins when an ESP is authorized 68. The management device 10 verifies the ESP's user identification and password before allowing access to the CCC 26 and the management device 10. Once the ESP is authorized, it selects the end-user or end-user customer group that will be subject to a curtailment event 70. Group selection may be based on previously defined groups, the energy available for curtailment, notification lead times, trigger price thresholds, the available time for curtailment, or any other criteria or record the ESP elects. After the end-user or group is selected, the ESP sets the curtailment parameters for the selected end- user or group 72. In the preferred embodiment, the ESP can designate the curtailment date, the curtailment start-time, the curtailment end-time, and enter an alphanumeric pager and/or facsimile and/or e-mail message. In alternative embodiments, the ESP can designate other CCC 26 fields. After the curtailment parameters are selected, the ESP can elect a real curtailment 74, a test curtailment 76, or a customer warning notification mode 78. When the ESP elects a real curtailment 74, E1-2000 alarm(s) are activated and pager, facsimile, and e-mail messages ("unified messages") are sent to the end- user'(s) designated contact(s). If the end-user elected automatic control, the E1- 2000 4 initiates load reductions through its relay ("digital") and analog voltage channels. If the end-user elected manual control, the end-user makes load reductions or activates its internal generators after the authorized contact commits to a curtailment. When the ESP elects a test curtailment 76, the ESP has the option of activating the E1-2000 alarm(s) and/or sending the unified messages. Under test curtailment mode 76, any notifications sent to the designated contact(s) will be preceded by a designated message such as "Test Curtailment." When the ESP elects a customer warning notification 78, E1-2000 alarm(s) are activated and unified messages are sent to the designated contact(s). However, like the test curtailment mode 76, no relay or analog voltage channels are activated.
0067In the preferred embodiment, the ESP can put an end-user or group also into a stand-by-mode 80. In a stand-by-mode 80, the management device 10 issues a ring instruction that causes the E1 -2000 4 to connect to the management device 10. After the management device 10 and E1-2000 4 interface, the E1- 2000 4 downloads an updated Configuration File that preferably causes the E1- 2000 4 to call the management device 10 at a greater frequency until the E1- 2000's 4 callback field is reprogrammed.
0068In the preferred embodiment, the curtailment monitor 36 shown in FIG. 4 allows the ESP to display the status of the end-user notification(s) and curtailment performance. Preferably, the status page 82 displays each end-user's name in curtailment by group(s), their load reduction commitments, the potential load reduction capacity, and their notification status. The notification status will indicate if the communication was acknowledged or if a commitment or a rejection was received by the management device 10 shown in FIG. 1. In addition to displaying the status of the end-user's notification, the curtailment monitor 36 allows the ESP to set load trigger points and view load profile and load control information in a variety of user selectable formats including tables and graphs. Load trigger points are set to notify the ESP and end-user when the end-user is not in compliance with a projected or an agreed performance commitment. Curtailment performance 84 can be measured by selecting a performance table or graph that illustrates the end-user's forecasted and actual demand. The difference between these two sets of data is one measure of the end-user's curtailment performance.
0069As shown in FIG. 4, the preferred embodiment also provides a settlement module 38. The settlement module 38 determines end-user credits based on monitored load reduction performance. The end-user curtailment performance interface 86 is a collection of records that provides the ESP with information concerning Energy Price Exchange data, end-user identifications, the time(s) and date(s) of the curtailment event(s), and the actual and projected load reduction(s). End- user settlements can then be calculated in any preferred manner. As illustrated in FIG. 4, credits can be calculated 88 by evaluating load reduction performance and agreed price schedules.
0070FIG. 5 illustrates a block-diagram describing the end-user's curtailment notification and acknowledgement process 40, the end-user's identity and load management attributes 42, and the methods of implementing load management 44. An end-users curtailment notification and acknowledgement 40 begins when an ESP issues a curtailment request. An ESP sends out notification requests to selected end-user contacts individually or collectively by selection of curtailment group(s) 90. Designated end-user contact(s) receive notice through selected messaging or unified messaging or through E1-2000 alarms. When the end- user(s) receive a notice, a designated end-user contact logs onto an on-line Site through the ISP 12 and the customer or end-user interface 6 shown in FIG. 1. In the preferred embodiment, the on-line Site is located on the Internet 16 at Energy1st.com. After designated contact logs onto the Site by providing a valid username and password, the on-line Site immediately prompts the designated contact to acknowledge the curtailment request by either accepting or rejecting the request 92. An acceptance or rejection is then entered into the CCC 26 database, which can be accessed through the customer or end-user interface 6 or the ESP interface 8 by selecting the curtailment history. Preferably, end-user performance can be tracked by selecting any one of a user selectable performance tables or graphs that illustrates the end-user's actual demand 94. Depending on the E1-2000's 4 callback schedule, curtailment can be reviewed on a programmed time delay or in real-time.
0071Preferably, the end-user identity and load management records 42 include notification records 96, load reduction records 98, and historical curtailment records 100. The customer notification records 96 include fields for multiple contact names and addresses for selected or unified messaging. End-user load reduction records 98 include a listing of load reduction/displacement items, such as for example, generators, HVAC units, lighting controls systems, and building control systems that control other devices. These records preferably include attributes that describe projected kilowatt reductions, trigger prices (i.e. dollars/mega-watt hour), number of days, hours per day, and years a particular load or energy generating device can be subject to a curtailment event, notification lead times, the method of curtailment, whether curtailment will occur by a manual or an automatic method, and the method of control whether it be by E1-2000 4 relay or analog control channels. The method of control can further include fields identifying a designated relay for a relay control channel and its designated pulse width(s) and/or the designated analog channel(s), its interval limits, and its defined voltage steps.
0072The historical curtailment records 100 preferably include load curtailment information for current and historical curtailment notices, the dates of messaging including unified messaging, the amount of power committed for curtailment, the day and the time that the designated contact was notified, the designated contact's response, the calculated curtailment credits, and other end-user and ESP selectable data that can be tracked by an end-user or an ESP in a selectable table or graph format. When end-users commit to a curtailment event, the end-user can reduce energy use manually or automatically with the assistance of the E1-2000 4. End-users' load reduction items 102 include any energy-consuming device that consumes power or generating device that provides power. Thus, load reduction occurs when an end-user turns off one or several elevator banks, electric pumps, electric furnaces, electric motors, electric chillers, or even reduces compressor loads on air conditioning units by setting thermostats to higher temperature setting, for example. Load reductions, for example, can also include turning off non- essential lighting or activating light dimmers or ballast controllers or can include activating end-user generators, turbines, or fuel cells. Any load reduction item 102, including the exemplary items described above, is tracked by the CCC 26 and can be part of an end-user curtailment program.
0073Preferably, there are at least two methods of curtailment 104, a manual method and an automatic method. A manual method occurs when dispensable loads are switched off-line or alternative energy supplies are utilized without using the E1- 2000 4. An automatic method occurs through the E1-2000 4 which preferably utilizes standard interfaces such as an RS-232 / RS-485 asynchronous serial communication port or other interfaces and/or its relay and analog voltage channels to switch loads off-line and/or activate alternative energy supplies.
0074An exemplary detailed E1-2000 4 flowchart is illustrated in FIG. 6. The E1-2000 4 flowchart is broken up into four exemplary sections: Section 1 illustrates an E1- 2000 4 overview; Section 2 illustrates a log-in process; Section 3 illustrates a handshake process; and Section 4 illustrates an E1-2000 4 communication process.
0075In Section 1 (106), an E1-2000 4 overview is illustrated. As shown, each end- user facility has one or multiple E1 -2000s 4 that perform protocol conversions for the ISP 12 and the management device 10, data translations and conversions, and message handling. The E1-2000 4 preferably operates on a LINUX™ Operating System that controls the allocation and usage of hardware resources such as memory, processing unit time, and peripheral devices. The E1-2000 4 supports many types of communication protocols including for example Transmission Control Protocol/Internet Protocol ("TCP/IP") that governs the breakup of data streams into packets to be sent via the ISP 12, and the reassembly and verification of the complete messages from packets received by Internet Protocol ("IP"); Point-to-Point Protocol ("PPP") that provides protection for data integrity and security; and Common Object Request Broker Architecture ("CORBA") which works in object-oriented environments where portions of programs (objects) communicate with other objects in other programs, even when the programs are written in different programming languages and/or are operating on different software platforms. A CORBA program makes its request for objects through an Object Request Broker or ("ORB") and thus does not need to know the structure of the program that created the object. In the preferred embodiment, the E1-2000 4 is capable of hosting many objected orientated languages including Delphi and C++ programming languages, for example.
0076In Section 2 (108), the E1-2000 4 login process is illustrated. In Section 2, the E1-2000 4 interfaces the management device 10 through the ISP 12 continuously or at defined time intervals. Each E1-2000 4 connects to the management device 10 through the ISP 12 through either a modem or a LAN. In the preferred embodiment, a LAN sustains continuous connections. In alternative preferred embodiments, either a LAN or a modem sustains continuous or periodic connections. Preferably, each E1-2000 4 possess a unique identification code and share a common user name and password to interface the management device 10 and on-line Site through one global ISP 12 account. However, in alternative preferred embodiments the E1-2000 4 possess unique identification codes, user names, and passwords as a security measure.
0077In Section 3 (110), the E1-2000 4 initial handshake process is illustrated. In Section 3, the E1-2000 4 first interfaces the management device 10 and connects to an on-line Site through the ISP 12. Preferably, the E1-2000 establishes a CORBA communication link before identifying itself and its current Application Software version. The E1-2000 4 then validates its Application Software and synchronizes its internal clock. After synchronizing its clock, the E1-2000 4 preferably executes a number of initial administrative tasks, including: updating its permanent and stand-by communication schedule, assuring its Configuration File, updating its primary and fallback ISP 12 phone numbers and/or its Internet provider addresses, updating its primary and secondary one-line Site addresses, updating its meter configurations, meter identifications, E1-2000 4 meter channel assignments, autopolling intervals, and meter/channel memory maps.
0078In Section 4 (112), a standard E1-2000 4 connection process is illustrated. After the initial handshake process is complete the E1-2000 4 executes its programmed communication process with the management device 10. As previously described, the E1-2000 4 first identifies itself through its unique identification code. The management device 10 compares this code against a stored list of authorized E1-2000 4 codes. When the code is validated, the management device 10 allows the E1-2000 4 access. The E1-2000 4 then validates its Application Software and synchronizes its internal clock with the system clock of the management device 10. After its clock is synchronized, the E1-2000 4 uploads each of its individual meter or device readings, which are validated by the management device 10 and then stored in the CCC 26 database. If any Watermark violations occurred since the last E1-2000 4 interface, these violations are uploaded, validated, and entered in the CCC 26 database. The E1-2000 4 next downloads its callback connection schedule and validates its Configuration File. In the preferred embodiment, when the Configuration File is updated the callback connection field is updated as well. If any curtailment instructions were entered at the on-line Site or sent directly to the management device 10 by the ESP interface 8, the E1-2000 4 downloads curtailment notification instructions before clearing expired or uploaded data, logging off of the management device 10, and disconnecting from the ISP 12.
0079FIG. 7 illustrates a preferred embodiment of the management device 10. The management device 10 is a controller or program that responds to commands from the E1-2000 4, the customer or end-user interface 6, the ESP interface 8, and an administrative interface 122. Preferably, the management device 10 operates in a time-sharing environment of data management, information sharing between ESPs, end-users, Energy Price Exchanges, E1-2000's 4, and other peripheral user interfaces and devices and provides sophisticated network administrative and security features including Firewalls and ring instructions. In the preferred embodiment, the management device 10 comprises a control device 234 that interfaces the network access device through a distributed network and further supports an on-line Site that comprises a communication service 116, an information service 118 such as the CCC 26 database service, and a distributed network service 120. In the preferred embodiment, the distributed network service 120 is a Web Application Service that arranges text, images, and buttons to be read and utilized by Internet users all across the world.
0080As shown in FIG. 7, the management device 10 supports an on-line Site that supports three service elements. Each service element resides on one or more servers that preferably are supported by secondary servers that are connected to a separate access provider such as an ISP 12 then the primary servers they backup and support. The secondary servers mirror the primary servers in their services and functionality.
0081The communication service 116 is preferably a server-side device that allows the E1 -2000s 4 to seamlessly interface a control device 284 shown in FIG. 1. The control device 284 is a circuit, software or any other device, system, or code that connects hardware or platforms so that information can be moved from place to place. Preferably, the communication service 116 supports TCP/IP, PPP, and CORBA communication protocols. The communication service 116 supports many other communication protocols in alternative preferred embodiments including Serial Line Internet Protocol ("SLIP") communication protocol, for example. Moreover, the communication service 116 can provide a secure connection between devices meaning the information end-user, E1 -2000 and ESP interfaces 6, 4, and 8 provide, such as energy curtailment goals and realtime demand, can be encrypted so that it cannot be read or intercepted by unauthorized devices or users. Preferably, the database service 118 is also a server-side αevice. in tne preferred embodiment, the database service 118 comprises a server that supports a relational database that has OLE capabilities that stores information in tables - rows and columns of data. The rows of the table represent records and the columns represent fields. The database allows searches to be conducted in which the database matches information from a field in one table with information in a corresponding field of another table to produce a third table that combines requested data from both tables in a high-resolution graphic or table format. In other words, the preferred database uses values from multiple fields to relate information to other fields.
0082Preferably, the Web Application service 120 hosts all end-user and ESP related interfaces 6 and 8 and functions that are accessible through the customer or end- user interface 6, the ESP interface 8, and the administrative interface 122. It further comprises a group of related text files that contain not only Hypertext
0083Markup Language ("HTML") and Extensible Markup Language ("XML") tags as in standard Internet documents, but also can contain commands, written in scripting language such as Visual Basic Script ("VBScript") that can be executed by the servers. The Web Application service 120 enables end-users and ESP's to customize the viewing, delivery, and exchange of information through standard Uniform Resource Locators ("URL") through Web browsers, such as Microsoft Internet Explorer™ or Netscape Navigator™, for example.
0084FIGS. 8 - 24 illustrate the Graphical User Interfaces ("GUI") that represent programs, files, and end-user and ESP options by means of icons, menus, and dialog boxes. The user can activate these options by pointing and clicking a mouse, entering a keyboard command, or using many other communication devices. All of the icons, menus, and dialog boxes function the same way across many software platforms, because the GUI provides standard software routines that make these functions compatible with many URLs. Other network connections are provided in alternative preferred embodiments including command-line-interfaces and menu-driven interfaces. A command-line-interface is an interface that allows users to enter commands. A command-line-interface can be considered more difficult to use than GUIs because they are programmable interfaces. Menu-driven interfaces can also be considered easier to use than command-line-interfaces as these interfaces provide menus of all available user choices and options.
0085FIG. 8 illustrates an exemplary start-page of the on-line Site. This page is accessible through the Internet 16 and serves to welcome users, provide information about the Site, and direct the users to energy information, rate analysis, management of loads and energy supplies, and set up modifications after the end-user or ESP logs on to the on-line Site using their usernames and passwords. In other words, this page functions as a table of contents of the Site. A brief overview of the ESP accessible pages is described below.
0086After an ESP selects Energy Info, the on-line Site directs the user to FIG. 9. FIG. 9 illustrates an exemplary address dialog-box. As shown, Accounts 124 is a menu-driven field that allows ESPs to view existing accounts or add new accounts to the Site. This page preferably records address and telephone data.
0087FIG. 10 illustrates an exemplary contact dialog-box that solicits the designated contact's addresses. These fields preferably include primary and secondary pager access numbers 126 and 128, a facsimile number 132, and e-mail or net address(es) 130.
0088FIG. 11 illustrates an exemplary load summary dialog-box. The exemplary load- summary dialog-box preferably displays a summary of reduction/displacement items 148 that can be updated by a click of a mouse. The exemplary load-dialog- box preferably includes reduction/displacement item attributes that indicate if the items are active 134, the kilowatt reduction 136, the trigger method whether it be manual or method 138, the notification lead times 140, the days each item is available in the season 142, the hours per day 144, and the trigger price 146.
0089FIG. 12 illustrates an exemplary option dialog-box. The exemplary option dialog- box allows the ESP to identify the E1-2000 4 and its associated peripheral load(s) or generator(s) that are referred to as items 150. It further includes attributes on each item that preferably includes kilowatt reductions 152, a trigger price 154, the days per year 156, hours per day 158, notification lead time in minutes 160, and whether the item is activated and/or deactivated by the analog and/or relay 5 controlled ("digital") voltage channels 162 - 168.
0090FIG. 13 illustrates an exemplary end-user forecast. The end-user forecast is selectable by customer and date and preferably provides an hourly forecast of expected energy use in kilowatts.
009110.
0092FIG. 14 illustrates an exemplary communication summary. The communication summary preferably summarizes the curtailment date 170, whether a unified message or selected message was sent 172, the amount of energy committed for curtailment 174, the date and time the end-user contact was notified 176, the
009315 expected curtailment time 178, and the end-user's contact response to the curtailment notification 180.
0094FIG. 15 illustrates an exemplary E1-2000 4 dialog-box describing a HVAC interface assigned to an exemplary zone. FIG. 15 shows all of the definable
009520 fields of an interface, which includes the device assignment or owner 182, the type of device or name 184, the zone identification 186, the communication line access field and telephone number 190 and 192, the password 194, the MAC address 196, the communication minutes of the device 198, the temporary communication minutes 200, a description of the device 204 and a list of user
009625 selectable options 206.
0097FIG. 15 further illustrates exemplary meter attributes. It illustrates the zone identifications of multiple standard meters 208, their respective accumulator channel assignments 218, their alias 210, the type of meter 212, their autopolling 30 intervals 216, and their multipliers. Because the aggregate pulse count of the exemplary standard meter of FIG. 15 is proportional to the total watt-hours tracked by the meter, a multiplier field is provided which allows the management device 10 to calculate the precise amount of energy monitored by the meter. As illustrated, the total watt-hours tracked by the exemplary standard meter of FIG. 15, is directly proportional to the aggregate pulse count of the standard meter and thus the multiplier is one. In alternative preferred embodiments, the multiplier can be any real number that when multiplied by the aggregate pulse count calculates the total watt-hours consumed by the device.
0098FIG. 16 illustrates an exemplary log of an exemplary zone. Besides identifying the date 220 and time 224 of the communication between the E1-2000 4 and management device 10 it also provides a status message 226 indicating the condition of the communication link.
0099FIG. 17 illustrates an exemplary E1-2000 dialog box assigned to another exemplary zone. It identifies the alias 210, the type of device 212, the multiplier 214, the autopolling interval 216 in minutes, and a list of user selectable options 206.
0100FIG. 18 illustrates an exemplary Watermark dialog-box of the exemplary zone. In the preferred embodiment, the Watermark dialog-box includes the type 228, which identifies HI, LO, EQ, and LONZ fields, the limits for these respective fields 230, and whether the Watermark zone is active 232 or suspect 234. A summary of recent Watermark violations is also illustrated which identifies the rule 236 that was violated, the timestamp 238, the kilowatt reading that caused the violation 240, and whether the management device 10 was notified 242 of the violation.
0101FIG. 19 illustrates an exemplary application function. As shown, the ESP can sort by end-user names 244 or by ESP definable groups 246. Each end-user selected by name or by groups can be displayed with the number of kilowatts they committed to curtailment 248, their respective notification lead times 250, the days the commitments are available 252, the hours per day 254, the total kilowatts available 256, the trigger price 258, and the communication or dispatch method 260, whether it be by alarm or messaging.
0102FIG. 20 illustrates an exemplary start-page dialog-box of the curtailment system. An ESP must provide a valid usemame and password before being granted access.
0103FIG. 21 illustrates an exemplary application function for the curtailment system. As shown, the ESP can sort by end-user names or ESP definable groups. ESP selectable fields can further define each end-user. These fields preferably include energy use 264, available power for curtailment 266, minimum or maximum lead times 268, and curtailment duration intervals 270.
0104FIG. 22 illustrates the exemplary message initiation functions. As shown, the ESP can customize its unified messaging and schedule their dispatch.
0105FIG. 23 illustrates an exemplary curtailment notification/acknowledgement status summary. The summary includes end-user addresses 272, designated contacts 274, curtailment notification status 276, the time of acknowledgement 278, their kilowatts committed 280, and the end-user's potential kilowatt reductions 282.
0106FIG. 24 illustrates an exemplary user-defined graphic. As shown, incremental kilowatt load forecast data over twenty four-hour periods is graphed against actual demand. The difference between these graphs is one measure of the end- user's curtailment performance.
0107From the foregoing description is should be apparent that the system and method of the present invention facilitates energy redistribution and trade initiated by ESPs in response to energy market conditions and time and day constraints. The invention provides monitoring, control, and analysis of load profiles and energy market prices that cover a large number of distributed end-users. One preferred embodiment of the invention relies on the infrastructure of the Internet utilizing a star topology and TCP/IP and CORBA protocols. The CORBA protocol streamlines the communication between end-users, ESPs and E1 -2000s 4 with the management device 10 and on-line Site thus enabling a large number of users to report to one management device 10 or a single server. Moreover, one preferred embodiment monitors multiple power consuming devices at decentralized locations to initiate load-shedding processes and also utilizes end- users generation capacity for load displacement, initiating manual and automatic load reduction plans using unified messaging, and can make unutilized energy available for resale on the spot or open market through its interface(s) to Energy Price Exchanges.
0108The foregoing description has described only a few of the many forms that the invention can take, and should therefore be taken as illustrative rather than limiting. It is only the following claims, including all equivalents, which are intended to define the scope of the invention.
0109<img file="EP1309902A1_D0001.tif" /> IMAGE EVALUATION TEST TARGET QA-3
0110<img file="EP1309902A1_D0002.tif" />
0111.25 1.4 1.6
0112150mm
01136"
USA
0115<img file="EP1309902A1_D0003.tif" /><img file="EP1309902A1_D0004.tif" /> FILE: 485.C
0116This File handles the ppp connection to the isp. It is executed when kw_client is scheduled to communicate its readings to the database.
0117=*/
0118#include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <stdio.h> #include <signal.h>
0119//#defιne DETACH l* baudrate settings are defined in <asm/termbits.h>, which is included by <termios.h> <sup>*</sup>/ #define BAUDRATE B9600 /* change this definition for the correct port <sup>*</sup>/ //#defιne MODEMDEVICE dev/ttyS1" #define _POSIX_SOURCE 1 /* POSIX compliant source <sup>*</sup>/
0120#defιne FALSE 0 #define TRUE 1 volatile int STOP=FALSE; void onkill(int which)
0121{ if (which==SIGTERM || which==SIGHUP)
0122{ printf("Process stopped by interruptλn");
0123STOP=TRUE;
0124}
0125} main(int argc, char **argv) //argv[1]==modemname
0126{ int fd,c, res, res2, child; struct termios oldtio.newtio; char buf[255]; char devicename[64]; char devicelock[64]; struct stat st; int superparent;
0127#ifdef DETACH fclose(stdin); fclose(stdout); superparent=fork(); if (superparent > 0)
0128{ //waitpid(superparent,NULL,0); exit(O);
0129} freopen(7tmp/callonring","a",stdout); freopen("/tmp/callonring","r",stdin); freopen("/tmp/callonring"<sub>)</sub>"a"<sub>1</sub>stderr);
0130#endif signal(SIGTERM,onkill); signal(SIGHUP,onkill);
0131/*
0132Open modem device for reading and writing and not as controlling tty because we don't want to get killed if linenoise sends CTRL-C. */ // sleep(15); //to wait for a connecting PPPD memset(devicename,0,64); if (argc<2)
0133{ strcpy(devicename,7dev/ttyS1 "); printf("No devicename specified, using %s\n",devicename);
0134} else strncpy(devicename,argv[1],63); sprintf(devicelock,"/var/lock/LCK..%s",strrchr(devicename<sub>I</sub>'/<sup>,</sup>)+1); fd=-1; while (fd < 0)
0135{ fd = open(devicename, O_ RDWR | O_NOCTTY | O_NONBLOCK); if (fd<0) perror("Error opening modem: "); sleep(5);
0136} printf("Modem device %s opened!\n",devicename); tcgetattr(fd,&oldtio); /* save current serial port settings <sup>*</sup>/ bzero(&newtio, sizeof(newtio)); /<sup>*</sup> clear struct for new port settings <sup>*</sup>/ /*
0137BAUDRATE: Set bps rate. You could also use cfsetispeed and cfsetospeed.
0138CRTSCTS : output hardware flow control (only used if the cable has all necessary lines. See sect. 7 of Serial-HOWTO)
0139CS8 : 8n1 (8bit,no parity, 1 stopbit)
0140CLOCAL : local connection, no modem contol
0141CREAD : enable receiving characters 7
0142//newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD; newtio.c_cflag = BAUDRATE | CLOCAL | CS8 | CREAD;
0143/*
0144IGNPAR : ignore bytes with parity errors
0145ICRNL : map CR to NL (otherwise a CR input on the other computer will not terminate input) otherwise make device raw (no other input processing) newtio.cjflag = IGNPAR | ICRNL;
0146/*
0147Raw output. 7 newtio.c_oflag = 0;
0148/*
0149ICANON : enable canonical input disable all echo functionality, and don't send signals to calling program 7 newtio.cjflag = ICANON;
0150/* initialize all control characters default values can be found in /usr/include/termios.h, and are given in the comments, but we don't need them here 7 newtio.c_cc[VlNTR] = 0; /* Ctrl-c 7 newtio.c_ccr QUIT] = 0; /* Ctrl-\ 7 newtio.c_cc[VERASE] = 0; /* del 7 newtio.c_cc[VKILL] = 0; /<sup>*</sup> @ 7 newtio.c_cc[VEOF] = 4; /* Ctrl-d 7 newtio.c_cc[VTIIvlE] = 0; /* inter-character timer unused 7 newtio.c_cc[VMIN] = 1; /* blocking read until 1 character arrives 7 newtio.c_cc[VSWTC] = 0; /<sup>*</sup> ΛO' 7 newtio.c_cc[VSTART] = 0; /<sup>*</sup> Ctrl-q 7 newtio.c_cc[VSTOP] = 0; I<sup>*</sup> Ctrl-s 7 newtio.c_cc[VSUSP] = 0; /<sup>*</sup> Ctrl-z 7 newtio.c_cc[VEOL] = 0; /<sup>*</sup> '\0' 7 newtio.c_cc[VREPRINη = 0; /<sup>*</sup> Ctrl-r 7 newtio.c_cc[VDISCARD] = 0; /<sup>*</sup> Ctrl-u 7 newtio.c_cc[VWERASE] = 0; /<sup>*</sup> Ctrl-w 7 newtio.c_cc[VLNEXη = 0; /* Ctrl-v 7 newtio.c_cc VEOL2] = 0; /<sup>*</sup> '\0' 7
0151/* now clean the modem line and activate the settings for the port 7 tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio);
0152/* terminal settings done, now handle input
0153In this example, inputting a 'z' at the beginning of a line will exit the program. 7 write(fd,<sup>,,</sup>?\r\r\nRD\n",7); while (STOP==FALSE)
0154{
0155/* loop until we have a terminating condition 7
0156/* read blocks program execution until a line terminating character is input, even if more than 255 chars are input. If the number of characters read is smaller than the number of chars available, subsequent reads will return the remaining chars, res will be set to the actual number of characters actually read 7
0157// printf("starting read/write cycle.. Λn");
0158//res = read(fd,buf,255); //this line worked if BLOCKING fflush(NULL); res=0; memset(buf,0,255); while (STOP==FALSE && !strchr(buf,10))
0159{ res2=read(fd,buf+res,255-res); if (res2>0)
0160{ printf("%s",buf); res+=res2;
0161} else
0162{ //sleep(1); memset(buf,0,255); gets(buf); write(fd,buf,strlen(buf)); sleep(1);
0163} } if (STOP==TRUE)
0164{ printf(Εxiting...\n"); break; }
0165//check for a lock file! (ie from pppd) //printf("Checking for lock: %s \n",devicelock); if (stat(devicelock,&st)==0)
0166{ printf("Sleeping because of modemlock: %s\n",devicelock); while (STOP==FALSE && stat(devicelock,&st)==0) sleep(10); printf("Lock released !\n"); tcflush(fd, TCIOFLUSH);
0167} //else //printf("No device lock found\n"); buf[res]=0; /* set end of string, so we can printf 7 printf("%s", buf); fflush(NULL); if (strstr(buf,"RING") || strstr(buf,"Ring"))
0168{ child=fork(); if (child==0)
0169{ sleep(20); execl('7bin/sh<sup>,,</sup>,7bin/sh","/usr/sbin/ppp-on",NULL);
0170} else
0171{ printf("Spawning child!\n"); fflush(NULL); while(STOP==FALSE && !waitpid(child,NULL,WNOHANG)) sleep(10); printf("Done waiting for child!\n"); c!ose(fd); sleep(1); fd = open(devicename, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd<0) perror("Error opening modem: "); fflush(NULL);
0172}
0173} //if (buf[0]=='z') STOP=TRUE;
0174}
0175/* restore the old port settings 7 tcsetattr(fd,TCSANOW,&oldtio); }
0176FILE: callonring.c
0177This file handles negotiation with the isp after a modem connection has been made.
0178*/
0179#include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <stdio.h> #include <signal.h>
0180#defιne DETACH
0181#defιne PPPTIMEOUTMINUTES 15
0182/* callonring listens to the specifies serial port [/dev/ttyS1 by default] unless the -o option is specified (don't listen to any port). When a RING comes in from the modem, or a SIGALRM is received, callonring launches /usr/sbin/ppp-on. If the modem was launched by SIGALRM, and it receives a SIGHUP, callonring will kill (SIGTERM) the pppd process. If callonring is listening to its serial port, and a lock file is created (/var/lock/{portname}), callonring will suspend listening to the port, and will ignore SIGALRM, as long as the lock file exists. callonring waits 20 seconds after receiving a RING or SIGALRM before dialing. This is to allow the incoming RING phone-call to fully terminate before attempting to dial. 7
0183/* baudrate settings are defined in <asm/termbits.h>, which is included by <termios.h> 7 #defιne BAUDRATE B38400 /* change this definition for the correct port 7 //#define MODEMDEVICE 7dev/ttyS1" #define _POSIX_SOURCE 1 /* POSIX compliant source 7
0184#defιne FALSE 0 #define TRUE 1
0185typedef struct
0186{ int ready; char password[256]; char username[256j; char phone[256]; } ispstruct;
0187//global int signal_alarm; int sighup; int ispcount; ispstruct isps[15]; volatile int STOP=FALSE;
0188LoadlSPsO
0189{ FILE <sup>*</sup>f1; char buf[1024]; char *p1; f1=fopen(7etc/pepper/isps","r"); if (!f1)
0190. { printf("Error opening /etc/pepper/isps!\n"); return(-1);
0191} ispcount=0; while (!feof(f1))
0192{ memset(buf,0,1024); fgets(buf,1023,f1); printf("\n\nLine->|%s|\n",buf); p1=buf; while (isspace(Tpl)) p1++; if (<sup>*</sup>p1==<sup>,</sup>#' || strlen(p1) < 11) continue; p1=strtok(p1 ,":"); strcpy(isps[ispcount].username,p1); p1=strtok(NULL,":"); strcpy(isps[ispcount]. password, p1); p1=strtok(NULL,":\n"); strcpy(isps[ispcount].phone,p1); isps[ispcount].ready=1 ; printf(":%s:%s:%s:\n\n",isps[ispcount].username,isps[ispcount].password;isps[isp count], phone); ispcount++;
0193} fclose(fl); return(O);
0194}
0195void Log(char *message, char *mess2)
0196{ time_t now; struct tm *st; char buf[256]; now=time(NULL); st=(struct tm *)localtime((time_t *)&now); memset(buf,0,256); sprintf(buf,"[%24.24s] %s\n",asctime(st),message); if (mess2) printf(buf,mess2); else printf uf); fflush(NULL); return;
0197} int fexist(char <sup>*</sup>fιlename)
0198{ FILE <sup>*</sup>fl; if (!(f1=fopen(filename,V))) return(O); else
0199{ fclose(fl); return(1); } } void onkill(int which) { if (which==SIGTERM)
0200{
0201LogC'Process stopped by interrupt (SIGTERM)",NULL);
0202STOP=TRUE;
0203}
0204}
0205void onalarm(int which)
0206{ if (which==SIGALRM)
0207{
0208Log("Got SIGALRM, start dialing.",NULL); signal_alarm=1;
0209//now re-install the signal handler signal(SIGALRM,onalarm);
0210} if (which==SIGHUP)
0211{
0212Log("Got SIGHUP, kill pppd.",NULL); signal_alarm=0; sighup=1; signal(SIGHUP,onalarm);
0213}
0214} int writepidfiIe(const char *filename)
0215{ FILE *f1; f 1 =fopen(filename,"w"); if (!f1) return(-1); fprintf(f1,"%d\n",getpid0); fclose(f1); retum(O);
0216}
0217int PrepPPPEnvironment(int whichtry)
0218{ char buf[1024]; if (isps[whichtry].ready==0) return(-1); memset(buf,0,1024); sprintf(buf,"PASSWORD=%s",isps[whichtry].password); putenv(buf); memset(buf,0,1024); sprintf(buf,"ACCOUNT=%s",isps[whichtry].usemame); putenv(buf); memset(buf,0,1024); sprintf(buf,"TELEPHONE=%s",isps[whichtry].phone); putenv(buf); return(O); } int LaunchConnection(int whichtry) //no longer used!!!!!!!
0219{ char buf[1024]; int success; pid_t child; success=0; if (isps[whichtry].ready==0) return(O); memset(buf,0,1024); sprintf(buf,"PASSWORD=%s",isps[whichtry].password); putenv(buf); memset(buf,0,1024); sprintf(buf,"ACCOUNT=%s",isps[whichtry].username); putenv(buf); memset(buf,0,1024); sprintf(buf,"TELEPHONE=%s",isps[whichtry].phone); putenv(buf); printf("LaunchConnection() launched with %s\n", buf); fflush(NULL);
0220child=fork(); if (child==0)
0221{ execl("/bin/sh",7bin/sh",7usr/sbin/ppp-on",NULL); } else
0222{ putenv("PASSWORD=null"); while(!waitpid(child,NULL,WNOHANG))
0223{ if (fexist(7var/lock/corbanet"))
0224{ success=1; sleep(5);
0225} else
0226{ sleep(1);
0227} } } return(success);
0228}
0229main(int argc, char **argv) //argv[1]==modemname
0230{ int fd,i, c, res, res2, child; struct termios oldtio.newtio; char buf[255]; char devicename[64]; char devicelock[64]; struct stat st; int superparent; int nonlistener; int alarm_up; time_t now, timestop; int success,tries; alarm_up=0; signal_alarm=0; nonlistener=0; sighup=0;
0231#ifdef DETACH fclose(stdin); fclose(stdout); superparent=fork(); if (superparent > 0)
0232{
0233//waitpid(superparent,NULL,0); exit(O);
0234} writepidfιle("/var/lock/callonring.pid"); freopen(7var/log/callonring","a",stdout); freopen(7var/log/callonring","r",stdin); freopen(7var/log/callonring","a",stderr); #endif signal(SIGTERM,onkill); //signal(SIGHUP,onkill); signal(SIGALRM,onalarm); signal(SIGHUP,onalarm); for (i=1;i<argc;i++)
0235{ if (strcmp(argv[i],"-o")==0)
0236{ nonlistener=1;
0237LogC'This callonring is a non-listener.",NULL); } } if (LoadlSPsO)
0238{ //LoadDefaultlSP();
0239} for(i=0;i<ispcount;i++)
0240{ printf("Loaded %d: %s\n",i,isps[i].phone);
0241} if (inonlistener)
0242{
0243/*
0244Open modem device for reading and writing and not as controlling tty because we don't want to get killed if linenoise sends CTRL-C.
02457
0246// sleep(15); //to wait for a connecting PPPD memset(devicename,0,64); if (argc<2)
0247{ strcpy(devicename,7dev/ttyS1 "); Log("No devicename specified, using %s",devicename);
0248} else strncpy(devicename,argv[1],63); sprintf(devicelock,"/var/lock/LCK..%s",strrchr(devicename,'/')+1); fd=-1; while (fd < 0)
0249{ fd = open(devicename, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd<0) perror("Error opening modem: "); sleep(5);
0250} LogC'Modem device %s opened !",devicename); tcgetattr(fd,&oldtio); /<sup>*</sup> save current serial port settings 7 bzero(&newtio, sizeof(newtio)); I* clear struct for new port settings 7
0251/*
0252BAUDRATE: Set bps rate. You could also use cfsetispeed and cfsetospeed.
0253CRTSCTS : output hardware flow control (only used if the cable has all necessary lines. See sect. 7 of Serial-HOWTO)
0254CS8 : 8n1 (8bit,no parity, 1 stopbit)
0255CLOCAL : local connection, no modem contol
0256CREAD : enable receiving characters 7
0257//newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD; newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CREAD;
0258I<sup>*</sup>
0259IGNPAR : ignore bytes with parity errors
0260ICRNL : map CR to NL (otherwise a CR input on the other computer will not terminate input) otherwise make device raw (no other input processing) 7 newtio.cjflag = IGNPAR | ICRNL;
0261/*
0262Raw output. 7 newtio.c_oflag = 0;
0263/* ICANON : enable canonical input disable all echo functionality, and don't send signals to calling program 7 newtio.cjflag = ICANON;
0264/* initialize all control characters default values can be found in /usr/include/termios.h, and are given in the comments, but we don't need them here 7 newtio.c_cc[VINTR] = 0; /* Ctrl-c 7 newtio.c_cc[VQUITj = 0; /* Ctrl-\ 7 newtio.c_cc[VERASE] = 0; /* del 7 newtio.c_cc[VKILL] = 0; /* @ 7 newtio.c__cc[VEOF] = 4; /* Ctrl-d 7 newtio.c_cc[VTIME] = 0; /* inter-character timer unused 7 newtio.c_cc[VMIN] = 1; /* blocking read until 1 character arrives 7 newtio.c xr SWTC] = 0; /* '\0' 7 newtio.c_cc[VSTART] = 0; /* Ctrl-q 7 newtio.c_cc[VSTOP] = 0; /* Ctrl-s 7 newtio.c_cc[VSUSP] = 0; /* Ctrl-z 7 newtio.c_cc[VEOL] = 0; /* '\0' 7 newtio.c_cc[VREPRINT] = 0; /* Ctrl-r 7 newtio.c_cc[VDISCARD] = 0; /* Ctrl-u 7 newtio.c__cc[VWERASE] = 0; /* Ctrl-w 7 newtio.c_cc[VLNEXη = 0; /* Ctrl-v 7 newtio.c_cc[VEOL2] = 0; /* '\0' 7
0265/* now clean the modem line and activate the settings for the port 7 tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio);
0266/* terminal settings done, now handle input In this example, inputting a 'z' at the beginning of a line will exit the program.
02677 }//endif non-listener
0268write(fd,"+++ATZS7=45S0=0Q0V1&c1 E1\n",25); while (STOP==FALSE)
0269{
0270/<sup>*</sup> loop until we have a terminating condition 7
0271/<sup>*</sup> read blocks program execution until a line terminating character is input, even if more than 255 chars are input. If the number of characters read is smaller than the number of chars available, subsequent reads will return the remaining chars, res will be set to the actual number of characters actually read 7
0272//res = read(fd,buf,255); //this line worked if BLOCKING fflush(NULL); memset(buf, 0,255); if (inonlistener)
0273{ res=0; memset(buf,0,255); while (STOP==FALSE && !strchr(buf,10) && !signal_alarm)
0274{ res2=read(fd,buf+res,255-res); if (res2>0) res+=res2; sleep(1);
0275} if (STOP==TRUE)
0276{
0277Log("Exiting...",NULL); break;
0278} }//endif non-listener else sleep(1);
0279//check for a lock file! (ie from pppd) // printf("Checking for lock: %s \n",devicelock); if (stat(devicelock,&st)==0)
0280{
0281Log("Sleeping because of modemlock: %s",devicelock); while (STOP==FALSE && stat(devicelock,&st)==0) sleep(10); LogC'Lock released!",NULL); if (Inonlistener) tcflush(fd, TCIOFLUSH);
0282} // else // Log("No device lock found",NULL);
0283if (Inonlistener) { buf[res]=0; /* set end of string, so we can printf 7
0284Log("READ FROM MODEM: %s", buf);
0285} if (strstr(buf,"RING") || strstr(buf,"Ring") || signal_alarm)
0286{ if (signal_alarm) alarm_up=1; //it was SIGALRM, not RING that brought up link! else alarm_up=0; success=0; tries=0; while (Isuccess && tries < ispcount)
0287{ child=fork(); if (child==0)
0288{ if (!PrepPPPEnvironment(tries)) execl("/bin/sh","/bin/sh","/usr/sbin/ppp-on",NULL); else exit(0); //success=LaunchConnection(tries);
0289} else
0290{
0291Log("Spawning child!",NULL); now=time(NULL); timestop=now+(60*PPPTIMEOUTMINUTES); while(STOP==FALSE && !waitpid(child,NULL,WNOHANG) && now < timestop)
0292{ if (fexist("/var/lock corbanet"))
0293{ success=1;
0294Log("Success",NULL);
0295} now=time(NULL); if (now >= timestop)
0296Log("PPPTIMEOUT reached, killing connection.",NULL); if (sighup)
0297Log("Killing PPPD because of SIGHUP.",NULL); if (alarm_up && !signal_alarm)
0298LogC'Killing PPPD because alarm has been rescinded.",NULL); if ((alarm jp && !signal_alarm) || sighup || now >=timestop) { kill(child.SIGTERM); sighup=0;
0299} sleep(5);
0300} LogC'Done waiting for child!",NULL); unlink("/var/lock/corbanet");
0301} tries++;
0302} signal_alarm=0; if (inonlistener)
0303{ close(fd); sleep(1); fd = open(devicename, O_RDWR | OjMOCTTY | OjMONBLOCK); if (fd<0) perror("Error opening modem: "); } fflush(NULL);
0304} //if (buf[0]=='z') STOP=TRUE;
0305}
0306/<sup>*</sup> restore the old port settings 7 if (Inonlistener) tcsetattr(fd .TCSANOW, &oldtio) ; }
0307FILE: client.cxx
0308This file handles the client side of the corba talk
0309============================================================*/
0310#include "iccm_client.h" #include "storage, h" #include "omnithread.h" #include "kwjnserter.hh" #include "spa2.h" #include "logcodes.h" #include "notif.h"
0311#include <sys/socket.h> #include <net/if.h> #include <sys/ioctl.h> #include <netinet/in.h>
0312#defιne USETHREADS
0313#ifdef USETHREADS #include <pthread.h>
0314//need some extra globals if using threads: char *thread_mac_addr; storageobj <sup>*</sup>thread_storage; schedulerobj *thread_corbaschedule; watermarksobj *thread_watermarks; spa2 *spaboard; #endif static CORBA: :Object_ptr getObjectReference(CORBA::ORB_ptr orb);
0315//global variables int commandargcount; char **commandargs; int signalpoll; char argvlog[256]; int suppressupgrades; int timed_dial ime; int timed_dial_happened; int firstcommo;
0316CollectionBase sendlogitems; notifications notifs; int killfpid(int which, const char <sup>*</sup>1ϊlename) {
0317FILE I; char bufT256]; if (!(f1=fopen(fιlename,"r")))
0318{
0319//Log(PIDERR,"Unable to find pid for foreign program!"); //this was happening way too often (impossible to read logs! return(-1);
0320} fgets(buf,255,f1); fclose(fl); if (atoi(buf)>0) kill(atoi(buf),which); return(O);
0321} int fexist(char *filename)
0322{ FILE *f1; if (!(f1=fopen(filename,"r"))) return(O); else
0323{ fclose(fl); return(1); } } void WriteMinutesToFile(const char *filename,long numminutes)
0324{ FILE I; f 1 =fopen(filename,"w"); if (!f1)
0325{ printfC'Unable to create swatchdog target file: %s\n",filename); return;
0326} fprintf(f 1 ,"%ld\n",numminutes); fclose(fl); return;
0327} void onhup(int which)
0328{ signalpoll=1; signal(SIGHUP,onhup); }
0329int corbatalk(char *mac_addr, storageobj *storage, schedulerobj <sup>*</sup>corbaschedule, watermarksobj *watermarks)
0330{
0331CORBA: :ORB_ptr orb;
0332CORBA::BOA_ptr _myboa; int ij.ret; kwjnserter_var myobjRef; kwjnserter *kwi, *prekwi; dateobj temptime; char buf[256]; time in gmt; long iccmid; long meterid; char *p1; const char *p2; int needupgrade; watermarkviolation *tempwm; long tempver; timej temptimet; long notificationcount; notificationobj *tempnotif; long newaddminutes;
0333ORBsobj orbs; int orbnum; int connected;
0334ORB *temporb;
0335FILE *f1; orbs.Load(7etc/pepper/orbs");
0336CORBA: :Object_var obj;
0337Log(INFO,"Entering CORBATALK()"); orbnum=0; connected=0; #ifdef CORBAFALLBACK while ({connected && orbnum<orbs.cb.Count())
0338{ temporb=(ORB *)orbs.cb.ltem(orbnum); if (itemporb)
0339{
0340Log(CORBAERR,"Error locating orbs in memory"); return(-1); } if ((f1=fopen(7etc/omniORB.cfg","w"))==NULL)
0341{ orbnum++; printf("Error opening /etc/omniORB.cfg for writing. \n"); continue;
0342} fprintf(f1 ,'ORBInitialHost %s\nORBInitialPort %s\n",temporb->host,temporb- >port); fclose(fl); orbnum++; printf("Trying ORB: '%s' '%s' \n",temporb->host,temporb->port); orb=NULL; try{ orb=CORBA::ORBJnit(commandargcount, commandargs,"omniORB2");
0343} catch(...)
0344{
0345Log(CORBAERR,"Error creating CORBA ORB."); continue;
0346} try { _myboa=orb->BOAJnit(commandargcount, commandargs,"omniORB2j3OA");
0347} catch(...)
0348{
0349Log(CORBAERR,"Error creating BOA."); continue;
0350} try { obj=getObjectReference(orb);
0351} catch(...)
0352{
0353Log(CORBAERR,"Error connecting to to CORBA object."); continue; } if (CORBA: :is_nil(obj))
0354{
0355Log(CORBAERR,"obj says that it is _nil()."); continue;
0356} if ((unsigned long)orbnum >= orbs.cb.Count())
0357{
0358Log(CORBAERR,"Unable to connect to ANY CORBA object!"); return(1);
0359} connected=1;
0360} #else orb=NULL;
0361Log(CORBAERR,"About to run ::ORBJnit()"); try { orb=CORBA::ORBJnit(commandargcount, commandargs, "omniORB2");
0362} catch(...)
0363{
0364Log(CORBAERR,"Error creating CORBA ORB."); return(-1); }
0365Log(CORBAERR,"About to run ::BOAJnit0"); try { _myboa=orb->BOAJnit(commandargcount, commandargs,"omniORB2_BOA");
0366} catch(...)
0367{
0368Log(CORBAERR,"Error creating BOA."); return(-2); } if (orb==NULL) {
0369Log(CORBAERR,"The orb is NULL, aborting corbatalk()"); return(-1);
0370<sup>'</sup>} if (_ yboa==NULL)
0371{
0372Log(CORBAERR,"The _myboa is NULL, aborting corbatalkQ"); return(-1);
0373<sup>■</sup> }
0374Log(CORBAERR,"About to GetObjectReference()"); try
0375{ obj=getObjectReference(orb);
0376} catch(...)
0377{
0378Log(CORBAERR,"Error connecting to to CORBA object."); return(-3);
0379}
0380Log(CORBAERR,"About to see if obj is_nil()"); if (CORBA::is_nil(obj))
0381{
0382Log(CORBAERR,"obj says that it is _nil()."); return(-4);
0383} #endif
0384utime("/tmp/commosuccess",NULL); //touch the times to now
0385Log(CORBAERR,"About to ::_narrow(obj)"); try { prekwi=kwJnserter::_narrow(obj);
0386} catch(...)
0387{
0388Log(CORBAERR,"unable to _narrow() prekwi."); return(1);
0389} if (Iprekwi || CORBA: :is_nil(prekwi))
0390{
0391Log(CORBAERR,"After _narrow, prekwi says that it is _nil()"); return(-3); } char Tiewobj; printf("Old Object IOR: %s\n",orb->objectJo_string(prekwi)); try { prekwi->KWFactory(newobj);
0392} catch(...)
0393{
0394Log(CORBAERR,"Factory failed!"); return(-1);
0395} printfC'New Obj IOR: %s\n",newobj); try { obj=orb->stringJo_object(newobj);
0396} catch(...)
0397{
0398Log(CORBAERR,"Error in stringJo_object");
0399} try { kwi=kw_inserter::_narrow(obj);
0400} catch(...)
0401{
0402Log(CORBAERR,"Unable to narrow obj to kwi");
0403} if (!kwi || CORBA::is_nil(kwi))
0404{
0405Log(CORBAERR,"After_narrow, kwi says that it is _nil()"); return(-3);
0406} try { kwi->Log(0L,LOG 3OTFACTORY,"New Factory Object!",LOGTIMEjNOW,LOGJNFO3);
0407} catch(...)
0408{
0409Log(CORBAERR,"Unable to insert into the server log."); return(-1); } try { iccmid=kwi->HWLogin(mac_addr);
0410} catch (...)
0411{
0412Log(CORBAERR,"Error using the kwjnserter object!"); retum(-4);
0413} Log(CORBAERR,"Performed HWLOGIN");
0414//we are now using a file (/tmp/commosuccess) instead of a signal //killfpid(SIGCONT,"/var/lock/swatchdog.pid");
0415#ifdef USETHREADS
0416/* if (spaboard->buttons || spaboard->chirps)
0417{ sprintf(buf,"Buttons: %d Chirps: %d",spaboard->buttons, spaboard->chirps); try { kwi->Log(iccmid,LOGj3UTTONS,buf,LOGTIME_NOW,LOG_ACK3);
0418} catch(...)
0419{
0420Log(CORBAERR,"Unable to insert into the server log."); return(-1);
0421} } 7 #endif if (firstcommo)
0422{ p1=new char[12]; memset(p1 ,0,12); sprintf(p1, "First Pass"); sendlogitems.Add((void *)p1); firstcommo=0;
0423} if (sendlogitems.CountO > 0)
0424{
0425Log(INFO,"Trying to send misc log items to the server."); for (i=0;i< (int)sendlogitems.Count();i++) { if ((p2=(const char *)sendlogitems.Item(i)))
0426{ try { kwi->Log(iccmid,LOG_MISC,p2,LOGTIME_NOW,LOGJJNK);
0427} catch(...)
0428{
0429Log(CORBAERR,"Unable to insert into the server log.");
0430} sendlogitems.Remove(i);
0431} } } else
0432{
0433Log(INFO,"No misc log items to send to the server.");
0434} Log(INFO,"Done sending misc log items to the server.");
0435/* if (firstcommo)
0436{ try { kwi->Log(iccmid,LOG_FlRSTPASS,"First Pass",LOGTIME_NOW,LOGJNFO9);
0437} catch(...)
0438{
0439Log(CORBAERR,"Unable to insert into the server log.");
0440} firstcommo=0;
0441}
04427
0443try{ tempver=kwi->Version(iccmid,VERSION_CODIFIED,VERSlON_HUMAN);
0444} catch(...)
0445{
0446Log(CORBAERR,"Error checking client version"); return(-5);
0447} if (tempver > VERSION_CODIFIED) { needupgrade=1;
0448Log(INFO,"We need to upgrade kw_client (after uploading readings)."); try { kwi->Log(iccmid,LOG_NEEDUPGRADE,"This ICCM needs to perform remote upgrade.",LOGTIME_NOW,LOGJNFO9);
0449} catch(...)
0450{
0451Log(CORBAERR,"Unable to insert log entry on server.");
0452} } else needupgrade=0; if (needupgrade && suppressupgrades)
0453{ sprintf(buf,"Upgrades are suppressed for %d more communications.",suppressupgrades); Log(INFO,buf); suppressupgrades-; needupgrade=0; // <-- the actual suppression, tada
0454} if (argvlog[0])
0455{
0456Log(INFO.argvlog); try{ kwi- >Log(iccmid,LOG_COMMANDLINE,argvlog,LOGTIME_NOW,LOG_UNK);
0457} catch(...)
0458{
0459Log(CORBAERR,"Unable to insert log entry on server.");
0460} } in_gmt=0L; try { in_gmt=kwi->GetGMT();
0461} catch(...)
0462{
0463Log(CORBAERR,"Unable to fetch time from server."); return(-6); } if (stime(&in_gmt)) sprintf(buf,"Error setting local clock; perhaps kw_client was started by a non- root user."); else sprintf(buf,"Just set the time to %ld.",in_gmt); Log(INFO.buf);
0464for (i=0;i<storage->Meters();i+<sup>+</sup>)
0465{
0466//printf("About to fetch METERID\n");
0467//fflush(NULL); meterid=0L; try { meterid=kwi->GetMeterlD(iccmid,storage->GetMeterName(i));
0468} catch(...)
0469{
0470Log(CORBAERR,"Unable to lookup meter id on server.");
0471}
0472//printf("METERID: %ld\n",meterid); //fflush(NULL); if (meterid < 1 L)
0473{
0474Log(CONFERR,"Unable to resolve meter id."); try{ kwi->Log(iccmid,LOG_ERRMETERRESOLVE,"Unable to resolve meter id.",LOGTIME_NOW,LOGjΞRR3);
0475} catch(...)
0476{
0477Log(CORBAERR,"Unable to insert log entry on server.");
0478} } if (storage->Readings(i)) printf(" Inserting Readings (%d):",storage->Readings(i)); else printf(" No Readings to upload\n"); for (j=storage->Readings(i)-1 ;j>=0;j~)
0479{ temptime.Set(storage->TimeStamp(i,j)); printfC'."); fflush(NULL); ret=-1 ; try { ret=kwi->lnsertKW( meterid, temptime.Get("simple",NULL<sub>1</sub>0), storage->Reading(i,j), 0L);
0480} catch (...)
0481{
0482Log(CORBAERR,"Error in kwi->lnsertKW()");
0483} //if (!ret)
0484// { storage->MarkXmitted(i,j); storage->Delete(ij); // } } printf("\n"); fflush(NULL);
0485} newaddminutes=corbaschedule->addminutes; try { newaddminutes=kwi->FetchSchedule(iccmid,"*","*");
0486} catch(...)
0487{
0488Log(CORBAERR,"Unable to Fetch Commo Schedule from server.");
0489} if (newaddminutes != corbaschedule->addminutes)
0490{ corbaschedule->addminutes=newaddminutes; printf("CORBA schedule set to %d minutes.\n",corbaschedule->addminutes); fflush(NULL);
0491WriteMinutesToFile("/tmp/commotry",newaddminutes+15); WriteMinutesToFile("/tmp/commosuccess",(newaddminutes*5)+15);
0492}
0493//upload any pending violations if (watermarks->ViolationCount())
0494{
0495Log(INFO,"Uploading Watermark Violations"); tempwm=watermarks->GetFirst(); while (tempwm) { try { kwi->Watermark(tempwm->wmid,tempwm->zoneid,tempwm-
0496>wwhen.Get("simple",NULL,0),tempwm->kw);
0497} catch(...)
0498{
0499Log(CORBAERR,"Unable to insert watermark violation on server.");
0500} tempwm=watermarks->GetNext();
0501} watermarks->ClearViolations(); Log(INFO,"Finished uploading Watermark Violations.");
0502} else Log(INFO,'There were no Watermark Violations to upload.");
0503//printf(<sup>,,</sup>\nViolationCount()=%d\n",watermarks->ViolationCount()); notificationcount=OL; try{ notifιcationcount=kwi->GetNotificationCount(iccmid);
0504} catch(...)
0505{
0506Log(CORBAERR,"Unable to fetch notifications;');
0507} printf("There are %ld notifications to download.\n",notificationcount); if (notificationcount)
0508{
0509Log(INFO,"Downloading Notifications:"); notifs.Lock(42,60); //lock with my identifier for (j=0;j<notificationcount;j++)
0510{ tempnotif=new notificationobj; try { kwi->GetNotifιcation(iccmid,j,tempnotif->facility,tempnotif- >code1 ,tempnotif->code2);
0511} catch(...)
0512{
0513Log(CORBAERR,"Error fetching a single notification.");
0514} printf("Just Fetched Notification: %Id, %ld, %ld\n",tempnotif- >faciIity,tempnotif->code1,tempnotif->code2); notifs.notifs.Add(tempnotif);
0515} notifs.UnLock(42);
0516} else
0517Log(INFO,"There were no notifications to download.");
0518//download new kw__client software if necessary if (needupgrade)
0519{
0520//we need an upgrade!!!
0521Log(INFO,"About to fork() for upgrade..."); if ((needupgrade=fork())==0)
0522{
0523Log(INFO,"GoodBye."); sleep(10); if (execlp("/bin/sh","sh"<sub>1</sub>"-c",7usr/local/pepper kwupgrade.sh",NULL))
0524{
0525Log(INFO,"An error occurred while execl()ing kwupgrade.sh"); perror("errno="); try{ kwi->Log(iccmid,LOGjΞRRUPGRADE,"execl0 error on kwugrade.sh",LOGTIME_NOW,LOG_ERR5);
0526} catch(...)
0527{
0528Log(CORBAERR,"Unable to insert log entry on server.");
0529} }
0530} else
0531{
0532Log(INFO,"GoodBye."); exit(0); //parent should terminate! }
0533//nowload a new meterconfiguration if one exists . struct stat st; if (stat(7etc/pepper/meters",&st)) st.st_mtime=0; //unable to stat /etc/pepper/meters, force download; // printf("iccm update time local: %ld remote: %Id meters:%d\n",st.st_mtime, kwi->GetlCCMUpdate(iccmid), storage->Meters()); try { temptimet= kwi->GetlCCMUpdate(iccmid);
0534} catch(...)
0535{
0536Log(CORBAERR,"Unable to get ICCM updated time from server."); temptimet=0L;
0537} if (st.st_mtime < temptimet) { try{ kwi->Log(0L,LOG_FETCHCONFIG,"Fetching config (meter,watermark,orb,isp).",LOGTIME_NOW,LOGJNFO4);
0538} catch(...)
0539{
0540Log(CORBAERR,"Unable to insert into the server log.");
0541}
0542Log(INFO,"Downloading new meter configuration."); if (!(f 1 =fopen(7etc/pepper/meters","w")))
0543{
0544Log(CONFERR,"Error writing new /etc/pepper/meters.");
0545} else
0546{ try { p1 =kwi->GetMeterConf(iccmid);
0547} catch(...)
0548{
0549Log(CORBAERR,"Error fetching meter config from server."); p1=NULL;
0550} if (pi) fwrite(p1 ,strlen(p1),1 ,f1); fclose(fl); storage->ClearMeters(); if (storage->LoadMeters("/etc/pepper/meters")) Log(CONFERR,"Some meters failed to load (err in /etc/pepper/meters?)"); else Log(INFO,"Finished loading /etc/pepper/meters.");
0551} }
0552if (stat("/etc/pepper/watermarks",&st)) st.st_mtime=0; //unable to stat /etc/pepper/watermarks, force download; if (st.st_mtime < temptimet) {
0553Log(INFO,"Downloading new watermarks."); if (!(f 1 =fopen(7etc/pepper/watermarks","w")))
0554{
0555Log(CONFERR,"Error writing new /etc/pepper/watermarks.");
0556} else
0557{ try{ p1 =kwi->GetWatermarks(iccmid);
0558} catch(...)
0559{
0560Log(CORBAERR,"CORBA Error fetching watermarks."); p1=NULL;
0561} if (p1) fwrite(p1,strlen(p1),1,f1); fclose(f1); if (watermarks->Load ("/etc/pepper/watermarks")) Log(CONFERR,"Some watermarks failed to load (err in /etc/pepper/watermarks?)"); else Log(INFO,"Finished loading /etc/pepper/watermarks.");
0562} } if (stat(7etc/pepper/orbs",&st)) stst_mtime=0; //unable to stat /etc/pepper/orbs, force download; if (st.st_mtime < temptimet) { Log(INFO,"Downloading new orb locations."); if (!(f 1 =fopen(7etc/pepper/orbs","w")))
0563{
0564Log(CONFERR,"Error writing new /etc/pepper/orbs.");
0565} else
0566{ try{ p1 =kwi->GetORBs(iccmid);
0567} catch(...)
0568{
0569Log(CORBAERR,"CORBA Error fetching orbs."); p1=NULL;
0570} if (p1) fwrite(p1,strlen(p1),1,f1); fclose(fl);
0571} } if (stat("/etc/pepper/isps",&st)) st.st_mtime=0; //unable to stat /etc/pepper/isps, force download; if (st.stjTitime < temptimet) {
0572Log(INFO,"Downloading new isps."); if (!(f1 =fopen(7etc/pepper/isps","w")))
0573{
0574Log(CONFERR,"Error writing new /etc/pepper/isps.");
0575} else
0576{ try { p1 =kwi->GetlSPs(iccmid);
0577} catch(...)
0578{
0579Log(CORBAERR,"CORBA Error fetching isps."); p1=NULL;
0580} if (p1) fwrite(p1,strlen(p1),1,f1); fclose(fl);
0581} }
0582Log(INFO,"Exiting CORBATALK0");
0583try { kwi->Logout(newobj);
0584} catch(...)
0585{
0586Log(CORBAERR,"Unable to finish Logout().");
0587} try {
0588CORBA::release(kwi);
0589} catch(...)
0590{
0591Log(CORBAERR,"Unable to release kwi.");
0592} try {
0593CORBA::release(prekwi);
0594} catch(...)
0595{
0596Log(CORBAERR,"Unable to release prekwi."); <sup>""</sup>
0597} //kwi->_dispose();
0598Log(INFO,"CORBATALK() exited!"); return(O);
0599}
0600int corbatalkwrapper(char *mac_addr, storageobj <sup>*</sup>storage, schedulerobj *corbaschedule, watermarksobj *watermarks)
0601{ int usingppp; int retval; timej timeout; char *p1; utime(7tmp/commotry",NULL); //touch the times to now usingppp=0; timeout=time(NULL) + 900; //15 minutes retval=-1; if (!fexist(7var/lock corbanet"))
0602{ usingppp=1;
0603Log(INFO,"We are using PPP, initiate connection."); killfpid(SIGALRM,7var/lock/callonring.pid");
0604} else Log(INFO,"Route already exists (ethernet?)"); while (!fexist("/var/lock corbanet") && timeout > time(NULL))
0605{ printf("."); fflush(NULL); sleep(1);
0606} if (timeout < time(NULL))
0607{
0608Log(PPPERR,"Unable to open PPP link"); p1=new char[16]; memset(p1,0,16); sprintf(p1 ,"PPP Link Failed"); sendlogitems.Add((void *)p1); corbascheduIe->finished(); return(-1);
0609} if (fexist("/var/lock/corbanet"))
0610{ printf("Link :-)\n"); sleep(2); retval=corbatalk(mac_addr,storage,corbaschedule,watermarks);
0611} else
0612{ p1=new char[50]; memset(p1 ,0,50); strncpy(p1, "Unusual error getting Link (but not a timeout?)",49); sendlogitems.Add((void <sup>*</sup>)p1);
0613} corbaschedule->finished(); if (usingppp)
0614{ killfpid(SIGHUP,"/var/lock/callonring.pid");
0615} return(retval);
0616}
0617int Log (int code, char Tnsg)
0618{ dateobj now; fprintf(stdout,"LOG: %s\t%s (%4.4d)\n",now.Get("simple",NULL,0),msg<sub>I</sub>code); fflush(NULL); return(O);
0619} int getMACaddr(char <sup>*</sup>mac_addr, int MAC_LEN)
0620{ int fd; struct ifreq si; char *p1; unsigned char buf[32]; char buf2[32];
0621fd=socket(PFJNET, SOCKjDGRAM, IPPROTOJP); strcpy (si.ifr_name, "ethO"); if (ioctl (fd, SIOCGIFHWADDR, &si) < 0)
0622{ return(-2);
0623} memcpy (buf, si.ifr_hwaddr.sa_data, 6); memset(buf2,0,32); sprintf(buf2,"%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); strcpy(mac_addr,buf2); return(O);
0624/<sup>*</sup> FILE I ; char buf[255]; char *ptr; memset(mac_addr,0,MACJ-EN); f 1 =fopen(7etc/pepper/mac","r"); if (!f1)
0625{
0626Log(NOMAC,"Unable to open /etc/pepper/mac"); retum(-1);
0627} fgets(buf,254,f1); // while (!(strstr(buf,"ethO"))) // if (fgets(buf,254,f1)==0) II break; ptr=strchr(buf,':'); if (!ptr)
0628Log(NOMAC,"Unable to determine MAC address"); else
0629{ ptr-=2; strncpy(mac_addr,ptr, 18); while (isspace(mac_addr[strlen(mac_addr)-1])) mac_addr[strlen(mac_addr)-1]=0;
0630} return(O); 7 }
0631#ifdef USETHREADS
0632//global pthread_mutexj mut = PTHREADj UTEXJNITIALIZER; void *threadlaunch(void *ignore)
0633{ sleep(1); if (pthread_mutexJrylock(&mut))
0634{
0635Log(INFO,"Mutex Locked, Duplcate thread. "); sleep(2); pthread_exit(0);
0636} if (thread_corbaschedule->busy)
0637{
0638Log(INFO,"Duplicate thread exiting (not calling corbatalkQ"); pthread_mutex_unlock(&mut); pthread_exit(0);
0639} thread_corbaschedule->busy=1 ;
0640Log(INFO,"Thread Launched!"); corbatalkwrapper(thread_mac_addr,thread_storage,thread_corbaschedule,threa d_watermarks);
0641Log(INFO,"Thread exiting."); pthread_mutex_unlock(&mut); pthread_exit(0);
0642} #endif
0643int CheckTimedDial() //not being used right now!
0644{ FILE *f1 ; int hours; int minutes; char buf[256]; int needtodial; dateobj start, now, dial;
0645if (timed_dial_happened==-1)
0646{
0647//we haven't read the /etc/pepper/timeddial file yet f1=fopen(7etc/pepper/timeddial","r"); if (!f1)
0648{
0649Log(COMMERR,"Unable to open /etc/pepper/timeddial!"); return(-1);
0650} fgets(buf,255,f1); fclose(f1); hours=atoi(buf); minutes=atoi(buf+3); timed_dialjime=(hours*60)+minutes; timed_dial_happened=0; sprintf(buf, "Timed dial should happen %d minutes into each day.",timed_dialjime); Log(INFO.buf); } start. DayStartTimeQ; diaI.Set(start.Get()+(timed_dialJime*60)); if (timed_dial_happened >=0 && (now.GetQ > dial.GetQ) && (now.GetQ- dial.Get() 3600)) timed_dial_happened=0; //reset from day to day if (timed_dial_happened == 0 && (now.GetQ > dial.GetQ) && (now.GetQ- dial.GetO < 3600)) needtodial=(now.Get()-dial.Get())/60; //minutes ago we should have dialed else needtodial=0;
0651#ifdef USETHREADS if (thread_corbaschedule->busy==1)
0652{ if (needtodiaI> 15)
0653{
0654Log(INFO,"corbaschedule is still busy, so we are going to override it."); thread_corbaschedule->busy=0; signalpoll=1; timed_dial_happened=1 ;
0655} else
0656{
0657Log(INFO,"We need to do our dialy timed dial, but corbaschedule is busy :
0658("); retum(O); }
0659} #endif
0660Log(INFO,"lt is time to do our dialy timed dial."); signalpoll=1; timed_dial_happened=1 ; return(O); }
0661int setTZO
0662{
0663FILE 71; char buf[255]; char *ptr; f1=fopen("/etc/pepper/timezone","r"); if (!f1)
0664{
0665Log(TIMEERR,"Unable to open /etc/pepper/timezone"); return(-1);
0666} sprintf(buf,"TZ="); fgets(buf+3,251 ,f1); while (isspace(buf[strien(buf)-1 ])) buf[strlen(buf)-1]=0; if (strlen(buf) >= 6) putenv(buf); else
0667Log(TlMEERR,"TZ is too short, not setting."); return(O);
0668}
0669main(int argc, char **argv)
0670{ schedulerobj *pollschedule; schedulerobj *corbascheduIe; storageobj *storage; watermarksobj watermarks; char mac_addr[64]; int cycles; char buf[256]; char <sup>*</sup>p1; int i; notificationobj <sup>*</sup>tempnotif; int usetemplogs;
0671WriteMinutesToFileC'/tmp/commotry", 15); WriteMinutesToFile("/tmp/commosuccess",45); if (getenv("OMNIORB_CONFIG")==NULL) putenv("OMNIORB_CONFIG=/etc/omniORB.cfg");
0672cycles=9; fιrstcommo=1;
0673commandargcount=argc; commandargs=argv; //memcpy(commandargs,argv,(sizeof(char *)argc)); setTZQ; p1=NULL; suppressupgrades=0; usetemplogs=0; for (i=1;i<argc;i++)
0674{ p1=argv[i]; if (strcmp(p1 ,"-testtube")==0)
0675{
0676Log(INFO,"This was a testtube execution. Exiting..."); exit(99);
0677} if (strcmp(p1,"-L")==0)
0678{ memset(argvlog, 0,256); strncpy(argvIog,argv[i+1],255);
0679} if (strcmp(p1 ,"-U")==0) suppressupgrades=30; if (strcmp(p1 ,"-v")==0) printf("kw_client %s (%ld)\ncopyright 1999,2000 by Stonewater Software, lnc.\n\n",VERSION_HUMAN,(unsigned long)VERSION_CODIFIED); if (strcmp(p1 ,"-V")==0)
0680{ printf("kw_client %s (%ld)\ncopyright 1999,2000 by Stonewater Software, lnc.\n\n",VERSION_HUMAN,(unsigned long)VERSION_CODIFlED); exit(0);
0681} if (strcmp(p1,"-t")==0) usetemplogs=1 ; }
0682#ifdef USETHREADS spaboard=new spa2; spaboard->connect(); #endif storage=NULL; signalpoll=0; signal(SIGHUP,onhup); getMACaddr(mac_addr,64); printfC'Starting with MAC address: %s\n",mac_addr); timed_dial_happened=-1 ; //we haven't read the /etc/pepper/timedial file yet if (!(storage=new storageobj))
0683{
0684Log(OUTMEM,"Unable to create storage obj...exiting"); exit(1);
0685} if (!(pollschedule=new schedulerobj))
0686{
0687Log(OUTMEM,"Unable to create POLL scheduler...exiting"); exit(1);
0688} if (!(corbaschedule=new schedulerobj))
0689{
0690Log(OUTMEM,"Unable to create CORBA scheduler...exiting\n"); exit(1);
0691}
0692#ifdef USETHREADS pthreadj corbathread; thread_mac_addr=mac_addr; thread_storage=storage; thread_corbaschedule=corbaschedule; thread_watermarks=&watermarks; pthread_create(&corbathread,NULL,threadlaunch,NULL); pthread_detach(corbathread);
0693#else corbatalkwrapper(mac_addr,storage,corbaschedule,&watermarks); #endif
0694//corbaschedule->finished(); //this func now called inside corbatalkQ!!!
0695if (storage->Meters()==0)
0696{ if (storage->LoadMeters("/etc/pepper/meters"))
0697{
0698Log(CONFERR,"Some meters failed to load (error in
0699/etc/pepper/meters?)"); } }
0700if (polIschedule->Load("poll"))
0701{
0702Log(NOPOLLSCH,"Unable to load POLL schedule...exiting\n"); exit(1);
0703} if (corbaschedule->Load("corba"))
0704{
0705Log(NOCORBASCH,"Unable to load CORBA schedule...exiting\n"); exit(1);
0706} if (watermarks.Load(7etc/pepper/watermarks")) Log(CONFERR,"Some watermarks failed to load (err in /etc/pepper/watermarks?)") ; else Log(INFO,"Finished loading /etc/pepper/watermarks.");
0707while (1)
0708{
0709//fprintf(stderr,"+"); if (usetemplogs && (cycles % 10 ==0))
0710{ freopen("/tmp/kw","w",stdout);
0711} storage->Poll(); //poll all meters
0712// CheckTimedDialQ; killfpid(SIGPROF,"/var/lock swatchdog.pid"); storage->CheckWatermarks(&watermarks); if (watermarks .ViolationCountQ) { Log(INFO,"Because Watermark Violations exist, we are initiating corbatalk()."); corbaschedule->Later(0); //we need to upload the violations! } if (signalpoll)
0713{ corbaschedule->Later(0); //now! signalpoll=0;
0714} if ((corbaschedule->istime() && !corbaschedule->busy))
0715{ #ifdef USETHREADS pthread corbathread; thread_mac_addr=mac_addr; thread_storage=storage; thread_corbaschedule=corbaschedule; thread_watermarks=&watermarks;
0716//need to do this quickly to avoid many corbatalkQ threads signalpoll=0; sleep(1); pthread_create(&corbathread,NULL,threadlaunch,NULL); pthread_detach(corbathread); #else if (storage->PollSoon(3))
0717{
0718Log(INFO,"One or meters are going to poll within 3 minutes, corbatalkQ deferred for 4 minutes."); corbaschedule->Later(4); //push 4 minutes into the future
0719} else
0720{ corbatalkwrapper(mac_addr,storage,corbaschedule, &watermarks);
0721//corbaschedule->finished(); //this call moved into corbatalkQ signalpoll=0;
0722} #endif
0723} else
0724{ #ifdef USETHREADS if (notifs.Lock(13,60)==0) //lock the notification collection with this thread's lock code (13) { for (i=0;i<notifs.Count();i++)
0725{ tempnotif=notifs.ltem(i); if (tempnotif) spaboard->activate((unsigned long)tempnotif->facility,(unsigned long)tempnotif->code1.(unsigned long)tempnotif->code2,0L); else
0726Log(INFO,"Error accessing one of the notification items.");
0727} notifs.RemoveAIIQ; notifs.UnLock(13);
0728} cycles++; if (cycles % 10 ==0)
0729{ corbaschedule->istime("corba");
0730//Log(INFO,"Trying to Poll the Green Button."); cycles=0; spaboard->housekeep();
0731} else sleep(1); if (spaboard->buttons || spaboard->chirps)
0732{ sprintf(buf,"Buttons: %d, Chirps: %d\n",spaboard->buttons,spaboard- >chirps); spaboard->buttons=0; spaboard->chirps=0; p1=new char[strlen(buf)+1]; strcpy(p1,buf); sendlogitems.Add((void *)p1); corbaschedule->Later(0);
0733} #else sleep(1); #endif
0734} } exit(0); } #define CONTEXTNAMEID "stonergy" #define CONTEXTNAMEKIND "context" #define NAMEID "kwjnserter" #define NAMEKIND "Object"
0735static
0736CORBA::Object_ptr getObjectReference(CORBA::ORB_ptr orb) { CosNaming::NamingContext_var rootContext; try { // Obtain a reference to the root context of the Name service: CORBA::Object_var initServ; printf("\tA\n"); fflush(NULL); initServ = orb->resolveJnitial_references("NameService");
0737// Narrow the object returned by resolveJnitial_references() //to a CosNaming::NamingContext object: printf("\tB\n"); fflush(NULL); rootContext CosNaming::NamingContext::_narrow(initServ); if (CORBA: :is_nil(rootContext))
0738{ cerr « "Failed to narrow naming context." « endl; return CORBA::Object::_nil(); } } // catch(CORBA::ORB::lnva!idName& ex) { catch(...) { cerr « "Service required is invalid [does not exist] ' « endl; return 0; }
0739printf("\tC\n"); fflush(NULL);
0740CosNaming::Name contextName; contextName.length(2); contextName[0].id = (const char*) CONTEXTNAMEID; // string copied contextName[0].kind = (const char<sup>*</sup>) CONTEXTNAMEKIND; // string copied contextName[1].id = (const char*) NAMEID; // string copied contextName[1].kind = (const char*) NAMEKIND; // string copied CORBA::Object_ptr obj; printf("\tD\n"); fflush(NULL); try { obj=rootContext->resolve(contextName);
0741} catch (...)
0742{ cerr« "Caught a fatal exception in COS Naming Service"«endl; return CORBA::Object::_nil(); } printf("\tE\n"); fflush(NULL); return obj; }
0743FILE: dbifaceobj.h encapsulates the database connectivity required by the server side of the corba implementation .
0744#ifndef_DBIFACEOBJ_H #define _DBIFACEOBJ_H
0745#include "stdincludes.h"
0746#include "dateobj. h"
0747#include "collectionbase.h"
0748#include "keyring. h"
0749#include "libpq++.h"
0750#include "stonergy_defs.h"
0751#include "../sib/kw_client/logcodes.h"
0752#ifndef MAXULONG #define MAXULONG Oxffffffff #endif
0753class DBIFACEObj
0754{ public:
0755DBIFACEObJO;
0756-DBIFACEObjQ; int UsableQ; char *GetTableKey(long zoneid, long moduleid, long keyid, char *dest, int destlen); long SetTableKey(long zoneid, long moduleid, long keyid, const char <sup>*</sup>val); long FindlCCM(const char *HWADDR); long GetZoneParent(unsigned long zoneid); long FindHWKey(const char *HWADDR); long GetlCCMMeterByName(unsigned long iccmzoneid, const char <sup>*</sup>metername); int Archive(dateobj *startdate, dateobj *enddate, long Meterld); long ArbitrarySQL(char <sup>*</sup>qrystr); int lnsertKW(unsigned long zoneid, dateobj <sup>*</sup>wwhen, float KW, unsigned long scenario=0L); long GetZoneBySource(long ancestorid, const char <sup>*</sup>meter_number); long Log(long userid, long zoneid, char <sup>*</sup>when, char <sup>*</sup>action, long severity); long GetlCCMUpdate(long iccmid); long GetMeterConf(long iccmid, char <sup>*</sup>conf); long GetCommoSchedule(long iccmid); long lnsertWatermark(unsigned long wmid, dateobj <sup>*</sup>temp, float KW); long GetWatermarks(unsigned long zoneid, char <sup>*</sup>buf); long GetlSPs(unsigned long zoneid, char *buf); long GetORBs(unsigned long zoneid, char *buf); long GetNotificationCount(unsigned long zoneid); long GetNotification(long zoneid, long which, long &facility, long &code1, long &code2); long SendEmail(unsigned long zoneid, const char *message, const char *subject=NULL); protected: bool status; //pglib boolean //PgEnv env; PgDatabase <sup>*</sup>db; //PgCursor *data; PgDatabase *data; int needDoneQuery;
0757PgCursor *NewQuery(const char *inqrystr); int EndQuery(PgCursor *tempdata); long RunQuery(char <sup>*</sup>inqrystr); int DoneQueryQ; unsigned long DBIFACEObj::GetSequence(const char *seqname);
0758};
0759#endif
0760FILE: dbifaceobj.cxx implementation file for the database interface
0761#include "dbifaceobj.h" #include "notifier.h"
0762//protected stuff :
0763/*long DBIFACEObj::RunQuery(char *inqrystr)
0764{ char qrystr[2048];
0765// printf("============= Run Query =============\n"); if (needDoneQuery) DoneQueryO; needDoneQuery=1 ; sprintf(qrystr,"DECLARE ceces%ldcur CURSOR FOR %s",getpidQ,inqrystr); if (status=data->Exec("begin transaction") != PGRES_COMMAND_OK)
0766{ fprintf(stderr,"BEGIN command failed\n"); data->Exec("end transaction"); needDoneQuery=0; return(-IL);
0767} status=data->Exec(qrystr); if (status != PGRES_COMMAND_OK && status!= PGRES_EMPTY_QUERY)
0768{ fprintf(stderr,"DECLARE CURSOR command failed (status=%d): \n(%s)\n",status,qrystr); needDoneQuery=0; return(-2);
0769} // printf("status=%d\n",status); if (status==PGRES_EMPTY_QUERY)
0770{ printf("Empty queryΛn"); needDoneQuery=0; return(OL); } sprintf(qrystr,"FETCH ALL in ceces%ldcur",getpidQ); if (status=data->Exec(qrystr) != PGRES_TUPLES_OK)
0771{ fprintf(stderr,"FETCH ALL command didn't return tuples properly\n"); needDoneQuery=0; retum(-3);
0772} return(data->TuplesQ); }
0773int DBIFACEObj::DoneQuery()
0774{ char qrystr[1024]; int tries; if (IneedDoneQuery) return(O); needDoneQuery=0; sprintf(qrystr,"CLOSE ceces%Idcur",getpidQ); data->Exec(qrystr); data->Exec("end transaction"); return(O);
0775} 7
0776PgCursor *DBIFACEObj::NewQuery(const char *inqrystr)
0777{ char qrystr[2048]; int tries; int localstatus; dateobj now; char cursorname[256];
0778PgCursor *tempdata; sprintf(cursorname,"c%ld_%ld_%ld",getpid(), now.GetQ, randomQ); tempdata=new PgCursor((const char <sup>*</sup>)"dbname=stonergy",(const char <sup>*</sup>)cursorname); if (tempdata->ConnectionBadQ) { printf("Error connecting to database!\n"); return(NULL);
0779} tries=0; localstatus=0; while (ϋocalstatus && tries < 100)
0780{ tries++;
0781Iocalstatus=tempdata->Declare(inqrystr); if (ϋocalstatus) sleep(1); } if (ϋocalstatus)
0782{ fprintf(stderr,"DECLARE CURSOR command failed (status=%d):
0783\n(%s)\n",status ,q rystr) ; return(NULL);
0784} localstatus=tempdata->Fetch(); if (ϋocalstatus)
0785{ fprintf(stderr,"FETCH ALL command didn't return tuples proper!y\n"); return(NULL); } retum(tempdata); } int DBIFACEObj::EndQuery(PgCursor *tempdata)
0786{ if (tempdata)
0787{ tempdata->Close(); delete tempdata;
0788} return(O);
0789}
0790/*long DBIFACEObj::RunQuery(char *inqrystr)
0791{ char qrystr[2048]; int tries; if (needDoneQuery)
0792DoneQueryQ; needDoneQuery=1 ; tries=0; status=0; while (istatus && tries < 100)
0793{ tries++; status=data->Declare(inqrystr); if (Istatus) sleep(1); } if (istatus) // != PGRES_COMMAND_OK && status!= PGRES_EMPTY_QUERY)
0794{ fprintf(stderr,"DECLARE CURSOR command failed (status=%d): \n(%s)\n",status,qrystr); needDoneQuery=0; retum(-2);
0795} if (status==PGRES_EMPTY_QUERY)
0796{ printf("Empty queryΛn"); needDoneQuery=0; return(OL);
0797} status=data->Fetch(); if (istatus) //=data->Exec(qrystr) != PGRES_TUPLES_OK)
0798{ fprintf(stderr,"FETCH ALL command didn't return tuples properlyW); needDoneQuery=0;- return(-3);
0799} return(data->TuplesQ); }
0800int DBIFACEObj::DoneQuery()
0801{ char qrystr[1024]; if (JneedDoneQuery) retum(O); needDoneQuery=0; data->Close(); return(O);
0802} 7 long DBIFACEObj::RunQuery(char *inqrystr)
0803{ char qrystr[2048]; int tries;
0804DoneQueryQ; needDoneQuery=1 ; tries=0; status=0; status=data->Exec(inqrystr); if (istatus) //data->Exec(qrystr) != PGRES_TUPLES_OK)
0805{ fprintf(stderr,"Exec() didn't return tuples properly\n"); needDoneQuery=0; return(-3);
0806} return(data->TuplesQ); }
0807int DBIFACEObj::DoneQuery()
0808{ char qrystr[1024]; if (ineedDoneQuery) retum(O); needDoneQuery=0;
0809//data->Close(); return(O);
0810}
0811unsigned long DBIFACEObj::GetSequence(const char<sup>*</sup>seqname) { char qrystr[2048]; unsigned long tempjd;
0812sprintf(qrystr,"select nextval('%s')",seqname); RunQuery(qrystr); tempJd=atol(data->GetValue(0,0)); DoneQueryQ; retum(tempjd); }
0813int DBIFACEObj::Usable()
0814{ return(!data->ConnectionBadQ);
0815}
0816DBIFACEObj-DBIFACEObJO
0817{ dateobj now; char cursorname[256]; sprintf(cursorname,"c%ld_%id_%ld",getpid(), now.GetQ, randomQ); data=new PgDatabase("dbname=stonergy"); //db=new PgDatabase((const char <sup>*</sup>)"dbname=stonergy"); db=data;
0818//data=new PgCursor((const char *)"dbname=stonergy",(const char *)cursomame); if (data->ConnectionBadQ)
0819{ printf("Error connecting to database!\n");
0820} needDoneQuery=0;
0821}
0822DBIFACEObj::~DBIFACEObj()
0823{ DoneQueryO;
0824//if (db)
0825// {
0826// delete db; } if (data) delete data;
0827}
0828long DBIFACEObj::GetZoneBySource(long ancestorid, const char *meter_number)
0829{ char *p1,<sup>*</sup>p2,*p3; char qrystr[2048]; char temp[2048]; long ret; if (meter_number==NULL) return(OL);
0830//note: this is not yet truly an ancestor id (only a prentid). //an skey (:4:23:112:2213:) would make an ancestor search very easy! sprintf(qrystr,"select * from zones where (source='%s' and parentid=%ld) where active order by priority",meter_number, ancestorid);
0831RunQuery(qrystr); if (!data->TuplesQ) return(OL); ret=atol(data->GetValue(0,"zoneid"));
0832DoneQueryQ; return(ret);
0833}
0834long DBIFACEObj::FindlCCM(const char *HWADDR)
0835{ char qrystr[2048]; unsigned long temp; PgCursor *tempdata; sprintf(qrystr,"select * from iccm where (hwaddr='%s')",HWADDR);
0836// printf("%s\n",qrystr);
0837//tempdata=NewQuery(qrystr); RunQuery(qrystr); if (!data->TuplesQ) retum(OL); temp=atol(data->GetValue(0,"zoneid"));
0838//EndQuery(tempdata);
0839DoneQueryQ;
0840Log(LOG_HWLOGIN,temp,"now","HWLogin",1); return(temp);
0841} long DBIFACEObj::GetlCCMMeterByName(unsigned long iccmzoneid, const char <sup>*</sup>metername)
0842{ charqrystr[2048]; unsigned long temp; sprintf(qrystr,"select * from iccmmeters where (iccmzoneid=%ld and alias='%s')"<sub>)</sub>iccmzoneid,metername);
0843// printf("%s\n",qrystr);
0844RunQuery(qrystr); if (!data->Tuples()) return(MAXULONG); temp=atol(data->GetValue(0,"meterzoneid"));
0845DoneQueryQ; returnrtemp);
0846} long DBIFACEObj::GetZoneParent(unsigned long zoneid)
0847{ char qrystr[2048]; unsigned long temp; sprintf(qrystr,"select * from zones where (zoneid=%ld)",zoneid); RunQuery(qrystr); if (!data->Tuples()) return(MAXULONG); temp=atol(data->GetValue(0,"parentid"));
0848DoneQueryQ; return(temp);
0849} long DBIFACEObj::FindHWKey(const char *HWADDR)
0850{ char qrystr[2048]; unsigned long temp; sprintf(qrystr,"select * from keys where (moduleid=%ld and keyid=%ld)",MODULE_KWJNSERTER,KEY_HWADDR); RunQuery(qrystr); if (!data->TuplesQ) return(OL); temp=atol(data->GetValue(0,"value"));
0851DoneQueryQ; retumftemp);
0852} char *DBIFACEObj::GetTableKey(long zoneid, long moduleid, long keyid, char *dest, int destlen)
0853{ char qrystr[2038]; sprintf(qrystr, "select * from keys where (zoneid=%d and scenario=0 and moduleid=%ld and keyid=%ld)",zoneid, moduleid, keyid); //printf("%s — ",qrystr); RunQuery(qrystr); if (!data->TuplesQ) return(dest); strncpy(dest,data->GetVaIue(0,"keyval"),destlen);
0854//printf("%s\n",dest);fflush(NULL);
0855DoneQueryO; return(dest);
0856} long DBIFACEObj::SetTableKey(long zoneid, long moduleid, long keyid, const char *val)
0857{ char qrystr[2038]; long status; sprintf(qrystr,"select * from keys where (zoneid=%d and scenario=0 and moduleid=%ld and keyid=%Id)",zoneid, moduleid, keyid); RunQuery(qrystr); status=data->Tuples();
0858DoneQueryQ;
0859//if (!data->TuplesQ)
0860// return(dest); if (status > 0)
0861{ sprintf(qrystr,"update keys set keyval- %s' where (zoneid=%ld and scenario=0 and moduleid=%ld and keyid=%ld)",val,zoneid, moduleid, keyid); // printf("%s\n",qrystr); if (!db->ExecCommandOk((const char *)qrystr)) printf("Error pg_exec()ing query: %s\n\n",qrystr);
0862} else
0863{ sprintf(qrystr,"insert into keys values (%ld,%ld,0,%ld,'%s')",zoneid,moduleid,keyidNal); // printf("%s\n",qrystr); data-> Exec(q rystr) ; } return(OL); }
0864int DBIFACEObj::Archive(dateobj *startdate, dateobj *enddate, long Meterld)
0865{ char qrystr[2048]; memset(qrystr,0,2048); sprintf(qrystr, "delete from readings where (wwhen between '%s' and '%s' ", startdate->Get("simple",NULL,0),enddate->Get("simple",NULL,0)); if (JMeterld) strcat(qrystr,")"); else sprintf(qrystr+strlen(qrystr)," and zoneid=%ld",Meterld); data-> Exec(q rystr) ; return(O);
0866}
0867long DBIFACEObj::Log(long userid, long zoneid, char *when, char *action, long severity) { char bufJ256]; sprintf(buf,"insert into log values (%ld,%ld,'%s','%s',%ld)", userid, zoneid, when, action, severity); data->Exec(buf); printf("DBIFACE LOG: %s\n",buf); fflush(NULL); return(OL);
0868} long DBIFACEObj::ArbitrarySQL(char *qrystr) { data-> Exec(q rystr) ; return(OL);
0869}
0870int DBIFACEObj::lnsertKW(unsigned.long zoneid, dateobj *wwhen, float KW, unsigned long scenario)
0871{ char qrystr[2048]; sprintf(qrystr, "insert into readings (zoneid, wwhen, reading) values (%ld,'%s',%2.2fO)",zoneid,wwhen->Get("simpIe",NULL,0),KW);
0872//maybe we should be doing some data validation...meter validation...etc // printf("%s\n",qrystr); fflush(NULL); if (!db->ExecCommandOk((const char *)qrystr)) printf("Error pg_exec()ing query: %s\n\n",q rystr); return(O); } long DBIFACEObj::GetlCCMUpdate(long iccmid)
0873{ char qrystr[2048]; timej tempj; dateobj temp_d; sprintf(qrystr, "select * from iccm where zoneid=%ld",iccmid);
0874// printf("%s\n",qrystr); fflush(NULL);
0875RunQuery(qrystr); if (!data->TuplesQ) return(OL); temp_d.Set(data->GetValue(0,"updated"),"timestamp"); // printf("%s\t%s\n",data-
0876>GetValue(0,"updated"),temp_d.Get("simple",NULL,0)); tempJ=temp_d.Get();
0877DoneQueryQ; return(tempj); } long DBIFACEObj::GetMeterConf(long iccmid, char <sup>*</sup>conf)
0878{
0879//copies a configuration line into confline char buf[256]; char qrystr[2048]; char metertype[64]; int i; dateobj tempdate; sprintf(qrystr,"select * from iccmmeters where iccmzoneid=%ld",iccmid);
0880// printf("%s\n",qrystr); fflush(NULL);
0881RunQuery(qrγstr); if (!data->TuplesQ).
0882{ conf=NULL; return(-1);
0883} sprintf(buf,"#Meter configuration downloaded at %s\n\n",tempdate.Get("simple",NULL,0)); strcat(conf,buf); for (i=0;i<data->Tuples();i++)
0884{ memset(buf,0,256); memset(metertype,0,64); // switch (atol(data->GetValue(i,"mtype")))
0885// {
0886// case 10: //random 1
0887// sprintf(metertype,"random1");
0888// break;
0889// case 20: //newyorkpulsel // sprintf(metertype,"newyorkpulse1 ");
0890// break;
0891// default:
0892// sprintf(metertype,"random1");
0893// } sprintf(buf,"%ld:%s:%s:%d:%2.2f:%s\n", atol(data->GetValue(i,"meterzoneid")), data->GetValue(i,"alias"), data->GetValue(i,"mtype") , atoi(data->GetVaIue(i,"minutes")), atof(data->GetVaIue(i,"multiplier")), data->GetValue(i,"misc")); strcat(conf.buf);
0894} sprintf(buf,"\n\n"); strcat(conf.buf); DoneQueryQ; retum(O); } long DBIFACEObj::GetCommoSchedule(long iccmid)
0895{ long minutes.tempminutes; char qrystr[2048]; sprintf(qrystr,"select * from iccm where zoneid=%ld",iccmid); // printf("%s\n",qrystr); fflush(NULL); RunQuery(qrystr); if (!data->TuplesQ)
0896{ return(OL);
0897} tempminutes=atol(data->GetValue(0,"tempschedule")); minutes=atol(data->GetValue(0,"commoschedule"));
0898DoneQueryQ; return((tempminutes<minutes)?tempminutes:minutes);
0899} long DBlFACEObj::lnsertWatermark(unsigned long wmid, dateobj <sup>*</sup>temp, float KW)
0900{ char qrystr[2048]; sprintf(qrystr,"insert into hilolog values (%ld,'%s',%2.2f0)",wmid,temp- >Get("simple",NULL,0),KW); printf("lnserting Watermark: %s\n",qrystr); fflush(NULL); data->Exec(qrystr); return(OL);
0901} long DBIFACEObj::GetWatermarks(unsigned long zoneid, char <sup>*</sup>conf)
0902{ char buf[256]; char qrystr[2048]; char wtype[64]; int i; dateobj tempdate; sprintf(qrystr,"select * from hilowat where (zoneid=%ld or zoneid in (select zoneid from zones where (parentid=%ld)) and active) order by seq",zoneid,zoneid);
0903// printf("%s\n",qrystr); fflush(NULL);
0904RunQuery(qrystr); if (!data->TuplesQ)
0905{ conf=NULL; return(-1); } sprintf(buf,"#Watermarks downloaded at %s\n\n",tempdate.Get("simple",NULL,0)); strcat(conf.buf); for (i=0;i<data->Tuples();i++)
0906{ memset(buf,0,256); memset(wtype,0,64); switch(atoi(data->GetValue(i,"wtype"))) { case HI WATER: sprintf(wtype,"HI"); break; case LOWATER: sprintf(wtype,"LO"); break; case EQWATER: sprintf(wtype,"EQ"); break; case LOWATERNZ: sprintf(wtype,"LONZ"); break; default: sprintf(wtype,"HI"); }
0907sprintf(buf,"%ld:%ld:%s:%2.2f:%s\n", atol(data->GetValue(i,"id")), atol(data->GetValue(i,"zoneid")), wtype, atof(data->GetValue(i, "watermark")), data->GetValue(i,"suspect"));
0908strcat(conf,buf);
0909} sprintf(buf,"\n\n"); strcat(conf,buf); DoneQueryQ; return(O); } long DBIFACEObj::GetlSPs(unsigned long zoneid, char *conf)
0910{ char buf[256]; char qrystr[2048]; int i; dateobj tempdate; char predial[32]; int iccmareacode; memset(predial,0,32); iccmareacode=0; sprintf(qrystr,"select * from iccm where zoneid=%ld",zoneid);
0911RunQuery(qrystr); if (!data->Tuples()) printf("::GetlSPs() Unable to lookup ICCM zoneid (%ld)\n",zoneid); else
0912{ strncpy(predial,data->GetValue(0,"dialprefix"),31); iccmareacode=atoi(data->GetValue(0,"areacode"));
0913DoneQueryQ;
0914} sprintf(qrystr,"select <sup>*</sup> from zoneisps, isps where (zoneid=%ld and zoneisps.ispid=isps.ispid and isps.active and zoneisps.active) order by priority",zoneid); printf("%s\n",qrystr); fflush(NULL);
0915RunQuery(q rystr); if (!data->TuplesQ)
0916{ conf=NULL; return(-1); } sprintf(buf,"#ISPs downloaded at %s\n\n",tempdate.Get("simple",NULL,0)); strcat(conf.buf); printf(conf); fflush(NULL);
0917for (i=0;i<data->Tuples();i++)
0918{ memset(buf , 0 ,256) ; if (atoi(data->GetValue(i,"areacode")) !=iccmareacode) //userid:passwd:phone sprintf(buf,"%s:%s:%s1 %s%s\n", data->GetValue(i,"userid"), data->GetVal ue(i ,"passwd") ,
0919(strlen(predial)?predial:""), data->GetValue(i,"areacode"), data->GetValue(i,"phone")); else //userid :passwd: phone sρrintf(buf,"%s:%s:%s%s\n", data->GetValue(i,"userid"), data->GetValue(i,"passwd"),
0920(strlen(predial)?predial:""), data->GetValue(i,"phone")); printf("%s",buf); fflush(NULL); strcat(conf,buf);
0921} sprintf(buf,"\n\n"); strcat(conf,buf); DoneQueryO; printf("\nExiting ::GetlSPs()\n"); fflush(NULL); return(OL); } long DBIFACEObj::GetORBs(unsigned long zoneid, char <sup>*</sup>conf)
0922{ char buf[256]; char qrystr[2048]; char wtype[64]; int i; dateobj tempdate; sprintf(q rystr, "select * from zoneorbs, orbs (zoneid=%ld and zoneorbs.orbid=orbs.orbid and zoneorbs. active and orbs.active) order by zoneorbs. priority",zoneid);
0923// printf("%s\n",qrystr); fflush(NULL);
0924RunQuery(qrystr); if (!data->TuplesQ)
0925{ conf=NULL; retum(-1); } sprintf(buf,"#ORBs downloaded at %s\n\n",tempdate.Get("simple",NULL,0)); strcat(conf,buf); for (i=0;i<data->Tuples();i++)
0926{ memset(buf,0,256); sprintf(buf,"%ld:%sJ/os\n", atol(data->GetValue(i,"id")), data->GetValue(i,"ip"), data->GetValue(i,"port")); strcat(conf,buf);
0927} sprintf(buf,"\n\n"); strcat(conf,buf);
0928DoneQueryQ; return(O);
0929} long DBIFACEObj::GetNotifιcationCount(unsigned long zoneid)
0930{ char qrystr[2048]; long i; sprintf(qrystr,"select count(*) from notifymessages where (zoneid=%ld and senttime='epoch')",zoneid); printf("%s\n",qrystr); fflush(NULL);
0931RunQuery(qrystr); if (!data->TuplesQ)
0932{ retum(-1);
0933} i=atol(data->GetValue(0,0));
0934DoneQueryQ; return(i);
0935} long DBIFACEObj::GetNotification(long zoneid, long which, long &facility, long &code1 , long &code2)
0936{ char qrystr[2048]; long i; sprintf(qrystr,"select * from notifymessages where (zoneid=%ld and senttime='epoch') order by starttime",zoneid);
0937RunQuery(q rystr); if (!data->TuplesQ)
0938{ printfC'No Tuples\n"); return(-1); } if (which < 0 || which >= data->TuplesQ)
0939{ printffMessage out of bounds\n");
0940DoneQueryQ; return(-2);
0941} facility=atol(data->GetValue(which,"facility")) codel =atol(data->GetValue(which,"code1 ")) code2=atol(data->GetValue(which,"code2")) sprintf(qrystr,"update notifymessages set senttime=now() where (zoneid=%ld and starttime='%s' and facility=%s)",zoneid,data-
0942>GetValue(which,"starttime"),data->GetValue(which,"facility")); printf("%s\n",qrystr); fflush(NULL);
0943DoneQuery(); d ata-> Exec(q rystr) ;
0944return(O); } long DBIFACEObj::SendEmail(unsigned long zoneid, const char Tnessage, const char *subject)
0945{ notifierobj email; char recipient[256]; char qrystr[2048]; int i; sprintf(qrystr,"select * from notify where ((zoneid=%ld or zoneid in (select zoneid from zones where zpath like '%%:%s:%%'))and (method=%d or method=%d or method=%d) and active and curtail)",zoneid, zoneid, NOTIF_EMAlL,NOTIF_PAGER,NOTlF_FAX);
0946RunQuery(qrystr); if (!data->Tuples())
0947{ return(-1);
0948} for (i=0;i<data->Tupies();i++) { memset(recipient,0,256); strcpy(recipient,data->GetValue(i,"address")); email.SendEmail("127.0.0.1",recipient,"ENERGY',subject,message);
0949} DoneQueryQ; return(O); }
0950FILE: iccm_client.h. Header for client.cxx
0951#ifndef _ICCM_CLIENT_H #define _ICCM_CLIENT _H
0952#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <iostream.h> #include <ctype.h> #include <sys/types.h> #include <utime.h>
0953#include "dateobj.h" #include "meterdrivers/drivers.h" #include "meterdrivers/meterobj.h" #incIude "common/collectionbase.h" #include "stonergy_defs.h"
0954#define VERSION_CODIFIED 0x00000209 #define VERSION HUMAN "vO.0.2.9"
0955#define USENAMES
0956#define VEND_STONEWATER 1 L
0957#defιne TYPE_MISC 0L
0958//define local log conditions #define NOMAC 31 #defιne OUTMEM 32 #define NOPOLLSCH 33 #define NOCORBASCH 34 #define NOCONF 35 #define CONFERR 36 #define PIDERR 37 #define CORBAERR 38 #define INFO 39 #define PPPERR 40 #define COMMERR 41 #define TIMEERR 42 #ifndef MAXULONG #define MAXULONG Oxffffffff #endif
0959int Log (int code, char *msg);
0960class storageobj; class schedulerobj;
0961#endif
0962FILE: divclient.cxx entry point in kw_client for connecting to the orb and getting the object reference for the other side.
0963============================================================ */
0964#include <stdio.h> #include <stdlib.h> #include <iostream.h> #include "omnithread.h" #include "kwjnserter.hh" #include "dateobj. h"
0965#define USENAMES
0966#define VEND_STONEWATER 1L #define TYPE_MISC 0L static CORBA: :Object_ptr getObjectReference(CORBA::ORB_ptr orb);
0967main(int argc, char **argv)
0968{
0969CORBA::ORB_ptr orb;
0970CORBA::BOA_ptr _myboa; kw_inserter_var myobjRef; kwjnserter *kwi; orb=CORBA::ORBJnit(argc, argv,"omniORB2"); _myboa=orb->BOAJnit(argc, argv,"omniORB2_BOA");
0971CORBA: :Object_var obj;
0972#ifdef USENAMES try
0973{ obj=getObjectReference(orb);
0974} catch(...)
0975{ cerr«"Error connecting to to CORBA object."«endl; exit(1);
0976} #endif if (CORBA::is_nil(obj)) printf("obj says that it is _nil()\n"); kwi=kwJnserter::_narrow(obj); if (CORBA: :is_nil(kwi)) printf("After _narrow, kwi says that it is _nil()\n");
0977if (argc<7)
0978{ printf("usage: divclient zoneid secret start-date-time end-date-time demand consumption\n"); exit(1); } float temp.individual.added; float kw.kwh; long inserted; dateobj start, end, begun, ended; int needchunks.i; kwi->Login(atol(argv[1]),argv[2]); begun. NowQ; start.Set(argv[3],"simple"); end.Set(argv[4],"simple"); kw=atof(argv[5]); kwh=atof(argv[6]); if (!kw || !kwh)
0979{ printf("Both consumption and demand must be greater than zero!\n\n"); exit(1); } inserted=1L;
0980//needchunks=(kwh-(kw/2)) / (kw); //could use (kw/2)+1, but why push it? added=kw/2; kwi->lnsertKW(atol(argv[1]),start.Get("simple",NULL,0),kw/2,0L); //demand
0981individual=((kwh-(kw/2)) / (kwh / ((kw/2)-5))); //-5 is fudge factor //for (i=1 ;i<needchunks;i++) while (added < kwh)
0982{ start.Add(1800); if (kwh - added < individual) kwi->lnsertKW(atol(argv[1]),start.Get("simple",NULL,0),kwh-added,0L); else kwi->lnsertKW(atol(argv[1]),start.Get("simple",NULL,0),individual,0L); inserted++; added+=individual; //this is ok that added will be too large on last loop
0983} ended. Now(); printf("lnserted %ld records in %ld seconds (%ld inserted / second)\n\n"<sub>I</sub>inserted,ended.Get()-begun.Get(),inserted/(ended.GetQ- begun.GetQ)); exit(0); }
0984#define CONTEXTNAMEID "stonergy" #define CONTEXTNAMEKIND "context" #define NAMEID "kwjnserter" #define NAMEKIND Object"
0985static
0986CORBA: :Object_ptr getObjectReference(CORBA::ORB_ptr orb)
0987{ CosNaming::NamingContext_var rootContext;
0988try { // Obtain a reference to the root context of the Name service: CORBA::Object_var initServ; initServ = orb->resolveJnitiaI_references("NameService");
0989// Narrow the object returned by resolveJnitial_references()
0990//to a CosNaming::NamingContext object: rootContext = CosNaming::NamingContext::_narrow(initServ); if (CORBA::is_nil(rootContext))
0991{ cerr « "Failed to narrow naming context" « endl; return CORBA.:Object::_nil(); } } catch(CORBA::ORB::lnvalidName& ex) { cerr « "Service required is invalid [does not exist]." « endl; return 0; }
0992// Bind a context called "test" to the root context:
0993CosNaming::Name contextName; contextName.length(2); contextName[0].id = (const char<sup>*</sup>) CONTEXTNAMEID; // string copied cαntextName[0].kind = (const char*) CONTEXTNAMEKIND; // string copied contextName[1].id = (const char*) NAMEID; // string copied contextName[1].kind = (const char*) NAMEKIND; // string copied
0994CORBA: :Object_ptr obj; try { obj=rootContext->resolve(contextName);
0995} catch (...)
0996{ cerr« "Caught a fatal exception in COS Naming Service"«endl; return CORBA::Object::_nil();
0997} return obj;
0998}
0999FILE: installer.c a program for gathering configuration information before we install new software on the iccm. Also creates scripts for setting up iccm configuration and start up scripts
1000=7
1001#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <netinet/in.h>
1002typedef struct install
1003{ int isethemet; int isdhcp; int glibc; char modempath[64]; long modemspeed; int callonring; //0== use -o to suppress callonring char spapath[64]; int server; //1=buster, 2=chloe, etc char mac[64J; char hostname[128];
1004} installstruct;
1005AskAway(installstruct *inst)
1006{ char buf[256]; int i; char *p1; memset(buf,0,256); printf("Which C Lib do you use (20=GLIBC2.0, 21=GLIBC2.1)? "); fgets(buf,255,stdin); if (p1=strchr(buf,10)) *p1=0; inst->glibc=atoi(buf); memset(inst->hostname,0,256); printf("Enter a hostname for this ICCM: "); fgets(inst->hostname,127,stdin); memset(buf,0,256); printf("ls this an Ethernet customer [y/N]? "); fgets(buf,255,stdin); if (p1=strchr(buf,10))
1007<sup>*</sup>p1=0; if (strlen(buf)==0 || buf[0]=='N' || buf[0]==<sup>*</sup>n') inst->isethernet=0; else
1008{ printf("ls this a DHCP customer [Y/n]? "); fgets(buf,255,stdin); if (p1=strchr(buf,10))
1009<sup>*</sup>p1=0; if (strlen(buf)==0 || buf[0]=='N<sup>*</sup> || buf[0]==<sup>*</sup>n') printf("You must configure the ICCM IP address and network information by hand according to information from the Customer's IS staff!\n"); else inst->isdhcp=1; inst->isethernet=1; } memset(buf,0,256); printf("What serial port is the modem on [/dev/modem]? "); fgets(buf,255,stdin); if (p1=strchr(buf,10))
1010*p1=0; if (strlen(buf)<5) strcpy(inst->modempath,"/dev/modem"); else strncpy(inst->modempath,buf,63); memset(buf,0,256); printf("What is the modem speed [57600]? "); fgets(buf,255,stdin); if (p1=strchr(buf,10))
1011*p1=0; if (strlen(buf)==0 || atol(buf)==0L) inst->modemspeed=57600; else inst->modemspeed=atol(buf); memset(buf,0,256); printf ("Should we honor call on ring [Y/n]? "); fgets(buf,255,stdin); if (p1=strchr(buf,10))
1012*p1=0; if (strlen(buf)==0 || buf[0]==<sup>«</sup>r || buf[0]=='y') inst->callonring=1; else inst->callonring=0; memset(buf,0,256); printfC'What serial port is the Pulse Accumulator on [/dev/ttySO]? "); fgets(buf,255,stdin); if (p1=strchr(buf,10))
1013*p1=0; if (strlen(buf)==0) strcpy(inst->spapath,"/dev/ttySO"); else strncpy(inst->spapath,buf,63);
1014// system("/sbin/ifconfig ethO");
1015// memset(buf,0,256);
1016// printfC'What is the MAC address of the Ethernet card [REQUIRED]? ");
1017// fgets(buf,255,stdin);
1018// if (p1=strchr(buf,10))
1019// *p1=0;
1020// for (i=0;i<strlen(buf);i++)
1021// if (buf[i]!=':' && isalpha(buf[i]) && islower(buf[i]))
1022// buf[i]=toupper(buf[i]);
1023// strncpy(inst->mac,buf,63); return(O); }
1024CreateDHCPStartupScript(installstruct <sup>*</sup>inst)
1025{ FILE *f1;
1026f1=fopen(7etc/init.d/dhcp","w"); if (!f1)
1027{ printfC'Unable to create /etc/init.d/dhcp, exiting\n"); retum(-1); } fprintf(f1,"#! /bin/sh\n\n"); fprintf(f1,"case \"$1\" in\n"); fprintf(f1," start)\n"); fprintf(f1 ," echo V'Starting dhcp...\"\n"); fprintf(f1," /usr/local/pepper/dhcpcd -h %s\n",inst->hostname); fprintf(f1," sleep 45\n"); fprintf(f1," ;;\n"); fprintf(f1,"esac\n\n"); fclose(f1); chmod("/etc/init.d/dhcp",SJXOTH | SJROTH | SJXGRP | SJRGRP SJXUSR | SJRUSR); if (inst->isdhcp) symlink("/etc/init.d/dhcp","/etc/rc2.d/S91dhcρ"); return(O); }
1028CreatePepperStartupScript(installstruct *inst)
1029{ FILE *f1; f1=fopen(7etc/init.d/pepper","w"); if (!f1)
1030{ printfC'Unable to create /etc/init.d/pepper, exiting\n"); retum(-1);
1031} fprintf(f1,"#! /bin/sh\n\n"); fprintf(f1,"case \"$1\" in\n"); fprintf(f1," start)\n"); fprintf(f1 ," echo V'Starting pepper... \"\n");
1032//fprintf(f 1 ," setserial /dev/ttyS2 irq 4 fprintf(f1 ," export OMNIORB_CONFIG=/etc/omniORB.cfg\n"); fprintf(f1 ," export TZ=CST6CDT\n"); if (inst->isethernet)
1033{ fprintf(f1 ," echo > /var/lock/corbanet\n");
1034} fprintf(f1," /usr/local/pepper/callonring %s %s\n",inst->modempath,
1035(inst->callonring?"":"-o")); fprintf(f1 ," /usr/local/pepper/kw_client > /dev/null &\n"); fprintf(f1 ," /usr/local/pepper/swatchdog /etc/pepper/swatchdog.rules\n\n"); fprintf(f1," ;;\n"); fprintf(f1,"esac\n\n"); fclose(fl); chmod("/etc/init.d/pepper",SJXOTH | SJROTH | SJXGRP | SJRGRP | SJXUSR | SJRUSR); symlink("/etc/init.d/pepper","/etc/rc2.d/S99pepper"); return(O); }
1036CreatePPPFiles(installstruct <sup>*</sup>inst)
1037{ FILE *f1; f 1 =fopen(7etc/ppp/ip-up","w"); if (!f1)
1038{ printfC'Unable to create /etc/ppp/ip-up, exiting\n"); return(-1);
1039} fprintf(f1,"#!/bϊn/sh\n\n");
1040// fprintf(f1," /sbin/route add -host 209.219.108.69 pρp0\n"); fprintf(f1 ," /sbin/route add default ppp0\n"); // fprintf(f1 ," /usr/local/pepper/curl http://209.219.108.68/%s\n",inst->hostname); fprintf(f1 ," echo > /var/lock corbanet\n"); fprintf(f1 ," killall -HUP kw_client \n"); fclose(fl); chmod("/etc/ppp/ip-up",SJXOTH | SJROTH | SJXGRP | SJRGRP | SJXUSR | SJRUSR);
1041f1=fopen(7etc/ppp/ip-down","w"); if (!f1)
1042{ printfC'Unable to create /etc/ppp/ip-down, exiting\n"); retum(-1);
1043ill } fprintf(f1 ,"#!/bin/sh\n\n"); fprintf(f1 ,"rm /var/lock/corbanet\n"); fprintf(f1 ,"/sbin/route del default pppO\n"); fprintf(f1 ,"/sbin/route add default ethO \n"); fclose(fl); chmod("/etc/ppp/ip-down",SJXOTH | SJROTH | SJXGRP | SJRGRP | SJXUSR | SJRUSR); f1=fopen("/usr/sbin/ppp-on","w"); if (!f1)
1044{ printfC'Unable to create /usr/sbin/ppp-on, exiting\n"); return(-1);
1045} fprintf(f1,"#!/bin/sh\n\n"); fprintf(f1 ,"if [ \"$TELEPHONE\" = \T ]; then\n echo Overriding TELEPHONED TELEPHONE=5560085\nfi\n"); fprintf(f1 ,"if [ \"$NETMASK\" = \"\" ]; then \n echo Overriding NETMASKVi NETMASK=255.255.255.0\nfι\n"); fprintf(f1."if [ \"$ACCOUNT\" = \"\" ]; then \n echo Overriding ACCOUNTλn ACCOUNT=stonewater@mindspring.com\nfi\n"); fprintf(f1 ,"if [ \"$PASSWORD\" = \"\" ]; then \n echo Overriding PASSWORDVn PASSWORD=fp8fgyby\nfι\n"); fprintf(f1 ,"#need to put over-ridable ISP userid/passwd here\n"); fprintf(f1 ,"PPPSTART=\"\"\n"); fprintf(f1 ,"RMTRPROMPT=\"\"\n"); fprintf(f1."export ACCOUNT PASSWORD TELEPHONE RMTRPROMPT PPPSTARTλn"); fprintf(f1 ,"DIALER_SCRIPT=/usr/bin/ppp-on-dialer\n"); fprintf(f1."exec /usr/sbin/pppd -detach %s %Id defaultroute connect $DIALER_SCRIPT\n\n",inst->modempath,inst->modemspeed); fclose(f1); chmod("/usr/sbin/ppp-on",SJXOTH | SJROTH | SJXGRP | SJRGRP | SJXUSR | SJRUSR); f1=fopen("/etc/ppp/options","w"); if (!f1)
1046{ printfC'Unable to create /etc/ppp/options, exiting\n"); return(-1 ); } fprintf(f1 ,"crtscts\nasyncmap O\nlock\ndefaultroute\n"); fclose(fl); return(O);
1047}
1048CreateDirectoriesQ { mkdir("/usr/locai ,SJXOTH|SJROTH|SJXGRP|SJRGRP|SJXUSR|SJRUSR); mkdir("/usr/local/pepper/",SJXOTH|SJROTH|SJXGRP|SJRGRP|SJXUSR|SJ RUSR);
1049mkdir("/etc/pepper/",SJXOTH|SJROTH|SJXGRP|SJRGRP|SJXUSR|SJRUS
1050R); mkdir("/etc/ppp/",SJXOTH|SJROTH|SJXGRP|SJRGRP|SJXUSR|SJRUSR); return(O); }
1051CreateUpgradeScript(installstruct *inst)
1052{ FILE *f1;
1053f1=fopen("/usr/local/pepper/kwupgrade.sh","w"); if (!f1)
1054{ printfC'Unable to create /usr/local/pepper/kwupgrade.sh, exiting\n"); return(-1);
1055} fprintf(f1,"#!/bin/sh\n\n"); fprintf(f1 /'echo V'Attempting to download a new kw_client\"\n"); fprintf(f1 ,"rm -f /tmp/kw_client\n\n"); fprintf(f 1 ,"#switch to the RAM disk (to avoid over-exposing the FLASH disk, and because our FLASH disk is full!)\n"); fprintf(f1 ,"/usr/local/pepper/curl ftp://anon:nullpasswd@buster.gnassoc.com/kw_client.glibc%d -o /tmp/kw_client\n\n",inst->glibc); fprintf(f1 ,"#if buster failed, try cara (use IP addr for this one (DNS failure?))\n"); fprintf(f1 ,"if [ ! -f /tmp/kw_client ]; then\n"); fprintf(f1,"echo Trying cara...\n"); fprintf(f1,"/usr/local/pepper/curl ftp://anon:nullpasswd@216.217.51.130/kw_client.glibc%d -o /tmp/kw_client\n",inst->glibc); fprintf(f1,"fi\n\n"); fρrintf(f 1 ,"if [ -f /tmp/kw_client ]; then\n"); fprintf(f1 ," echo V'Found the kw_client, proceeding...\"\n"); fprintf(f 1 ," chmod 744 /tmp/kw_client\n"); fprintf(f1,"else\n"); fprintf(f1 ," echo V'Unable to locate /tmp/kw_client, re-executing /usr/local/pepper/kw_client with upgrade suppression!\"\n"); fprintf(f 1 ," exec /usr/local/pepper/kw_c!ient -L V'Starting with upgrades suppressedΛ" -U\n"); fprintf(f1," exit\n"); fprintf(f1,"fι\n\n"); fprintf(f1,"#only if the executable acts OK do we copy it\n"); fprintf(f1 ,7tmp/kw_client ~testtube\n"); fprintf(f1 ,"if [ $? -eq 99 ]; then\n"); fprintf(f1 ," echo V'Testtube SucceededW); fprintf(f1 ," cp /tmp/kw_client /usr/Iocal/pepper/kw_client\n"); fprintf(f1," rm /tmp/kw_client\n"); fprintf(f1 ," chmod 744 /usr/locaI/pepper/kw_client\n"); fprintf(f1,"else\n"); fprintf(f1 ," echo V'Testtube failed\";\n"); fprintf(f1," /bin/sleep 5\n"); fprintf(f1 ," exec /usr/local/pepper/kw_client -L V'Error in TESTTUBE upgrade\";\n"); fprintf(f1,"fi\n\n\n"); fprintf(f 1 ,"#now close the PPP connection if there is one\n"); fprintf(f1 ,"if [ -f /var/lock/callonring.pid ]; then\n"); fprintf(f1 ," kill -s SIGHUP 'cat /var/lock/callonring.pid^n"); fprintf(f1,"fi\n\n"); fprintf(f1 ,"#now restart kw_client\n"); fprintf(f1 ,"exec /usr/local/pepper/kw_client -FIRSTλn"); fclose(fl); chmod("/usr/local/pepper/kwupgrade.sh",SJXOTH | SJROTH | SJXGRP | SJRGRP | SJXUSR | SJRUSR); return(O); }
1056CreateETCfiles(instalIstruct <sup>*</sup>inst) {
1057FILE *f1; char buf[256]; int sock;
1058//auto-detect the MAC address...doesn't work :-(
1059//sock=socket(PF INET, SOCK DGRAM, IPPROTO _IP);
1060//ioctl(sock, SIOCGIFHWADDR, buf);
1061//printf("\n\n%s\n\n",buf);
1062// f 1 =fopen("/etc/pepper/mac","w");
1063// if (!f1)
1064// {
1065// printfC'Unable to create /etc/pepper/mac, exiting\n<sup>*</sup> ');
1066// return(-1);
1067// }
1068// fprintf(f1 ,"%s",inst->mac);
1069// fclose(fl);
1070f1=fopen("/etc/pepper/swatchdog.rules","w"); if (!f1)
1071{ printfC'Unable to create /etc/pepper/swatchdog. rules, exiting\n"); return(-1);
1072} fprintf(f1 ,"#we expect a SIGPROF every 5 minutes (actually happens, every 30 seconds)\n"); fprintf(f1 ,"#regardless of ICCM communication. If we do not get our SIGPROF, it\n"); fprintf(f1 ,"#probably means that our kw_client died completely\n"); fprintf(f1 ,"SIGNAL:27:5\n\n"); fprintf(f1,"FILE:/tmp/commotry\n\n"); fprintf(f1 ,"FILE:/tmp/commosuccess\n"); fclose(fl);
1073//f1=fopen("/etc/pepper/newyorkpulseaccumulator","w"); f 1 =fopen("/etc/pepper/spa1 ","w"); if (!f1)
1074{ printfC'Unable to create /etc/pepper/spa1, exiting\n"); return(-1);
1075} fprintf(f1 ,"%s",inst->spapath); fclose( l); f1=fopen("/etc/omniORB.cfg","w"); if (!f1)
1076{ printfC'Unable to create /etc/omniORB.cfg, exiting\n"); return(-1);
1077} fprintf(f1,"ORBInitialHost 209.219.108.69\nORBInitialPort 12345\n"); fclose( l);
1078return(O); }
1079FetchEXEs(installstruct <sup>*</sup>inst)
1080{ char buf[1024]; sprintf(buf,"Jcurl ftp://anon:nullpasswd@209.219.108.67/kw_client.glibc%d -o /usr/local/pepper/kw_client\n",inst->glibc); system(buf); chmod(7usr/local/pepper/kw_client",SJXOTH | SJROTH | SJXGRP | SJRGRP | SJXUSR | SJRUSR); sprintf(buf,"Jcurl ftp://anon:nullpasswd@209.219.108.67/callonring.glibc%d -o /usr/local/pepper/callonring\n",inst->glibc); system(buf); chmod(7usr/local/pepper/callonring",SJXOTH | SJROTH | SJXGRP | SJRGRP | SJXUSR | SJRUSR); sprintf(buf,"Jcurl ftp://anon:nullpasswd@209.219.108.67/swatchdog.glibc%d -o /usr/local/pepper/swatchdog\n",inst->glibc); system(buf); chmod("/usr/local/pepper/swatchdog",SJXOTH | SJROTH | SJXGRP | SJRGRP | SJXUSR | SJRUSR); sprintf(buf,"./curl ftp://anon:nullpasswd@209.219.108.67/dhcpcd.glibc%d -o /usr/local/pepper/dhcpcd\n",inst->glibc); system(buf); chmod("/usr/local/pepper/dhcpcd",SJXOTH | SJROTH | SJXGRP | SJRGRP
1081I SJXUSR I SJRUSR); if (FileExists("./curl")) Iink("./curt",7usr/local/pepper/curl"); //create a hard link return(O); }
1082FileExists(const char *filename)
1083{ FILE *f1 ; f1 =fopen(filename,"r"); if (!f1) return(O); fclose(f1); return(1); //this return-logic might seem backwards, but we are answering a question }
1084CheckRequiredEXEsQ
1085{ int failed; char buf[256];
1086failed=0; if (!FileExists("curl"))
1087{ printf("You must put the program: curl in the local directory for installation to finishΛn"); failed++;
1088} if (!FileExists("dhcpcd"))
1089{ printf("WARNING: if this is a dhcp installation, you must put the program: dhcpcd in the local directory An"); printff Do you want to stop installation now [Y/n]? "); fgets(buf,255,stdin); if (strpbrk(buf,"NnfFO"))
1090{ return(O);
1091} } return(failed);
1092} main(int argc, char **argv)
1093{ installstruct inst; int i; int dhcponly;
1094dhcponly=0;
1095//handle command-line arguments if (argc>1) for (i=1;i<argc;i++)
1096{ if (strncasecmp(argv[i],"-v",2)-=0)
1097{ printf("Pepper Installer Version 2.8\n"); return(O);
1098} if (strcmp(argv[i],"~dhcp")==0)
1099{ dhcponly=1; if (argc-i>1 && argv[i+1][0]!='-') strcpy(inst.hostname, argv[i+1]); else strcpy(inst.hostname,"newlCCM");
1100} if (strcmp(argv[i],"-testtube")==0) return(99); } if (CheckRequiredEXEsQ) return(-1);
1101CreateDirectoriesQ; if (dhcponly)
1102{ CreateDHCPStartupScript(&inst); link("Jdhcpcd","/usr/locaI/pepper/dhcpcd"); //create a hard link printf("DHCP has been installed, exitingΛn"); return(O);
1103}
1104AskAway(&inst); CreateDHCPStartupScript(&inst);
1105CreatePepperStartupScript(&inst);
1106CreatePPPFiles(&inst);
1107CreateUpgradeScript(&inst);
1108CreateETCfiles(&inst);
1109//FetchEXEs(&inst);
1110}
1111FILE: kwjnserterjmpl.h This file is created by the omniORB idl2cpp compiler
1112========================================================*/
1113#ifndef _KWJNSERTERJMPL_H #define _KWJNSERTERJMPL_H
1114#include "kwjnserter.hh" #include "dbifaceobj.h"
1115#define KW_CLIENT_VERSION_CODIFIED 0x00000200 #define KW_CLIENT_VERSION_HUMAN "vθ.0.2.0" class kwjnserterjmpl : public virtual _sk_kwjnserter
1116{ public: kwJnserterJmplQ;
1117-kwJnserterJmplQ; virtual CORBA::Long KWFactory(char* & new_kwJnserterJOR); virtual CORBA::Long HWLogin(const char <sup>*</sup>HWADDR); //initial, or after reboot virtual CORBA::Long Login(CORBA::Long deviceid, const char *secret); virtual CORBA:: Boolean UsableQ; virtual CORBA::Boolean Logout(const char <sup>*</sup>slOR); virtual char *GetTableKey(CORBA:: Long moduleid, CORBA::Long keyid); virtual CORBA::Long SetTableKey(CORBA::Long moduleid, CORBA::Long keyid, const char *val); virtual CORBA::Long GetZoneBySource(CORBA::Long ancestorid, const char <sup>*</sup>meter_number); virtual CORBA::Long GetMeterlD(CORBA::Long iccmid, const char
1118* metername); virtual CORBA::Long lnsertKW(CORBA::Long zoneid, const char *wwhen, CORBA::Float KW, CORBA::Long scenario=0L); virtual CORBA::Long GetlCCMUpdate(CORBA::Long iccmid); virtual char <sup>*</sup>GetMeterConf(CORBA::Long iccmid); virtual CORBA::Long GetClock_epoch1999Q; virtual CORBA::Long GetGMTQ; virtual CORBA::Long NeedScheduleQ; virtual CORBA::Long FetchScheduIe(CORBA::Long iccmid, const char <sup>*</sup>dayofweek, const char *heatlevel); virtual CORBA::Long Version(CORBA::Long iccmid, CORBA::Long codified, const char <sup>*</sup>humanreadable); virtual CORBA: :Long Watermark(CORBA::Long wmid, CORBA. ong zoneid, const char <sup>*</sup>wwhen, CORBA::Float KW); virtual char *GetWatermarks(CORBA::Long zoneid); virtual CORBA::Long Log(CORBA::Long zoneid, CORBA::Long code, const char *message, CORBA::Long datetime, CORBA::Long priority); int cleanupQ; //shutdown the db connection virtual char *GetlSPs(CORBA::Long zoneid); virtual char *GetORBs(CORBA::Long zoneid); virtual CORBA::Long GetNotificationCount(CORBA::Long zoneid); virtual CORBA::Long GetNotification(CORBA::Long zoneid, CORBA::Long which, CORBA::Long &facility, CORBA::Long &code1, CORBA::Long &code2); private: //non-CORBA exposed unsigned long zoneid; //OL until logged in DBIFACEObj *DBIFace; int isfactory;
1119};
1120#endif
1121FILE: kw inserter.cxx this file sets the corba server up to run as a daemon "
1122===========================================================*/
1123#include <stdio.h> #include <iostream.h> #include <sys/types.h> #include <sys/wait.h> #include "omnithread.h" #include "kwjnserterjmpl.h"
1124#define USENAMES
1125static CORBA::Boolean bindObjectToName(CORBA::ORB_ptr,CORBA::Object_ptr); int MLog(long codes, const char *body)
1126{ dateobj now; printf("%s: %s\n",now.Get("simple",NULL,0),body); fflush(NULL); return(O);
1127}
1128//globals now CORBA::ORB_ptr orb; CORBA::BOA_ptr _myboa; main(int argc, char **argv)
1129{ // CORBA: :ORB_ptr orb;
1130// CORBA::BOA_ptr _myboa; pid J superparent;
1131#ifdef DETACH fclose(stdiή); fclose(stdout); superparent=fork(); if (superparent>0) exit(0); //first detach fclose(stdin); fclose(stdout); superparent=fork(); while (superparent > 0)
1132{ waitpid(superparent,NULL,0); superparent=fork();
1133} freopen("/var/log/kwJnserter","a",stdout); freopen("/var/log/kwJnserter","r",stdin); freopen("/var/log/kwJnserter","a",stderr); #endif
1134MLog(1, "Starting kwjnserter server vO.0.2.7'); kwjnserter_var myobjRef; kwjnserterjmpl *kwi; orb=CORBA::ORBJnit(argc, argv,"omniORB2"); _myboa=orb->BOAJnit(argc, argv,"omniORB2_BOA");
1135kwi=new kwJnserterJmplQ; kwi->_objJs_ready(_myboa);
1136#ifdef USENAMES
1137{ myobjRef = kwi->Jhis(); if (!bindObjectToName(orb, myobjRef))
1138{
1139MLog(9,"Unable to bind to name"); return 1;
1140}
1141} #endif
1142_myboa->implJs_ready(); //the BOA's default behavior is to block forever
1143//getchar();
1144}
1145#define CONTEXTNAMEID "stonergy" #define CONTEXTNAMEKIND "context" #define NAMEID "kwjnserter" #define NAMEKIND "Object"
1146static
1147CORBA::Boolean bindObjectToName(CORBA::ORB_ptr orb,CORBA::Object_ptr obj)
1148{ CosNaming::NamingContext_var rootContext; try{ // Obtain a reference to the root context of the Name service: CORBA::Object_var initServ; initServ = orb->resolveJnitial_references("NameService");
1149// Narrow the object returned by resolveJnitiaI_references() //to a CosNaming::NamingContext object: rootContext = CosNaming::NamingContext::_narrow(initServ); if (CORBA::is_nil(rootContext))
1150{ cerr « "Failed to narrow naming context ' « endl; return 0;
1151} } catch(CORBA::ORB::lnvalidName& ex) { cerr « "Service required is invalid [does not exist] ' « endl; return 0;
1152}
1153try { // Bind a context called "test" to the root context:
1154CosNaming::Name contextName; contextName.length(l); contextName[0].id = (const char*) CONTEXTNAMEID; // string copied contextName[0].kind = (const char*) CONTEXTNAMEKIND; // string copied
1155// Note on kind: The kind field is used to indicate the type
1156// of the object. This is to avoid conventions such as that used
1157// by files (name.type - e.g. test.ps = postscript etc.)
1158CosNaming::NamingContext_vartestContext; try { // Bind the context to root, and assign testContext to it: testContext = rootContext->bind_new_context(contextName);
1159} catch(CosNaming::NamingContext::AlreadyBound& ex) {
1160// If the context already exists, this exception will be raised.
1161// In this case, just resolve the name and assign testContext
1162// to the object returned:
1163CORBA: :Object_var tmpobj; tmpobj = rootContext->resoIve(contextName); testContext = CosNaming::NamingContext::_narrow(tmpobj); if (CORBA::is_nil(testContext)) { cerr « "Failed to narrow naming context." « endl; return 0;
1164} }
1165// Bind the object (obj) to testContext, naming it Echo:
1166CosNaming::Name objectName; objectName.length(1 ); objectName[0].id = (const char*) NAMEID; // string copied objectName[0].kind = (const char*) NAMEKIND; //string copied
1167// Bind obj with NAMEID Echo to the testContext: try { testContext->bind(objectName,obj);
1168} catch(CosNaming::NamingContext::AlreadyBound& ex) { testContext->rebind(objectName,obj);
1169}
1170// Note: Using rebindQ will overwrite any Object previously bound
1171// to /test Echo with obj.
1172// Alternatively, bindQ can be used, which will raise a
1173// CosNaming::NamingContext::AlreadyBound exception if the name
1174// supplied is already bound to an object.
1175// Amendment: When using OrbixNames, it is necessary to first try bind // and then rebind, as rebind on it's own will throw a NotFoundexception if //the Name has not already been bound. [This is incorrect behaviour - // it should just bind].
1176} catch (CORBA::COMM_FAILURE& ex) { cerr « "Caught system exception COMM_FAILURE, unable to contact the "
1177« "naming service." « endl; return 0;
1178} catch (omniORB::fatalException& ex) { throw;
1179} catch (...) { cerr « "Caught a system exception while using the naming service."« endl; return 0;
1180} return 1;
1181}
1182FILE: kwdiv.cxx this file implements the server side of kwjnserter corba object
1183#include "kwjnserterjmpl.h"
1184#define TRUE 1 #define FALSE 0
1185kwjnserterjmpl::kwjnserterjmpl()
1186{ zoneid=0L;
1187DBIFace=new DBIFACEObj; }
1188CORBA::Long kwjnserterjmpl::HWLogin(const char *HWADDR)
1189{ char qrystr[128]; zoneid=DBIFace->FindHWKey(HWADDR); return(zoneid);
1190}
1191CORBA::Long kwJnserterJmpl::Login(CORBA::Long deviceid, const char <sup>*</sup>secret)
1192{ char qrystr[255]; if (deviceid==0L) retum(OL);
1193DBIFace- >GetTableKey(deviceid,MODULE_KWJNSERTER,KEY_ZONESECRET,qrystr, 255); if (!strcmp(qrystr,secret)) zoneid=deviceid; return(zoneid); }
1194CORBA::Boolean kwJnserterJmpl::Usable() { if (izoneid) return(FALSE); if (DBIFace->Usable()) return(TRUE); else return(FALSE); }
1195CORBA::Long kwJnserterJmpl::GetTableKey(CORBA::Long moduleid, CORBA::Long keyid, char * &dest, CORBA::Long &destlen)
1196{ char <sup>*</sup>temp; if (Izoneid) return(OL); temp=new char[2048];
1197DBIFace->GetTableKey(zoneid, moduleid, keyid,temp,2047); if (itemp)
1198{ dest=NULL; return(OL);
1199} dest=new char[strlen(temp)+1]; memset(dest,0,strlen(temp)+1 ); strcpy(temp,dest); &destlen=strlen(temp); return(strlen(temp)); }
1200CORBA::Long kwJnserterJmpI::lnsertKW(CORBA::Long zoneid, const char *wwhen, CORBA::Float KW, CORBA::Long scenario)
1201{ dateobj temp; if (Izoneid) return(OL); temp.Set(wwhen,"simpIe");
1202DBIFace->lnsertKW(zoneid,&temp,KW,scenario); return(1 L);
1203} CORBA::Long kwJnserterJmpl::GetClock_epoch1999Q
1204{ return(OL); //not implemented
1205}
1206CORBA::Long kwJnserterJmpl::NeedSchedule()
1207{ return(OL);
1208}
1209CORBA::Long kw_inserterJmpl::FetchSchedule(const char *dayofweek, const char <sup>*</sup>heatlevel, char * &dest)
1210{ return(OL);
1211}
1212FILE: logcodes.h
1213================================*/
1214//Log codes:
1215#define LOG_GOTFACTORY 1L
1216#define LOGjBUTTONS 2L
1217#define LOG_FIRSTPASS 3L
1218#define LOG_MISC 4L
1219#defιne LOGj EEDUPGRADE 5L
1220#define LOG_COMMANDLINE 6L
1221#define LOGjΞRRMETERRESOLVE 7L
1222#define LOGjΞRRUPGRADE 8L
1223#define LOG_FETCHCONFIG 9L
1224#define LOGjHWLOGIN 10L
1225//Log timecodes (send actual Julians, except OL means NOW): #define LOGTIME NOW 0L
1226//Log severity levels: #define LOGJNFO 1L #define LOGJNFO1 1L #define LOGJNFO2 2L #define LOGJNFO3 3L #define LOGJNFO44L #define LOGJNFO5 5L #define LOGJNFO6 6L #defιne LOGJNFO7 7L #define LOGJNFO8 8L #define LOGJNFO9 9L #define LOGJNFO10 10L
1227#defιne LOG Λ/ARN 16L #define LOG /VARN1 16L #defιne LOG WARN2 17L #define LOG WARN3 18L #define LOG WARN4 19L #define LOGJWARN5 20L #define LOG Λ/ARN6 21 L #define LOG WARN7 22L #define LOG WARN8 23L #define LOG WARN9 24L #define LOG WARN10 25L #define LOGjΞRR 32L #define LOGJΞRR1 32L #define LOGJΞRR2 33L #define LOGJΞRR3 34L #define LOG_ERR4 35L #define LOGJΞRR5 36L #define LOGJΞRR6 37L #define LOGJΞRR7 38L #define LOGjΞRRδ 39L #define LOGJΞRR940L #define LOG_ERR1041L
1228#define LOG_ACK 64L #define LOG_ACK1 64L #define LOG_ACK2 65L #define LOG_ACK3 66L #define LOG_ACK4 67L #define LOG_ACK568L
1229#define LOGjJNK 128L #define LOGDEBUG 129L;
1230FILE: meterobj.h relevant classes for the pulse accumulator and the a structure to store the information ( readingobj )
1231==================================================*/
1232#ifndef _METEROBJ_H #define METEROBJ H
1233#define RANDOM1 10 #define NEWYORKPULSE1 20 #define SPA1 30
1234#include <stdio.h> #include <string.h> #include <stdlib.h> #include "dateobj.h" #include "collectionbase.h"
1235#include "drivers, h"
1236#define READINGjREADY 1 #define READING_XMITTED 2 #define READING BUSY 4
1237class readingobj
1238{ public: readingobjQ; int pulses; timej stoptime; int status; int watermarkvetted;
1239}; class meterobj
1240{ public: meterobj (); int initialize(char *initstring); float getreading(timej start, timej end); //pulses pre-multiplier int pollQ; int SpyO; int markxmitted(unsigned long which); unsigned long readingcount(); float getreading(unsigned long which); timej getreadingtime(unsigned long which); int WatermarksChecked(unsigned long which); int Remove(unsigned long which); int PollSoon(int minutes=3); unsigned long id; char key[256]; float multiplier; int type; int pollschedule; //# minutes between checks dateobj lastpoll.nextpoll; CollectionBase readings; protected: meter_driver_random1 <sup>*</sup>r1; meter_driver_newyorkpulse1 *nyp1; meter_driver_spa1 *spa1; int deletedfirstreading;
1241};
1242#endif
1243FILE meterobj.cxx implementation file for the meterdriver
1244#include "meterobj. h" readingobjr.readingobjQ
1245{ pulses=0; stoptime=0; watermarkvetted=0;
1246}
1247meterobj::meterobj()
1248{ id=0; memset(key,0,256); type=0; deletedfirstreading=0; pollschedule=30; //default to every half-hour multipliers .0; lastpoll.Set(OL); nextpoll.Set(OL); r1=NULL; nyp1=NULL; spa1=NULL; } int meterobj::initialize(char *initstring)
1249{
1250//num:name:type:multiplier:{rest depends on type} char buf[256]; char stype[256]; char *p1, *p2; int failed; memset(buf,0,256); memset(stype,0,256); lastpolI.Set(OL); nextpoll.Set(OL);
1251//printf("meterobj::initiaIize(\"%s\")\n",initstring); //fflush(NULL); if (strlen(initstring) < 5)
1252{ printf("meterobj::initialize() inittstring is too short!\n"); return(O);
1253} failed=0; strncpy(buf,initstring,256); while (isspace(buf[strlen(buf)-1 ])) buf[strlen(buf)-1]=0; p1=strtok(buf,":"); id=atol(p1); p1=strtok(NULL,":"); p2=strtok(NULL,":"); strncpy(key,p1 ,p2-p1-1); p1=p2; // p2=strtok(NULL,":"); // stmcpy(stype,p1 ,p2-p1 -1 ); strncpy(stype,p1 ,256); if (strcmp(stype,"random1")==0) type=RANDOM1; if (strcmp(stype,"newyorkpulse1 ")==0) type=NEWYORKPULSE1 ; if (strcmp(stype,"spa1")==0) type=SPA1; p1=strtok(NULL,":"); pollschedule=atoi(p1 ); p1=strtok(NULL,":"); multiplier=atof(p1 ); p1=strtok(NULL,":"); switch (type)
1254{ case RANDOMI: r1=new meter_driver_random1 ; r1->initialize(p1); break; case NEWYORKPULSE1: nyp1=new meter_driver_newyorkpulse1 ; nyp1->initialize(p1); break; case SPAI: spal =new meter_driver_spa1 ; spa1->initialize(p1); break; default: failed++;
1255} return(failed); } int meterobj::poll()
1256{ dateobj now; int temppulse; readingobj <sup>*</sup>tempreading;
1257if ((nextpoll.GetQ == OL) || (nextpoll.GetQ > (now.Get() + ((pollschedule+15) <sup>*</sup> 60))))
1258{ nextpoll.Set(now.GetBoundry(poIlschedule,1)); printf("Next Poll is at: %s\n",nextpoll.Get("simple",NULL,0)); }
1259// if (inow.lsBoundry(pollschedule) || abs(lastpolI.Get() - now.GetQ) <
1260(pollschedule<sup>*</sup>60))
1261// return(O); if (now.Get() >= nextpoll.GetQ)
1262{ printf("Polling meter: %d %s (%s)\n",id,key,now.Get("simpIe",NULL,0)); fflush(NULL); nextpoll.Set(now.GetBoundry(pollschedule, 1 )); printf("Next Poll is at: %s\n",nextpoll.Get("simple",NULL,0)); lastpoll.Set(now.GetQ); temppulse=0; switch (type)
1263{ case RAN DOM 1: temppulse=r1->poll(); break; case NEWYORKPULSE1: printf("about to poll channel(id) == %ld (%d)\n",id,(int)id); temppulse=nyp1->poll((int)id-1); break; case SPAI: printf("about to poll spa metersVn"); temppulse=spa1->poll((int)id-1); break; } if (temppulse)
1264{ tempreading=new readingobj; tempreading->pulses=temppulse; tempreading->stoptime=Iastpoll.Get(); temρreading->status=READING_READY; if (deletedfirstreading) readings.Add(tempreading); else deletedfirstreading=1 ;
1265SpyO; }
1266} return(O);
1267} int meterobj::Remove(unsigned long which)
1268{ readingobj *tempreading; tempreading=(readingobj *)readings.ltem(which); if (itempreading) retum(-1); if (tempreading->status != READING_XMITTED) return(-2); //can't delete a reading until after xmit! return(readings.Remove(which)); //CollectionBase already checks for bounds errors
1269} unsigned long meterobj::readingcount()
1270{ return(readings.CountQ);
1271} int meterobj::markxmitted(unsigned long which) { readingobj *temp; if (which < 0 || which > readings.Count()-1) return(-1); temp=(readingobj <sup>*</sup>)readings.ltem(which); if (temp) temp->status=READING_XMITTED; retum(O); } int meterobj ::WatermarksChecked(unsigned long which)
1272{ readingobj *temp; if (which < 0 || which > readings.Count()-1) return(1); temp=(readingobj *)readings.ltem(which); if (temp && temp->status==READING_READY && !temp->watermarkvetted) return(1); else return(O);
1273} float meterobj::getreading(unsigned long which)
1274{ readingobj *temp; if (which < 0 || which > readings.Count()-1) return(-LO); temp=(readingobj *)readings.ltem(which); if (temp && temp->status==READING_READY) return(temp->pulses * multiplier); else return(-LO);
1275} timej meterobj::getreadingtime(unsigned long which)
1276{ readingobj *temp; if (which < 0 || which > readings.Count()-1) return(OL); temp=(readingobj *)readings.ltem(which); if (temp && temp->status!=READlNGj3USY) return(temp->stoptime); else return(OL);
1277}
1278float meterobj::getreading(timeJ start, timej end)
1279{
1280/*switch (type)
1281{ case RAN DOM 1: if (r1) return(r1->getreading(start,end)); case NEWYORKPULSE1: if (nyp1) return(nyp1->getreading(start,end)); case SPA1 : if (spa 1) return(spa1->getreading(start,end)); default: return(O);
1282} 7 int i; readingobj *tempreading; for (i=0;i<readings.Count();i++)
1283{ tempreading=(readingobj <sup>*</sup>)readings.ltem(i); if (tempreading && tempreading->status != READINGJ3USY)
1284{ if (tempreading->stoptime >= start && tempreading->stoptime <= end) return(tempreading->pulses * multiplier);
1285}
1286} retum(O.O); } int meterobj ::Spy()
1287{ int i; dateobj tdate; readingobj *temp; printfC**<sup>******</sup>*<sup>*</sup> \nNumber: %d\nlD: %s Type: %d Poll: %d Multiplier: %f\n", id,key,type,polIschedule, multiplier); if (readings.CountQ)
1288{ for (i=0;i<readings.Count();i++)
1289{ temp=(readingobj *)readings.ltem(i); if (temp)
1290{ tdate.Set(temp->stoptime); printf("\t%3.3d\t%s\t%d\n",i,tdate.Get("simple",NULL,0),temp->pulses);
1291} } } fflush(NULL); return(O); }
1292int meterobj::PollSoon(int minutes)
1293{ dateobj now; if (nextpoll.GetO - now.GetQ < (minutes <sup>*</sup> 60)) return(1); else return(O); }
1294FILE: newyorkdev1.fi header for the newyork pulse meter driver
1295#ifndef_NEWYORKDEV1_H #defιne NEWYORKDEV1 H
1296#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <signal.h> #include <ctype.h> #include "dateobj.h"
1297#define BAUDRATE B9600
1298#define _POSIX_SOURCE 1 /* POSIX compliant source 7
1299#define FALSE 0
1300#define TRUE 1
1301class newyorkdevl
1302{ public: newyorkdevl (); int Connect(char <sup>*</sup>port); int Poll(int whichmeter=-1); int Send(char *buf); int GetLine(char *buf, int size, int timeout); int Get(int which); int Close(); protected: intfd; int newvalue; struct termios oldtio.newtio;
1303}; ģendif
1304FILE: newyorkdevl .cxx
1305Implementation for development version of the newyork pulse accumulator
1306#include "newyorkdev h" #define NYDEBUG newyorkdevl "newyorkdevl ()
1307{ fd=0; newvalue=0;
1308}
1309int newyorkdevl ::Connect(char *port)
1310{ fd=-1; while (fd < 0)
1311{ fd = open ort, O_RDWR | O_NOCTTΥ | OjNlONBLOCK); if (fd<0) printf("Error opening NewYorkDevice (%s): ",port); sleep(5);
1312} #ifdef NYDEBUG printf("Modem device %s opened!\n",port); #endif tcgetattr(fd,&oldtio); /* save current serial port settings 7 bzero(&newtio, sizeof(newtio)); /* clear struct for new port settings 7 newtio.c_cflag = BAUDRATE | CLOCAL | CS8 | CREAD; newtio.cjflag = IGNPAR | ICRNL; newtio.c_oflag = 0; newtio.c Iflag = ICANON; newtio.c_cc[VINTR] = 0; /* Ctrl-c 7 newtio.c_cc[VQUIT] = 0; /* Ctrl-\ 7 newtio.c_cc[VERASE] = 0; /* del 7 newtio.c_cc[VKILL] = 0; /* @ 7 newtio.c_cc[VEOF] = 4; /* Ctrl-d 7 newtio.c cc[VTIME] = 0; /* inter-character timer unused 7 newtio.c_cc[VMIN] = 1; /* blocking read until 1 character arrives 7 newtio.c_cc[VSWTC] = 0; /* '\0' 7 newtio.c_cc[VSTART] = 0; /* Ctrl-q 7 newtio.c_cc[VSTOP] = 0; /* Ctrl-s 7 newtio.c_cc[VSUSP] = 0; /<sup>*</sup> Ctrl-z 7 newtio.c_cc[VEOL] = 0; /<sup>*</sup> '\0' 7 newtio.c_cc[VREPRINT] = 0; /<sup>*</sup> Ctrl-r 7 newtio.c_cc[VDISCARD] = 0; /* Ctrl-u 7 newtio.c_cc[VWERASE] = 0; /* Ctrl-w 7 newtio.c_cc[VLNEXT] = 0; /* Ctrl-v 7 newtio.c_cc[VEOL2] = 0; /* '\0' 7 tcflush(fd, TCIFLUSH); tcsetattr(fd .TCSANOW.&newtio) ;
1313return(O); } int newyorkdevl ::Send(char *buf)
1314{ #ifdef NYDEBUG printf("Sending: %s\n",buf); #endif write(fd,buf,strlen(buf)); sleep(1); tcdrain(fd); return(O);
1315} int newyorkdevl ::Getϋne(char <sup>*</sup>buf, int size, int timeout)
1316{ char *p1; int i, remaining, done; dateobj start, now; remaining=size-1 ; i=0; done=0; p1=buf; memset(buf,0,size); while (istrchr uf, 10))
1317{ i=read(fd,p1.remaining); if (i>0)
1318{ #ifdef NYDEBUG printf("+%s+",buf); fflush(NULL); #endif p1+=i; remaining-=i;
1319} else printfC'J'); fflush(NULL); now.NowQ; if (now.GetQ - start.GetQ > timeout) return(-1);
1320} return(O);
1321} int newyorkdevl ::Poll(int whichmeter)
1322{ int i; char buf[256]; char *p1, *p2; tcflush(fd.TCIOFLUSH);
1323Send("\r"); tcflush(fd,TCIOFLUSH);
1324// while (strncmp(buf,"Box",3)!=0) // Getl_ine(buf,256,5); //get a prompt sprintf(buf,"rd %d\r",whichmeter+1 ); Send(buf);
1325GetLine(buf,256,5) GetLine(buf,256,5) GetLine(buf,256,5) GetLine(buf,256,5)
1326#ifdef NYDEBUG printf("My Pulses: %s\n",buf); #endif p2=strtok(buf,"="); p2=strtok(NULL,"="); if (!p2)
1327{ printf("Error getting pulses on channel %d.\n",whichmeter); return(O); } newvalue=atoi(p2); // Send("li\r"); // GetLine(buf,256,5); // Send("cmc001\r"); // GetLine(buf,256,5); sprintf(buf,"cl %d\r",whichmeter+1);
1328Send(buf);
1329GetLine(buf,256,5); #ifdef NYDEBUG printf("%s",buf); #endif
1330return(O); }
1331int newyorkdevl ::Get(int which)
1332{ if (which < 0 1| which > 7) return(O); return(newvalue); } int newyorkdevl ::Close()
1333{ c!ose(fd); return(tcsetattr(fd,TCSANOW,&oldtio));
1334}
1335/*===========================================-=========
1336FILE: newyorkpulsel. h header file for the implementation version of the newyorkpulse meter
1337======================================================*/
1338#ifndef_NEWYORKPULSE1_H #define _NEWYORKPULSE1_H
1339#include "drivers, h" #include "newyorkdevl. h" class meter_driver_newyorkpulse1
1340{ public: meter_driver_newyorkpulse1 (); int isfluidQ; int initialize(char *initstring); int poll(int whichmeter); unsigned int getreading(time start, timej end); //pulses pre-multiplier protected: int lastval; int newval; int channel;
1341};
1342#endif
1343FILE: newyorkpulsel .cxx implementation file for production newyork pulse reader
1344#include "newyorkpulsel. h" meter_driver__newyorkpulse1 ::meter_driver_newyorkpulse1 ()
1345{ } int meter_driver_newyorkpulse1 ::isfluid()
1346{ return(O); //the newyorkpulsel driver is not fluid (?)
1347} int meter_driver_newyorkpulse1::initialize(char *initstring)
1348{ channel=atoi(initstring); return(O);
1349} int meter_driver_newyorkpulse1::poll(int whichmeter)
1350{
1351//need all of the polling code right here!!! newyorkdevl nyd;
1352FILE *f1; char tempdevice[256]; char *p1; if (!(f1=fopen("/etc/pepper/newyorkpulseaccumulator","r"))) sprintf(tempdevice,"/dev/ttySO"); else
1353{ fgets(tempdevice,255,f 1 ); p1 =strchr(tempdevice,':'); if (p1) *p1=0; p1=strchr(tempdevice,10); if (p1)
1354*p1=0; p1 =strchr(tempdevice, 13); if (p1) *<sub>P</sub>1=0; fclose(fl);
1355} nyd.Connect(tempdevice); nyd.Poll(channel); newval=nyd.Get(channel); nyd.Close(); return(newval); } unsigned int meter_driver_newyorkpulse1::getreading(timeJ start, timej end)
1356{
1357//pulses are pre-multiplier return(newval); }
1358FILE: notif.h
1359Sets up a data structure to handle curtailment notification.
1360As such it is server side resident.
1361#include "collectionbase.h" #include <unistd.h> class notifications; class notificationobj; class notifications
1362{ public: notificationsQ;
1363~notificationsQ; int Lock(int lockcode, int timeout); int UnLock(int unlockcode); int Add(long facility, long codel, long code2); long CountQ; notificationobj *ltem(long which); int MarkDoneøong which); int RemoveAIIQ;
1364CollectionBase notifs; protected: int internallock;
1365}; class notificationobj
1366{ public: notificationobjO;
1367~notificationobj(); long facility, codel , code2; int processed;
1368}; FILE: notif.cxx
1369This file implements curtailment notification data structures and algorithms
1370=======================================================*/
1371#include "notif.h"
1372notifications::notifications()
1373{ internallock=0;
1374} notifications: :~notifications()
1375{ if (CountQ) RemoveAHQ;
1376} int notifications: :Lock(int lockcode, int timeout)
1377{ int tries; tries=0; while (internallocki=0)
1378{ if (tries > timeout) return(-1); sleep(1); tries++;
1379} internallock=lockcode; return(O);
1380} int notifications::UnLock(int unlockcode)
1381{ if (internallock==unIockcode) intemallock=0; } int notifications::Add(long facility, long codel, long code2)
1382{ notificationobj *temp; temp=new notificationobj; temp->facility=facility; temp->codei =code1 ; temp->code2=code2; notifs.Add(temp); return(O);
1383} long notifications::Count()
1384{ return(notifs.CountQ);
1385} notificationobj *notifications::ltem(long which)
1386{ notificationobj *temp; temp=(notificationobj *)notifs.ltem(which); return(temp);
1387} int notifιcations::MarkDone(long which)
1388{ notificationobj *temp; temp=(notificationobj <sup>*</sup>)notifs.ltem(which); if (temp) temp->processed=1 ; else return(-1); return(O);
1389} int notifications::RemoveA!IQ
1390{ notifs.RemoveAIIQ;
1391} notificationobj ::notificationobj()
1392{ facility=0L; codel =0L code2=0L processed=0; } notificationobj::~notificationobjQ
1393{ if (Iprocessed) printffWe are destroying a notificationobj that has not been processed! (%ld,%ld,%ld).\n",facility,code1 ,code2); }
1394FILE: notifier.h
1395_* /
1396#ifndef_NOTIFIER_H #define _NOTIFIER_H
1397#include <stdio.h> #include "easyaddress.h" #include "easyneterror.h" #include "easysocket.h" #include <iostream> #include <string> #include <stdlib.h> using namespace std; class notifierobj
1398{ public: int SendEmail(const char *inhost, const char *sender, const char Recipient, const char *subject, const char *body);
1399};
1400#endif
1401FILE: notifier.cxx implementation file for the email sender
1402#include "notifier.h" int notifierobj::SendEmaiI(const char *inhost, const char <sup>*</sup>sender, const char <sup>*</sup>recipient, const char <sup>*</sup>subject, const char *body)
1403{ try
1404{ string ipOrHost; string recv; char buf[1024]; string buf2;
1405ipOrHost=inhost; EasyAddress host(ipOrHost); cout « "\n\nTrying to connect on port 25..An"; EasySocket sock(host, 25); sprintf(buf,"mail from: %s\r\n",sender); buf2=buf; sock.Write(buf2); sock.Read(recv,25); cout « recv « endl; sprintf(buf,"rcpt to: %s\r\n",recipient); buf2=buf; sock.Write(buf2); sock.Read(recv,25); cout « recv « endl; sock.Write("DATA\r\n"); //close the SMTP message! sock.Read(recv,25); . cout « recv « endl; sprintf(buf,"From: %s\r\n",sender); buf2=buf; sock.Write(buf2); sprintf(buf,"Reply-To: %s\r\n",sender); buf2=buf; sock.Write(buf2); sprintf(buf,"Subject: %s\r\n\r\n",subject); buf2=buf; sock.Write(buf2); buf.sprintf("%s\r\n",body); buf2=body; sock.Write(buf2); sock.Write("\r\n\r\n.\r\n"); //close the SMTP message! sock.Read(recv,25); cout « recv « endl; sock.Write("quit\r\n");
1406} catch(EasyNetError &e)
1407{ cerr « "An exception occurred in " « e.whereQ « endl; cerr « "Description: " « e.what() « endl; cerr « "Error num: " « e.erromumQ « endl; return EXIT_SUCCESS;
1408} return EXIT_SUCCESS; }
1409FILE: rule.h a helper class that stores the rules for swatchdog
1410#include <stdio.h> #include <string.h> #include <time.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <utime.h> class rule
1411{ public: ruleQ;
1412~rule(); int initialize(int insignal, int inminutes); int initialize(const char *infilename); int incomingsignal(int which); int checkyourfileQ; int isviolationQ; char logmessage[256]; char filename[256]; int isactiverule; int whichsignal; int XMitLog(const char *logmessage); int tripped_once; protected: timej lastupdate; long minutesallowed;
1413};
1414FILE: rule.h a helper class that stores the rules for swatchdog
1415===================================================*/
1416#include <stdio.h> #include <string.h> #include <time.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <utime.h> class rule
1417{ public: rule();
1418~rule(); int initialize(int insignal, int inminutes); int initialize(const char *infilename); int incomingsignal(int which); int checkyourfileO; int isviolationQ; char logmessage[256]; char filename[256]; int isactiverule; int whichsignal; int XMitLog(const char *logmessage); int tripped_once; protected: timej lastupdate; long minutesallowed;
1419};
1420F!LE: spa1.h
1421Header for stonewater pulse accumulator.
1422========================================= */
1423#ifndef _SPA1_H #define _SPA1_H
1424#include "drivers.h" #include "spadevl.h" #include ",./spa2.h" extern spa2 *spaboard; class meter_driver_spa1
1425{ public: meter_driver_spa1 Q; int isfluidQ; int initialize(char *initstring); int poll(int whichmeter); unsigned int getreading(timej start, timej end); //pulses pre-multiplier protected: int lastval; int newval; int channel; static time recentpoll;
1426};
1427#endif
1428FILE: spal .cxx
1429Implementation file for the stonewater pulse accumulator.
1430=====================================================7
1431#include "spa1.h"
1432timej meter_driver_spa1 ::recentpoll=(time )0L; meter_driver_spa1 : :meter_driver_spa1 Q { } int meter_driver_spa1::isfluid()
1433{ return(O); //the spal driver is not fluid (?)
1434} int meter_driver_spa1::initialize(char *initstring)
1435{ channel=atoi(initstring); return(O);
1436} int meter_driver_spa1::poll(int whichmeter)
1437{
1438//need all of the polling code right here!!! spadevl *spa; char buf[16]; dateobj now;
1439#ifdef USETHREADS spa=spaboard->spadev; if (!spa) printf("spaboard->spadev is NULL\n"); #else
1440FILE *f 1 ; char tempdevice[256]; char *p1 ; if (!(f 1 =fopen(7etc/pepper/spa1 ","r"))) sprintf(tempdevice,7dev/ttyS0"); else
1441{ fgets(tempdevice,255,f1); p1=strchr(tempdevice,':'); if (<sub>P</sub>1)
1442*p1=0; p1 =strchr(tempdevice, 10); if (p1) *p1=0; p1=strchr(tempdevice,13); if (p1)
1443*p1=0; fclose(f1);
1444} spa=new spadevl ; spa->Connect(tempdevice); #endif if ((now.GetQ-recentpoll) > 59) //if not polled recently, flip-flop & clr
1445{ spa->Send("c0"); //clear the inactive buffer spa->GetLine(buf , 16,1); spa->Send("b0"); spa->GetLine(buf,16,1); //flip-flop the active and inactive buffers recentpoll=now.Get();
1446} spa->Poll(channel); newval=spa->Get(channel); printf("$$$$$$$$$$$$$$$$$\nJust got reading: %d\n$$$$$$$$$$$$$$$$$$\n",newval);
1447#ifndef USETHREADS spa->Close(); delete spa; #endif return(newval); } unsigned int meter_driver_spa1::getreading(timej start, timej end)
1448{
1449//pulses are pre-multiplier return(newval); } File: spa2.h
1450This file is the driver for the stonewater pulse accumulator.
1451=====================================================*/
1452#ifndef_SPA2_H #define_SPA2_H
1453#include "stonergy_defs.h" #include "meterdrivers/spadevl .h"
1454#define ISRELAY 1 #define ISAUDIO 2 #define ISVOLTAGE 4
1455class spa2
1456{ public: spa2();
1457~spa2(); int connectQ; int activate(unsigned long facility, long paraml, long param2, long param3); int initialize(char *initstring); int poll(int whichmeter); unsigned int getreading(int which, timej start, timej end); //pulses pre- multiplier long housekeepQ; int buttons; int chirps; spadevl *spadev; protected: int connected; static timej recentpoll; char <sup>*</sup>serialport; int portfiledes;
1458};
1459#endif FILE: spa2.cxx
1460Implementation file for the driver for the stonewater pulse accumulator.
1461=====================================================7
1462#include "spa2.h" #include <unistd.h> #include <linux/reboot.h> timej spa2::recentpoϋ=(timeJ)0L; spa2::spa2()
1463{ buttons=0; chirps=0; } int spa2::connect()
1464{ spadev=new spadevl ; char buf[16]; dateobj now;
1465FILE *f1; char tempdevice[256]; char <sup>*</sup>p1; if (!(f1 =fopen("/etc/pepper/spa1 ","r")))
1466{ printfC'Unable to open file /etc/pepper/spa1 , this session will ignore the spal device.\n"); fflush(NULL); connected=0;
1467} else
1468{ fgets(tempdevice,255,f 1 ); p1=strchr(tempdevice,':'); if (p1) <sup>fc</sup>p1=0; p1=strchr(tempdevice,10); if (p1) *p1=0; p1 =strchr(tempdevice, 13); if (p1) <sup>*</sup><sub>P</sub>1=0; fclose(fl); spadev->Connect(tempdevice); connected=1; } } spa2::~spa2()
1469{ if (spadev)
1470{ spadev->Close(); connected=0; delete spadev; spadev=NULL;
1471}
1472} int spa2::initialize(char *initstring)
1473{ return(O);
1474} int spa2::activate(unsigned long facility, long paraml, long param2, long param3)
1475{ char buf[9]; if (lconnected) return(-1); memset(buf,0,9); printf("Activate(%ld, %ld, %ld)\n",facility,param1 ,param2); if (facility == RELAY_X )
1476{ if (paraml < OL || paraml > 9L) return(-1); sprintf(buf,"X%c",'0<sup>*</sup>+param1 ); } if (facility == RELAY_Y )
1477{ if (paraml < OL || paraml > 9L) return(-1); sprintf(buf,"Y%c",'0'+param1 ); } if (facility == RELAY_Z )
1478{ if (paraml < OL || paraml > 9L) return(-1); sprintf(buf,"Z%c",'0<sup>*</sup>+param1); } if (facility == AUDIO_1)
1479{ if (paraml < 0 || paraml > 7) return(-1); sprintf(buf,"S%c",O'+param1); } if (facility == VOLTAGE_1)
1480{ if (paraml < 0 || paraml > 100 ) retum(-1); sprintf(buf,"V%c",param1 ); } if (facility == VOLTAGE_2)
1481{ if (paraml < 0 || paraml > 100 ) return(-1); sprintf(buf,"W%c",param 1 ); }
1482spadev->Send(buf); return(O);
1483}
1484int spa2::poll(int whichmeter)
1485{ int newval; dateobj now; char buf[16]; if ((connected) return(-1); if ((now.Get()-recentpolI) > 59) //if not polled recently, flip-flop & clr
1486{ spadev->Send("c0"); //clear the inactive buffer spadev->GetLine(buf , 16,1); spadev->Send("bO"); spadev->GetLine(buf,16,1); //flip-flop the active and inactive buffers recentpoll=now.Get();
1487} spadev->Poll(whichmeter); newval=spadev->Get(whichmeter) ; printf("$$$$$$$$$$$$$$$$$\nJust got reading: %d\n$$$$$$$$$$$$$$$$$$\n",newval); return(newval); } unsigned int spa2::getreading(int channel, timej start, timej end)
1488{
1489//pulses are pre-multiplier if (iconnected) return(-1); return(O); //newval); } long spa2::housekeep()
1490{ char buf[32]; if (Iconnected) return(-1);
1491//if chirps > 0 do something spadev->Send("A0"); spadev->GetLine(buf,31 ,5); buttons+=atoi(buf+8); chirps+=atoi(buf+20); if (chirps > 2)
1492{ syncQ;
1493//first, try the GLIBC21 rebootQ if (reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART)) {
1494//if that failed, try the GLIBC20 and older rebootQ if (reboot(0xfee1dead,672274793,0x1234567)) system("reboot");
1495} exit(0); } return(OL); }
1496FILE: spadevl .h
1497Implementation file for the development version of stonewater pulse accumulator.
1498=========================================================:=*/
1499#ifndef __SPADEV1_H #defιne __SPADEV1_H
1500#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <signal.h> #include <ctype.h> #include "dateobj.h"
1501#define BAUDRATE B9600
1502#defιne _POSIX_SOURCE 1 /* POSIX compliant source 7
1503#defϊne FALSE 0
1504#define TRUE 1 class spadevl
1505{ public: spadevl (); int Connect(char <sup>*</sup>port); int Poll(int whichmeter=-1); int Send(char *buf); int GetLine(char *buf, int size, int timeout); int Get(int which); int CloseQ; protected: int fd; int newvalue; int connected; char portname[256]; struct termios oldtiopewtio;
1506};
1507#endif FILE: spadevl .cxx
1508Implementation file for the stonewater pulse accumulator development version.
1509=========================================================*/
1510#include "spadevl .h" #define SPADEBUG 1 spadevl ::spadev1 Q
1511{ fd=0; newvalue=0; connected=0;
1512}
1513int spadevl ::Connect(char *port)
1514{ if (connected) retum(O); if (port) strncpy(portname,port,255); if (Iport && strlen(portname)==0) strcpy(portname,"/dev/ttySO") ; fd=-1; while (fd < 0)
1515{ fd = open ortname, O_RDWR | O_NOCTTY | O_NONBLOCK); if (fd<0) printf("Error opening SPA (%s): ".portname); connected=0; sleep(5);
1516} connected=1;
1517#ifdef SPADEBUG printf("Modem device %s opened!\n",port); #endif tcgetattr(fd,&oldtio); /* save current serial port settings 7 bzero(&newtio, sizeof(newtio)); /<sup>*</sup> clear struct for new port settings 7 newtio.c_cflag = BAUDRATE | CLOCAL | CS8 | CREAD; newtio.cjflag = IGNPAR | ICRNL; newtio.c_oflag = 0; newtio.cjflag = ICANON; newtio.c_cc[VINTR] = 0; /* Ctrl-c 7 newtio.c_cc[VQUIT] = 0; /* Ctrl-\ 7 newtio.c_cc[VERASE] = 0; /* de! 7 newtio.c_cc[VKILL] = 0; /* @ 7 newtio.c_cc[VEOF] = 4; /* Ctrl-d 7 newtio.c_cc[VTIME] = 0; /* inter-character timer unused 7 newtio.c_cc[VMIN] = 1; /* blocking read until 1 character arrives 7 newtio.c_cc[VSWTC] = 0; /* '\0' 7 newtio.c_cc[VSTART] = 0; /* Ctrl-q 7 newtio.c_cc[VSTOP] = 0; /* Ctrl-s newtio.c_cc[VSUSP] = 0; I* Ctrl-z 7 newtio.c_cc[VEOL] = 0; I* <sup>*</sup>\0' 7 newtio.c_cc[VREPRINT] = 0; I<sup>*</sup> Ctrl-r 7 newtio.c_cc[VDISCARD3 = 0; /* Ctri-u 7 newtio.c_cc[VWERASE] = 0; /* Ctrl-w 7 newtio.c_cc[VLNEXT] = 0; /* Ctrl-v 7 newtio.c_cc[VEOL2] = 0; /* <sup>*</sup>\0' 7 tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); return(O); } int spadevl ::Send(char <sup>*</sup>buf)
1518{ if (iconnected)
1519Connect(NULL); if ('connected) return(-1);
1520#ifdef SPADEBUG printf("Sending: %s\n",buf); #endif write(fd,buf,strlen(buf)); sleep(1); tcdrain(fd); retum(O);
1521} int spadevl ::GetLine(char <sup>*</sup>buf, int size, int timeout) { char *p1; int i, remaining, done; dateobj start, now; if (iconnected)
1522Connect(NULL); if (iconnected) return(-1); remaining=size-1 ; i=0; done=0; p1=buf; memset(buf.O,size); while (istrchr uf, 10))
1523{ i=read(fd,p1.remaining); if (i>0)
1524{ #ifdef SPADEBUG printf("+%s+",buf); fflush(NULL); #endif p1+=i; remaining-=i;
1525} //else
1526// printfC'J'); fflush(NULL); now.NowQ; if (now.GetQ - start.Get() > timeout) return(-1);
1527} return(O);
1528} int spadevl ::Poll(int whichmeter)
1529{ int i; char buf[256]; char *p1, <sup>*</sup>p2; if (iconnected)
1530Connect(NULL); if (iconnected) return(-1); tcflush(fd,TCIOFLUSH); while (GetLine(buf,256,1) != -1); //clear any previous lines sprintf(buf,"r%d",whichmeter); Send(buf);
1531GetLine(buf,256,5);
1532#ifdef SPADEBUG printfC'My Pulses: %s\n",buf); #endif p2=strtok(buf,":"); p2=strtok(NULL,":"); if ('p2)
1533{ printf("Error getting pulses on channel %d.\n",whichmeter); return(O); } newvalue=atoi(p2); return(O); } int spadevl ::Get(int which)
1534{ if (which < 0 || which > 7) return(O); return(newvalue);
1535} int spadevl ::Close()
1536{ close(fd); connected=0; return(tcsetattr(fd,TCSANOW,&oidtio));
1537}
1538FILE: stdincludes.h
1539A package of header files and releveant classes for the iccm implementation.
1540#ifndef _ STDINCLUDES H #define _ _STDINCLUDES _H
1541#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h>
1542class BillEstObj; class BillMeterObj; class ClientlnfoObj; class DBIFACEObj; class LineltemObj; class LineltemsObj; class MadObj; class stonergyprotoengine; class ReadingObj; class RRDLLObj; class RRDLLsObj; class RRMeterRelationObj; class RRMetersObj; class TimePeriodObj; class ZoneNodeObj; class ZoneTreeObj; class RR Base; class Riderβ;
1543#endif
1544FILE: storage. h
1545The header file sets up methods and classes to handle iccm instructions, data, and communications status.
1546=================:==================:=====================*/
1547#ifndef _ICCM_STORAGE_H #define _ICCM_STORAGE_H
1548#include "iccm_client.h" class storageobj; class schedulerobj; class watermarkobj; class watermarksobj; class watermarkviolation;
1549class storageobj
1550{ public: storageobjQ; int LoadMeters(char <sup>*</sup>conf ile=NULL); long ID(int meter); timej TimeStamp(int meter, int readingindex); float Reading(int meter, int readingindex); int MarkXmitted(int meter, int readingindex); char *GetMeterName(int meter); int DeleteAIIO; int Delete(int meter, int readingindex); int MetersQ; int Readings(int meter); int PollQ; int PollSoon(int minutes=3); int SpyO; int ClearMetersQ; int CheckWatermarks(watermarksobj *wms); protected: CollectionBase cb; unsigned long iccm_zoneid; unsigned long iccm_rootid;
1551}; class schedulerobj { public: schedulerobjQ; int Load(char <sup>*</sup>section); int istime(const char *description=NULL); int fϊnishedQ; int Later(int minutes); dateobj nextcomm; int addminutes; int busy;
1552}; class watermarksobj
1553{ public: watermarksobjQ; int Load(const char *fϊlename); int ClearWatermarksQ; int ClearViolationsQ; //clears violations int Check(unsigned long zoneid, timej wwhen, float kw); int ViolationCount(); watermarkviolation <sup>*</sup>GetFirst(); watermarkviolation <sup>*</sup>GetNext(); protected: CollectionBase watermarks; CollectionBase violations; int currviolation;
1554}; class watermarkobj
1555{ public: watermarkobjO; int initialize(char *initstring); int set(unsigned long id, unsigned long zoneid, intwmtype, float wm); int Check(unsigned long zoneid, timej wwhen, float kw); unsigned long id; unsigned long zoneid; int wtype; float wm;
1556}; class watermarkviolation
1557{ public: watermarkviolationQ; int set(unsigned long wmid, unsigned long zoneid, timej wwhen, float kw); unsigned long wmid; unsigned long zoneid; dateobj wwhen; float kw;
1558};
1559class ORBsobj
1560{ public:
1561ORBsobj(); -ORBsobjQ; int Load(const char <sup>*</sup>filename); int Add(const char <sup>*</sup>host, const char *port);
1562CollectionBase cb;
1563};
1564class ORB
1565{ public:
1566ORBQ; char host[256]; char port[32]; dateobj lastsuccess; int failurecount;
1567};
1568#endif
1569FILE: storage.cxx
1570Implementation for storage on the iccm. Encapsulates the major functionality of the iccm outside of corba. This is the collection that stores information that the client sends and recieves.
15717
1572#include "iccm_client.h" #include "storage.h"
1573storageobj::storageobj() { } int storageobj::LoadMeters(char *conf_file)
1574{
1575FILE *f1; int i.finished; char buf[255]; char <sup>*</sup>p1; meterobj *temp; f1=fopen(conf_file,"r"); if (!f1)
1576{
1577Log(NOCONF,"Unable to open configuration file"); return(1); } finished=0; while (ifinished && !feof(f1))
1578{ memset(buf,0,255); fgets(buf,254,f1); p1=buf; while(*p1 && isspace(*p1)) p1++; if (p1 && *p1 !='#' && strlen(p1)>5)
1579{ temp=new meterobj; temp->initialize(p1); cb.Add(temp); //,atol(p1));
1580} // else
1581// printf("Skipping empty or comment line in /etc/pepper/meters\n");
1582} fclose(fl); for(i=0;i<cb.Count();i++)
1583{ temp=(meterobj <sup>*</sup>)cb.ltem(i); if (temp) temp->Spy();
1584} return(O);
1585} long storageobj::ID(int meter)
1586{ meterobj *temp; temp=(meterobj *)cb.ltem(meter); if (Itemp) retum(OL); else return(temp->id); } timej storageobj::TimeStamp(int meter, int readingindex)
1587{ meterobj *temp; temp=(meterobj *)cb.ltem(meter); if (temp) return(temp->getreadingtime(readingindex)); else return(OL); } float storageobj: :Reading(int meter, int readingindex)
1588{ meterobj *temp; temp=(meterobj *)cb.ltem(meter); if (temp) return(temp->getreading(readingindex)); else return(-LO); } int storageobj::MarkXmitted(int meter, int readingindex)
1589{ meterobj <sup>*</sup>temp; temp=(meterobj <sup>*</sup>)cb.ltem(meter); if (temp) return(temp->markxmitted(readingindex)); else return(-1);
1590} char <sup>*</sup>storageobj::GetMeterName(int meter)
1591{ meterobj *temp; temp=(meterobj *)cb.ltem(meter); if (temp) return(temp->key); else return(NULL); } int storageobj::DeleteAll()
1592{ meterobj *temp; int i,j; for(i=0;i<cb.Count();i++)
1593{ temp=(meterobj *)cb.ltem(i); if (temp)
1594{ if (temp->readings.CountQ) for(j=0;j<temp->readings.Count();j++) temp->Remove(j);
1595} else printf("storageobj::Delete() Trying to remove non-existant readingW);
1596} return(O);
1597} int storageobj ::Delete(int meter, int readingindex) { meterobj *temp; temp=(meterobj *)cb.ltem(meter); if (temp) temp->Remove(readingindex); else printf("storageobj::Delete() Trying to remove non-existant readingW); return(O); } int storageobj::Meters()
1598{ return(cb.CountQ);
1599} int storageobj::Readings(int meter)
1600{ meterobj *temp; temp=(meterobj <sup>*</sup>)cb.ltem(meter); if (temp) return(temp->readingcountQ); else return(O); } int storageobj::PolIQ
1601{ int i; meterobj *temp;
1602//Log(0,"Polling all meters"); for (i=0;i<cb.Count();i++)
1603{ temp=(meterobj *)cb.ltem(i); if (temp)
1604{ temp->poll();
1605} //printf("Reading on meter %d: %d\n",i,temp->getreading(0,0));
1606//printfC'Polling meter %d: %d\n"<sub>1</sub>i,temp->poll());
1607} return(O);
1608} int storageobj::PollSoon(int minutes)
1609{ int i; meterobj <sup>*</sup>temp; for (i=0;i<cb.Count();i++)
1610{ temp=(meterobj <sup>*</sup>)cb.ltem(i); if (temp) if (temp->PollSoon(minutes)) return(1);
1611} return(O);
1612} int storageobj::ClearMeters()
1613{ meterobj *temp; int i,j; printf("destroying storageobj\n"); fflush(NULL); for (i=cb.Count()-1;i>=0;i~)
1614{ temp=(meterobj *)cb.ltem(i); if (temp)
1615{ for (j=temp->readingcount()-1 ;j>=0;j-) temp->Remove(j); cb.Remove(i);
1616} } printfC'storageobj destroyed\n"); fflush(NULL); return(O);
1617} int storageobj::CheckWatermarks(watermarksobj *wms)
1618{ meterobj *temp; int i,j;
1619for (i=cb.Count()-1;i>=0;i-)
1620{ temp=(meterobj <sup>*</sup>)cb.ltem(i); if (temp) { for (j=temp->readingcount()-1 ;j>=0;j~) if (!temp->WatermarksChecked(j)) wms->Check(temp->id,temp->getreadingtimeG),temp->getreading(j));
1621}
1622} return(O);
1623} schedulerobj::schedulerobj()
1624{ nextcomm.Set(OL); addminutes=5; busy=0;
1625} int schedulerobj::Load(char *section)
1626{ //nextcomm.Set(OL);
1627//addminutes=60; //bad idea (made the first pause after boot-up always 1hr) busy=0; return(O);
1628} int schedulerobj::istime(const char *description)
1629{ dateobj now; if (nextcomm.GetQ == OL) nextcomm.Set(now.GetQ); //will commo on startup if (ibusy && nextcomm.GetQ <= now.GetQ)
1630{ return(1);
1631} if (description) printf("Next scheduled %s time is: %s %s\n",description,nextcomm.Get("simple",NULL,0),busy?"BUSY":""); fflush(NULL); return(O); } int schedulerobj::Later(int minutes) { nextcom m . N o w() ; nextcomm.Add(minutes <sup>*</sup> 60); printf("The next Communication schedule is for %s (added %d minutes).\n",nextcomm.Get("simple",NULL,0), minutes); return(O); } int schedulerobj::finished()
1632{
1633Later(addminutes); //add specified minutes until next commo printf("lnside ::fιnished() Next commoschedule is for: %s\n",nextcomm.Get("simple",NULL,0)); busy=0; return(O);
1634}
1635watermarksobj: :watermarksobj()
1636{ currviolation=0;
1637} int watermarksobj: :Load(const char *filename)
1638{
1639FILE *f1; int finished, i; char buf[256]; char *p1; watermarkobj *temp;
1640ClearWatermarksQ;
1641ClearViolationsO; f 1 =fopen(fiiename,"r"); if (Ifi)
1642{
1643Log(NOCONF,"Unable to open watermarks file for reading."); return(1); } finished=0; while (ifinished && !feof(f1)) { memset(buf,0,256); fgets(buf,255,f1); p1=buf; while(*p1 && isspace(*p1)) p1++; if (p1 && *p1 !='#' && strlen(p1)>5)
1644{ temp=new watermarkobj; temp->initialize(p1); watermarks.Add(temp);
1645} // else
1646// printf("Skipping empty or comment line in
1647/etc/pepperpepper//watermarks\n");
1648} fclose(f1); for (i=0;i<watermarks,Count();i++)
1649{ temp=(waterrnarkobj *)watermarks.Item(i); printfC'Watermark Spy: %ld %Id %d %f\n",temp->id,temp->zoneid,temp- >wtype,temp->wm);
1650} return(O);
1651} int watermarksobj::ClearWatermarksQ
1652{ watermarkobj *temp; int i; for (i=watermarks.Count()-1 ;i>=0;i-)
1653{
1654// temp=(watermarkobj *)watermarks.ltem(i);
1655// if (temp)
1656// delete temp; watermarks.Remove(i);
1657} return(O);
1658} int watermarksobj::ClearViolationsQ //clears violations
1659{ watermarkviolation <sup>*</sup>temp; int i; currviolation=0; for (i=violations.Count()-1 ;i>=0;i— )
1660{ // temp=(watermarkviolation *)violations.ltem(i); // if (temp) // delete temp; violations . Remove(i) ;
1661} return(O);
1662} int watermarksobj::Check(unsigned long zoneid, timej wwhen, float kw)
1663{ watermarkobj *temp; watermarkviolation *temp2; int i.retval; retval=0;
1664//printfC'Checking Watermark: zone=%ld\tkw=%f\n",zoneid,kw); for (i=0;i<watermarks.Count();i++)
1665{ //printf(">"); temp=(watermarkobj *)watermarks.ltem(i); if (temp)
1666{ if (temp->Check(zoneid,wwhen,kw))
1667{ printfC'Watermark %ld violated (%f KW).\n",temp->id,kw); temp2=new watermarkviolation; temp2->set(temp->id,zoneid,wwhen,kw); violations.Add(temp2); retval++;
1668}
1669} else printf("Error getting pointer to watermarkobjΛn");
1670} return(retval);
1671} intwatermarksobj::ViolationCount()
1672{ return(violations.CountQ);
1673} watermarkviolation <sup>*</sup>watermarksobj::GetFirst()
1674{ currviolation=-1; return(GetNextQ); } watermarkviolation *watermarksobj::GetNext()
1675{ watermarkviolation <sup>*</sup>temp; currviolation++; if (currviolation >= violations.CountQ) return(NULL); temp=(watermarkviolation *)violations.ltem(currviolation); return(temp);
1676}
1677watermarkobj::watermarkobj()
1678{ id=0L; zoneid=0L; wtype=0; wm=0.0;
1679} int watermarkobj::initialize(char *initstring)
1680{
1681//id :zoneid : wtype: val ue char buf[256]; char swtype[256]; char *p1,*p2; memset(buf,0,256); if (strlen(initstring) < 5)
1682{ printf("watermarkobj::initialize() inittstring is too short!\n"); return(O); } strncpy(buf,initstring,256); while (isspace(buf[strlen(buf)-1])) buf[strlen(buf)-1]=0; ρ1=strtok(buf ,":"); id=atol(p1); p1=strtok(NULL,":"); zoneid=atol(p1); memset(swtype,0,256); p1=strtok(NULL,":"); p2=strtok(NULL,":"); stmcpy(swtype,p1 ,p2-p1-1); p1=p2;
1683//printf("GARBAGE: |%s|\n"<sub>1</sub>swtype); fflush(stdout);
1684if (strcasecmp(swtype,"HI")==0) wtype=HIWATER; if (strcasecmp(swtype,"LO")==0) wtype=LOWATER; if (strcasecmp(swtype,"EQ")==0) wtype=EQWATER; if (strcasecmp(swtype,"LONZ")==0) wtype=LOWATERNZ;
1685//p1=strtok(NULL,":"); wm=atof(p1); retum(O); } int watermarkobj::set(unsigned long iid, unsigned long izoneid, int iwtype, float iwm)
1686{ id=iid; zoneid=izoneid; wtype=iwtype; wm=iwm;
1687} int watermarkobj::Check(unsigned long izoneid, timej wwhen, float kw)
1688{ //printfC'\t%ld\t%f\t\t%ld\t%d\t%An",izoneid,kw,zoneid,wtype,wm); if (izoneid==zoneid) { switch (wtype)
1689{ case HIWATER: if (kw>wm) return(1); break; case LOWATER: if (kw<wm) return(1); break; case EQWATER: if (kw==wm) return(1); break; case LOWATERNZ: if (kw != 0.0 && kw < wm) return(1); break; }
1690} return(O);
1691}
1692watermarkviolation::watermarkviolation()
1693{ set(0L,0L,0,O.0);
1694} int watermarkviolation::set(unsigned long iwmid, unsigned long izoneid, timej iwwhen, float ikw)
1695{ wmid=iwmid; zoneid=izoneid; wwhen.Set(iwwhen); kw=ikw; return(O);
1696}
1697ORBsobj::ORBsobj()
1698{ }
1699ORBsobj::~ORBsobjQ { cb.RemoveAIIQ; } int ORBsobj::Load(const char *filename)
1700{
1701FILE *f1 ; char buf[1024]; char <sup>*</sup>p1; f1 =fopen(filename,"r"); if (f1==NULL)
1702{ printfC'Unable to open new orbs!\n"); if (cb.CountQ < 5)
1703{
1704Add("209.219.108.69","12345");
1705Add("209.219.108.70","12345"); Add("corba.stonewatersoft are.com","12345"); Add("corba2.stonewatersoftware.com","12345"); Add("buster.stonewatersoftware.com","12345");
1706} retum(-1);
1707} cb.RemoveAIIQ; while(Jfeof(f1))
1708{ memset(buf,0,1024); fgets(buf,1023,f1); if (strlen(buf))
1709{ while (isspace(buf[strlen(buf)-1 ])) buf[strlen(buf)-1]=0; p1=strchr(buf,':');
1710<f (!p1) continue; //not a valid entry *p1=0; p1++; Add(buf.pl);
1711}
1712} fclose(f1);
1713} int ORBsobj::Add(const char *host, const char <sup>*</sup>port) { ORB *temp; temp=new ORB; strncpy(temp->host, host, 255); strncpy(temp->port, port, 31); cb.Add(temp); retum(O);
1714}
ORB::ORB()
1716{ memset(host,0,256); memset(port,0,32); lastsuccess.Set(OL); failurecount=0;
1717}
1718FILE: swatchdog. cxx swatchdog watches the iccm clinet to see when it needs to be rebooted.
1719#iήclude <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <time.h> #include <signal.h> #include <stdlib.h> #include <ctype.h> #include <sys/wait.h>
1720#include "rule.h"
1721//prototypes int LoadRules(const char *filename, rule <sup>*</sup>rules); int ShowHelpQ; int InstallSignalHandler(int which); int GotSignal(int which); int TrapSignals(rule *rules); int CheckViolations(rule *rules); int lnvokeAIIRules(rule *rules); int DoRebootQ; int DetachQ; int writepidfile(const char <sup>*</sup>filename); void sighandler(int which)
1722{ GotSignal(which);
1723}
1724//global rule rules[64]; main(int argc, char **argv) { if (argc<2)
1725{ ShowHelpQ; return(1); } DetachO;
1726LoadRules(argv[1], rules); TrapSignals(rules); while (1)
1727{ InvokeAIIRules(rules); if (CheckViolations(rules)) DoReboot(); sleep(30); } exit(0); }
1728int writepidfιle(const char <sup>*</sup>filename)
1729{
1730FILE *f1; f 1 =fopen(filename,"w"); if (!f1) return(-1); fprintf(f1 ,"%d\n",getpidQ); fclose(fl); return(O); }
1731DetachQ .
1732{ pid J a,b,c; fclose(stdin); fclose(stdout); a=fork(); if (a > 0)
1733{ //waitpid(superparent,NULL,0); exit(0);
1734} // b=fork(); // if (b>0)
1735// { waitpid(b,NULL,0); fprintf(stderr,"Swatchdog child was killed...rebootingΛn");
1736DoRebootQ;
1737} else writepidfile("/var/lock/swatchdog.pid"); freopen(7var/log/swatchdog","a",stdout); freopen("/var/log/swatchdog","r",stdin); freopen("/var/log/swatchdog","a",stderr); return(O); }
1738DoRebootQ
1739{ printfC**************** ReBooting in 3 minutes <sup>*</sup>**<sup>**********</sup>*<sup>**</sup>*\n"); sleeρ(360); printf("******************** ReBooting NOW!!! **********<sup>**</sup>*******\<sub>n</sub>"); system("/sbin/reboot"); exit(99);
1740} lnvokeAIIRules(ruIe *rules)
1741{ int i; for (i=0;i<64;i++)
1742{ if (rules[i].whichsignal == 0) rules[i].checkyourfile();
1743} retum(O);
1744}
1745GotSignal(int which)
1746{ int i; for (i=0;i<64;i++)
1747{ if (rules[i].whichsignal ==which) rules[i].incomingsignal(which);
1748} return(O);
1749} CheckViolations(rule *rules)
1750{ int i; for (i=0;i<64;i++)
1751{ if (rules[i].isvio!ation()) return(1);
1752} retum(O);
1753}
1754TrapSignals(rule *rules)
1755{ int i; for (i=0;i<64;i++)
1756{ if (rules[i].whichsigna! > 0) lnstallSignalHandler(ru!es[i].whichsignal);
1757} return(O);
1758}
1759LoadRules(const char <sup>*</sup>filename, rule *rules)
1760{ FILE *f1; char buf[256]; int signum, numminutes, currrule; char *p1, *p2;
1761f1=fopen(filename,"r"); if (!f1)
1762{ printfC'Unable to open the swatchdog rules fileΛn"); return(-1); }
1763currrule=0; while (!feof(f1))
1764{ memset(buf,0,256); fgets(buf,255,f1); if (strlen(buf)<5) continue; if (strncasecmp(buf,"SIGNAL",6)==0)
1765{ p1=strtok(buf,":"); p1=strtok(NULL,":"); signum=atoi(p1); p1=strtok(NULL,":"); numminutes=atoi(p1); rules[currrule].initialize(signum, numminutes); currrule++;
1766} if (strncasecmp(buf,"FILE"<sub>)</sub>4)==0)
1767{ ρ1=strtok(buf,":"); p1=strtok(NULL,":"); p2=p1; while (!isspace(*p2)) p2++; *p2=0; rules[currrule].initialize(p1); currrule++; } } fclose(f1); return(O);
1768} int InstallSignalHandIer(int which)
1769{ struct sigaction sa; sa.sa_handler=sighandler; sa.sa_flags=SA_RESTART; sigaction(which,&sa,NULL); return(O);
1770}
1771int ShowHelpQ
1772{ printfC'Swatchdog v2.7, Copyright 2000, Stonewater Software, lnc.\n\n"); printf("Usage:\n\tswatchdog [-1 outlogfile] [-kh sighup_frequency] [-ku siguser2Jrequency] [-vp processname] filename [filename ...]\n\n\n"); printf("\t-l outfile\t\tthe path and name of the file into which severe \n\t\t\t\tlog entries should be put\n\n");
1773<sup>"</sup> printf("\t-kh sighup Jrequency\tif swatchdog does not receive a sighup \n\t\t\t\tevery sighup Jrequency minutes, then it\n\t\t\t\twill reboot\n\n"); printf("\t-ku siguser2Jrequency\tif swatchdog does not receive a \n\t\t\t\tsiguser2 signal every siguser2Jrequency\n\t\t\t\tminutes, then it will reboot\n\n"); printf("Vt-vp processname\t\tjust before reboot, swatchdog will check to \n\t\t\t\tsee if the specified process is running and log \n\t\t\t\tthe presence/absence of the specified \n\t\t\t\tprocess name, -vp can be invoked multiple \n\t\t\t\ttimes to watch up to 5 process names\n\n"); printf("\tfilename\t\tthis should be the complete path to a text \n\t\t\t\tfile. This text file should contain a number, \n\t\t\t\twhich is the maximum number of minutes old\n\t\t\t\tthat the file is allowed to be before \n\t\t\t\tswatchdog reboots the system\n\n"); return(O); }
1774<img file="EP1309902A1_D0005.tif" /> IMAGE EVflLUflTION TEST TARGET Qfl-3
17751.0 lϋέ f 2.2
1776I.! L8
177711.25 1.4 Lό
1778<img file="EP1309902A1_D0006.tif" />
Contents7
6 sheets
Sheet 1 Sheet 2 Sheet 3 Sheet 4 Sheet 5 Sheet 6
Every citation, both ways
| Document | Relation | Office | Cited during |
|---|---|---|---|
| WO0017984A1 | Cites | World Intellectual Property Organization (WIPO) | Search report |
| US5216623A | Cites | United States of America | Search report |
| US5696695A | Cites | United States of America | Search report |
| US5761083A | Cites | United States of America | Search report |
| US5924486A | Cites | United States of America | Search report |
15 members in 6 offices
Priority claims3
| Document | Office | Kind | Date |
|---|---|---|---|
| 602071 | United States of America | – | |
| 60207100 | United States of America | A | |
| 0120121 | United States of America | W |
Members15
| Document | Office | Kind | |
|---|---|---|---|
| WO0198851A1 | World Intellectual Property Organization (WIPO) | A1 | |
| WO0198851A1 | World Intellectual Property Organization (WIPO) | A1 | |
| AU7012001A | Australia | A | |
| AU7012001A | Australia | A | |
| US6519509B1 | United States of America | B1 | |
| EP1309902A1This record | European Patent Office (EPO) | A1 | |
| TW535039B | Taiwan Province of China | B | |
| WO0198851A9 | World Intellectual Property Organization (WIPO) | A9 | |
| WO0198851A9 | World Intellectual Property Organization (WIPO) | A9 | |
| US2003158632A1 | United States of America | A1 | |
| JP2004501599A | Japan | A | |
| US6681154B2 | United States of America | B2 | |
| US2004174071A1 | United States of America | A1 | |
| EP1309902A4 | European Patent Office (EPO) | A4 | |
| US7088014B2 | United States of America | B2 |
8 legal events, as the office reported them to INPADOC
Over the term
Point at a mark for the eventEvents
| Event | Code | |
|---|---|---|
| Application deemed to be withdrawnWithdrawn18D | 18D | |
| Information on the status of an ep patent application or granted ep patentGrantedSTATUS: THE APPLICATION IS DEEMED TO BE WITHDRAWNSTAA | STAA | |
| Supplementary search report drawn up and despatchedA4 | A4 | |
| Designated contracting states (corrected)RBV | RBV | |
| Request for examination filed17P | 17P | |
| Designated contracting statesAK | AK | |
| Request for extension of the european patentAX | AX | |
| Public reference made under article 153(3) epc to a published international application that has entered the european phaseORIGINAL CODE: 0009012PUAI | PUAI |
Numbers
- Publication
- 1309902
- Application
- 19486695
Titles3
- German
- SYSTEM UND VERFAHREN ZUR ÜBERWACHUNG UND STEUERUNG DER ENERGIEVERTEILUNG
- English
- SYSTEM AND METHOD FOR MONITORING AND CONTROLLING ENERGY DISTRIBUTION
- French
- SYSTEME ET PROCEDE DE SURVEILLANCE ET DE MAITRISE DE DISTRIBUTION D'ENERGIE
Classification
- CPC, 7
- H02J3/008
- Y02B70/3225
- Y04S20/222
- Y04S50/10
- H02J3/17
- H02J2105/52
- H02J2105/55
- IPC, 5
- H02J3 00
- G06Q50 00
- H02J3 14
- H02J3 46
- H02J13 00
Designated states26
- Contracting states, 20
- Austria
- Belgium
- Switzerland
- Cyprus
- Germany
- Denmark
- Spain
- Finland
- France
- United Kingdom
- Greece
- Ireland
- Italy
- Liechtenstein
- Luxembourg
- Monaco
- Netherlands (Kingdom of the)
- Portugal
- Sweden
- Türkiye
- Extension states, 6
- Albania
- Lithuania
- Latvia
- North Macedonia
- Romania
- Slovenia
