예제 #1
0
void Player::on_get_public_data(void *argument)
{
    PublicDataRequest *pdr = static_cast<PublicDataRequest *>(argument);

    if(!pdr->starts_with(player_checksum)) return;

    if(pdr->second_element_is(is_playing_checksum) || pdr->second_element_is(is_suspended_checksum)) {
        static bool bool_data;
        bool_data = pdr->second_element_is(is_playing_checksum) ? this->playing_file : this->suspended;
        pdr->set_data_ptr(&bool_data);
        pdr->set_taken();

    } else if(pdr->second_element_is(get_progress_checksum)) {
        static struct pad_progress p;
        if(file_size > 0 && playing_file) {
            p.elapsed_secs = this->elapsed_secs;
            p.percent_complete = (this->file_size - (this->file_size - this->played_cnt)) * 100 / this->file_size;
            p.filename = this->filename;
            pdr->set_data_ptr(&p);
            pdr->set_taken();
        }
    }
}
예제 #2
0
void Network::on_get_public_data(void* argument) {
    PublicDataRequest* pdr = static_cast<PublicDataRequest*>(argument);

    if(!pdr->starts_with(network_checksum)) return;

    if(pdr->second_element_is(get_ip_checksum)) {
        pdr->set_data_ptr(this->ipaddr);
        pdr->set_taken();

    }else if(pdr->second_element_is(get_ipconfig_checksum)) {
        // NOTE caller must free the returned string when done
        char buf[200];
        int n1= snprintf(buf,             sizeof(buf),         "IP Addr: %d.%d.%d.%d\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
        int n2= snprintf(&buf[n1],       sizeof(buf)-n1,       "IP GW: %d.%d.%d.%d\n", ipgw[0], ipgw[1], ipgw[2], ipgw[3]);
        int n3= snprintf(&buf[n1+n2],    sizeof(buf)-n1-n2,    "IP mask: %d.%d.%d.%d\n", ipmask[0], ipmask[1], ipmask[2], ipmask[3]);
        int n4= snprintf(&buf[n1+n2+n3], sizeof(buf)-n1-n2-n3, "MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\n",
            mac_address[0], mac_address[1], mac_address[2], mac_address[3], mac_address[4], mac_address[5]);
        char *str = (char *)malloc(n1+n2+n3+n4+1);
        memcpy(str, buf, n1+n2+n3+n4);
        str[n1+n2+n3+n4]= '\0';
        pdr->set_data_ptr(str);
        pdr->set_taken();
    }
}
예제 #3
0
void TemperatureControl::on_get_public_data(void *argument)
{
    PublicDataRequest *pdr = static_cast<PublicDataRequest *>(argument);

    if(!pdr->starts_with(temperature_control_checksum)) return;

    if(pdr->second_element_is(pool_index_checksum)) {
        // asking for our instance pointer if we have this pool_index
        if(pdr->third_element_is(this->pool_index)) {
            static void *return_data;
            return_data = this;
            pdr->set_data_ptr(&return_data);
            pdr->set_taken();
        }

    }else if(pdr->second_element_is(poll_controls_checksum)) {
        // polling for all temperature controls
        // add our data to the list which is passed in via the data_ptr

        std::vector<struct pad_temperature> *v= static_cast<std::vector<pad_temperature>*>(pdr->get_data_ptr());

        struct pad_temperature t;
        // setup data
        t.current_temperature = this->get_temperature();
        t.target_temperature = (target_temperature <= 0) ? 0 : this->target_temperature;
        t.pwm = this->o;
        t.designator= this->designator;
        t.id= this->name_checksum;
        v->push_back(t);
        pdr->set_taken();

    }else if(pdr->second_element_is(current_temperature_checksum)) {
        // if targeted at us
        if(pdr->third_element_is(this->name_checksum)) {
            // ok this is targeted at us, so set the requ3sted data in the pointer passed into us
            struct pad_temperature *t= static_cast<pad_temperature*>(pdr->get_data_ptr());
            t->current_temperature = this->get_temperature();
            t->target_temperature = (target_temperature <= 0) ? 0 : this->target_temperature;
            t->pwm = this->o;
            t->designator= this->designator;
            t->id= this->name_checksum;
            pdr->set_taken();
        }
    }

}
예제 #4
0
void Switch::on_get_public_data(void *argument)
{
    PublicDataRequest *pdr = static_cast<PublicDataRequest *>(argument);

    if(!pdr->starts_with(switch_checksum)) return;

    if(!pdr->second_element_is(this->name_checksum)) return; // likely fan, but could be anything

    // ok this is targeted at us, so send back the requested data
    // this must be static as it will be accessed long after we have returned
    static struct pad_switch pad;
    pad.name = this->name_checksum;
    pad.state = this->switch_state;
    pad.value = this->switch_value;

    pdr->set_data_ptr(&pad);
    pdr->set_taken();
}
예제 #5
0
void TemperatureControl::on_get_public_data(void* argument){
    PublicDataRequest* pdr = static_cast<PublicDataRequest*>(argument);

    if(!pdr->starts_with(temperature_control_checksum)) return;

    if(!pdr->second_element_is(this->name_checksum)) return; // will be bed or hotend

    // ok this is targeted at us, so send back the requested data
    if(pdr->third_element_is(current_temperature_checksum)) {
        // this must be static as it will be accessed long after we have returned
        static struct pad_temperature temp_return;
        temp_return.current_temperature= this->get_temperature();
        temp_return.target_temperature= (target_temperature == UNDEFINED) ? 0 : this->target_temperature;
        temp_return.pwm= this->o;

        pdr->set_data_ptr(&temp_return);
        pdr->set_taken();
    }
}