AT_CODEC_ERROR_CODE host_write(uint8_t *buffer, int32_t *len) { if( func_ptrs.write != NULL ) return func_ptrs.write( buffer, len ); if( atcodec_write != NULL ) { return VP_FAILED(atcodec_write(&at_socket, buffer, len)) ? AT_CODEC_WRITE_ERROR : AT_CODEC_WRITE_OK; } return AT_CODEC_WRITE_OK; }
DEFINE_THREAD_ROUTINE_STACK(ATcodec_Commands_Client,data,ATCODEC_STACK_SIZE) { AT_CODEC_ERROR_CODE res; int32_t v_loop; v_continue = 1; PRINT("Thread AT Commands Client Start\n"); while(!atcodec_lib_init_ok) { vp_os_thread_yield(); } while(v_continue) { // open and init if((res = func_ptrs.open()) != AT_CODEC_OPEN_OK) v_continue = 0; for ( v_loop = 1 ; v_loop ; ) { // vp_os_delay(ATCODEC_SERVER_YIELD_DELAY); vp_os_thread_yield(); // wait a successful ATcodec_Queue_... has been called vp_os_mutex_lock(&ATcodec_cond_mutex); //vp_os_cond_wait(&ATcodec_wait_cond); //ATCODEC_PRINT("Must send \"%s\"\n", &ATcodec_Message_Buffer[0]); if(ATcodec_Message_len && func_ptrs.write((int8_t*)&ATcodec_Message_Buffer[0], (int32_t*)&ATcodec_Message_len) != AT_CODEC_WRITE_OK) v_loop = 0; ATcodec_Message_len = 0; vp_os_mutex_unlock(&ATcodec_cond_mutex); } // close and un-init : user-defined if((res = func_ptrs.close()) != AT_CODEC_CLOSE_OK) v_continue = 0; } if((res = func_ptrs.shutdown()) != AT_CODEC_SHUTDOWN_OK) { ATCODEC_PRINT("ATcodec Shutdown error\n"); } return((THREAD_RET)0); }
ATCODEC_RET ATcodec_Send_Messages() { ATCODEC_RET res = ATCODEC_TRUE; if(!atcodec_lib_init_ok) return ATCODEC_FALSE; vp_os_mutex_lock(&ATcodec_cond_mutex); if(ATcodec_Message_len > INTERNAL_BUFFER_SIZE) printf("ATcodec_Send_Messages : buf=%s, len=%d\n", &ATcodec_Message_Buffer[0], ATcodec_Message_len); if(ATcodec_Message_len && func_ptrs.write((uint8_t*)&ATcodec_Message_Buffer[0], (int32_t*)&ATcodec_Message_len) != AT_CODEC_WRITE_OK) res = ATCODEC_FALSE; ATcodec_Message_len = 0; vp_os_mutex_unlock(&ATcodec_cond_mutex); return res; }
static ATCODEC_RET test_process_node(ATcodec_Tree_t *tree, ATcodec_Tree_Node_t *node, const char *cpy, ATcodec_Memory_t *memory, int *len_dec, int depth) { ATcodec_Tree_Node_t *son; AT_CODEC_Message_Received ptr; AT_CODEC_MSG_ID id = (AT_CODEC_MSG_ID)-1; char *fmt_str; int32_t output_len; char output_params[INTERNAL_BUFFER_SIZE]; uint8_t output_str[INTERNAL_BUFFER_SIZE]; ATcodec_Memory_t output, dest, fmt; if(test_dyn_strs(tree, node, depth, cpy, memory, &ptr, len_dec) == ATCODEC_TRUE) { ATcodec_Memory_Init(&output, &output_params[0], INTERNAL_BUFFER_SIZE, 1, NULL, NULL); VP_OS_ASSERT(ptr); ptr(memory, &output, &id); if((int)id != -1) { son = ATcodec_Tree_Node_get(tree, id); fmt_str = (char *)ATcodec_Buffer_getElement(&tree->strs, ((ATcodec_Message_Data_t *)ATcodec_Buffer_getElement(&tree->leaves, son->data))->total_str); ATcodec_Memory_Init(&dest, (char*)&output_str[0], INTERNAL_BUFFER_SIZE, 1, NULL, NULL); ATcodec_Memory_Init(&fmt, fmt_str, 0, 1, NULL, NULL); output.current = (char *)output.start; if(vp_atcodec_sprintf_params(&dest, &output_len, &fmt, &output) != ATCODEC_TRUE) return ATCODEC_FALSE; if(func_ptrs.write(&output_str[0], &output_len) != AT_CODEC_WRITE_OK) return ATCODEC_FALSE; } return ATCODEC_TRUE; } return ATCODEC_FALSE; }