Subversion Repositories HomeAutomation

Rev

Rev 1642 | Rev 1665 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1642 Rev 1657
Line 181... Line 181...
181
{
181
{
182
    this->ResetTimeout();
182
    this->ResetTimeout();
183
   
183
   
184
    State target_state = this->GetTransitionTarget(event);
184
    State target_state = this->GetTransitionTarget(event);
185
   
185
   
186
    LOG.Debug("Trigger called on " + common::ToHex(this->id_) + ", current state: " + Node::state_names_[this->state_] + ", event: " + Node::event_names_[event] + ", target state: "  + Node::state_names_[target_state]);
186
    LOG.Debug("Trigger called on " + this->id_ + ", current state: " + Node::state_names_[this->state_] + ", event: " + Node::event_names_[event] + ", target state: "  + Node::state_names_[target_state]);
187
   
187
   
188
    if (target_state == STATE_INVALID)
188
    if (target_state == STATE_INVALID)
189
    {
189
    {
190
        this->SendReset();
190
        this->SendReset();
191
        target_state = STATE_NORM_OFFLINE;
191
        target_state = STATE_NORM_OFFLINE;
Line 205... Line 205...
205
        }
205
        }
206
        else if (this->state_ == STATE_BPGM_END)
206
        else if (this->state_ == STATE_BPGM_END)
207
        {
207
        {
208
            float speed = (float)this->code_->GetLength() / (float)(time(NULL) - this->program_start_time_);
208
            float speed = (float)this->code_->GetLength() / (float)(time(NULL) - this->program_start_time_);
209
           
209
           
210
            LOG.Info("Data was successfully transferred to " + common::ToHex(this->id_) + ", speed was " + boost::lexical_cast<std::string>(speed) + " B/s");
210
            LOG.Info("Data was successfully transferred to " + this->id_ + ", speed was " + boost::lexical_cast<std::string>(speed) + " B/s");
211
           
211
           
212
            LOG.Debug("Sending application programming copy to node " + common::ToHex(this->id_));
212
            LOG.Debug("Sending application programming copy to node " + this->id_);
213
            can::Message* payload = new can::Message("nmt", "", "", 0, "Pgm_Copy");
213
            can::Message* payload = new can::Message("nmt", "", "", 0, "Pgm_Copy");
214
           
214
           
215
            unsigned int source0 = GET_LOW_BYTE_16(this->start_offset_);
215
            unsigned int source0 = GET_LOW_BYTE_16(this->start_offset_);
216
            unsigned int source1 = GET_HIGH_BYTE_16(this->start_offset_);
216
            unsigned int source1 = GET_HIGH_BYTE_16(this->start_offset_);
217
           
217
           
Line 232... Line 232...
232
        }
232
        }
233
        else
233
        else
234
        {
234
        {
235
            float speed = (float)this->code_->GetLength() / (float)(time(NULL) - this->program_start_time_);
235
            float speed = (float)this->code_->GetLength() / (float)(time(NULL) - this->program_start_time_);
236
           
236
           
237
            LOG.Info("Programming was completed successfully on " + common::ToHex(this->id_) + ", speed was " + boost::lexical_cast<std::string>(speed) + " B/s");
237
            LOG.Info("Programming was completed successfully on " + this->id_ + ", speed was " + boost::lexical_cast<std::string>(speed) + " B/s");
238
        }
238
        }
239
    }
239
    }
240
   
240
   
241
    if (target_state == STATE_NORM_LIST)
241
    if (target_state == STATE_NORM_LIST)
242
    {
242
    {
Line 256... Line 256...
256
            LOG.Error("Code is not valid, aborting...");
256
            LOG.Error("Code is not valid, aborting...");
257
            target_state = STATE_NORM_OFFLINE;
257
            target_state = STATE_NORM_OFFLINE;
258
        }
258
        }
259
        else
259
        else
260
        {
260
        {
261
            LOG.Debug("Sending programming start to node " + common::ToHex(this->id_));
261
            LOG.Debug("Sending programming start to node " + this->id_);
262
            can::Message* payload = new can::Message("nmt", "", "", 0, "Pgm_Start");
262
            can::Message* payload = new can::Message("nmt", "", "", 0, "Pgm_Start");
263
            payload->SetVariable("HardwareId", boost::lexical_cast<std::string>(this->id_));
263
            payload->SetVariable("HardwareId", boost::lexical_cast<std::string>(common::FromHex(this->id_)));
264
           
264
           
265
            this->start_offset_ = target_state == STATE_BPGM_START ? 0 : this->code_->GetAddressLower();
265
            this->start_offset_ = target_state == STATE_BPGM_START ? 0 : this->code_->GetAddressLower();
266
           
266
           
267
            unsigned int address0 = GET_LOW_BYTE_16(this->start_offset_);
267
            unsigned int address0 = GET_LOW_BYTE_16(this->start_offset_);
268
            unsigned int address1 = GET_HIGH_BYTE_16(this->start_offset_);
268
            unsigned int address1 = GET_HIGH_BYTE_16(this->start_offset_);
Line 290... Line 290...
290
            LOG.Warning("Offset received in ACK was incorrect got " + boost::lexical_cast<std::string>(offset) + " expected " + boost::lexical_cast<std::string>(this->expected_ack_data_) + ", aborting...");
290
            LOG.Warning("Offset received in ACK was incorrect got " + boost::lexical_cast<std::string>(offset) + " expected " + boost::lexical_cast<std::string>(this->expected_ack_data_) + ", aborting...");
291
            target_state = STATE_NORM_OFFLINE;
291
            target_state = STATE_NORM_OFFLINE;
292
        }
292
        }
