Right click on your virtue machine -> setting-> hardware -> display and deselect the option "3D acceleration"
source
Monday, February 13, 2017
Thursday, July 30, 2015
Rangkaian Kiprok Sepeda Motor (Shunt Regulator)
Friday, January 3, 2014
Passing two dimensional array
#include
#include
foo(char in[][10]){
char *a = "Hello";
char *b = "Helle";
memcpy(in[0],a,strlen(a)+1);
memcpy(in[1],b,strlen(b)+1);
}
int main(int argc, char *argv[]){
char var[2][10];
foo(var);
printf("out: %s %s \n", var[0], var[1]);
return(0);
}
#include
foo(char in[][10]){
char *a = "Hello";
char *b = "Helle";
memcpy(in[0],a,strlen(a)+1);
memcpy(in[1],b,strlen(b)+1);
}
int main(int argc, char *argv[]){
char var[2][10];
foo(var);
printf("out: %s %s \n", var[0], var[1]);
return(0);
}
Thursday, November 28, 2013
NTP Client
Linux version
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h >
int main(void)
{
int sockfd = 0, n = 0, ii = 1;
char recvBuff[1024];
struct sockaddr_in serv_addr;
setvbuf(stdout, NULL, _IONBF, 0);
printf("Retrieving time, please wait ");
memset(recvBuff, '0',sizeof(recvBuff));
n=-1;
while(n<=0)
{
// printf("====== attempt %d \n\n", ii);
printf(".");
if (ii == 50)
{
printf("\n");
ii =0;
}
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
printf("\n Error : Could not create socket \n");
return 1;
}
serv_addr.sin_addr.s_addr = inet_addr("64.90.182.55");
// serv_addr.sin_addr.s_addr = inet_addr("96.47.67.105");
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(13);
if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
printf("\n Error : Connect Failed \n");
return 1;
}
n = read(sockfd, recvBuff, sizeof(recvBuff)-1);
close(sockfd);
usleep(10000);
ii++;
}
recvBuff[n] = 0;
printf("%s\n",recvBuff);
return 0;
}
Windows version
//============================================================================
// Name : windows_time_client.cpp
// Author : Norma Hermawan
// Version :
// Copyright : Your copyright notice
// Description : CONNECT TO REMOTE HOST (CLIENT APPLICATION)
// Include the needed header files.
// Don’t forget to link libws2_32.a to your program as well
// 2. To set the library
// Bring up the properties box for the project.
// Select all configurations.
// In the linker section on the left handside - select Input and in the right hand side add
// ws2_32.lib in the Additional Dependencies box
//============================================================================
#include "stdafx.h"
#include <winsock.h>
#include <iostream>
using namespace std;
#define TIMESERV_PORT 13
//#define TIMESERV_IP "96.47.67.105" // this is time server IP
#define TIMESERV_IP "64.90.182.55" // this is time server IP
//#define TIMESERV_IP "128.138.188.172" // this is time server IP
//#define TIMESERV_IP "211.233.40.78" // this is time server IP
//#define TIMESERV_IP "203.160.128.178" // this is time server IP
//#define TIMESERV_IP "113.20.31.30" // this is time server IP
int main() {
SOCKET sfd; //Socket handle
char buffer[80];
int n, ii =1;
time_t prev_stamp;
printf("Retrieving time, please wait ",ii);
do{
// system ("ping 64.90.182.55");
//Start up Winsock…
// printf("Starting winsock ============================= attempt %d\n\n",ii);
// printf("Retrieving time, attempt %d\n\n",ii);
printf(".");
if (ii==50){
printf("\n");
ii = 0;
}
WSADATA wsadata;
int error = WSAStartup(0x0202, &wsadata);
//Fill out the information needed to initialize a socket…
SOCKADDR_IN addr; //Socket address information
addr.sin_family = AF_INET; // address family Internet
addr.sin_port = htons (TIMESERV_PORT); //Port to connect on
addr.sin_addr.s_addr = inet_addr (TIMESERV_IP); //Target IP
// printf("Create socket\n");
sfd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); //Create socket
// printf("Establishing Connection \n");
int res = connect(sfd, (sockaddr*) &addr, sizeof(addr));
// printf("Connectition is established \n");
memset(buffer, 0, sizeof(buffer)); //Clear the buffer
// printf("Receiving signal \n\n");
prev_stamp = time(NULL);
//Put the incoming text into our buffer
n = recv (sfd, buffer, sizeof(buffer)-1, 0);//) <= 0) &&((time(NULL) - prev_stamp) < 5))
closesocket(sfd);
WSACleanup(); //Clean up Winsock
// Sleep(10);
ii++;
}
while(n<=0);
printf("\nTime: ", n);
buffer[n] = 0;
printf("%s\n",buffer);
system("Pause");
return 0;
}
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h >
int main(void)
{
int sockfd = 0, n = 0, ii = 1;
char recvBuff[1024];
struct sockaddr_in serv_addr;
setvbuf(stdout, NULL, _IONBF, 0);
printf("Retrieving time, please wait ");
memset(recvBuff, '0',sizeof(recvBuff));
n=-1;
while(n<=0)
{
// printf("====== attempt %d \n\n", ii);
printf(".");
if (ii == 50)
{
printf("\n");
ii =0;
}
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
printf("\n Error : Could not create socket \n");
return 1;
}
serv_addr.sin_addr.s_addr = inet_addr("64.90.182.55");
// serv_addr.sin_addr.s_addr = inet_addr("96.47.67.105");
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(13);
if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
printf("\n Error : Connect Failed \n");
return 1;
}
n = read(sockfd, recvBuff, sizeof(recvBuff)-1);
close(sockfd);
usleep(10000);
ii++;
}
recvBuff[n] = 0;
printf("%s\n",recvBuff);
return 0;
}
Windows version
//============================================================================
// Name : windows_time_client.cpp
// Author : Norma Hermawan
// Version :
// Copyright : Your copyright notice
// Description : CONNECT TO REMOTE HOST (CLIENT APPLICATION)
// Include the needed header files.
// Don’t forget to link libws2_32.a to your program as well
// 2. To set the library
// Bring up the properties box for the project.
// Select all configurations.
// In the linker section on the left handside - select Input and in the right hand side add
// ws2_32.lib in the Additional Dependencies box
//============================================================================
#include "stdafx.h"
#include <winsock.h>
#include <iostream>
using namespace std;
#define TIMESERV_PORT 13
//#define TIMESERV_IP "96.47.67.105" // this is time server IP
#define TIMESERV_IP "64.90.182.55" // this is time server IP
//#define TIMESERV_IP "128.138.188.172" // this is time server IP
//#define TIMESERV_IP "211.233.40.78" // this is time server IP
//#define TIMESERV_IP "203.160.128.178" // this is time server IP
//#define TIMESERV_IP "113.20.31.30" // this is time server IP
int main() {
SOCKET sfd; //Socket handle
char buffer[80];
int n, ii =1;
time_t prev_stamp;
printf("Retrieving time, please wait ",ii);
do{
// system ("ping 64.90.182.55");
//Start up Winsock…
// printf("Starting winsock ============================= attempt %d\n\n",ii);
// printf("Retrieving time, attempt %d\n\n",ii);
printf(".");
if (ii==50){
printf("\n");
ii = 0;
}
WSADATA wsadata;
int error = WSAStartup(0x0202, &wsadata);
//Fill out the information needed to initialize a socket…
SOCKADDR_IN addr; //Socket address information
addr.sin_family = AF_INET; // address family Internet
addr.sin_port = htons (TIMESERV_PORT); //Port to connect on
addr.sin_addr.s_addr = inet_addr (TIMESERV_IP); //Target IP
// printf("Create socket\n");
sfd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); //Create socket
// printf("Establishing Connection \n");
int res = connect(sfd, (sockaddr*) &addr, sizeof(addr));
// printf("Connectition is established \n");
memset(buffer, 0, sizeof(buffer)); //Clear the buffer
// printf("Receiving signal \n\n");
prev_stamp = time(NULL);
//Put the incoming text into our buffer
n = recv (sfd, buffer, sizeof(buffer)-1, 0);//) <= 0) &&((time(NULL) - prev_stamp) < 5))
closesocket(sfd);
WSACleanup(); //Clean up Winsock
// Sleep(10);
ii++;
}
while(n<=0);
printf("\nTime: ", n);
buffer[n] = 0;
printf("%s\n",buffer);
system("Pause");
return 0;
}
Tuesday, November 26, 2013
Time Slice Multitasking
This is a code example of time slice multitasking in C.
#include
#define KERNEL_SLEEP_US 1000
#define msleep(x) sleepc++; if(sleepc != x){return;}else{sleepc=0;}
int program_end = 0;
void task1(void) {
static int pc=0,sleepc=0;
switch (pc){
case 0: goto label0;
case 1: goto label1;
case 2: goto label2;
case 3: goto label3;
case 4: goto label4;
case 5: goto label5;
case 6: goto label6;
case 7: goto label7;
default: return;
} // task code section
// =========================================
label0: /* a task code -> */ while(1){
pc=1; return; label1: /* a task code -> */
pc=2; return; label2: /* a task code -> */
pc=3; return; label3: /* a task code -> */
pc=4; return; label4: /* a task code -> */
pc=5; return; label5: /* a task code -> */ printf("Hello from task 1\n");
pc=6; return; label6: /* a task code -> */ msleep(250); }
pc=7; return; label7: /* a task code -> */
pc=8; return; // ========================================
}
void task2(void) {
static int pc=0,sleepc=0,ii;
switch (pc){
case 0: goto label0;
case 1: goto label1;
case 2: goto label2;
case 3: goto label3;
case 4: goto label4;
case 5: goto label5;
case 6: goto label6;
case 7: goto label7;
default: return;
} // task code section
// =========================================
label0: /* a task code -> */ for(ii=0;ii<5 font="" ii="">5>
pc=1; return; label1: /* a task code -> */ printf("<<-- --="" 2="" d="" font="" ii="" n="" task="">-->
pc=2; return; label2: /* a task code -> */ msleep(1000); };
pc=3; return; label3: /* a task code -> */
pc=4; return; label4: /* a task code -> */ program_end = 1;
pc=5; return; label5: /* a task code -> */
pc=6; return; label6: /* a task code -> */
pc=7; return; label7: /* a task code -> */
pc=8; return; // =========================================
}
my_kernel(){
usleep(KERNEL_SLEEP_US); // sleep 100 ms
}
int main(void)
{
while(!program_end)
{
task1();
task2();
my_kernel();
}
return 0;
}
#include
#define KERNEL_SLEEP_US 1000
#define msleep(x) sleepc++; if(sleepc != x){return;}else{sleepc=0;}
int program_end = 0;
void task1(void) {
static int pc=0,sleepc=0;
switch (pc){
case 0: goto label0;
case 1: goto label1;
case 2: goto label2;
case 3: goto label3;
case 4: goto label4;
case 5: goto label5;
case 6: goto label6;
case 7: goto label7;
default: return;
} // task code section
// =========================================
label0: /* a task code -> */ while(1){
pc=1; return; label1: /* a task code -> */
pc=2; return; label2: /* a task code -> */
pc=3; return; label3: /* a task code -> */
pc=4; return; label4: /* a task code -> */
pc=5; return; label5: /* a task code -> */ printf("Hello from task 1\n");
pc=6; return; label6: /* a task code -> */ msleep(250); }
pc=7; return; label7: /* a task code -> */
pc=8; return; // ========================================
}
void task2(void) {
static int pc=0,sleepc=0,ii;
switch (pc){
case 0: goto label0;
case 1: goto label1;
case 2: goto label2;
case 3: goto label3;
case 4: goto label4;
case 5: goto label5;
case 6: goto label6;
case 7: goto label7;
default: return;
} // task code section
// =========================================
label0: /* a task code -> */ for(ii=0;ii<5 font="" ii="">5>
pc=1; return; label1: /* a task code -> */ printf("<<-- --="" 2="" d="" font="" ii="" n="" task="">-->
pc=2; return; label2: /* a task code -> */ msleep(1000); };
pc=3; return; label3: /* a task code -> */
pc=4; return; label4: /* a task code -> */ program_end = 1;
pc=5; return; label5: /* a task code -> */
pc=6; return; label6: /* a task code -> */
pc=7; return; label7: /* a task code -> */
pc=8; return; // =========================================
}
my_kernel(){
usleep(KERNEL_SLEEP_US); // sleep 100 ms
}
int main(void)
{
while(!program_end)
{
task1();
task2();
my_kernel();
}
return 0;
}
Tuesday, August 6, 2013
Mini Transistor Audio Amplifier
When I was childhood, I always curious about how electronic circuitry works. I remembered when I wanted to build a transistor audio amplifier, but didn't have any supporting knowledge. Internet hadn't come to my place at that time, not like today. Well, I need some time to build and test all those circuits. Even if I can design a much more complicated circuit than a simple audio amplifier today, but recalling the romance of the past is always exciting. Someday, when knowledge is no longer needed for my work, I will use it for myself fun.
Source:
link1
link2
link3
link4
link5
1. Class AB 4 Transistor Amplifier
2. Class A Headphone amplifier
3. Small audio amplifier circuit diagram
4. Power Amplifier OTL Cassette Radio Booster by TIP41+TIP42
5. Power Amplifier Class A by Transistor
6. Mic/Guitar Compressor with Transistor Bias Control
7. 50 mW 3 Transistors Amplifier
https://www.eleccircuit.com/4-transistor-audio-amplifier-circuit/
https://www.deeptronic.com/electronic-circuit-design/small-audio-power-amplifier-using-3-transistors/
http://www.bowdenshobbycircuits.info/page8.htm
Source:
link1
link2
link3
link4
link5
1. Class AB 4 Transistor Amplifier
2. Class A Headphone amplifier
3. Small audio amplifier circuit diagram
4. Power Amplifier OTL Cassette Radio Booster by TIP41+TIP42
5. Power Amplifier Class A by Transistor
6. Mic/Guitar Compressor with Transistor Bias Control
https://www.eleccircuit.com/4-transistor-audio-amplifier-circuit/
https://www.deeptronic.com/electronic-circuit-design/small-audio-power-amplifier-using-3-transistors/
http://www.bowdenshobbycircuits.info/page8.htm
Monday, July 29, 2013
Sudoku Solver
Sudoku is one of my favorite games. I used to play it a lot. One day, I meet a difficult sudoku problem that I can't solve easily, that simply perturb my mind. Rather than solving the problem, I prefer to make a solver code. I knew there are a lot of sudoku solver out there. But dude, that is the game. Creating a solver is the game itself, at least for me.
Then I did a little research. Wikipedia is always a good introductory. There are at least three methods to implement the solver:
1. Unique / Coloring / Possible Value
2. Booked Space
3. Back Track / Brute Force / Fill Empty Space
the last one is the most simple method for a practically infinite computation resource.
Ok. The solver is implemented and well tested. The screenshot shows a preview of mine.
Bellow is the C source code
link
Subscribe to:
Posts (Atom)








