// Lua: wifi.sta.config(ssid, password) static int wifi_station_config( lua_State* L ) { size_t sl, pl; struct station_config sta_conf; int i; const char *ssid = luaL_checklstring( L, 1, &sl ); if (sl>32 || ssid == NULL) return luaL_error( L, "ssid:<32" ); const char *password = luaL_checklstring( L, 2, &pl ); if (pl>64 || password == NULL) return luaL_error( L, "pwd:<64" ); c_memset(sta_conf.ssid, 0, 32); c_memset(sta_conf.password, 0, 64); c_memset(sta_conf.bssid, 0, 6); c_memcpy(sta_conf.ssid, ssid, sl); c_memcpy(sta_conf.password, password, pl); sta_conf.bssid_set = 0; NODE_DBG(sta_conf.ssid); NODE_DBG(" %d\n", sl); NODE_DBG(sta_conf.password); NODE_DBG(" %d\n", pl); wifi_station_set_config(&sta_conf); wifi_station_set_auto_connect(true); wifi_station_disconnect(); wifi_station_connect(); // station_check_connect(0); return 0; }
txString fxMergePath(txString base, txString name, txString path) { txSize baseLength, nameLength; txString separator = strrchr(base, mxSeparator); if (separator) { separator++; baseLength = separator - base; } else baseLength = 0; nameLength = c_strlen(name); if (baseLength) c_memcpy(path, base, baseLength); #if mxWindows { char c ; separator = path + baseLength; while ((c = *name)) { if (c == '/') *separator++ = mxSeparator; else *separator++ = c; name++; } *separator = 0; } #else c_memcpy(path + baseLength, name, nameLength + 1); #endif return path; }
/** * @brief Wifi ap scan over callback to display. * @param arg: contain the aps information * @param status: scan over status * @retval None */ static void wifi_scan_done(void *arg, STATUS status) { uint8 ssid[33]; char temp[128]; if(wifi_scan_succeed == LUA_NOREF) return; if(arg == NULL) return; lua_rawgeti(gL, LUA_REGISTRYINDEX, wifi_scan_succeed); if (status == OK) { struct bss_info *bss_link = (struct bss_info *)arg; bss_link = bss_link->next.stqe_next;//ignore first lua_newtable( gL ); while (bss_link != NULL) { c_memset(ssid, 0, 33); if (c_strlen(bss_link->ssid) <= 32) { c_memcpy(ssid, bss_link->ssid, c_strlen(bss_link->ssid)); } else { c_memcpy(ssid, bss_link->ssid, 32); } if(getap_output_format==1) //use new format(BSSID : SSID, RSSI, Authmode, Channel) { c_sprintf(temp,"%s,%d,%d,%d", ssid, bss_link->rssi, bss_link->authmode, bss_link->channel); lua_pushstring(gL, temp); NODE_DBG(MACSTR" : %s\n",MAC2STR(bss_link->bssid) , temp); c_sprintf(temp,MACSTR, MAC2STR(bss_link->bssid)); lua_setfield( gL, -2, temp); } else//use old format(SSID : Authmode, RSSI, BSSID, Channel) { c_sprintf(temp,"%d,%d,"MACSTR",%d", bss_link->authmode, bss_link->rssi, MAC2STR(bss_link->bssid),bss_link->channel); lua_pushstring(gL, temp); lua_setfield( gL, -2, ssid ); NODE_DBG("%s : %s\n", ssid, temp); } bss_link = bss_link->next.stqe_next; } } else { lua_newtable( gL ); } lua_call(gL, 1, 0); if(wifi_scan_succeed != LUA_NOREF) { luaL_unref(gL, LUA_REGISTRYINDEX, wifi_scan_succeed); wifi_scan_succeed = LUA_NOREF; } }
// Lua: wifi.ap.config(table) static int wifi_ap_config( lua_State* L ) { struct softap_config config; size_t len; wifi_softap_get_config(&config); if (!lua_istable(L, 1)) return luaL_error( L, "wrong arg type" ); lua_getfield(L, 1, "ssid"); if (!lua_isnil(L, -1)){ /* found? */ if( lua_isstring(L, -1) ) // deal with the ssid string { const char *ssid = luaL_checklstring( L, -1, &len ); if(len>32) return luaL_error( L, "ssid:<32" ); c_memset(config.ssid, 0, 32); c_memcpy(config.ssid, ssid, len); config.ssid_len = len; config.ssid_hidden = 0; NODE_DBG(config.ssid); NODE_DBG("\n"); } else return luaL_error( L, "wrong arg type" ); } else return luaL_error( L, "wrong arg type" ); lua_getfield(L, 1, "pwd"); if (!lua_isnil(L, -1)){ /* found? */ if( lua_isstring(L, -1) ) // deal with the password string { const char *pwd = luaL_checklstring( L, -1, &len ); if(len>64) return luaL_error( L, "pwd:<64" ); c_memset(config.password, 0, 64); c_memcpy(config.password, pwd, len); config.authmode = AUTH_WPA_WPA2_PSK; NODE_DBG(config.password); NODE_DBG("\n"); } else return luaL_error( L, "wrong arg type" ); } else{ config.authmode = AUTH_OPEN; } config.max_connection = 4; wifi_softap_set_config(&config); // system_restart(); return 0; }
txString fxConcatString(txMachine* the, txSlot* a, txSlot* b) { txSize aSize = c_strlen(a->value.string); txSize bSize = c_strlen(b->value.string); txString result = (txString)fxNewChunk(the, aSize + bSize + 1); c_memcpy(result, a->value.string, aSize); c_memcpy(result + aSize, b->value.string, bSize + 1); a->value.string = result; a->kind = XS_STRING_KIND; return result; }
static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) { NODE_DBG("socket_dns_found is called.\n"); struct espconn *pesp_conn = arg; if(pesp_conn == NULL){ NODE_DBG("pesp_conn null.\n"); return; } lnet_userdata *nud = (lnet_userdata *)pesp_conn->reverse; if(nud == NULL) return; if(gL == NULL) return; if(ipaddr == NULL) { dns_reconn_count++; if( dns_reconn_count >= 5 ){ NODE_ERR( "DNS Fail!\n" ); lua_gc(gL, LUA_GCSTOP, 0); if(nud->self_ref != LUA_NOREF){ luaL_unref(gL, LUA_REGISTRYINDEX, nud->self_ref); nud->self_ref = LUA_NOREF; // unref this, and the net.socket userdata will delete it self } lua_gc(gL, LUA_GCRESTART, 0); return; } NODE_ERR( "DNS retry %d!\n", dns_reconn_count ); host_ip.addr = 0; espconn_gethostbyname(pesp_conn, name, &host_ip, socket_dns_found); return; } // ipaddr->addr is a uint32_t ip if(ipaddr->addr != 0) { dns_reconn_count = 0; if( pesp_conn->type == ESPCONN_TCP ) { c_memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4); NODE_DBG("TCP ip is set: "); NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr))); NODE_DBG("\n"); } else if (pesp_conn->type == ESPCONN_UDP) { c_memcpy(pesp_conn->proto.udp->remote_ip, &(ipaddr->addr), 4); NODE_DBG("UDP ip is set: "); NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr))); NODE_DBG("\n"); } socket_connect(pesp_conn); } }
void fx_String_charAt(txMachine* the) { txString aString; txInteger aLength; txInteger anOffset; aString = fxCoerceToString(the, mxThis); if (!aString) mxDebug0(the, XS_TYPE_ERROR, "String.prototype.charAt: this is null or undefined"); aLength = fxUnicodeLength(aString); if ((mxArgc > 0) && (mxArgv(0)->kind != XS_UNDEFINED_KIND)) anOffset = fxToInteger(the, mxArgv(0)); else anOffset = -1; if ((0 <= anOffset) && (anOffset < aLength)) { anOffset = fxUnicodeToUTF8Offset(aString, anOffset); aLength = fxUnicodeToUTF8Offset(aString + anOffset, 1); if ((anOffset >= 0) && (aLength > 0)) { mxResult->value.string = (txString)fxNewChunk(the, aLength + 1); c_memcpy(mxResult->value.string, mxThis->value.string + anOffset, aLength); mxResult->value.string[aLength] = 0; mxResult->kind = XS_STRING_KIND; } else { mxResult->value.string = mxEmptyString.value.string; mxResult->kind = mxEmptyString.kind; } } else { mxResult->value.string = mxEmptyString.value.string; mxResult->kind = mxEmptyString.kind; } }
LUA_API lua_State *lua_newthread (lua_State *L) { global_State *g = G(L); lua_State *L1; lua_lock(L); luaC_checkGC(L); /* create new thread */ L1 = &cast(LX *, luaM_newobject(L, LUA_TTHREAD, sizeof(LX)))->l; L1->marked = luaC_white(g); L1->tt = LUA_TTHREAD; /* link it on list 'allgc' */ L1->next = g->allgc; g->allgc = obj2gco(L1); /* anchor it on L stack */ setthvalue(L, L->top, L1); api_incr_top(L); preinit_thread(L1, g); L1->hookmask = L->hookmask; L1->basehookcount = L->basehookcount; L1->hook = L->hook; resethookcount(L1); /* initialize L1 extra space */ c_memcpy(lua_getextraspace(L1), lua_getextraspace(g->mainthread), LUA_EXTRASPACE); luai_userstatethread(L, L1); stack_init(L1, L); /* init stack */ lua_unlock(L); return L1; }
static int gprs_readTimeStamp( lua_State* L ) { int timeout = luaL_checkinteger(L, 1)*1000000; uint8_t result = 3; char *ret; if( gprs_StartSocket(L) == 1 ) { result = 4; if( gprs_SendSocket(L,"GET") == 1 ) { //if( (ret = readCommand(NULL,"}\r\n","}\r\n","{\"time\":","}\r\n",L)) != NULL ) if( (ret = readCommand(NULL,"}\r\n","}\r\n","{","}\r\n",L)) != NULL ) { char saida[512]; memset(saida,0,512); c_memcpy(saida,ret,c_strlen(ret)); sendCommand((char*)CIPCLOSE, MSG_OK, MSG_NOK, strlen(CIPCLOSE), timeout/10); //lua_pushlstring(L,tm, 10); lua_pushlstring(L,saida, c_strlen(saida)); lua_pushinteger(L,0); return 2; }else result = 5; } } lua_pushinteger(L,result); return 1; }
// ws2812.writergb(4, string.char(255, 0, 0)) uses GPIO2 and sets the first LED red. // ws2812.writergb(3, string.char(0, 0, 255):rep(10)) uses GPIO0 and sets ten LEDs blue. // ws2812.writergb(4, string.char(0, 255, 0, 255, 255, 255)) first LED green, second LED white. static int ICACHE_FLASH_ATTR ws2812_writergb(lua_State* L) { const uint8_t pin = luaL_checkinteger(L, 1); size_t length; const char *rgb = luaL_checklstring(L, 2, &length); // dont modify lua-internal lstring - make a copy instead char *buffer = (char *)c_malloc(length); c_memcpy(buffer, rgb, length); // Ignore incomplete Byte triples at the end of buffer: length -= length % 3; // Rearrange R G B values to G R B order needed by WS2812 LEDs: size_t i; for (i = 0; i < length; i += 3) { const char r = buffer[i]; const char g = buffer[i + 1]; buffer[i] = g; buffer[i + 1] = r; } // Initialize the output pin platform_gpio_mode(pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT); platform_gpio_write(pin, 0); // Send the buffer os_intr_lock(); ws2812_write(pin, (uint8_t*) buffer, length); os_intr_unlock(); c_free(buffer); return 0; }
// initializes the cache void spiffs_cache_init(spiffs *fs) { if (fs->cache == 0) return; u32_t sz = fs->cache_size; u32_t cache_mask = 0; int i; int cache_entries = (sz - sizeof(spiffs_cache)) / (SPIFFS_CACHE_PAGE_SIZE(fs)); if (cache_entries <= 0) return; for (i = 0; i < cache_entries; i++) { cache_mask <<= 1; cache_mask |= 1; } spiffs_cache cache; c_memset(&cache, 0, sizeof(spiffs_cache)); cache.cpage_count = cache_entries; cache.cpages = (u8_t *)((u8_t *)fs->cache + sizeof(spiffs_cache)); cache.cpage_use_map = 0xffffffff; cache.cpage_use_mask = cache_mask; c_memcpy(fs->cache, &cache, sizeof(spiffs_cache)); spiffs_cache *c = spiffs_get_cache(fs); c_memset(c->cpages, 0, c->cpage_count * SPIFFS_CACHE_PAGE_SIZE(fs)); c->cpage_use_map &= ~(c->cpage_use_mask); for (i = 0; i < cache.cpage_count; i++) { spiffs_get_cache_page_hdr(fs, c, i)->ix = i; } }
mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topic, const char* data, int data_length, int qos, int retain, uint16_t* message_id) { init_message(connection); if(topic == NULL || topic[0] == '\0') return fail_message(connection); if(append_string(connection, topic, c_strlen(topic)) < 0) return fail_message(connection); if(qos > 0) { if((*message_id = append_message_id(connection, 0)) == 0) return fail_message(connection); } else *message_id = 0; if(connection->message.length + data_length > connection->buffer_length) return fail_message(connection); c_memcpy(connection->buffer + connection->message.length, data, data_length); connection->message.length += data_length; return fini_message(connection, MQTT_MSG_TYPE_PUBLISH, 0, qos, retain); }
txString fxNewLinkerString(txLinker* linker, txString buffer, txSize size) { txString result = fxNewLinkerChunk(linker, size + 1); c_memcpy(result, buffer, size); result[size] = 0; return result; }
void fxBufferSymbols(txLinker* linker, txInteger modulo) { if (modulo) { linker->symbolsBuffer = fxNewLinkerChunkClear(linker, 2); linker->symbolsSize = 2; } else { txByte* p; txS2 c, i; txSymbol** address; txInteger size; c = (txS2)(linker->symbolIndex); size = 2; address = &linker->symbolArray[0]; for (i = 0; i < c; i++) { size += (*address)->length; address++; } linker->symbolsBuffer = fxNewLinkerChunk(linker, size); linker->symbolsSize = size; p = linker->symbolsBuffer; mxEncode2(p, c); address = &(linker->symbolArray[0]); for (i = 0; i < c; i++) { c_memcpy(p, (*address)->string, (*address)->length); p += (*address)->length; address++; } } }
txString fxNewParserString(txParser* parser, txString buffer, txSize size) { txString result = fxNewParserChunk(parser, size + 1); c_memcpy(result, buffer, size); result[size] = 0; return result; }
txString fxConcatStringC(txMachine* the, txSlot* a, txString b) { txSize aSize = c_strlen(a->value.string); txSize bSize = c_strlen(b); txSize resultSize = aSize + bSize + 1; txString result = C_NULL; if (a->kind == XS_STRING_KIND) result = (txString)fxRenewChunk(the, a->value.string, resultSize); if (!result) { result = (txString)fxNewChunk(the, resultSize); c_memcpy(result, a->value.string, aSize); a->value.string = result; a->kind = XS_STRING_KIND; } c_memcpy(result + aSize, b, bSize + 1); return result; }
/** * @brief Wifi ap scan over callback to display. * @param arg: contain the aps information * @param status: scan over status * @retval None */ static void wifi_scan_done(void *arg, STATUS status) { uint8 ssid[33]; char temp[128]; if(wifi_scan_succeed == LUA_NOREF) return; if(arg == NULL) return; lua_rawgeti(gL, LUA_REGISTRYINDEX, wifi_scan_succeed); if (status == OK) { struct bss_info *bss_link = (struct bss_info *)arg; bss_link = bss_link->next.stqe_next;//ignore first lua_newtable( gL ); while (bss_link != NULL) { c_memset(ssid, 0, 33); if (c_strlen(bss_link->ssid) <= 32) { c_memcpy(ssid, bss_link->ssid, c_strlen(bss_link->ssid)); } else { c_memcpy(ssid, bss_link->ssid, 32); } c_sprintf(temp,"%d,%d,"MACSTR",%d", bss_link->authmode, bss_link->rssi, MAC2STR(bss_link->bssid),bss_link->channel); lua_pushstring(gL, temp); lua_setfield( gL, -2, ssid ); // NODE_DBG(temp); bss_link = bss_link->next.stqe_next; } } else { lua_pushnil(gL); } lua_call(gL, 1, 0); }
txString fxCopyStringC(txMachine* the, txSlot* a, txString b) { txSize bSize = c_strlen(b); txString result = (txString)fxNewChunk(the, bSize + 1); c_memcpy(result, b, bSize + 1); a->value.string = result; a->kind = XS_STRING_KIND; return result; }
txString fxAdornStringC(txMachine* the, txString prefix, txSlot* string, txString suffix) { txSize stringSize = c_strlen(string->value.string); txSize prefixSize = prefix ? c_strlen(prefix) : 0; txSize suffixSize = suffix ? c_strlen(suffix) : 0; txSize resultSize = stringSize + prefixSize + suffixSize + 1; txString result = (txString)fxNewChunk(the, resultSize); if (prefix && prefixSize) c_memcpy(result, prefix, prefixSize); if (stringSize) c_memcpy(result + prefixSize, string->value.string, stringSize); if (suffix && suffixSize) c_memcpy(result + prefixSize + stringSize, suffix, suffixSize); result[prefixSize + stringSize + suffixSize] = 0; string->kind = XS_STRING_KIND; string->value.string = result; return result; }
coap_status_t ICACHE_FLASH_ATTR handle_observe_request(lwm2m_context_t * contextP, lwm2m_uri_t * uriP, lwm2m_server_t * serverP, coap_packet_t * message, coap_packet_t * response) { lwm2m_observed_t * observedP; lwm2m_watcher_t * watcherP; LOG("handle_observe_request()\r\n"); if (!LWM2M_URI_IS_SET_INSTANCE(uriP) && LWM2M_URI_IS_SET_RESOURCE(uriP)) return COAP_400_BAD_REQUEST; if (message->token_len == 0) return COAP_400_BAD_REQUEST; observedP = prv_findObserved(contextP, uriP); if (observedP == NULL) { observedP = (lwm2m_observed_t *)lwm2m_malloc(sizeof(lwm2m_observed_t)); if (observedP == NULL) return COAP_500_INTERNAL_SERVER_ERROR; c_memset(observedP, 0, sizeof(lwm2m_observed_t)); c_memcpy(&(observedP->uri), uriP, sizeof(lwm2m_uri_t)); observedP->next = contextP->observedList; contextP->observedList = observedP; } watcherP = prv_findWatcher(observedP, serverP); if (watcherP == NULL) { watcherP = (lwm2m_watcher_t *)lwm2m_malloc(sizeof(lwm2m_watcher_t)); if (watcherP == NULL) return COAP_500_INTERNAL_SERVER_ERROR; c_memset(watcherP, 0, sizeof(lwm2m_watcher_t)); watcherP->server = serverP; watcherP->next = observedP->watcherList; observedP->watcherList = watcherP; } watcherP->tokenLen = message->token_len; c_memcpy(watcherP->token, message->token, message->token_len); coap_set_header_observe(response, watcherP->counter++); return COAP_205_CONTENT; }
void fxStringBuffer(txMachine* the, txSlot* theSlot, txString theValue, txSize theSize) { theSlot->value.string = (txString)fxNewChunk(the, theSize + 1); if (theValue) c_memcpy(theSlot->value.string, theValue, theSize); else theSlot->value.string[0] = 0; theSlot->value.string[theSize] = 0; theSlot->kind = XS_STRING_KIND; }
static void socket_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) { NODE_DBG("socket_dns_found is called.\n"); struct espconn *pesp_conn = arg; if(pesp_conn == NULL){ NODE_DBG("pesp_conn null.\n"); return; } if(ipaddr == NULL) { dns_reconn_count++; if( dns_reconn_count >= 5 ){ NODE_ERR( "DNS Fail!\n" ); return; } NODE_ERR( "DNS retry %d!\n", dns_reconn_count ); host_ip.addr = 0; espconn_gethostbyname(pesp_conn, name, &host_ip, socket_dns_found); return; } // ipaddr->addr is a uint32_t ip if(ipaddr->addr != 0) { dns_reconn_count = 0; if( pesp_conn->type == ESPCONN_TCP ) { c_memcpy(pesp_conn->proto.tcp->remote_ip, &(ipaddr->addr), 4); NODE_DBG("TCP ip is set: "); NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr))); NODE_DBG("\n"); } else if (pesp_conn->type == ESPCONN_UDP) { c_memcpy(pesp_conn->proto.udp->remote_ip, &(ipaddr->addr), 4); NODE_DBG("UDP ip is set: "); NODE_DBG(IPSTR, IP2STR(&(ipaddr->addr))); NODE_DBG("\n"); } socket_connect(pesp_conn); } }
static void ctr_setIV(crypt_mode_t *mode, const void *iv, size_t ivsize) { crypt_cipher_t *cipher = mode->cipher; size_t blksz = cipher->blockSize; c_memset(mode->em_buf, 0, sizeof(mode->em_buf)); if (ivsize > blksz) ivsize = blksz; c_memcpy(&mode->em_buf[blksz - ivsize], iv, ivsize); }
void process_then(xsMachine* the) { xsIntegerValue c = xsToInteger(xsArgc), i; process_then_parameters = malloc(sizeof(char *)*(c + 1)); for (i = 0; i < c; i++) { xsStringValue string = xsToString(xsArg(i)); xsIntegerValue length = strlen(string) + 1; process_then_parameters[i] = malloc(length); c_memcpy(process_then_parameters[i], string, length); } process_then_parameters[c] = NULL; }
static int append_string(mqtt_connection_t* connection, const char* string, int len) { if(connection->message.length + len + 2 > connection->buffer_length) return -1; connection->buffer[connection->message.length++] = len >> 8; connection->buffer[connection->message.length++] = len & 0xff; c_memcpy(connection->buffer + connection->message.length, string, len); connection->message.length += len; return len + 2; }
txString fxToStringBuffer(txMachine* the, txSlot* theSlot, txString theBuffer, txSize theSize) { char* aString; txSize aSize; aString = fxToString(the, theSlot); aSize = c_strlen(aString) + 1; if (aSize > theSize) mxRangeError("Cannot buffer string"); c_memcpy(theBuffer, aString, aSize); return theBuffer; }
int ICACHE_FLASH_ATTR lwm2m_observe(lwm2m_context_t * contextP, uint16_t clientID, lwm2m_uri_t * uriP, lwm2m_result_callback_t callback, void * userData) { lwm2m_client_t * clientP; lwm2m_transaction_t * transactionP; lwm2m_observation_t * observationP; uint8_t token[4]; if (!LWM2M_URI_IS_SET_INSTANCE(uriP) && LWM2M_URI_IS_SET_RESOURCE(uriP)) return COAP_400_BAD_REQUEST; clientP = (lwm2m_client_t *)lwm2m_list_find((lwm2m_list_t *)contextP->clientList, clientID); if (clientP == NULL) return COAP_404_NOT_FOUND; observationP = (lwm2m_observation_t *)lwm2m_malloc(sizeof(lwm2m_observation_t)); if (observationP == NULL) return COAP_500_INTERNAL_SERVER_ERROR; c_memset(observationP, 0, sizeof(lwm2m_observation_t)); observationP->id = lwm2m_list_newId((lwm2m_list_t *)clientP->observationList); c_memcpy(&observationP->uri, uriP, sizeof(lwm2m_uri_t)); observationP->clientP = clientP; observationP->status = STATE_REG_PENDING; observationP->callback = callback; observationP->userData = userData; token[0] = clientP->internalID >> 8; token[1] = clientP->internalID & 0xFF; token[2] = observationP->id >> 8; token[3] = observationP->id & 0xFF; transactionP = transaction_new(COAP_TYPE_CON, COAP_GET, clientP->altPath, uriP, contextP->nextMID++, 4, token, ENDPOINT_CLIENT, (void *)clientP); if (transactionP == NULL) { lwm2m_free(observationP); return COAP_500_INTERNAL_SERVER_ERROR; } observationP->clientP->observationList = (lwm2m_observation_t *)LWM2M_LIST_ADD(observationP->clientP->observationList, observationP); coap_set_header_observe(transactionP->message, 0); coap_set_header_token(transactionP->message, token, sizeof(token)); transactionP->callback = prv_obsRequestCallback; transactionP->userData = (void *)observationP; contextP->transactionList = (lwm2m_transaction_t *)LWM2M_LIST_ADD(contextP->transactionList, transactionP); return transaction_send(contextP, transactionP); }
void fxSerializeJSONChars(txMachine* the, txJSONSerializer* theSerializer, char* s) { txSize aSize = c_strlen(s); if ((theSerializer->offset + aSize) >= theSerializer->size) { char* aBuffer; theSerializer->size += ((aSize / 1024) + 1) * 1024; aBuffer = c_realloc(theSerializer->buffer, theSerializer->size); if (!theSerializer->buffer) fxSerializeJSONError(the, theSerializer, XS_RANGE_ERROR); theSerializer->buffer = aBuffer; } c_memcpy(theSerializer->buffer + theSerializer->offset, s, aSize); theSerializer->offset += aSize; }
void fxBufferPaths(txLinker* linker) { txByte* p; txLinkerScript* script; linker->pathsBuffer = fxNewLinkerChunk(linker, linker->pathsSize); p = linker->pathsBuffer; mxEncode2(p, linker->scriptCount); script = linker->firstScript; while (script) { c_memcpy(p, script->path, script->pathSize); p += script->pathSize; script = script->nextScript; } }
void fxSerializeJSONChars(txMachine* the, txJSONSerializer* theSerializer, char* s) { //fprintf(stderr, "%s", s); txSize aSize = c_strlen(s); if ((theSerializer->offset + aSize) >= theSerializer->size) { char* aBuffer; theSerializer->size += ((aSize / 1024) + 1) * 1024; aBuffer = c_realloc(theSerializer->buffer, theSerializer->size); if (!aBuffer) mxUnknownError("out of memory"); theSerializer->buffer = aBuffer; } c_memcpy(theSerializer->buffer + theSerializer->offset, s, aSize); theSerializer->offset += aSize; }