293
        else if (this->current_offset_ >= this->code_->GetLength())
293
        else if (this->current_offset_ >= this->code_->GetLength())
294
        {
294
        {
295
            LOG.Debug("Sending programming end to node " + common::ToHex(this->id_));
295
            LOG.Debug("Sending programming end to node " + this->id_);
296
           
296
           
297
            unsigned int checksum = this->code_->GetChecksum();
297
            unsigned int checksum = this->code_->GetChecksum();
298
            this->expected_ack_data_ = SWAP_BYTE_ORDER_16(checksum);
298
            this->expected_ack_data_ = SWAP_BYTE_ORDER_16(checksum);
299
           
299
           
300
            can::Message* payload = new can::Message("nmt", "", "", 0, "Pgm_End");
300
            can::Message* payload = new can::Message("nmt", "", "", 0, "Pgm_End");
Line 302... Line 302...
302
           
302
           
303
            target_state = target_state == STATE_BPGM_DATA ? STATE_BPGM_END : STATE_APGM_END;
303
            target_state = target_state == STATE_BPGM_DATA ? STATE_BPGM_END : STATE_APGM_END;
304
        }
304
        }
305
        else
305
        else
306
        {
306
        {
307
            LOG.Debug("Sending programming data to node " + common::ToHex(this->id_));
307
            LOG.Debug("Sending programming data to node " + this->id_);
308
            can::Message* payload = new can::Message("nmt", "", "", 0, "Pgm_Data_48");
308
            can::Message* payload = new can::Message("nmt", "", "", 0, "Pgm_Data_48");
309
           
309
           
310
            unsigned int offset0 = GET_LOW_BYTE_16(this->start_offset_ + this->current_offset_);
310
            unsigned int offset0 = GET_LOW_BYTE_16(this->start_offset_ + this->current_offset_);
311
            unsigned int offset1 = GET_HIGH_BYTE_16(this->start_offset_ + this->current_offset_);
311
            unsigned int offset1 = GET_HIGH_BYTE_16(this->start_offset_ + this->current_offset_);
312
           
312
           
Line 325... Line 325...
325
            broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get())));
325
            broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get())));
326
        }
326
        }
327
    }
327
    }
328
    else if (target_state == STATE_BPGM_COPY)
328
    else if (target_state == STATE_BPGM_COPY)
329
    {
329
    {
330
        LOG.Debug("Preparing to send null application to node " + common::ToHex(this->id_));
330
        LOG.Debug("Preparing to send null application to node " + this->id_);
331
       
331
       
332
        this->code_->Reset();
332
        this->code_->Reset();
333
       
333
       
334
        this->code_->AddByte(0xFF);
334
        this->code_->AddByte(0xFF);
335
        this->code_->AddByte(0xFF);
335
        this->code_->AddByte(0xFF);
Line 365... Line 365...
365
}
365
}
366
 
366
 
367
void Node::ResetTimeout()
367
void Node::ResetTimeout()
368
{
368
{
369
    this->last_active_ = time(NULL);
369
    this->last_active_ = time(NULL);
-
 
370
}
-
 
371
 
-
 
372
void Node::Reset()
-
 
373
{
-
 
374
    common::StringMap variables;
-
 
375
   
-
 
376
    this->Trigger(EVENT_RESET, variables);
370
}
377
}
371
 
378
 
372
void Node::ProgramApplication(Code::Pointer code)
379
void Node::ProgramApplication(Code::Pointer code)
373
{
380
{
374
    this->code_ = code;
381
    this->code_ = code;
Line 387... Line 394...
387
    this->Trigger(EVENT_PROGRAM_BIOS, variables);
394
    this->Trigger(EVENT_PROGRAM_BIOS, variables);
388
}
395
}
389
 
396
 
390
void Node::SendReset()
397
void Node::SendReset()
391
{
398
{
392
    LOG.Info("Sending node reset to " + common::ToHex(this->id_));
399
    LOG.Info("Sending node reset to " + this->id_);
393
    can::Message* payload = new can::Message("nmt", "", "", 0, "Reset");
400
    can::Message* payload = new can::Message("nmt", "", "", 0, "Reset");
394
    payload->SetVariable("HardwareId", boost::lexical_cast<std::string>(this->id_));
401
    payload->SetVariable("HardwareId", boost::lexical_cast<std::string>(common::FromHex(this->id_)));
395
   
402
   
396
    broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get())));
403
    broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get())));
397
}
404
}
398
 
405
 
399
void Node::SendListRequest()
406
void Node::SendListRequest()
400
{
407
{
401
    LOG.Debug("Sending module listing on node " + common::ToHex(this->id_));
408
    LOG.Debug("Sending module listing on node " + this->id_);
402
    can::Message* payload = new can::Message("mnmt", "To_Owner", "", 0, "List");
409
    can::Message* payload = new can::Message("mnmt", "To_Owner", "", 0, "List");
403
    payload->SetVariable("HardwareId", boost::lexical_cast<std::string>(this->id_));
410
    payload->SetVariable("HardwareId", boost::lexical_cast<std::string>(common::FromHex(this->id_)));
404
   
411
   
405
    broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get())));
412
    broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), Manager::Instance().get())));
406
}
413
}
407
 
414
 
408
}; // namespace control
415
}; // namespace control