/* * Function change_switch * ---------------------- * get contact status, tos command 'C9' * * return: contact status * */ int get_contact_status(int contact_id) { Serial_Message msg; char input_buf[4]; char contact_buf[5]; char *buf_ptr = contact_buf; *buf_ptr = 'C'; buf_ptr++; /* Give more space if contact_id is bigger than 1 */ if (contact_id > 9) { k_memcpy(buf_ptr, int_to_string[contact_id], 2); buf_ptr += 2; } else { k_memcpy(buf_ptr, int_to_string[contact_id], 1); buf_ptr += 1; } *(buf_ptr) = '\015'; buf_ptr++; *(buf_ptr) = '\0'; msg.output_buffer = contact_buf; msg.input_buffer = input_buf; msg.len_input_buffer = sizeof(input_buf); clear_buf(); send(serial_port, &msg); cmd_sleep(); /* int i = 0; kprintf("Got Message:"); for (i = 0; i < 6; i++) { kprintf("%x ", input_buf[i]); } kprintf("\n");*/ return input_buf[1] - '0'; }
void * k_pool_replace(MemPool_t *pool, ptr_t block, size_t bytes) { struct BlockHeader_t *pHeader = (struct BlockHeader_t *) block - 1; const byte newListNum = get_next_power_of_two(bytes + sizeof(struct BlockHeader_t)); if (pHeader->listNum != newListNum) { size_t oldSize = 1U << pHeader->listNum; void *newp = k_pool_select(pool, bytes); if (bytes <= oldSize) k_memcpy(newp, block, bytes); else k_memcpy(newp, block, oldSize); k_pool_release(pool, block); return newp; } else { return block; } }
static void scroll(WINDOW* wnd){ int i, base; for(i = 0; i< wnd->height; i++){ base = 0xb8000 + (wnd->x *2) + ((wnd->y + i)*160); k_memcpy(base, base + 160, wnd->width*2); } }
int test_memcpy_2() { char src[] = { 'a', 'b', 'c', 'd' }; char dst[] = { 'x', 'x', 'x', 'x' }; k_memcpy(dst, src, 0); if (dst[0] != 'x' || src[0] != 'a') return (1); return (TEST_OK); }
void train_test() { /* Check contact 2 should return 2 */ disable_keyboard(); Serial_Message msg; char input_buf[4]; char contact_buf[5]; char *buf_ptr = contact_buf; int contact_id = 2; *buf_ptr = 'C'; buf_ptr++; /* Give more space if contact_id is bigger than 1 */ if (contact_id > 9) { k_memcpy(buf_ptr, int_to_string[contact_id], 2); buf_ptr += 2; } else { k_memcpy(buf_ptr, int_to_string[contact_id], 1); buf_ptr += 1; } *(buf_ptr) = '\015'; buf_ptr++; *(buf_ptr) = '\0'; msg.output_buffer = contact_buf; msg.input_buffer = input_buf; msg.len_input_buffer = sizeof(input_buf); clear_buf(); kprintf("Send Message:"); send(serial_port, &msg); cmd_sleep(); int i = 0; kprintf("Got Message:"); for (i = 0; i < sizeof(input_buf); i++) { kprintf("%x ", input_buf[i]); } kprintf("\n"); kprintf("Result = %d, shoulde be 1", input_buf[1] - '0'); enable_keyboard(); }
int test_memcpy_1() { char src[] = { 'a', 'b', 'c', 'd' }; char dst[] = { 'x', 'x', 'x', 'x' }; k_memcpy(dst, src, 4); if (dst[0] != 'a' || dst[1] != 'b' || dst[2] != 'c' || dst[3] != 'd') return (1); if (src[0] != 'a' || src[1] != 'b' || src[2] != 'c' || src[3] != 'd') return (2); return (TEST_OK); }