Skip to content
Snippets Groups Projects
Select Git revision
  • 32eb4b905538c71ca5acee5f92e12c1aed992f4c
  • wip-bootstrap default
  • dualcore
  • ch3/leds
  • ch3/time
  • master
6 results

modesp.c

Blame
  • modesp.c 21.26 KiB
    /*
     * This file is part of the Micro Python project, http://micropython.org/
     *
     * The MIT License (MIT)
     *
     * Copyright (c) 2015 Paul Sokolovsky
     *
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     * THE SOFTWARE.
     */
    
    #include <stdio.h>
    #include <string.h>
    #include <stdbool.h>
    
    #include "py/nlr.h"
    #include "py/obj.h"
    #include "py/gc.h"
    #include "py/runtime.h"
    #include MICROPY_HAL_H
    #include "netutils.h"
    #include "queue.h"
    #include "user_interface.h"
    #include "espconn.h"
    #include "ip_addr.h"
    #include "spi_flash.h"
    #include "utils.h"
    
    STATIC const mp_obj_type_t esp_socket_type;
    
    typedef struct _esp_socket_obj_t {
        mp_obj_base_t base;
        struct espconn *espconn;
    
        mp_obj_t cb_connect;
        mp_obj_t cb_recv;
        mp_obj_t cb_sent;
        mp_obj_t cb_disconnect;
    
        uint8_t *recvbuf;
        mp_uint_t recvbuf_len;
    
        bool fromserver;
    
        mp_obj_list_t *connlist;
    } esp_socket_obj_t;
    
    // Due to the onconnect callback not being able to recognize the parent esp_socket,
    // we can have only one esp_socket listening at a time
    // This should be solvable by some PIC hacking
    STATIC esp_socket_obj_t *esp_socket_listening;
    
    STATIC mp_obj_t esp_socket_make_new_base() {
        esp_socket_obj_t *s = m_new_obj_with_finaliser(esp_socket_obj_t);
        s->recvbuf = NULL;