SingingCat 0
application
|
Files | |
file | boot_info.c |
constants is a struct in a special RAM area which is not cleared on reset | |
file | command-handler.c |
main command processor | |
file | command-parser.c |
code to encode/decode commands to a serialized or in-ram format | |
file | constants.c |
constants is a struct in a special RAM area which is not cleared on reset | |
file | decode_esp_packet.c |
packetizes streams from esp including escape/unescape | |
file | fets.c |
code to drive the fets | |
file | flashapp.c |
handling of flash via streams | |
file | forwarding.c |
code to forward to other nodes | |
file | forwarding.h |
definitions of routing table structures | |
file | led.c |
code to make the pretty LED blink | |
file | onewire.c |
code to interface via onewire. (uses bit-banging and timer) | |
file | packetbuffer.c |
packetizes streams of data from radio or wifi | |
file | powersave.c |
code to manage sensors by server | |
file | queue.c |
code to queue outbound commands. this is the "normal" way of sending out commands | |
file | routing.c |
code to discover other nodes | |
file | routing.h |
definitions of routing table structures | |
file | routing_functions.h |
definitions of routing table structures | |
file | sensor.c |
code to call all the sensors in the right frequency, with the correct configuration modify this file if you have new sensors! | |
file | sensor_command.c |
code to manage sensors by server | |
file | streams.c |
handling of streams | |
file | user_app_exe.c |
user application interface | |
file | userhooks.c |
START HERE - definition of user hooks to implement additional functionality. | |
Data Structures | |
struct | espbuf |
struct | hostroute |
struct | ledcolour |
struct | leddef |
struct | power_state |
struct | powersavething |
struct | queue_entry |
struct | sensorconfig |
definition of variable stuff for any one sensor this is seperate from runtime, because a copy will live in flash (cnw: err, no, not with a volatile pointer (*sensor)!!) More... | |
struct | stbuf |
Macros | |
#define | AT_COMMAND_OK 2 |
baudrate [0=9600,1=19200,2=38400,3=57600,4=115200,5=230400,6=460800,7=921600,8=74880] More... | |
#define | AT_COMMAND_TIMEOUT 7 |
#define | BROADCAST 0xFFFFFFFF |
#define | CHECK_TI1101_FAILURE if (ti1101_failed) { ti1101_failure(); return; } |
#define | CHECK_TI1101_FAILURE_S if (ti1101_failed) { ti1101_failure(); printf("TI1101 failed\r\n"); return; } |
#define | CHECK_TI1101_FAILURE_V if (ti1101_failed) { ti1101_failure(); return 0; } |
#define | CNWDEBUGCOM(a, ...) noop() |
#define | COM_QUEUE_SIZE 80 |
#define | COMMAND_AGE_BEFORE_GC 120 |
maximum amount of time a packet may remain allocated More... | |
#define | command_names_size 60 |
#define | ESP8266_AFTER_BOOT_DEFAULT_BAUDRATE 9600 |
#define | ESPMODE_ISAP 1 |
#define | HOSTROUTE_ENTRIES 40 |
#define | isNewStyleEnabled (sensors_enabled & (1 << 1)) |
#define | isOldStyleEnabled (sensors_enabled & (1 << 0)) |
#define | isProbing (sensors_enabled & (1 << 2)) |
#define | LED_TIMER_FREQUENCY 130 |
#define | MAX_ROUTE_AGE_SECONDS 600 |
any route that has not been used or seen for longer than this is subject to removal (the garbage collector) More... | |
#define | MAX_SECS_BEFORE_DELAYED_START 10 |
#define | MAX_SECS_BETWEEN_LOOP_SAMPLES 5 |
#define | MAX_SECS_BETWEEN_RADIO_BROADCASTS 300 |
#define | MAX_SECS_BETWEEN_STOP_WARNING 10 |
#define | MAX_SECS_BETWEEN_WIFI_DETECT 600 |
how often to check if a wifichip is attached More... | |
#define | MCULIB_USERAPP_HANDLE 7 |
#define | MEMAREA_SIZE 4096 |
#define | ONEWIRE_INTERVAL 600 |
#define | SECONDS_BEFORE_ATTEMPTING_TO_RECONNECT 600 |
if we fail to log in to [ssid], we fallback to 'singingcat'. If so, how often shall we retry to connect to [ssid] More... | |
#define | SECONDS_BEFORE_ESP_FAIL 30 |
if esp8266 fails to provide a valid ip after this time: reinitialise More... | |
#define | SECONDS_BEFORE_ESP_RESET_FAIL 30 |
after reset, how long before failure detection starts More... | |
#define | SECS_AFTER_BOOT_BEFORE_POWERSAFE 120 |
#define | SECS_AFTER_LASTCOM_BEFORE_POWERSAFE 3 |
#define | SECS_AFTER_WAKE_BEFORE_POWERSAFE 10 |
#define | SECS_BETWEEN_CLOUD_PROBES 300 |
how often to probe the cloud connection More... | |
#define | SECS_UNTIL_CONNECTION_DEAD (SECS_BETWEEN_CLOUD_PROBES * 4) |
if we don't receive an answer for this long (in seconds) assume connection is dead More... | |
#define | SENSOR_FLAG_ACTIVATED 4 |
#define | SENSOR_FLAG_DETECTED 2 |
#define | SENSOR_FLAG_ENABLED 0 |
#define | SENSOR_FLAG_ISDUE 1 |
#define | SENSOR_FLAG_PROBED 3 |
#define | SENSOR_TIMER 4 |
timer to use More... | |
#define | SENSOR_TIMER_FREQUENCY 1000 |
frequency our timer runs on More... | |
#define | TI1101_BURST 0x40 |
#define | TI1101_READ 0x80 |
Typedefs | |
typedef struct espbuf | _espbuf |
typedef struct hostroute | _hostroute |
typedef struct ledcolour | _ledcolour |
typedef struct leddef | _leddef |
typedef struct power_state | _power_state |
typedef struct powersavething | _powersavething |
typedef struct queue_entry | _queue_entry |
typedef struct sensorconfig | _sensorconfig |
definition of variable stuff for any one sensor this is seperate from runtime, because a copy will live in flash (cnw: err, no, not with a volatile pointer (*sensor)!!) | |
typedef struct stbuf | _stbuf |
Functions | |
int | _command_add_encoded_arg (struct command *com, byte *buf) |
long | adr_create_new_node_id () |
int | adr_isvalid (long a) |
int | all_sensors_probed () |
struct command * | alloc_command () |
allocate a free command More... | |
struct command * | alloc_command_with_minfree (int minfree) |
struct stream * | alloc_stream () |
find a free stream struct, alloc an fd and return struct More... | |
int | app_main (void) |
void | app_main_no_return () __attribute__((noreturn)) |
int | ascii_commandstring_to_num (const byte *buf, int size, int *const newpos) |
match a string to a command num. More... | |
void | bridge_packet (struct command *com) |
void | calc_power_mode () |
void | cat_send_local_instruction (const PACKET_TYPE type, const uint8_t *buf, const int len) |
send a packet to the esp8266 wifi chip More... | |
void | check_close (struct stream *stream) |
check if closing flash ist set and we received all the data up to close packet if, flush and close stream More... | |
void | check_strobe () |
void | clear_outbound_queue () |
clear the outbound queue any commands within the queue are silently discarded More... | |
void | close_stream (int fd, int reason) |
void | command_add_arg (struct command *com, const char *format,...) |
adds an arg to a partially initialised command structure More... | |
int | command_add_binary_arg (struct command *com, const int len, const byte *srcbuf) |
adds a binary parameter to command returns 0 if ok otherwise errorcode More... | |
void | command_add_varg (struct command *com, const char *format, va_list args) |
adds a varg list of parameters to a command More... | |
byte | command_calc_checksum (struct command *com) |
int | command_decode_ascii (struct command *com, const byte *buf, int size, int version) |
int | command_decode_binary (struct command *com, const byte *buf, int size) |
int | command_encode_ascii (struct command *com, int bufsize, char *buf) |
encode a command to an ascii blob properly surrounded by '{' and '}' and escaped returns length if ok or <0 if error More... | |
const char * | command_get_name (int num) |
given a command number returns its name More... | |
char * | command_get_source_name (byte sourcedev) |
returns a human readable text identifying a source device More... | |
void | command_init (struct command *com) |
initialize a command structure with default values More... | |
struct command * | command_parse (const byte *buf, int size) |
void | command_print (struct command *com) |
prints a command in human readable format to serial console More... | |
void | command_start () |
initialization for command parser More... | |
void | console_add_byte (uint8_t b) |
uint16_t | console_get_byte () |
int | console_get_line (char *outbuf, int outbufsize) |
void | console_reset () |
struct consts * | constants () |
int | constants_init () |
void | constants_print () |
void | constants_validate () |
int | count_open_streams () |
count number of open streams More... | |
void | create_new_node_id () |
void | dac_timer () |
const char * | decisionname (int decision) |
void | decode_esp_packet_init () |
const char * | decode_marcstate (int state) |
int | deliver_command (struct command *com, pkt_callback cb) |
deliver a command to a module More... | |
void | enter_esp_passthrough_mode () |
void | error_com (void *com) |
void | esp8266_add_ap (const char *ssid, const char *pw) |
add an ap to the list of known ap More... | |
int | esp8266_add_byte (byte b) |
feed this with one byte at a time More... | |
void | esp8266_bridge () |
bridge debug serialport and esp8266 (e.g. "wifidebug") More... | |
void | esp8266_cloud_connection_failed () |
called if the cloud connection failed More... | |
void | esp8266_cloud_loop () |
called from esp8266 event loop if we are connected More... | |
void | esp8266_decoder_print_info () |
void | esp8266_disable () |
disable the esp8266 (switch it off) More... | |
void | esp8266_dodebug (const char *paras) |
void | esp8266_enable () |
enable the esp8266 (switch it on) More... | |
void | esp8266_event_loop () |
byte * | esp8266_get_buf () |
get the buffer More... | |
int | esp8266_get_chip () |
struct ipv4address * | esp8266_get_current_ip () |
return last ip (null if none) More... | |
uint64_t | esp8266_get_firmware_base () |
int | esp8266_get_firmware_repo () |
int | esp8266_get_firmware_version () |
long | esp8266_get_invalid_commands () |
int | esp8266_get_operational_baudrate () |
long | esp8266_get_time_of_last_ip () |
long | esp8266_get_valid_commands () |
void | esp8266_got_packet (const byte *buf, int size) |
int | esp8266_is_accespoint () |
returns !=0 if we are currently an accesspoint More... | |
int | esp8266_is_enabled () |
byte | esp8266_is_in_packet () |
returns 1 if currently parsing a packet More... | |
void | esp8266_ota () |
tell the esp to do an OTA More... | |
int | esp8266_packet_size () |
returns 0 if no packet is in buf, otherwise returns size of packet in bytes More... | |
void | esp8266_read_byte_from_serialport (int val) |
this is called directly from the usart IRQ. be quick. and do not use printf() More... | |
void | esp8266_reset () |
reset state machine and esp8266 More... | |
void | esp8266_reset_buf () |
reset buf, e.g. after packet was processed More... | |
void | esp8266_reset_command_validity_ctrs () |
void | esp8266_send_config () |
void | esp8266_send_instructions () |
send our nodeid and other goodies to the esp8266 chip More... | |
void | esp8266_set_operational_baudrate (int baudrate) |
char * | esp8266_status_string () |
returns a human readable status string of the wifi connection More... | |
void | esp8266_test () |
void | esp8266_wifi_scan (struct command *com) |
void | esp8266_wififlash_bridge (void) |
set esp8266 to flash mode, sync and then bridge ("startflash") More... | |
void | esp_cloud_activate () |
activate the cloud. More... | |
void | esp_cloud_answered (struct command *com, struct command *reply) |
called on command timeout or reply More... | |
const char * | esp_cloud_connect_state_string () |
void | esp_cloud_deactivate () |
const char * | esp_cloud_get_desired_server () |
returns server we want to connect to More... | |
void | esp_cloud_init () |
this resets the cloud state More... | |
byte | esp_cloud_is_activated () |
return 1 if cloud connection is activated More... | |
int | esp_cloud_is_connected () |
void | esp_cloud_state_update (int code, int data) |
whenever the esp chip sends us an update about the cloud state this gets called by the event handler for the esp8266 (not in irq) More... | |
void | esp_empty_ringbuffer () |
empties the ringbuffer. More... | |
const char * | esp_get_last_pw () |
const char * | esp_get_last_ssid () |
int | esp_get_mac (char *buf, int bufsize) |
get the esp8266 mac address. More... | |
void | esp_info () |
void | esp_init () |
call this ONCE before calling anything else More... | |
int | esp_read_mac () |
void | factory_default (struct command *com) |
set the module back to factory default More... | |
void | fets_init () |
void | fets_loop () |
void | fets_set_com (struct command *com) |
void | flagstostr (char *buf, int flags) |
given a pointer to a buffer and command flags, it will fill the buffer with a human readable text describing the flags More... | |
int | flash_app_close (int fd, int reason) |
int | flash_app_consumer (int streamfd, byte *b, int size) |
called by stream whenever we got sufficient bytes (and only on full blocks!) More... | |
int | flash_app_init (void *base, uint32_t flags) |
void | flash_debug () |
int | flash_write (byte *b, void *adr, int size) |
unlock, erase, write, lock More... | |
void | flashcom (struct command *com) |
set up a flash connection, associate with stream, called by command-handler for command "flash-app" More... | |
void | flush (struct stream *stream) |
send remaining data to consumer (might be < packetsize!) More... | |
int | forward_packet (struct command *com) |
a command is forwarded to target based on our hostroutes More... | |
void | forward_radio (struct command *com) |
void | free_command (struct command *com) |
free a command More... | |
void | free_commands (int index) |
free commands by index (-1 for all) More... | |
const char * | get_arg (const struct command *com, int index) |
given an argument by index[0..n], will return a pointer to the bytearray (excluding the fieldtype) this is compatibility only, use get_arg_new() instead the argument may contain NUL bytes - use get_arg_size() to determine its length More... | |
int | get_arg_int_array (const struct command *com, const int index, int *result, const int arraysize) |
given a command and argument index, will attempt to parse the arg as array and return it array syntax is currently semi-comma delimited hex values returns the number of values parsed deprecated - use field arrays instead More... | |
const byte * | get_arg_new (const struct command *com, int index) |
given an argument by index[0..n], will returns a pointer to it. This will include the fieldnumber and fieldtype the argument may contain NUL bytes - use get_arg_size() to determine its length More... | |
int | get_arg_size (const struct command *com, int index) |
given an argument by index [0..n], will returns the size of the value in bytes. for a string/array it is the size of the array. for a uint8_t it is 1 and for uint16_t it is 2... More... | |
int | get_arg_size_inmem (const struct command *com, int index) |
given an argument by index [0..n], will returns the number in bytes this argument takes up in memory. for a string/array it is the fieldnum(1 byte) + fieldtype(1 byte) + arraylen(1 byte) + size of the array + nul-terminator(1byte) for a uint8_t it is 3 (fieldnum+fieldtype+1bytevalue) for a uint16_t it is 4 (fieldnum+fieldtype+2bytevalue) More... | |
void | get_config_flags (struct command *com) |
get config flags More... | |
struct command * | get_data_reply (struct command *com) |
allocates and initializes a packet to be send as "data" to the command typically you'd add some data to it and pass it to send_command(). after send_command() you'll need to free it More... | |
int | get_esp8266_usart_mode () |
int | get_esp_reboot_ctr () |
byte | get_hops_to_server () |
how many hops to the server? More... | |
struct mpm * | get_mpm () |
long | get_my_node_id () |
get the id of my node More... | |
int | get_outbound_command_count_important () |
return number of commands to be delivered (apart from announce/noop) More... | |
byte | get_routing_debug () |
struct sensorruntime * | get_runtime (int idx) |
struct userapp_info * | get_user_app () |
void | getcloudtoken (struct command *com) |
get the opaque cloud token More... | |
void | getpubkey (struct command *com) |
request the public key of this module More... | |
byte | got_new_packet (struct command *com, uint8_t signal_indicator) |
stack received a new packet (signal indicator is a 0-255 byte value, interface specific) More... | |
void | init_command_handler () |
resets the command handler More... | |
void | init_powersavething (struct powersavething *pst) |
int | internal_ti1101_init (struct network_context *onctx) |
int | invoke_on_command_received (struct command *com) |
void | invoke_on_new_node (struct hostroute *host) |
void | invoke_start (int MCULIBHANDLE) |
void | invoke_stop () |
void | invoke_user_loop () |
void | iplog (const char *format,...) |
log something to a remote node More... | |
void | irq_metric_counter (int pin) |
int | is_command_valid (struct command *com) |
int | is_device_online (int device) |
return 1 if the specified device is online and routing More... | |
int | is_last_ip_valid () |
return true if IP is set and valid More... | |
int | is_packet_for_us (struct command *com) |
check if a command needs to be routed More... | |
int | is_stack (void *adr) |
void | led_blink (LED_USAGE_TYPE lut, uint32_t colour, uint8_t brightness, uint32_t on, uint32_t off) |
will keep blinking until told otherwise will repeat endlessly. More... | |
void | led_blink_flags (LED_USAGE_TYPE lut, uint32_t colour, uint8_t brightness, uint32_t on, uint32_t off, uint32_t flags) |
void | led_flash (LED_USAGE_TYPE lut, uint32_t colour, uint32_t duration) |
will flash led once More... | |
void | led_indicate (LED_INDICATOR a) |
void | led_init () |
void | led_loop () |
void | led_off (LED_USAGE_TYPE lut) |
void | led_print_status () |
void | led_set_machine_managed () |
void | led_set_user_managed () |
void | led_set_wifi_managed () |
void | list_modules (struct command *com) |
we received a list-modules command More... | |
void | logging_event_loop () |
sends current buffer and empties it More... | |
void | logging_init () |
initialise logging. logging is disabled after calling this function More... | |
void | logging_off () |
disable logging and logging processing. guarantees that no buffers are used for logging More... | |
void | logging_on () |
enable logging and logging processing. buffers are used for logging More... | |
void | logging_set_node (long nodeid) |
log to a given node. Usually this would be an app or a server More... | |
void | mark_last_in_use (struct powersavething *pst) |
void | micro_strobe (struct command *com) |
do a nano strobe More... | |
void | mpm_free (void *mem) |
void * | mpm_reserve (int bytes) |
void | multi_mem_init () |
called very early on, even before printf works More... | |
const char * | namedarg (struct command *com, const char *name) |
get a named arg (key-value pair) or NULL More... | |
int | namedarg_uint16 (struct command *com, const char *name, uint16_t *value) |
get a named arg (key-value pair), parsed as integer. result in "value". if return value == 0 , it was parsed, otherwise error code More... | |
int | namedarg_uint32 (struct command *com, const char *name, uint32_t *value) |
get a named arg (key-value pair), parsed as integer. result in "value". if return value == 0 , it was parsed, otherwise error code More... | |
void | node_to_str (long l, char *buf) |
int | on_command_received (struct command *com) |
this is called for each command we receive More... | |
void | on_new_node (struct hostroute *host) |
called when and if a new node is detected. this may be used, to, for example to activate when a route to the cloud becomes available More... | |
int | onewire_init (byte idx) |
int | onewire_reading_size (byte idx) |
int | onewire_run (byte idx, byte *error) |
void | packet_buf_init (const int num) |
initialize (reset, clear) a given buffer More... | |
byte * | packet_getbuf (const int num) |
get pointer to the contents of the buffer More... | |
int | packet_getbytesinbuf (const int num) |
count bytes in the buffer More... | |
void | packet_init () |
initialize (reset, clear) all buffers More... | |
int | packet_isvalid (const int num) |
initialize (reset, clear) a given buffer More... | |
void | packet_mark_valid (const int num) |
mark this buffer as containing a valid packet More... | |
int | packet_put_byte (const int num, const byte b) |
add a byte to a buffer More... | |
void | pin_pwm (MCULIB_HANDLE handle, int pin, uint32_t state, int flags) |
void | power_main_loop () |
int | power_set_connectivity (struct power_state *ps, int turnon) |
void | power_set_speed (int speed) |
void | pretty_node_to_str (long l, char *buf) |
void | print_boot_info () |
print startup information More... | |
void | print_esp_core_info () |
void | print_node_id (long l) |
void | print_outbound_queue () |
void | print_pkt_state_update (int subsystem, int code, uint8_t d1, uint8_t d2) |
void | print_program_status () |
void | print_pwm_state () |
void | print_stream_info () |
print summary of current streams to console More... | |
void | printHelp () |
void | process_command (struct command *com) |
command is parsed, now execute it More... | |
void | process_command_queue () |
this gets called when we got some cpu cycles spare we then send out commands and timeout other commands and so on More... | |
int | process_queue_reply (struct command *ack) |
process a reply More... | |
void | process_strobe_command (struct command *com) |
void | process_terminal_input () |
int | query_onewire (struct onewire_hwdef *hw, byte *error) |
void | queue_init () |
int | received_radio_get_config (struct command *com) |
called when we received radio_get_config command sends back an answer with the current radio config More... | |
int | received_radio_set_config (struct command *com) |
called when we received radio_set_config command modified the current radio config More... | |
void | remove_stale_routes () |
"old" routes are being removed this is the route garbage collector More... | |
void | request_route (long nodeid) |
send an arp request (equivalent) More... | |
int | routing_count_nodes () |
determine number of nodes known More... | |
void | routing_error (struct command *com, int errorcode) |
void | routing_event_loop () |
struct hostroute * | routing_find_empty_slot () |
finds an empty slot in our routing entry list More... | |
struct hostroute * | routing_find_host (const long nodeid) |
find route to host or NULL if none known More... | |
struct hostroute * | routing_find_route (const long nodeid, const byte sourcedev) |
find specific hostroute to target or NULL if none known special case, if we ask for a route to server, we get any intermediary routes which announce themselves to have a connection a server More... | |
struct hostroute * | routing_get_node_by_index (const int index) |
finds a nodeid by index. [0...n] More... | |
void | routing_init () |
called when we power-up More... | |
void | routing_print_table () |
print routing table More... | |
void | routing_request_reply (const struct command *com) |
we call this when we receive a reply to a routing request this adds or updates a new route More... | |
void | sc_fancy_allocator_init () |
void | sc_free (void *ptr) |
void * | sc_realloc (void *ptr, size_t size) |
int | send_command (struct command *com) |
send a command to another module (or broadcast) More... | |
int | send_command_fw_info (struct command *com, int err) |
send a reply to a command More... | |
int | send_command_one_arg (int command, long target, const byte *arg1, int arg1len) |
helper function to quickly and easily send a command somewhere return 0 if ok, else errorcode More... | |
int | send_command_quietly (struct command *com) |
int | send_command_reply (struct command *com, byte flags) |
send a reply to a command More... | |
int | send_command_reply_with_args (struct command *com, byte flags, const char *format,...) |
send a reply to a command More... | |
int | send_data (struct command *com, const char *format,...) |
send the format string as data in response to command "com" More... | |
void | send_routing_update_now () |
int | send_user_app_status () |
void | sensor_activation (struct sensorruntime *sr, int activation) |
void | sensor_com_config (struct command *com) |
void | sensor_com_list (struct command *com) |
void | sensor_deregister (struct sensordev *sensor) |
void | sensor_info () |
int | sensor_loop () |
called periodically. this will either query sensors when they are due or will set the isdue flag for them to be picked up during IRQ returns true if new sensor data needs to be sent More... | |
void | sensor_probe () |
struct sensordev * | sensor_register (struct sensordev *sensor) |
register a sensor, e.g. from userhook. The sensordev struct is COPIED, so it may be reused by the caller. the RETURN value is a pointer to the new sensordev, or NULL More... | |
void | sensor_run_str (const char *str) |
int | sensor_submit_request (const long nodeid, int idx, const int readmillis, const int submitsec, const int max_values) |
int | sensor_update_config (const long nodeid, int idx, const int readmillis, const int submitsec, const int max_values) |
void | sensors_init () |
initialize sensors, runtime, config, powerup each sensor in turn etc.. More... | |
uint8_t | sensors_inited () |
void | sensors_newstyle () |
enable new-style sensors (and disable old) More... | |
void | sensors_off () |
disable sensors More... | |
void | serialirq (int port, byte b) __attribute__((no_instrument_function)) |
void | set_config_flag (struct command *com) |
set a single config flag More... | |
void | set_esp8266_debug (byte b) |
void | set_esp8266_usart_mode (int i) |
void | set_forward_debug (byte b) |
void | set_in_app (uint8_t a) |
void | set_logging (struct command *com) |
int | set_mcu_power_mode (int state) |
void | set_new_node_id (char *nodetxt) |
void | set_routing_debug (byte b) |
void | setcloudtoken (struct command *com) |
set a token to connect to the cloud More... | |
void | setdac (struct command *com) |
void | setpin (struct command *com) |
int | start (int mculib_handle, struct sc_firmware_api *uapi) |
this is called when the board powers up More... | |
void | start_strobe (int relay, int ton, int toff, int repeat) |
void | start_wifi_scan () |
void | stop () |
int | stream_associate (int fd, const struct consumerinfo *ci, byte *buf, int bufsize, int packetsize) |
associate a stream with a consumer. return 0 if ok otherwise errorcode More... | |
void | stream_disable () |
disable all stream handling More... | |
void | stream_enable () |
enable all stream handling (default) More... | |
void | stream_init () |
void | stream_loop () |
called periodically, checks for stale streams and/or hung ones More... | |
void | stream_seterror (int streamfd, const char *format,...) |
void | streamdata (struct command *com) |
called when we receive a stream data packet TODO: this is a really simplistic, memory-consumption optimized algorithm. it currently discards packets which are out-of-order and keeps requesting the next packet in order. Possible optimisations: More... | |
void | streamsetup (struct command *com) |
called when we receive a stream setup packet More... | |
int | ti1101_compare_config () |
check the config against the values in flash More... | |
int | ti1101_cssns () |
void | ti1101_disable () |
void | ti1101_disable_irq (struct network_context *ctx) |
void | ti1101_enable_irq () |
void | ti1101_event_loop_locked () |
void | ti1101_failure () |
void | ti1101_forward_radio (long node) |
forward all radio packets to this node mostly useful to debug and decode and sniff 3rd party protocols like door openers, thermostats etc... More... | |
byte | ti1101_get_last_irq_error () |
if we throw an error in the irq we cannot print it directly. save it and return it here. the irq_error is cleared by reading from it. More... | |
int | ti1101_irqpin () |
int | ti1101_is_enabled () |
int | ti1101_lock () |
lock, return 1 if ok, otherwise it is an error More... | |
int | ti1101_loop (struct network_context *ctx) |
this is called in the main thread periodically More... | |
int | ti1101_off () |
diable processing of ti1101 commands More... | |
void | ti1101_on () |
enable processing of radio More... | |
void | ti1101_print_config () |
void | ti1101_print_status () |
byte | ti1101_read_byte () |
int | ti1101_read_version () |
void | ti1101_receive_loop () |
void | ti1101_rx () |
void | ti1101_set_debug (byte b) |
set debug mode of ti1101 More... | |
int | ti1101_spiport () |
int | ti1101_transmit (struct network_context *nctx, const byte *data, uint16_t num_bytes) |
int | ti1101_tx () |
void | ti1101_unlock () |
int | update_all_runtimes () |
update runtimes (recalculate buffer positions). return 0 if ok (5 otherwise) More... | |
int | user_app_checksum_valid () |
void | user_app_control (struct command *com) |
void | user_app_disable () |
void | user_app_enable () |
void | user_app_exe_init () |
int | user_app_executable () |
int | user_app_info (struct command *com) |
int | user_app_is_enabled () |
int | user_app_is_valid () |
void | user_app_reset_state () |
void | user_loop () |
this is called frequently, but with no timing guarantees. essentially, it's called in the "idle-loop" of the mcu More... | |
int | user_serial_callback (int portnum, int byte) |
int | userapp_checksum_valid (void *baseadr) |
void | wifi_info (struct command *com) |
get some information about our currentwifi connection More... | |
void | wifi_new_creds (char *buf) |
void | wifi_send_data (const PACKET_TYPE type, const byte *buf, const int len) |
send a command via wifi More... | |
void | wifi_update_completed () |
void | wifi_update_progress (const uint8_t *buf) |
void | wifi_update_started () |
void | wireless_callback_state_change (int newstate, int oldstate) |
int | write_char_to_console (char b) |
int | write_serial_char (int port, char b) |
int | write_serial_line (int port, const char *txt) |
int | write_serial_string (int port, const char *txt) |
Variables | |
char | _estack |
char | _Minimum_Stack_Size |
int | ack_ctr |
uint32_t | acm_byte_received |
int | attemptctr |
const char * | BAUD_CHANGE_INDICATOR = "NEW BAUDRATE: [" |
uint8_t | brightness |
byte | buf [260] |
byte | buf [300] |
struct espbuf | bufs [7] |
pkt_callback | callback |
uint32_t | colour |
struct command * | command |
const char *const | command_names [] |
struct ringbuffer | console_ringbuffer |
uint8_t | device |
struct ringbuffer | esp_ringbuffer |
char | esptmpbuf [128] |
struct leddef | extled = { .pins = { 7, 110, 111 }, .timers = { 2, 1, 1 } } |
int | fd |
const struct consumerinfo | flashconsumerinfo = { &flash_app_consumer, &flash_app_close } |
struct hal_workspace | hal |
uint8_t | hops_to_server |
long | host |
uint8_t | hosttype |
see https://www.singingcat.net?linkid=routing More... | |
struct leddef | intled = { .pins = { 106, 107, 108 }, .timers = { 3, 3, 3 } } |
long | last_attempt |
struct ipv4address | lastip |
long | lastseen |
byte | lora_on |
struct ledcolour | machinecolour |
int | max_values |
int | MCULIBHANDLE |
long | nexthop |
here the nodeif of the intermediary hop (the proxy) More... | |
uint32_t | off |
uint32_t | on |
int | order |
struct cnw_packetbuf | packetbuffer1 |
uint32_t | permaramadr |
uint8_t | pin |
int | pins [3] |
struct power_state | prev_state |
uint8_t | pwm |
volatile uint32_t * | r_adr = (volatile uint32_t *)0x40020810 |
char | rbuf [10] |
int | readmillis |
char | sbuf [10] |
const struct sensordev * | sensor |
struct sensordev | sensors [] |
list of sensors... More... | |
uint8_t | signal_indicator |
int | size |
int | size |
uint32_t | speed |
const char * | statetable [] |
struct stream | streams [2] |
mgmt for streams (the more ram, the more simultanous streams we can handle More... | |
int | submitsecs |
long | target |
uint32_t | target_pwm |
char | tbuf [10] |
volatile byte | ti1101_in_read_loop = 0 |
volatile byte | ti1101_locked = 0 |
byte | ti1101_on |
int | timers [3] |
int | tn |
void * | UMM_MALLOC_CFG_HEAP_ADDR |
uint32_t | UMM_MALLOC_CFG_HEAP_SIZE |
struct userapp_info | userapp_vector |
struct ledcolour | usercolour |
uint32_t | value |
byte | wifi_on |
long | wifi_state_since = 0 |
long | wifi_state_since |
volatile uint32_t * | wr_adr = (volatile uint32_t *)0x40020814 |
#define AT_COMMAND_OK 2 |
#define CHECK_TI1101_FAILURE if (ti1101_failed) { ti1101_failure(); return; } |
#define CHECK_TI1101_FAILURE_S if (ti1101_failed) { ti1101_failure(); printf("TI1101 failed\r\n"); return; } |
#define CHECK_TI1101_FAILURE_V if (ti1101_failed) { ti1101_failure(); return 0; } |
#define CNWDEBUGCOM | ( | a, | |
... | |||
) | noop() |
Definition at line 31 of file command-parser.c.
#define COMMAND_AGE_BEFORE_GC 120 |
maximum amount of time a packet may remain allocated
#define command_names_size 60 |
Definition at line 29 of file command-parser.c.
#define MAX_ROUTE_AGE_SECONDS 600 |
#define MAX_SECS_BETWEEN_WIFI_DETECT 600 |
#define MCULIB_USERAPP_HANDLE 7 |
Definition at line 142 of file user_app_exe.c.
#define MEMAREA_SIZE 4096 |
Definition at line 72 of file multiram.c.
#define SECONDS_BEFORE_ATTEMPTING_TO_RECONNECT 600 |
if we fail to log in to [ssid], we fallback to 'singingcat'. If so, how often shall we retry to connect to [ssid]
Do not make this too short - it is annoying if devices attempt to configure it and get kicked out because we attempt to reconnect to a non-existing accesspoint
#define SECONDS_BEFORE_ESP_FAIL 30 |
#define SECONDS_BEFORE_ESP_RESET_FAIL 30 |
#define SECS_AFTER_BOOT_BEFORE_POWERSAFE 120 |
Definition at line 20 of file powersave.c.
#define SECS_AFTER_LASTCOM_BEFORE_POWERSAFE 3 |
Definition at line 24 of file powersave.c.
#define SECS_AFTER_WAKE_BEFORE_POWERSAFE 10 |
Definition at line 21 of file powersave.c.
#define SECS_BETWEEN_CLOUD_PROBES 300 |
how often to probe the cloud connection
Note: make sure it's less than route garbage collector (routing.c)
Definition at line 44 of file esp8266_cloud.c.
#define SECS_UNTIL_CONNECTION_DEAD (SECS_BETWEEN_CLOUD_PROBES * 4) |
if we don't receive an answer for this long (in seconds) assume connection is dead
Definition at line 48 of file esp8266_cloud.c.
#define SENSOR_TIMER_FREQUENCY 1000 |
}garbageend and you get: PKT_TYPE{a,1,00000001,19F05795,19F05795,1,3,noop} Explanation:
Note to developers: esp8266_add_byte is called from within the serial interrupt, please take great care when modifying this code to avoid race-conditions. The order of instructions is crucial and delicate! Keep each path short!
typedef struct hostroute _hostroute |
information about a single host
int _command_add_encoded_arg | ( | struct command * | com, |
byte * | buf | ||
) |
Definition at line 123 of file command-parser.c.
long adr_create_new_node_id | ( | ) |
Definition at line 20 of file addressing.c.
int adr_isvalid | ( | long | a | ) |
Definition at line 8 of file addressing.c.
struct command * alloc_command | ( | ) |
allocate a free command
long | my node id |
Definition at line 173 of file queue.c.
Referenced by get_config_flags(), get_data_reply(), getcloudtoken(), list_modules(), received_radio_get_config(), request_route(), send_command_fw_info(), send_command_one_arg(), send_command_reply(), send_command_reply_with_args(), and wifi_info().
struct stream * alloc_stream | ( | ) |
int ascii_commandstring_to_num | ( | const byte * | buf, |
int | size, | ||
int *const | newpos | ||
) |
match a string to a command num.
command string must be terminated by 0 or '}' or ',' upon return the int variable pointed to by newpos will point to the first character which is not part of the command name. (usually 0, '}' or ',')
Definition at line 208 of file command-parser.c.
void calc_power_mode | ( | ) |
Definition at line 103 of file powersave.c.
void cat_send_local_instruction | ( | const PACKET_TYPE | type, |
const uint8_t * | buf, | ||
const int | len | ||
) |
void check_close | ( | struct stream * | stream | ) |
void check_strobe | ( | ) |
Definition at line 689 of file command-handler.c.
void clear_outbound_queue | ( | ) |
void command_add_arg | ( | struct command * | com, |
const char * | format, | ||
... | |||
) |
adds an arg to a partially initialised command structure
Definition at line 130 of file command-parser.c.
References command_add_varg().
Referenced by get_config_flags(), getcloudtoken(), list_modules(), request_route(), and wifi_info().
int command_add_binary_arg | ( | struct command * | com, |
const int | len, | ||
const byte * | srcbuf | ||
) |
adds a binary parameter to command returns 0 if ok otherwise errorcode
Definition at line 167 of file command-parser.c.
Referenced by received_radio_get_config(), and send_command_one_arg().
void command_add_varg | ( | struct command * | com, |
const char * | format, | ||
va_list | args | ||
) |
adds a varg list of parameters to a command
Definition at line 140 of file command-parser.c.
Referenced by command_add_arg(), send_command_reply_with_args(), and send_data().
byte command_calc_checksum | ( | struct command * | com | ) |
Definition at line 740 of file command-parser.c.
int command_decode_ascii | ( | struct command * | com, |
const byte * | buf, | ||
int | size, | ||
int | version | ||
) |
Definition at line 346 of file command-parser.c.
int command_decode_binary | ( | struct command * | com, |
const byte * | buf, | ||
int | size | ||
) |
Definition at line 337 of file command-parser.c.
int command_encode_ascii | ( | struct command * | com, |
int | bufsize, | ||
char * | buf | ||
) |
encode a command to an ascii blob properly surrounded by '{' and '}' and escaped returns length if ok or <0 if error
Definition at line 573 of file command-parser.c.
const char * command_get_name | ( | int | num | ) |
given a command number returns its name
Definition at line 113 of file command-parser.c.
char * command_get_source_name | ( | byte | sourcedev | ) |
returns a human readable text identifying a source device
Definition at line 240 of file command-parser.c.
void command_init | ( | struct command * | com | ) |
initialize a command structure with default values
Definition at line 660 of file command-parser.c.
References command::com.
Referenced by get_data_reply(), list_modules(), received_radio_get_config(), send_command_fw_info(), send_command_reply(), and send_command_reply_with_args().
struct command * command_parse | ( | const byte * | buf, |
int | size | ||
) |
Definition at line 514 of file command-parser.c.
void command_print | ( | struct command * | com | ) |
prints a command in human readable format to serial console
Definition at line 300 of file command-parser.c.
Referenced by process_command().
void command_start | ( | ) |
initialization for command parser
Definition at line 107 of file command-parser.c.
struct consts * constants | ( | ) |
Definition at line 15 of file constants.c.
int constants_init | ( | ) |
Definition at line 26 of file constants.c.
void constants_print | ( | ) |
Definition at line 52 of file constants.c.
void constants_validate | ( | ) |
Definition at line 43 of file constants.c.
void dac_timer | ( | ) |
Definition at line 664 of file command-handler.c.
void decode_esp_packet_init | ( | ) |
reset decode to "factory defaults"
Definition at line 50 of file decode_esp_packet.c.
int deliver_command | ( | struct command * | com, |
pkt_callback | cb | ||
) |
deliver a command to a module
it is entirely possible that the callback will be called multiple times, for example at broadcasts
the callback will be called either way, even if no answer is received.
Definition at line 651 of file queue.c.
Referenced by get_config_flags(), getcloudtoken(), send_command_fw_info(), send_command_one_arg(), send_command_reply(), and send_command_reply_with_args().
void error_com | ( | void * | com | ) |
Definition at line 866 of file command-parser.c.
void esp8266_add_ap | ( | const char * | ssid, |
const char * | pw | ||
) |
int esp8266_add_byte | ( | byte | b | ) |
feed this with one byte at a time
will return number of bytes in buf if a complete packet was processed returns 0 otherwise
Definition at line 97 of file decode_esp_packet.c.
void esp8266_bridge | ( | ) |
bridge debug serialport and esp8266 (e.g. "wifidebug")
Definition at line 791 of file esp8266.c.
Referenced by esp8266_wififlash_bridge().
void esp8266_cloud_connection_failed | ( | ) |
void esp8266_cloud_loop | ( | ) |
called from esp8266 event loop if we are connected
Definition at line 123 of file esp8266_cloud.c.
void esp8266_decoder_print_info | ( | ) |
Definition at line 250 of file decode_esp_packet.c.
void esp8266_disable | ( | ) |
void esp8266_enable | ( | ) |
byte * esp8266_get_buf | ( | ) |
get the buffer
Definition at line 222 of file decode_esp_packet.c.
struct ipv4address * esp8266_get_current_ip | ( | ) |
void esp8266_got_packet | ( | const byte * | buf, |
int | size | ||
) |
packet from esp received ********************************
1) bytes are added to esp8266_add_byte in "decode_esp" from the IRQ (see esp8266_read_byte_from_serialport). 2) the main loop periodically checks if "decode_esp" reports a full packet, if so, it calls this this must be enclosed in '{}' buf -> PKT_COMMAND|PKT_IP_UDPATE or so
int esp8266_is_accespoint | ( | ) |
byte esp8266_is_in_packet | ( | ) |
returns 1 if currently parsing a packet
specifically: if it is within PKT_START and PKT_END byte
Definition at line 234 of file decode_esp_packet.c.
int esp8266_packet_size | ( | ) |
returns 0 if no packet is in buf, otherwise returns size of packet in bytes
Definition at line 241 of file decode_esp_packet.c.
void esp8266_read_byte_from_serialport | ( | int | val | ) |
void esp8266_reset_buf | ( | ) |
reset buf, e.g. after packet was processed
This is more complicated than just resetting the pointers: we might have gathered extra bytes in-between detecting first command, processing it and calling reset_buf. So there might be extra bytes we now need to keep. This must be done in a way that does not interfere with IRQs from the serialport
what we do is this:
there is still a small racecondition though: If we receive one or more bytes after 1, including an end-of-packet, before we do 2, we miss those bytes. we detect a packet with odd data. we got to fix that in get_buf(); (TODO)
Definition at line 197 of file decode_esp_packet.c.
void esp8266_send_instructions | ( | ) |
send our nodeid and other goodies to the esp8266 chip
Definition at line 1311 of file esp8266.c.
Referenced by setcloudtoken().
char * esp8266_status_string | ( | ) |
void esp8266_test | ( | ) |
void esp8266_wififlash_bridge | ( | void | ) |
set esp8266 to flash mode, sync and then bridge ("startflash")
Definition at line 675 of file esp8266.c.
References esp8266_bridge().
void esp_cloud_activate | ( | ) |
activate the cloud.
if the cloud is activated, we maintain a connection. if not we track the esp8266 IP connections, but do not initiate a command via server. This is set/maintained by the esp8266.c state. not a user function!
Definition at line 137 of file esp8266_cloud.c.
called on command timeout or reply
Definition at line 207 of file esp8266_cloud.c.
const char * esp_cloud_connect_state_string | ( | ) |
Definition at line 222 of file esp8266_cloud.c.
void esp_cloud_deactivate | ( | ) |
Definition at line 152 of file esp8266_cloud.c.
const char * esp_cloud_get_desired_server | ( | ) |
returns server we want to connect to
Definition at line 68 of file esp8266_cloud.c.
void esp_cloud_init | ( | ) |
this resets the cloud state
Definition at line 57 of file esp8266_cloud.c.
byte esp_cloud_is_activated | ( | ) |
return 1 if cloud connection is activated
Definition at line 167 of file esp8266_cloud.c.
int esp_cloud_is_connected | ( | ) |
Definition at line 173 of file esp8266_cloud.c.
void esp_cloud_state_update | ( | int | code, |
int | data | ||
) |
whenever the esp chip sends us an update about the cloud state this gets called by the event handler for the esp8266 (not in irq)
Definition at line 82 of file esp8266_cloud.c.
Referenced by print_pkt_state_update().
void esp_empty_ringbuffer | ( | ) |
int esp_get_mac | ( | char * | buf, |
int | bufsize | ||
) |
void esp_info | ( | ) |
Definition at line 234 of file esp8266_cloud.c.
void esp_init | ( | ) |
int esp_read_mac | ( | ) |
void factory_default | ( | struct command * | com | ) |
set the module back to factory default
Definition at line 223 of file command-handler.c.
void flagstostr | ( | char * | buf, |
int | flags | ||
) |
given a pointer to a buffer and command flags, it will fill the buffer with a human readable text describing the flags
Definition at line 264 of file command-parser.c.
int flash_app_close | ( | int | fd, |
int | reason | ||
) |
Definition at line 66 of file flashapp.c.
int flash_app_consumer | ( | int | streamfd, |
byte * | b, | ||
int | size | ||
) |
called by stream whenever we got sufficient bytes (and only on full blocks!)
Definition at line 102 of file flashapp.c.
int flash_app_init | ( | void * | base, |
uint32_t | flags | ||
) |
Definition at line 207 of file flashapp.c.
void flash_debug | ( | ) |
Definition at line 62 of file flashapp.c.
int flash_write | ( | byte * | b, |
void * | adr, | ||
int | size | ||
) |
unlock, erase, write, lock
Definition at line 157 of file flashapp.c.
void flashcom | ( | struct command * | com | ) |
set up a flash connection, associate with stream, called by command-handler for command "flash-app"
Definition at line 224 of file flashapp.c.
void flush | ( | struct stream * | stream | ) |
send remaining data to consumer (might be < packetsize!)
Definition at line 402 of file streams.c.
Referenced by check_close().
int forward_packet | ( | struct command * | com | ) |
a command is forwarded to target based on our hostroutes
returns 0 if successfull, otherwise errorcode
Definition at line 31 of file forwarding.c.
References command::flags, and hostroute::host.
void forward_radio | ( | struct command * | com | ) |
Definition at line 274 of file command-handler.c.
void free_command | ( | struct command * | com | ) |
free a command
long | my node id |
Definition at line 200 of file queue.c.
Referenced by list_modules(), request_route(), and send_data().
void free_commands | ( | int | index | ) |
const char * get_arg | ( | const struct command * | com, |
int | index | ||
) |
given an argument by index[0..n], will return a pointer to the bytearray (excluding the fieldtype) this is compatibility only, use get_arg_new() instead the argument may contain NUL bytes - use get_arg_size() to determine its length
Definition at line 728 of file command-parser.c.
Referenced by micro_strobe(), namedarg(), process_command(), received_radio_set_config(), routing_request_reply(), set_config_flag(), and setcloudtoken().
int get_arg_int_array | ( | const struct command * | com, |
const int | index, | ||
int * | result, | ||
const int | arraysize | ||
) |
given a command and argument index, will attempt to parse the arg as array and return it array syntax is currently semi-comma delimited hex values returns the number of values parsed deprecated - use field arrays instead
Definition at line 834 of file command-parser.c.
References command::com, get_arg_size(), and command::index.
const byte * get_arg_new | ( | const struct command * | com, |
int | index | ||
) |
given an argument by index[0..n], will returns a pointer to it. This will include the fieldnumber and fieldtype the argument may contain NUL bytes - use get_arg_size() to determine its length
Definition at line 671 of file command-parser.c.
int get_arg_size | ( | const struct command * | com, |
int | index | ||
) |
given an argument by index [0..n], will returns the size of the value in bytes. for a string/array it is the size of the array. for a uint8_t it is 1 and for uint16_t it is 2...
Definition at line 714 of file command-parser.c.
References command::com, and command::index.
Referenced by get_arg_int_array(), and received_radio_set_config().
int get_arg_size_inmem | ( | const struct command * | com, |
int | index | ||
) |
given an argument by index [0..n], will returns the number in bytes this argument takes up in memory. for a string/array it is the fieldnum(1 byte) + fieldtype(1 byte) + arraylen(1 byte) + size of the array + nul-terminator(1byte) for a uint8_t it is 3 (fieldnum+fieldtype+1bytevalue) for a uint16_t it is 4 (fieldnum+fieldtype+2bytevalue)
Definition at line 700 of file command-parser.c.
void get_config_flags | ( | struct command * | com | ) |
get config flags
Definition at line 326 of file command-handler.c.
References alloc_command(), command::com, command_add_arg(), command::connid, deliver_command(), command::encoding, command::flags, command::index, and command::target.
allocates and initializes a packet to be send as "data" to the command typically you'd add some data to it and pass it to send_command(). after send_command() you'll need to free it
Definition at line 271 of file queue.c.
References alloc_command(), command::com, command_init(), command::connid, command::encoding, command::flags, command::index, command::sourcedev, and command::target.
Referenced by send_data().
byte get_hops_to_server | ( | ) |
how many hops to the server?
0=no route, 1 = direct connection, 2=one intermediary etc..
Definition at line 526 of file routing.c.
Referenced by routing_print_table().
struct mpm * get_mpm | ( | ) |
Definition at line 31 of file multiram.c.
long get_my_node_id | ( | ) |
get the id of my node
long | my node id |
Definition at line 238 of file command-handler.c.
int get_outbound_command_count_important | ( | ) |
struct sensorruntime * get_runtime | ( | int | idx | ) |
struct userapp_info * get_user_app | ( | ) |
Definition at line 194 of file user_app_exe.c.
void getcloudtoken | ( | struct command * | com | ) |
get the opaque cloud token
Definition at line 388 of file command-handler.c.
References alloc_command(), command::com, command_add_arg(), command::connid, deliver_command(), command::encoding, command::flags, command::index, and command::target.
void getpubkey | ( | struct command * | com | ) |
request the public key of this module
Definition at line 417 of file command-handler.c.
References command::com, and send_command_reply().
byte got_new_packet | ( | struct command * | com, |
uint8_t | signal_indicator | ||
) |
stack received a new packet (signal indicator is a 0-255 byte value, interface specific)
return: 0==packet was discarded 1==packet was forwarded 2==packet was bridged 3==packet was processed locally (via process_command())
void init_command_handler | ( | ) |
resets the command handler
this must be called at least once when the firmware boots.
Definition at line 78 of file command-handler.c.
void init_powersavething | ( | struct powersavething * | pst | ) |
Definition at line 252 of file powersave.c.
int internal_ti1101_init | ( | struct network_context * | onctx | ) |
int invoke_on_command_received | ( | struct command * | com | ) |
Definition at line 325 of file user_app_exe.c.
void invoke_on_new_node | ( | struct hostroute * | host | ) |
Definition at line 332 of file user_app_exe.c.
void invoke_start | ( | int | MCULIBHANDLE | ) |
Definition at line 302 of file user_app_exe.c.
void invoke_stop | ( | ) |
Definition at line 313 of file user_app_exe.c.
void invoke_user_loop | ( | ) |
Definition at line 338 of file user_app_exe.c.
void iplog | ( | const char * | format, |
... | |||
) |
int is_command_valid | ( | struct command * | com | ) |
Definition at line 857 of file command-parser.c.
int is_device_online | ( | int | device | ) |
int is_last_ip_valid | ( | ) |
int is_packet_for_us | ( | struct command * | com | ) |
check if a command needs to be routed
we deal with all the stuff for the packet from here, unless it is a packet we should process. we return 1 if (and only if) the packet needs processing locally
Definition at line 120 of file command-handler.c.
Referenced by process_command().
int is_stack | ( | void * | adr | ) |
Definition at line 56 of file multiram.c.
void led_blink | ( | LED_USAGE_TYPE | lut, |
uint32_t | colour, | ||
uint8_t | brightness, | ||
uint32_t | on, | ||
uint32_t | off | ||
) |
void led_blink_flags | ( | LED_USAGE_TYPE | lut, |
uint32_t | colour, | ||
uint8_t | brightness, | ||
uint32_t | on, | ||
uint32_t | off, | ||
uint32_t | flags | ||
) |
void led_flash | ( | LED_USAGE_TYPE | lut, |
uint32_t | colour, | ||
uint32_t | duration | ||
) |
void list_modules | ( | struct command * | com | ) |
we received a list-modules command
Definition at line 452 of file command-handler.c.
References alloc_command(), command::com, command_add_arg(), command_init(), command::connid, command::encoding, command::flags, free_command(), hostroute::host, command::index, routing_count_nodes(), routing_get_node_by_index(), send_command(), send_command_reply(), command::sender, command::sourcedev, and command::target.
void logging_event_loop | ( | ) |
void logging_init | ( | ) |
void logging_off | ( | ) |
void logging_on | ( | ) |
void logging_set_node | ( | long | nodeid | ) |
void mark_last_in_use | ( | struct powersavething * | pst | ) |
Definition at line 256 of file powersave.c.
void micro_strobe | ( | struct command * | com | ) |
void mpm_free | ( | void * | mem | ) |
unreserve bytes
Definition at line 48 of file multiram.c.
void * mpm_reserve | ( | int | bytes | ) |
we reserve bytes from the command buffer (or other dynamic places) free it with mpm_free! (not yet implemented)
Definition at line 38 of file multiram.c.
void multi_mem_init | ( | ) |
called very early on, even before printf works
Definition at line 26 of file multiram.c.
const char * namedarg | ( | struct command * | com, |
const char * | name | ||
) |
get a named arg (key-value pair) or NULL
Definition at line 787 of file command-parser.c.
References command::com, and get_arg().
Referenced by namedarg_uint16(), and namedarg_uint32().
int namedarg_uint16 | ( | struct command * | com, |
const char * | name, | ||
uint16_t * | value | ||
) |
get a named arg (key-value pair), parsed as integer. result in "value". if return value == 0 , it was parsed, otherwise error code
Definition at line 816 of file command-parser.c.
References command::com, and namedarg().
int namedarg_uint32 | ( | struct command * | com, |
const char * | name, | ||
uint32_t * | value | ||
) |
get a named arg (key-value pair), parsed as integer. result in "value". if return value == 0 , it was parsed, otherwise error code
Definition at line 801 of file command-parser.c.
References command::com, and namedarg().
void node_to_str | ( | long | l, |
char * | buf | ||
) |
Definition at line 67 of file addressing.c.
int on_command_received | ( | struct command * | com | ) |
this is called for each command we receive
this is called as soon as a command is received that is destined for us (meaning: it is not called on routed packets). When this is called the packet is not yet ACK'ed to the sender.
int | 0 continue "normal" processing of command |
int | 1 ack the receipt of the command |
int | 2 nack the receipt of the command |
Definition at line 53 of file userhooks.c.
void on_new_node | ( | struct hostroute * | host | ) |
called when and if a new node is detected. this may be used, to, for example to activate when a route to the cloud becomes available
Definition at line 61 of file userhooks.c.
void packet_buf_init | ( | const int | num | ) |
initialize (reset, clear) a given buffer
the | number of the buffer (e.g. PACKETBUFFER_CC1101) |
none |
Definition at line 37 of file packetbuffer.c.
Referenced by packet_init().
byte * packet_getbuf | ( | const int | num | ) |
get pointer to the contents of the buffer
the | number of the buffer (e.g. PACKETBUFFER_ESP8266) |
byte* | get pointer to the buffer of bytes (all bytes, not just payload)!) |
Definition at line 143 of file packetbuffer.c.
int packet_getbytesinbuf | ( | const int | num | ) |
count bytes in the buffer
the | number of the buffer (e.g. PACKETBUFFER_ESP8266) |
int | return the number of bytes in the packet |
Definition at line 158 of file packetbuffer.c.
void packet_init | ( | ) |
initialize (reset, clear) all buffers
none |
none |
Definition at line 52 of file packetbuffer.c.
References packet_buf_init().
int packet_isvalid | ( | const int | num | ) |
initialize (reset, clear) a given buffer
the | number of the buffer (e.g. PACKETBUFFER_ESP8266) |
none |
returns 1 if there's a valid packet
Definition at line 125 of file packetbuffer.c.
void packet_mark_valid | ( | const int | num | ) |
mark this buffer as containing a valid packet
the | number of the buffer (e.g. PACKETBUFFER_ESP8266) |
none |
Definition at line 108 of file packetbuffer.c.
int packet_put_byte | ( | const int | num, |
const byte | b | ||
) |
add a byte to a buffer
num | the number of the buffer (e.g. PACKETBUFFER_ESP8266) |
b | the byte to add |
the | new length of buffer (or <0 on error) |
add a byte to the buffer returns NEW length of buf or <0 on error (e.g. overflow)
Definition at line 78 of file packetbuffer.c.
void pin_pwm | ( | MCULIB_HANDLE | handle, |
int | pin, | ||
uint32_t | state, | ||
int | flags | ||
) |
void power_main_loop | ( | ) |
Definition at line 107 of file powersave.c.
int power_set_connectivity | ( | struct power_state * | ps, |
int | turnon | ||
) |
Definition at line 44 of file powersave.c.
void power_set_speed | ( | int | speed | ) |
Definition at line 225 of file powersave.c.
void pretty_node_to_str | ( | long | l, |
char * | buf | ||
) |
Definition at line 71 of file addressing.c.
void print_boot_info | ( | ) |
print startup information
Definition at line 37 of file boot_info.c.
void print_node_id | ( | long | l | ) |
Definition at line 90 of file addressing.c.
void print_pkt_state_update | ( | int | subsystem, |
int | code, | ||
uint8_t | d1, | ||
uint8_t | d2 | ||
) |
print an esp8266 update packet in human readable format
Definition at line 1193 of file esp8266.c.
References esp_cloud_state_update().
void print_stream_info | ( | ) |
void process_command | ( | struct command * | com | ) |
command is parsed, now execute it
we call the router to update it (since we received a packet we might have just learned of the existence of another cat) then we branch out into any user supplied functions
Definition at line 808 of file command-handler.c.
References command::argctr, command::com, command_print(), command::flags, get_arg(), command::index, is_packet_for_us(), process_queue_reply(), and routing_request_reply().
void process_command_queue | ( | ) |
int process_queue_reply | ( | struct command * | ack | ) |
process a reply
there is an internal mechanism used by send_reply & friends: if the command in the queue already has the ACK flag set, then it will be sent out and freed but no further notification and/or processing will take place.
Definition at line 326 of file queue.c.
Referenced by process_command().
void process_strobe_command | ( | struct command * | com | ) |
Definition at line 791 of file command-handler.c.
int query_onewire | ( | struct onewire_hwdef * | hw, |
byte * | error | ||
) |
int received_radio_get_config | ( | struct command * | com | ) |
called when we received radio_get_config command sends back an answer with the current radio config
Definition at line 860 of file ti1101.c.
References alloc_command(), command::com, command_add_binary_arg(), command_init(), command::connid, command::flags, and command::target.
int received_radio_set_config | ( | struct command * | com | ) |
called when we received radio_set_config command modified the current radio config
Definition at line 905 of file ti1101.c.
References command::com, get_arg(), and get_arg_size().
void remove_stale_routes | ( | ) |
void request_route | ( | long | host | ) |
send an arp request (equivalent)
Definition at line 776 of file queue.c.
References alloc_command(), command::com, command_add_arg(), free_command(), and send_command().
int routing_count_nodes | ( | ) |
determine number of nodes known
int | number of nodes known to us excluding ourselves |
Definition at line 203 of file routing.c.
Referenced by list_modules().
void routing_error | ( | struct command * | com, |
int | errorcode | ||
) |
struct hostroute * routing_find_empty_slot | ( | ) |
finds an empty slot in our routing entry list
Definition at line 239 of file routing.c.
Referenced by routing_request_reply().
struct hostroute * routing_find_host | ( | const long | nodeid | ) |
struct hostroute * routing_find_route | ( | const long | nodeid, |
const byte | sourcedev | ||
) |
find specific hostroute to target or NULL if none known special case, if we ask for a route to server, we get any intermediary routes which announce themselves to have a connection a server
Definition at line 286 of file routing.c.
Referenced by routing_request_reply().
struct hostroute * routing_get_node_by_index | ( | const int | index | ) |
finds a nodeid by index. [0...n]
hoststructure | of this node. NULL if none at this index |
Definition at line 219 of file routing.c.
Referenced by list_modules().
void routing_init | ( | ) |
void routing_print_table | ( | ) |
print routing table
Definition at line 539 of file routing.c.
References get_hops_to_server(), and hostroute::host.
void routing_request_reply | ( | const struct command * | com | ) |
we call this when we receive a reply to a routing request this adds or updates a new route
Definition at line 359 of file routing.c.
References command::argctr, get_arg(), hostroute::host, routing_find_empty_slot(), routing_find_route(), command::sender, and command::sourcedev.
Referenced by process_command().
void sc_fancy_allocator_init | ( | ) |
Definition at line 78 of file multiram.c.
void sc_free | ( | void * | ptr | ) |
Definition at line 85 of file multiram.c.
void * sc_realloc | ( | void * | ptr, |
size_t | size | ||
) |
Definition at line 81 of file multiram.c.
int send_command | ( | struct command * | com | ) |
send a command to another module (or broadcast)
this is synchronous and a one-shot attempt return: 0 ok, >0 on permanent errors, <0 on temporary errors
Definition at line 374 of file queue.c.
Referenced by list_modules(), request_route(), and send_data().
int send_command_fw_info | ( | struct command * | com, |
int | err | ||
) |
send a reply to a command
Definition at line 533 of file queue.c.
References alloc_command(), command::com, command_init(), command::connid, deliver_command(), command::encoding, command::flags, command::index, command::sourcedev, and command::target.
int send_command_one_arg | ( | int | command, |
long | target, | ||
const byte * | arg1, | ||
int | arg1len | ||
) |
helper function to quickly and easily send a command somewhere return 0 if ok, else errorcode
Definition at line 567 of file routing.c.
References alloc_command(), command::com, command_add_binary_arg(), deliver_command(), and command::target.
int send_command_reply | ( | struct command * | com, |
byte | flags | ||
) |
send a reply to a command
Definition at line 562 of file queue.c.
References alloc_command(), command::com, command_init(), command::connid, deliver_command(), command::encoding, command::flags, command::index, command::sourcedev, and command::target.
Referenced by getpubkey(), list_modules(), set_config_flag(), and setcloudtoken().
int send_command_reply_with_args | ( | struct command * | com, |
byte | flags, | ||
const char * | format, | ||
... | |||
) |
send a reply to a command
Definition at line 588 of file queue.c.
References alloc_command(), command::com, command_add_varg(), command_init(), command::connid, deliver_command(), command::encoding, command::flags, command::index, command::sourcedev, and command::target.
int send_data | ( | struct command * | com, |
const char * | format, | ||
... | |||
) |
send the format string as data in response to command "com"
return 0 if ok, otherwise error code
Definition at line 294 of file queue.c.
References command::com, command_add_varg(), free_command(), get_data_reply(), and send_command().
int send_user_app_status | ( | ) |
Definition at line 355 of file user_app_exe.c.
void sensor_activation | ( | struct sensorruntime * | sr, |
int | activation | ||
) |
void sensor_com_config | ( | struct command * | com | ) |
Definition at line 70 of file sensor_command.c.
void sensor_com_list | ( | struct command * | com | ) |
Definition at line 24 of file sensor_command.c.
int sensor_loop | ( | ) |
register a sensor, e.g. from userhook. The sensordev struct is COPIED, so it may be reused by the caller. the RETURN value is a pointer to the new sensordev, or NULL
register a new sensor. returns 0 if ok
Definition at line 644 of file sensor.c.
References sensors, sensors_init(), and sensors_off().
int sensor_submit_request | ( | const long | nodeid, |
int | idx, | ||
const int | readmillis, | ||
const int | submitsec, | ||
const int | max_values | ||
) |
int sensor_update_config | ( | const long | nodeid, |
int | idx, | ||
const int | readmillis, | ||
const int | submitsec, | ||
const int | max_values | ||
) |
void sensors_init | ( | ) |
initialize sensors, runtime, config, powerup each sensor in turn etc..
Definition at line 382 of file sensor.c.
Referenced by sensor_register().
void sensors_newstyle | ( | ) |
void sensors_off | ( | ) |
void set_config_flag | ( | struct command * | com | ) |
set a single config flag
Definition at line 310 of file command-handler.c.
References command::argctr, get_arg(), and send_command_reply().
void set_forward_debug | ( | byte | b | ) |
Definition at line 23 of file forwarding.c.
void set_in_app | ( | uint8_t | a | ) |
Definition at line 145 of file user_app_exe.c.
void set_logging | ( | struct command * | com | ) |
Definition at line 159 of file command-handler.c.
int set_mcu_power_mode | ( | int | state | ) |
Definition at line 73 of file powersave.c.
void setcloudtoken | ( | struct command * | com | ) |
set a token to connect to the cloud
Definition at line 254 of file command-handler.c.
References command::argctr, esp8266_send_instructions(), get_arg(), and send_command_reply().
void setdac | ( | struct command * | com | ) |
Definition at line 425 of file command-handler.c.
void setpin | ( | struct command * | com | ) |
Definition at line 81 of file command-handler.c.
int start | ( | int | mculib_handle, |
struct sc_firmware_api * | uapi | ||
) |
this is called when the board powers up
all the initialisation of peripherals has been completed. a return code other than 0 is considered an error, userapp failed and no further code is called.
Definition at line 31 of file userhooks.c.
void start_strobe | ( | int | relay, |
int | ton, | ||
int | toff, | ||
int | repeat | ||
) |
Definition at line 719 of file command-handler.c.
void stop | ( | ) |
Definition at line 39 of file userhooks.c.
int stream_associate | ( | int | fd, |
const struct consumerinfo * | ci, | ||
byte * | buf, | ||
int | bufsize, | ||
int | packetsize | ||
) |
void stream_enable | ( | ) |
void stream_loop | ( | ) |
void stream_seterror | ( | int | streamfd, |
const char * | format, | ||
... | |||
) |
void streamdata | ( | struct command * | com | ) |
called when we receive a stream data packet TODO: this is a really simplistic, memory-consumption optimized algorithm. it currently discards packets which are out-of-order and keeps requesting the next packet in order. Possible optimisations:
void streamsetup | ( | struct command * | com | ) |
int ti1101_compare_config | ( | ) |
int ti1101_cssns | ( | ) |
Definition at line 9 of file ti1101-pinconfig.c.
void ti1101_disable_irq | ( | struct network_context * | ctx | ) |
void ti1101_forward_radio | ( | long | node | ) |
byte ti1101_get_last_irq_error | ( | ) |
int ti1101_irqpin | ( | ) |
Definition at line 15 of file ti1101-pinconfig.c.
int ti1101_lock | ( | ) |
int ti1101_loop | ( | struct network_context * | ctx | ) |
int ti1101_off | ( | ) |
diable processing of ti1101 commands
the radio remains fully operational but any IRQs for in/outbound data are effectively a noop this can (and is) used to temporarily and quickly disable the radio without the need to reinitialise the peripheral when re-enabling it return: 1 if it was enabled previously, 0 if it was not
void ti1101_on | ( | ) |
int ti1101_spiport | ( | ) |
Definition at line 12 of file ti1101-pinconfig.c.
int ti1101_transmit | ( | struct network_context * | nctx, |
const byte * | data, | ||
uint16_t | num_bytes | ||
) |
int update_all_runtimes | ( | ) |
int user_app_checksum_valid | ( | ) |
Definition at line 237 of file user_app_exe.c.
void user_app_control | ( | struct command * | com | ) |
Definition at line 417 of file user_app_exe.c.
void user_app_disable | ( | ) |
Definition at line 224 of file user_app_exe.c.
void user_app_enable | ( | ) |
Definition at line 208 of file user_app_exe.c.
void user_app_exe_init | ( | ) |
Definition at line 150 of file user_app_exe.c.
int user_app_executable | ( | ) |
Definition at line 282 of file user_app_exe.c.
int user_app_info | ( | struct command * | com | ) |
Definition at line 382 of file user_app_exe.c.
int user_app_is_enabled | ( | ) |
Definition at line 198 of file user_app_exe.c.
int user_app_is_valid | ( | ) |
Definition at line 265 of file user_app_exe.c.
void user_app_reset_state | ( | ) |
Definition at line 344 of file user_app_exe.c.
void user_loop | ( | ) |
this is called frequently, but with no timing guarantees. essentially, it's called in the "idle-loop" of the mcu
Definition at line 67 of file userhooks.c.
int user_serial_callback | ( | int | portnum, |
int | byte | ||
) |
Definition at line 551 of file user_app_exe.c.
int userapp_checksum_valid | ( | void * | baseadr | ) |
Definition at line 494 of file user_app_exe.c.
void wifi_info | ( | struct command * | com | ) |
get some information about our currentwifi connection
Definition at line 350 of file command-handler.c.
References alloc_command(), command_add_arg(), and esp8266_get_current_ip().
void wifi_send_data | ( | const PACKET_TYPE | type, |
const byte * | buf, | ||
const int | len | ||
) |
void wireless_callback_state_change | ( | int | newstate, |
int | oldstate | ||
) |
|
extern |
the ack_ctr for pings
byte buf[260] |
Definition at line 33 of file decode_esp_packet.c.
struct espbuf bufs[7] |
Definition at line 35 of file decode_esp_packet.c.
const char* const command_names[] |
Definition at line 41 of file command-parser.c.
struct ringbuffer console_ringbuffer |
struct ringbuffer esp_ringbuffer |
struct leddef extled = { .pins = { 7, 110, 111 }, .timers = { 2, 1, 1 } } |
const struct consumerinfo flashconsumerinfo = { &flash_app_consumer, &flash_app_close } |
Definition at line 23 of file flashapp.c.
long host |
the hosts nodeid this route refers to
Definition at line 21 of file routing.h.
Referenced by forward_packet(), list_modules(), routing_print_table(), and routing_request_reply().
uint8_t hosttype |
struct leddef intled = { .pins = { 106, 107, 108 }, .timers = { 3, 3, 3 } } |
struct ipv4address lastip |
long lastseen |
byte lora_on |
Definition at line 39 of file powersave.c.
int MCULIBHANDLE |
Definition at line 21 of file userhooks.c.
long nexthop |
int order |
Definition at line 31 of file decode_esp_packet.c.
struct cnw_packetbuf packetbuffer1 |
Definition at line 15 of file packetbuffer.c.
struct power_state prev_state |
Definition at line 42 of file powersave.c.
char rbuf[10] |
Definition at line 258 of file command-parser.c.
char sbuf[10] |
Definition at line 257 of file command-parser.c.
struct sensordev sensors[] |
list of sensors...
Definition at line 23 of file sensor.c.
Referenced by sensor_register().
int size |
Definition at line 32 of file decode_esp_packet.c.
const char* statetable[] |
struct stream streams[2] |
char tbuf[10] |
Definition at line 259 of file command-parser.c.
byte ti1101_on |
Definition at line 38 of file powersave.c.
void* UMM_MALLOC_CFG_HEAP_ADDR |
Definition at line 75 of file multiram.c.
uint32_t UMM_MALLOC_CFG_HEAP_SIZE |
Definition at line 76 of file multiram.c.
|
extern |
Definition at line 12 of file userapp_vector.c.
byte wifi_on |
Definition at line 37 of file powersave.c.