@@ -196,7 +196,10 @@ func (e *emuImpl) Close() {
196196 InfoLogger .Println ("closing the emu session." )
197197 e .cancel ()
198198 time .Sleep (closingGracePeriord )
199- e .conn .Close ()
199+ err := e .conn .Close ()
200+ if err != nil {
201+ ErrorLogger .Printf ("Close error: %v" , err )
202+ }
200203}
201204
202205// func (e *emuImpl) GetCumulativeEnergyConsumption() (*CumulativeEnergyConsumption, error) {
@@ -250,7 +253,8 @@ func (e *emuImpl) reader() {
250253 break
251254 }
252255 rp .process (line )
253- if rp .state == RspReceived {
256+ switch rp .state {
257+ case RspReceived :
254258 //For internal commands e.g. Demand and Contineous etc
255259 if e .cmdState != nil && e .cmdState .status == CmdSent {
256260 //check if response is for the command
@@ -275,7 +279,7 @@ func (e *emuImpl) reader() {
275279 WarningLogger .Printf ("Ignoring, %s cannot be processed for API message" , rp .resp .GetName ())
276280 }
277281 rp = newResponseProcessor ()
278- } else if rp . state == RspError {
282+ case RspError :
279283 WarningLogger .Printf ("Abandoning processing response: [%s, %+v]\n " , rp .state , rp .resp )
280284 rp = newResponseProcessor ()
281285 }
@@ -390,9 +394,9 @@ type commandState struct {
390394 command Command
391395}
392396
393- func newCommandState () * commandState {
394- return & commandState {status : CmdUnknown }
395- }
397+ // func newCommandState() *commandState {
398+ // return &commandState{status: CmdUnknown}
399+ // }
396400
397401func newResponseProcessor () * responseProcessor {
398402 return & responseProcessor {state : RspPending , resp : & messageImpl {Attribs : make (map [emuMessageAttribute ]any )}}
@@ -505,37 +509,37 @@ func (rp *responseProcessor) process(line string) {
505509 }
506510}
507511
508- func (rp * responseProcessor ) processv2 (line string ) {
509- //if state is RspReceiving then look for stopResponseTag and attributes
510- //else ignore line as it start to receive in the middle of an response
511- switch rp .state {
512- case RspPending :
513- if tag , ok := rp .startResponseTag (line ); ok {
514- rp .state = RspReceiving
515- rp .resp .Name = tag
516- } else {
517- WarningLogger .Printf ("starting to receive in the middle of the message, ignoring. line: %s" , line )
518- }
519- case RspReceiving :
520- if tag , ok := rp .stopResponseTag (line ); ok {
521- if rp .resp .Name == tag {
522- rp .state = RspReceived
523- } else {
524- WarningLogger .Printf ("invalid end of response %s received. expecting[%s, %+v]. line: %s" , tag , rp .resp .GetName (), rp .state , line )
525- rp .state = RspError
526- }
527- } else {
528- //parse xml element from the line with <key>vale</key>
529- //add key and value to the response Attribs[key] = value
530- key , value , err := rp .getAttrib (line )
531- if err != nil {
532- WarningLogger .Printf ("abandoning message %s as xml parse error:%v while processing. line: %s" , rp .resp .GetName (), err , line )
533- rp .state = RspError
534- } else {
535- rp .resp .Attribs [key ] = value
536- }
537- }
538- default :
539- ErrorLogger .Printf ("invalid response state %+v to receive. line: %s" , rp .state , line )
540- }
541- }
512+ // func (rp *responseProcessor) processv2(line string) {
513+ // //if state is RspReceiving then look for stopResponseTag and attributes
514+ // //else ignore line as it start to receive in the middle of an response
515+ // switch rp.state {
516+ // case RspPending:
517+ // if tag, ok := rp.startResponseTag(line); ok {
518+ // rp.state = RspReceiving
519+ // rp.resp.Name = tag
520+ // } else {
521+ // WarningLogger.Printf("starting to receive in the middle of the message, ignoring. line: %s", line)
522+ // }
523+ // case RspReceiving:
524+ // if tag, ok := rp.stopResponseTag(line); ok {
525+ // if rp.resp.Name == tag {
526+ // rp.state = RspReceived
527+ // } else {
528+ // WarningLogger.Printf("invalid end of response %s received. expecting[%s, %+v]. line: %s", tag, rp.resp.GetName(), rp.state, line)
529+ // rp.state = RspError
530+ // }
531+ // } else {
532+ // //parse xml element from the line with <key>vale</key>
533+ // //add key and value to the response Attribs[key] = value
534+ // key, value, err := rp.getAttrib(line)
535+ // if err != nil {
536+ // WarningLogger.Printf("abandoning message %s as xml parse error:%v while processing. line: %s", rp.resp.GetName(), err, line)
537+ // rp.state = RspError
538+ // } else {
539+ // rp.resp.Attribs[key] = value
540+ // }
541+ // }
542+ // default:
543+ // ErrorLogger.Printf("invalid response state %+v to receive. line: %s", rp.state, line)
544+ // }
545+ // }
0 commit comments